This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Simple dictionary to object class. | |
""" | |
from collections import Mapping | |
try: | |
from pprintpp import pformat | |
except ImportError: | |
from pprint import pformat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def interpolate(x0, y0, x1, y1, x): | |
return (y0 * (x1 - x) + y1 * (x - x0)) / (x1 - x0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 && \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |