Skip to content

Instantly share code, notes, and snippets.

View carlos-jenkins's full-sized avatar

Carlos Jenkins carlos-jenkins

View GitHub Profile
@carlos-jenkins
carlos-jenkins / base64.py
Created July 2, 2019 06:39
Calculate the length in bytes of a base64 string.
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
Last active June 15, 2020 17:38
Just a generic polling function
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 June 6, 2019 21:43
Access dictionary using dot notation
"""
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.js
Last active September 23, 2019 21:30
Auto-converter of arbitrary values to International System of Units (SI) human readable prefix.
/*
* Auto-converter of arbitrary values to International System of Units (SI)
* human readable prefix.
*
* Typical usage:
*
* const txpackets = 2450
* const txbytes = txpackets * 256
* const txtime = 2.0
*
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 September 27, 2018 08:55
Compressing and Decompressing in Python 3
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 September 27, 2018 08:36
After Windows 10 "Creators" update the fucker removes Grub and fucks your dual boot.
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.
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([
def interpolate(x0, y0, x1, y1, x):
return (y0 * (x1 - x) + y1 * (x - x0)) / (x1 - x0)
@carlos-jenkins
carlos-jenkins / install.sh
Created October 3, 2017 22:54
Install recent libtins and libpcap
#!/usr/bin/env bash
apt-get update && apt-get install -y --no-install-recommends libssl-dev flex bison && \
echo "Downloading libpcap" && \
cd /tmp && curl http://www.tcpdump.org/release/libpcap-1.7.4.tar.gz -o libpcap.tar.gz && \
tar -xf libpcap.tar.gz && cd /tmp/libpcap* && \
echo "Building libpcap" && \
./configure && make && \
echo "Installing libpcap" && \
make install && \