Skip to content

Instantly share code, notes, and snippets.

View pablogsal's full-sized avatar

Pablo Galindo Salgado pablogsal

View GitHub Profile
@LeslieK
LeslieK / CPython33Dict
Last active November 25, 2015 17:07
Routines that examine the internals of a CPython dictionary for python 3.3 (modification of Brandon Rhodes' code _dictinfo.py) (See comment at bottom.)
"""Routines that examine the internals of a CPython dictionary using python 3.3."""
from ctypes import Structure, c_ulong, POINTER, cast, py_object, CFUNCTYPE, pointer, c_ssize_t, c_void_p
#from math import log
UMAX = 2 ** 32
def cbin(n):
"""Return `n` as a clean 32-bit binary number, without a leading '0b'."""
@mattiaslundberg
mattiaslundberg / arch-linux-install
Last active March 29, 2024 08:38
Minimal instructions for installing arch linux on an UEFI system with full system encryption using dm-crypt and luks
# Install ARCH Linux with encrypted file-system and UEFI
# The official installation guide (https://wiki.archlinux.org/index.php/Installation_Guide) contains a more verbose description.
# Download the archiso image from https://www.archlinux.org/
# Copy to a usb-drive
dd if=archlinux.img of=/dev/sdX bs=16M && sync # on linux
# Boot from the usb. If the usb fails to boot, make sure that secure boot is disabled in the BIOS configuration.
# Set swedish keymap
@dutc
dutc / memoise.py
Created June 21, 2013 00:08
How short & how complete can we write a memoising decorator? I think the below is more complete than most formulations (which don't cache independent of arg-binding.) I think it also cuts straight to the core of what memoisation means. Three obvious deficiencies: [1] What do we do about instance and class methods? These can be meaningfully memoi…
from sys import version_info
assert version_info.major == 3 and version_info.minor >= 3, \
'requires PEP 362; Python 3.3 or later; python.org/dev/peps/pep-0362/'
from inspect import signature
class memoise(dict):
def __init__(self, func):
self.func, self.signature = func, signature(func)
def __missing__(self, key):
args, kwargs = key
@stesh
stesh / gist:3012428
Created June 28, 2012 16:44
hacky decorator for class-level properties in python using @classmethods
class classproperty(property):
def __get__(self, cls, inst):
return self.fget.__get__(None, inst)()
class MyClass(object):
numbers = [1,2,3,4,5]
@josephkern
josephkern / bloom.py
Created June 8, 2012 19:04
A Simple Bloom Filter in Python
#!/usr/bin/env python
"""A simple Bloom Filter implementation
Calculating optimal filter size:
Where:
m is: self.bitcount (how many bits in self.filter)
n is: the number of expected values added to self.filter
k is: the number of hashes being produced
(1 - math.exp(-float(k * n) / m)) ** k
http://en.wikipedia.org/wiki/Bloom_filter
"""
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2: