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 / 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 && \
@carlos-jenkins
carlos-jenkins / print.py
Last active April 20, 2018 01:18
Python format cheatsheet (PEP 3101 and PEP 3105)
# Python PEP 3101 specifies the string formatting function that
# replaces the old % operator on strings. In addition, PEP 3105
# also specifies the behavior of the print(), now standard in
# Python 3. This small cheat-sheet offer an overview of both.
# In Python 2.7 use with:
# from __future__ import print_function
# Print to stderr
>>> from sys import stderr
@carlos-jenkins
carlos-jenkins / collab_constructors.py
Last active July 7, 2017 22:42
Collaborative constructors for multiple inheritance.
#!/usr/bin/env python3
"""
Collaborative constructors for multiple inheritance.
Python 3 only. If using Python 2.7, collaborative constructor are broken for
positional arguments.
Collaborative constructors allow classes to collaborate in the way constructor
arguments are passed between all classes in the inheritance tree.