Skip to content

Instantly share code, notes, and snippets.

View llllllllll's full-sized avatar

Joe Jevnik llllllllll

View GitHub Profile
@llllllllll
llllllllll / wut
Created January 3, 2018 08:38
generator qualname
In [1]: def f():
...: def g():
...: yield
...: return g
...:
In [2]: g = f()
In [3]: g().__qualname__
Out[3]: 'f.<locals>.g'
"""
In [1]: from the_worst_way import why_though
In [2]: import ast
In [3]: code = '''
...: if a == 1 and a == 2 and a == 3:
...: print('ayy')
...: else:
...: print('lmao')
@llllllllll
llllllllll / a.pyx
Last active February 1, 2018 19:55
I sure love allocating PyObjects!
"""Tested with:
- cython==0.27.3
- cython==0.25.2
"""
cdef class PairWithConstructor:
cdef int a;
cdef int b;
#!/usr/bin/env python
import os
import statistics
import subprocess
from time import time as _time
class time:
def __init__(self):
self._start = None
"""Example usage:
In [1]: !cat ayy.s
.text
.global _start
.type _start, @function
_start:
movq $10, %rdx
pushw $10
import pandas as pd
import networkx
import toolz
df = pd.read_csv('/home/joe/downloads/debug.csv', escapechar='\\')
df.columns = ['stack', 'module', 'function', 'lineno', 'id', 'type', 'repr']
g = networkx.DiGraph()
@llllllllll
llllllllll / lazy_talk_code.py
Created January 4, 2019 17:36
lazy-talk-code
"""
$ qipython -i ~/projects/tmp/lazy_talk_code.py
Python 3.4.6 (default, Feb 16 2017, 15:43:12)
Type "copyright", "credits" or "license" for more information.
IPython 5.3.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: class Descr:
...: def __init__(self):
...: self.get_counter = 0
...:
...: def __get__(self, instance, owner):
...: if instance is None:
...: return self
...: self.get_counter += 1
...: return 1
...:
""" Example:
In [5]: class Class:
...: def __init__(self, a, b):
...: self.a = a
...: self.b = b
...:
...: @self_scope
...: def f(self):
...: return a + b
class WithLazyDoc:
def __init__(self, get_doc, f):
self._get_doc = get_doc
self._f = f
@property
def __wrapped__(self):
return self._f
@property