Skip to content

Instantly share code, notes, and snippets.

View akaptur's full-sized avatar

Allison Kaptur akaptur

View GitHub Profile
from dataclasses import dataclass
@dataclass
class A:
value: str
@dataclass
class B:
value: str
type State = "loading" | "loaded" | "error";
const x = "hi";
x = "hi"
@akaptur
akaptur / gist:3279183
Created August 6, 2012 22:46
quicksort in C
#include <stdio.h>
#include <stdlib.h>
void quicksort(int *array, int length);
void swap(int *a, int *b);
void print(int *array, int length);
int main()
>>> import sys
>>> def stuff():
... print("calling stuff!")
...
>>> def printer(frame, event, arg):
... print(frame, event, arg)
... return printer # return itself to keep tracing
...
>>> sys.settrace(printer) # register the tracing function
>>> stuff()
@akaptur
akaptur / activate
Created December 23, 2012 23:02
The version of virtualenv's activate on my machine
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
unset pydoc
# reset old environment variables
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
@akaptur
akaptur / gist:d8348c21e93d61ec9397
Created September 29, 2014 19:12
recursion limit checker
# 2.7
if (tstate->recursion_depth > recursion_limit) {
--tstate->recursion_depth;
PyErr_Format(PyExc_RuntimeError,
"maximum recursion depth exceeded%s",
where);
return -1;
# 3.4
>>> class Thing(object):
... def __init__(self, name, description):
... self.name = name
... self.desc = description
...
>>> b = Thing('box', 'empty')
>>> c = Thing('cat', 'fuzzy')
>>> collection = {'box': b, 'cat' : c}
>>> collection['box']
<__main__.Thing object at 0x1073a2150>
@akaptur
akaptur / gist:7217177
Created October 29, 2013 15:45
Possible misunderstanding of how `cause` interacts with context manager silencing in python 3
>>> class FalseContext(object):
... def __enter__(self):
... l.append('i')
... return self
... def __exit__(self, exc_type, exc_val, exc_tb):
... l.append('o')
... return False
...
>>> class TrueContext(object):
... def __enter__(self):