Skip to content

Instantly share code, notes, and snippets.

Carlos Jenkins carlos-jenkins

Block or report user

Report or block carlos-jenkins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@carlos-jenkins
carlos-jenkins / difftool.sh
Created Jul 19, 2019
Setup Meld for git difftool
View difftool.sh
sudo apt install meld
git config --global alias.difftree 'difftool --dir-diff'
git config --global diff.tool meld
git config --global difftool.prompt false
# Now use it:
# git difftree master..HEAD
# git difftree e49286eb1acbae69058856c744676c63d1154ba6..57adcd018d6e11c0982187cddfce6ee2bb641c6d
@carlos-jenkins
carlos-jenkins / base64.py
Created Jul 2, 2019
Calculate the length in bytes of a base64 string.
View base64.py
def b64len(b64str):
"""
Calculate the length in bytes of a base64 string.
This function could decode the base64 string to a binary blob and count its
number of bytes with len(). But, that's inefficient and requires more
memory that really needed.
Base64 encodes three bytes to four characters. Sometimes, padding is added
in the form of one or two '=' characters.
@carlos-jenkins
carlos-jenkins / async_poll.py
Created Jul 2, 2019
Just a generic polling function
View async_poll.py
from time import time
from asyncio import sleep
from .poll import NotReadyYet
async def poll(
func,
timeout_s=30.0, polling_s=5.0,
catchexcs=(NotReadyYet, ), pollcb=None,
@carlos-jenkins
carlos-jenkins / namespace.py
Last active Jun 6, 2019
Access dictionary using dot notation
View namespace.py
"""
Simple dictionary to object class.
"""
from collections import Mapping
try:
from pprintpp import pformat
except ImportError:
from pprint import pformat
@carlos-jenkins
carlos-jenkins / si.py
Created Jan 17, 2019
Auto-converter of arbitrary values to International System of Units (SI) human readable prefix.
View si.py
"""
Auto-converter of arbitrary values to International System of Units (SI) human
readable prefix.
Typical usage:
::
log.info(
'{0} packets for a total '
View sorters.py
def naturalsorted(iterable):
"""
Sort given iterable of strings using the "natural sorter" algorithm.
:param iterable: An iterable that yield strings.
:return: A list of elements in iterable naturally sorted.
:rtype: list
"""
from re import split
@carlos-jenkins
carlos-jenkins / compress.py
Created Sep 27, 2018
Compressing and Decompressing in Python 3
View compress.py
from zlib import compress, Z_BEST_COMPRESSION
# Compressing
def compress_ratio(original, compressed):
obytes = len(original)
cbytes = len(compressed)
return (obytes - cbytes) / obytes
original = b'Hello World'
@carlos-jenkins
carlos-jenkins / instructions.txt
Created Sep 27, 2018
After Windows 10 "Creators" update the fucker removes Grub and fucks your dual boot.
View instructions.txt
After Windows 10 "Creators" update the fucker removes Grub and fucks your dual boot.
To restore a Ubuntu 16.04 installation with the following characteristics:
- EFI mode.
- GPT partition table.
- One encrypted / partition.
- One /boot partition.
- One EFI partition.
- Dual boot with Windows 10.
View lovewins.py
def lovewins(text='LoveWins'):
def esc(*x):
return '\033[' + ';'.join(x) + 'm'
colors = [7, 1, 3, 63, 2, 4, 5, 7]
for byte in text.encode('ascii'):
print(''.join(
''.join([
View interpolate.py
def interpolate(x0, y0, x1, y1, x):
return (y0 * (x1 - x) + y1 * (x - x0)) / (x1 - x0)
You can’t perform that action at this time.