Skip to content

Instantly share code, notes, and snippets.

View encukou's full-sized avatar

Petr Viktorin encukou

View GitHub Profile
⎡ ⎛ ⎛ ⎛ c⋅e⎞ ⎞ ⎛ ⎛ d⋅e⎞ ⎛ b⋅i⎞ ⎞ ⎞ ⎛ ⎛ ⎛ b⋅i⎞ ⎞ ⎛ ⎛ c⋅e⎞ ⎛ b⋅m⎞ ⎞ ⎞ ⎛ ⎛ ⎛ c⋅e⎞ ⎛ b⋅m⎞ ⎞ ⎞ ⎛ ⎛ ⎛ c⋅e⎞ ⎞ ⎛ ⎛ d⋅e⎞ ⎛ b⋅i⎞ ⎞ ⎞ ⎛ ⎛ ⎛ c⋅e⎞ ⎞ ⎛ ⎛ d⋅e⎞ ⎛ b⋅i⎞ ⎞ ⎞ ⎛ ⎛ ⎛ c⋅e⎞ ⎞ ⎛ ⎛ d⋅e⎞ ⎛ b⋅i⎞ ⎞ ⎞ ⎤
⎢ ⎜ ⎜ b⋅⎜g - ───⎟ ⎟ ⎜ ⎜h - ───⎟⋅⎜j - ───⎟ ⎟ ⎟ ⎜ ⎜e⋅⎜j - ───⎟ ⎟ ⎜ ⎜g - ───⎟⋅⎜n - ───⎟ ⎟ ⎟ ⎜ ⎜ ⎜g - ───⎟⋅⎜n - ───⎟ ⎟ ⎟ ⎜ ⎜ b⋅⎜g - ───⎟ ⎟ ⎜ ⎜h - ───⎟⋅⎜j - ───⎟ ⎟
@encukou
encukou / getpatch.sh
Created November 13, 2012 09:04
get patches from remote repo, name them according to freeipa guidelines
#! /bin/bash
export project=freeipa
export username=pviktori
export localrepo=~/dev/freeipa
export patchdir=~/patches/in
export remote=vm081
# Usage: getpatch <patchnumber> [num_patches]
#
@encukou
encukou / dumppic.py
Created February 17, 2013 18:02
Print an image on 256-color xterm. Old but still works...
#! /usr/bin/env python
# Encoding: UTF-8
#
# Print an image that is given as a command-line parameter.
#
# If nothing is given, read the image from stdin.
#
# Only works on utf8 256-color-xterm-like terminals. No checks are done to
# enforce this.
@encukou
encukou / isb.py
Last active December 14, 2015 08:49
inspect.Signature.bind
import inspect
def func(a, b, c, d=4, **kw):
print(a, b, c, kw)
def call(func, *args, **kwargs):
try:
params = inspect.signature(func).bind(*args, **kwargs)
except TypeError:
@encukou
encukou / gist:7004106
Created October 16, 2013 07:48
RuPy 2013 notes
===============================================================================
9:20 Immutability in Clojure, Ruby, JavaScript, and Python
- Tero Parviainen
wormholes
Clojure view - everything should be immutable
Scores languages based on how close to Clojure they are... ??!
Ruby - can use mutable objects as hash keys; hashes are indexed "by value"
- freeze() on objects (shallow; lib with deep_freeze)
@encukou
encukou / sieve.py
Created March 24, 2014 19:35
Sieve of Eratosthenes
#! /usr/bin/python3
def sieve(ints):
prime = next(ints)
yield prime
yield from sieve(i for i in ints if i % prime)
for i in sieve(iter(range(2, 3000))):
print(i)
@encukou
encukou / unpacking_property.py
Last active August 29, 2015 13:57
Unpacking property example
from weakref import WeakKeyDictionary
class TupleProperty:
def __init__(self, *default_value):
self.values = WeakKeyDictionary()
self.length = len(default_value)
self.default_value = default_value
def __get__(self, obj, cls=None):
if obj:
@encukou
encukou / subTest
Created April 7, 2014 10:28
Python 3.4. subTest example
This is a comment on http://eli.thegreenplace.net/2014/04/02/dynamically-generating-python-test-cases/
@encukou
encukou / mrkac.py
Created June 6, 2014 12:37
asyncio blinkers
#! /usr/bin/python3
# for an async presentation at Ostravské Pyvo, 2014-06-05
# - http://srazy.info/pyvo-v-ostrave/4591
# - http://lanyrd.com/2014/ostrava-pyvo-june/
import random
import time
import asyncio
#! /usr/bin/env python3
# Python 3.4+
import inspect
def fix_public_signature(func):
"""Remove private arguments from the signature of a function
Private arguments are keyword-only, and prefixed by an underscore.
"""