Skip to content

Instantly share code, notes, and snippets.

View mynameisfiber's full-sized avatar

Micha Gorelick mynameisfiber

View GitHub Profile
#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
import re
def check_winner(board,row=4):
try:
return re.search(r"([^.|])(\1{%d}|%s)"%(row-1,"|".join(r"(.{%d}\1){%d}"%(len(a[0])+d,row-1) for d in range(-1,2))), "|".join("".join(x) for x in a)).group()[0]
except:
return "No one"
if __name__ == "__main__":
a = [
package main
import (
"bytes"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"path"
#!/bin/env python
# $ seq 50 | python chunk.py 5 "xargs echo '-> '"
# -> 1 2 3 4 5
# -> 6 7 8 9 10
# -> 11 12 13 14 15
# -> 16 17 18 19 20
# -> 21 22 23 24 25
# -> 26 27 28 29 30
# -> 31 32 33 34 35
# -> 36 37 38 39 40
@mynameisfiber
mynameisfiber / gist:2853066
Created June 1, 2012 15:44
Golang http close body blocking problem
package main
import (
"crypto/tls"
"net"
"net/http"
"time"
"fmt"
"errors"
)
@mynameisfiber
mynameisfiber / irc2ps.sh
Created July 25, 2012 18:40
irc to pubsub
#!/bin/bash
# Publishes IRC messages from a particular channel to a pubsub
server="irc.wikimedia.org"
channel="#en.wikipedia"
pubsub="http://localhost:8080/pub"
( echo "USER irc2ps * * :irc2ps_bot
NICK irc2ps$RANDOM
JOIN $channel"; cat -) | nc $server 6667 |
@mynameisfiber
mynameisfiber / gist:3426140
Created August 22, 2012 14:31
paste example
$ sort -m country.decodes.2012-07-* | grep -v "(null)" | uniq -c | sort -n > country.count
$ cat country.count.norm | column -t -c1 | cut -f1 -d" " | paste -sd+ | bc | xargs -I{} awk '{if ($1/{} > .001) {print $1/{} " " $2}}' country.count.norm | sort -n | column
$ #tl;tr?
@mynameisfiber
mynameisfiber / index.html
Last active December 10, 2015 05:48
Visualization of Forget Table
<!DOCTYPE html>
<!--
This visualization shows how a distribution gets decayed to uniform
using a poisson based decay model. This type of decay is implemented
in forgettable in order to store time relevant statistical models.
In this visualization, the blocks on the right (darker color)
represent the original distribution, while the blocks on the right
(lighter color) are the decayed values. The decay is currently
happening at a constant rate and the visualization can be reset by