Skip to content

Instantly share code, notes, and snippets.

View mynameisfiber's full-sized avatar

Micha Gorelick mynameisfiber

View GitHub Profile
@mynameisfiber
mynameisfiber / schedule.json
Last active August 29, 2015 13:57
Parse the pycon2014 schedule and create a json blob for great victory
[{"start_time":1397201400,"end_time":1397206800,"title":"Breakfast"},{"start_time":1397206800,"end_time":1397208600,"title":"Opening Statements: Diana Clarke"},{"start_time":1397208600,"end_time":1397211000,"title":"Keynote: John Perry Barlow"},{"start_time":1397211000,"end_time":1397213400,"title":"Break"},{"description":"Why are Python programmers crazy about lists and dictionaries, when\r\nother languages tout bitmaps, linked lists, and B+\u00c2\u00a0trees? Are we missing\r\nout? Come learn how data structures are implemented on bare metal, how\r\nto select the right data structure, how the list and dictionary cover a\r\nwide swath of use cases, and when to dip into the Standard Library or a\r\nthird-party package for an alternative.","title":"All Your Ducks In A Row: Data Structures in the Standard Library and Beyond","track":1,"start_time":1397213400,"speaker":"Brandon Rhodes","end_time":1397215800,"link":"https:\/\/us.pycon.org\/\/2014\/schedule\/presentation\/211\/"},{"description":"Many developers, in
@mynameisfiber
mynameisfiber / shared_numpy.py
Created April 15, 2014 18:21
The pains of multiprocessing and copy-on-write
import numpy as np
import multiprocessing
import ctypes
import mmap
data_normal = np.zeros((4, 10), dtype=np.uint8)
# This shows the important piece in this whole mystery has been the MAP_SHARED
# memory flag. Normally, memory that is compied when the process os.fork()'s
# is set to copy-on-write which essentially makes each fork has it's own
@mynameisfiber
mynameisfiber / supernone.py
Created July 21, 2014 17:50
SuperNone -- The most None a None type can get.
from functools import total_ordering
@total_ordering
class SuperNone(object):
# general properties / methods
def __getattr__(self, *args, **kwargs):
return self
def __call__(self, *args, **kwargs):
return self
def __setattr__(self, *args, **kwargs):
# Why does this work
def split_chars(words, chars):
itr = (words,)
for c in chars:
itr = tuple(chunk for word in itr for chunk in word.split(c))
return list(itr)
# but this not work
def split_chars_broken(words, chars):
itr = (words,)
@mynameisfiber
mynameisfiber / neighborhoods.json
Created August 13, 2014 15:16
Centroids for neighborhoods in Manhattan
[
{
"name": "Lower East Side",
"center": [
-73.9836180698,
40.7155233255
]
},
{
"name": "Marble Hill",
$ # Fails on port 80
$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: XXX.fastforwardlabs.com" -H "Origin: http://XXX.fastforwardlabs.com" http://XXX.fastforwardlabs.com/XXXX
HTTP/1.1 400 Bad Request
Server: nginx/1.4.6 (Ubuntu)
Date: Mon, 20 Oct 2014 23:22:48 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 34
Can "Upgrade" only to "WebSocket".
@mynameisfiber
mynameisfiber / multigram_search.py
Last active August 29, 2015 14:10
MultigramSearch looks up instances of ngrams within a target text
#!/usr/bin/env python2.7
"""
>>> import multigram_search
>>> mgs = multigram_search.MultigramSearch([("a", "b", "c"), ("o", "c", "z"),
('z','y')])
>>> list(mgs.intersection("hello world you a b c foo".split(" ")))
[['a', 'b', 'c']]
#include <stdio.h>
#include <functional>
double any_op(double, double, std::function<double(double,double)>);
int main()
{
std::function<double(double,double)> add = [](double a, double b) -> double { return a+b; };
std::function<double(double,double)> sub = [](double a, double b) -> double { return a-b; };
@mynameisfiber
mynameisfiber / gist:1642403
Created January 19, 2012 20:31
Numpy "masking" on index
In [21]: a = np.zeros( (20) )
In [22]: b = np.asarray( [2, 5, 7, 15] )
In [23]: a
Out[23]:
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0.])
In [24]: a[b] = 1
@mynameisfiber
mynameisfiber / gist:1653539
Created January 21, 2012 18:38
VIM 7.3 install
$ # First we set the correct python path and compilation flags
$ export vi_cv_path_python_plibs="-L/bitly/local/lib/python2.7/config/ -lpython2.7 -lpthread -lutil -Xlinker -export-dynamic"
$ # Configure will all the options we love the most
$ ./configure --with-features=huge --enable-pythoninterp --with-python-config-dir=/bitly/local/lib/python2.7/config/
$ # Make & install
$ make -j & sudo make install