Skip to content

Instantly share code, notes, and snippets.

@wootfish
wootfish / cached_memoize.py
Last active June 15, 2020 22:36
Measuring the resiliences of DHT networks
from functools import wraps
def _read_memo(fname="memo"):
with open(fname, "r") as f:
memo = eval(f.read())
return memo
def _write_memo(memo, fname="memo"):
@wootfish
wootfish / beta_test.py
Last active April 9, 2022 11:51
Test scripts for DHT size estimation
# this script samples the distributions of the k closest peers to randomly
# selected addresses and saves these to data files
import datetime
from multiprocessing import Process, Event
import os
import pprint
import random
@wootfish
wootfish / sobeldream.py
Last active February 24, 2016 05:23
Deep Dream with the Sobel operator
# imports and basic notebook setup
from cStringIO import StringIO
import numpy as np
import scipy.ndimage as nd
import PIL.Image
from IPython.display import clear_output, Image, display
from google.protobuf import text_format
from random import randint
@wootfish
wootfish / demosine.py
Last active August 29, 2015 14:24
Demo of sine transform
# imports and basic notebook setup
from cStringIO import StringIO
import numpy as np
import scipy.ndimage as nd
import PIL.Image
from IPython.display import clear_output, Image, display
from google.protobuf import text_format
import os
import sys
#!/usr/bin/python2.7
# imports and basic notebook setup
from cStringIO import StringIO
import numpy as np
import scipy.ndimage as nd
import PIL.Image
from IPython.display import clear_output, Image, display
from google.protobuf import text_format
#!/usr/bin/python2.7
# imports and basic notebook setup
from cStringIO import StringIO
import numpy as np
import scipy.ndimage as nd
import PIL.Image
from IPython.display import clear_output, Image, display
from google.protobuf import text_format
@wootfish
wootfish / gist:74114158a367cfd8356b
Last active August 29, 2015 14:15
Heron's Formula with SymPy
Python 2.7.8 (default, Oct 18 2014, 12:50:18)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sympy
>>> x1, x2, x3 = sympy.symbols('x1 x2 x3')
>>> y1, y2, y3 = sympy.symbols('y1 y2 y3')
>>>
>>> def distance(p1, p2):
... # still using the Pythagorean Theorem
... x = (p1[0] - p2[0]) ** 2
@wootfish
wootfish / gist:6d8a9ac708d391e7b8ca
Last active August 29, 2015 14:15
Heron's Formula in Python -- Naive
Python 2.7.8 (default, Oct 18 2014, 12:50:18)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def distance(p1, p2):
... # this just uses the Pythagorean Theorem
... x = (p1[0] - p2[0]) ** 2
... y = (p1[1] - p2[1]) ** 2
... return (x + y) ** 0.5
...
>>> def herons(a, b, c):