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"
>>> 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()
def countdown(n, times_called=[0],):
print(times_called[0], " ", n, " ")
# print "frame: %s" % id(inspect.currentframe())
times_called[0] += 1
if n == 1:
return times_called
else:
try:
return countdown(n-1)
except RuntimeError:
def countdown(n, times_called=[0]):
print times_called[0], " ", n, " "
times_called[0] += 1
if n == 1:
return times_called
else:
try:
return countdown(n-1)
except RuntimeError:
test ⚲ ./testopt
aflag = 0, bflag = 0, cvalue = (null)
test ⚲ ./testopt -a -b
aflag = 1, bflag = 1, cvalue = (null)
test ⚲ ./testopt -c
Option -c requires an argument.
test ⚲ ./testopt -ab
aflag = 1, bflag = 1, cvalue = (null)
test ⚲ ./testopt -c foo
aflag = 0, bflag = 0, cvalue = foo
@akaptur
akaptur / frame_counter.py
Created September 29, 2014 19:21
frame counter
def depth_one(n):
def depth_two(n):
def countdown(n, times_called=[0]):
times_called[0] += 1
if n == 0:
return times_called
else:
try:
return countdown(n-1)
except RuntimeError:
@akaptur
akaptur / gist:be988fc5cc3ff41f66c3
Created September 29, 2014 19:17
full recursion limit checker
int
_Py_CheckRecursiveCall(char *where)
{
PyThreadState *tstate = PyThreadState_GET();
#ifdef USE_STACKCHECK
if (PyOS_CheckStack()) {
--tstate->recursion_depth;
PyErr_SetString(PyExc_MemoryError, "Stack overflow");
return -1;