Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am palankai on github.
  • I am palankai (https://keybase.io/palankai) on keybase.
  • I have a public key whose fingerprint is 87F8 F047 D5F6 EF57 6602 C0C4 6325 1B9C 88EE E769

To claim this, I am signing this object:

@palankai
palankai / demo.py
Last active September 19, 2017 20:32
Recursive quick sort algorithm
import os
import random
import sys
def main(env, prog, argv):
# Set the seed constant, we will have the same result every time
random.seed(1)
elements = generate_unsorted_elements(10)
deep = 0
class Metaclass(type):
def __new__(metacls, name, bases, namespace, **kwargs):
cls = type.__new__(metacls, name, bases, namespace)
print('>>> Metaclass.__new__(metacls={}, name={}, bases={}, namespace={}, **kwargs={})'.format(
metacls, name, bases, namespace, kwargs, cls
))
print(cls)
return cls
@palankai
palankai / descriptor.py
Created February 11, 2016 08:05
Declarative class attributes
class Descriptor:
def __get__(self, instance, cls):
if instance is None:
return self
return instance.__dict__.get(self.name)
def bind(self, name):
self.name = name
@palankai
palankai / specification.py
Last active March 29, 2024 10:02
Python Specification Pattern
class Specification:
def __and__(self, other):
return And(self, other)
def __or__(self, other):
return Or(self, other)
def __xor__(self, other):
return Xor(self, other)