Skip to content

Instantly share code, notes, and snippets.

import inspect
from random import random
def foo_iterator():
while True:
caller_frame = inspect.currentframe().f_back
frame_info = inspect.getframeinfo(caller_frame)
if '.send(' in frame_info.code_context[0]:

Keybase proof

I hereby claim:

  • I am dhaffner on github.
  • I am dhaffner (https://keybase.io/dhaffner) on keybase.
  • I have a public key ASAKv3xsaN4c1hBlqC-e_JS6i3Hpa4G8CieKFGT8dtwMZAo

To claim this, I am signing this object:

@dhaffner
dhaffner / python-monkey-patch-built-ins.py
Created August 17, 2017 15:39 — forked from mahmoudimus/python-monkey-patch-built-ins.py
pythonic monkey patching built-in types
# found this from Armin R. on Twitter, what a beautiful gem ;)
import ctypes
from types import DictProxyType, MethodType
# figure out side of _Py_ssize_t
if hasattr(ctypes.pythonapi, 'Py_InitModule4_64'):
_Py_ssize_t = ctypes.c_int64
else:
_Py_ssize_t = ctypes.c_int
@dhaffner
dhaffner / gist:b909e6f4018963b9bd3f
Created December 15, 2014 22:30
Python features
#!/usr/bin/env python
from random import randint
def compose(*funcs):
'''Return a function that represents the composition
of an arbitrary number of functions.
'''
compose_once = lambda f, g: lambda x: f(g(x))
return reduce(compose_once, funcs)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>title</title>
<style type="text/css">
body, html {
width: 100%;
height: 100%;