Skip to content

Instantly share code, notes, and snippets.

View jrbenriquez's full-sized avatar

John Rei Enriquez jrbenriquez

View GitHub Profile
@jrbenriquez
jrbenriquez / chunks.py
Created January 4, 2023 03:16
Divide list to chunks
def divide_to_chunks(input_list, chunks_n):
for i in range(0, len(input_list), chunks_n):
yield input_list[i:i + chunks_n]
@jrbenriquez
jrbenriquez / gist:b555cc1b53e6ed39e91a6eeab8368fee
Created October 26, 2022 02:24
Replace string vim inside a directory
1. :cd {path to root directory}
==If looking to replace Sam==
2. :vimgrep /Sam/gj **/*
3. :cfdo %s/Sam/Bob/gc | update
Source: https://vi.stackexchange.com/questions/2776/vim-search-replace-all-files-in-current-project-folder
@jrbenriquez
jrbenriquez / dns.txt
Created April 21, 2022 22:48
Set DNS ubuntu via Network Manager
https://serverfault.com/questions/810636/how-to-manage-dns-in-networkmanager-via-console-nmcli
Here is the command to modify an existing connection.
nmcli con mod $connectionName ipv4.dns "8.8.8.8 8.8.4.4"
connectionName can be found by command: nmcli con. In the question case, it will be "System eth0"
If you want to ignore automatically configured nameservers and search domains, ie the settings passed from DHCP.
nmcli con mod $connectionName ipv4.ignore-auto-dns yes
Finally, to enable the changes, bring the connection down then up:
@jrbenriquez
jrbenriquez / user.py
Created April 20, 2022 14:52
Starting User Template for Django
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils import timezone
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from django.contrib.auth.models import PermissionsMixin
from phonenumber_field.modelfields import PhoneNumberField
from simple_email_confirmation.models import SimpleEmailConfirmationUserMixin
from core.constants import NAME_MAX_LENGTH
@jrbenriquez
jrbenriquez / mym1working.py
Created March 4, 2022 02:54
Always have problems installing stuff on M1 Mac. For now always stick to Rosetta and this command
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" GIT_SSH_COMMAND="ssh -i ~/.ssh/xxx -vvv" pip install -r requirements.txt
@jrbenriquez
jrbenriquez / premailer.py
Created November 20, 2020 12:46
[Premailer Reference] CK Editor Inline Styles
import re
PREMAIL_STYLE_LIST = [
'premail_ck_style_align_left',
'premail_ck_style_align_right',
'premail_ck_style_figcaption_image',
'premail_ck_style_img_image'
]
@jrbenriquez
jrbenriquez / patch fake bluetooh html
Created November 4, 2020 16:37
From https://unam.re/b/23/ Bluettoth Ubuntu Fix. Remove from Blacklist
<!DOCTYPE html>
<!-- saved from url=(0021)https://unam.re/b/23/ -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
unam.re | Fixing chinese Bluetooth dongle for Linux
</title>
<meta name="description" content="Hacking and random thoughts">
@jrbenriquez
jrbenriquez / Sort by last string
Last active July 29, 2020 09:34
Sort Ascending by last string
def sort_func(my_list):
# Iterate each item in list and swap positions if 1st item is greater than 2nd item
# If swapping happens set start_from_beginning to True para magulit uli from start na magcheck ng order
start_from_beginning = True
while start_from_beginning:
start_from_beginning = False
for i in range(0, len(my_list) - 1):
#1st iteration i.e my_list[i+1] = 'yes we goo'; my_list[i+1][-1] = 'o'
# my_list[i] = 'i am z' ; my_list[i+1][-1] = 'z'
# 'o' < 'z' = TRUE -> do SWAPPING
@jrbenriquez
jrbenriquez / longest_substring
Created July 29, 2020 04:30
[LeetCode] Longest Substring without repeating characters
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
ref_string = s
words = []
word = ''
for first_cursor in list(s):
for letter in ref_string:
if letter in word:
words.append(word)
word = ''
@jrbenriquez
jrbenriquez / Add_Two_Numbers_Linked_List
Created July 27, 2020 13:57
[LeetCode] Add Two Numbers Linked List.py
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:
# Add the values
# if values is more than 10 carry over
# if not continue adding the next nodes