Skip to content

Instantly share code, notes, and snippets.

@zackmdavis
zackmdavis / bear_hunt.py
Last active May 7, 2017 01:33
bear hunt
from collections import OrderedDict
OBSTACLES = OrderedDict([('grass', ("long, wavy", "swishy-swashy")),
('a river', ("deep, cold", "splash-splosh")),
('mud', ("thick, oozy", "squelch-squerch")),
('a forest', ("big, dark", "stumble-trip"))])
def hunting_anthem():
print("We're going on a bear hunt, &c.")
# if you can easily fit it in less than one and a half tweets, I don't think it
# deserves to be called a "project"
from string import ascii_uppercase as u, ascii_lowercase as l; c = lambda m, n: ''.join((chr((ord(c)-97+n)%26+97) if c in l else chr((ord(c)-65+n)%26+65)) if c in l+u else c for c in m)
in [1]: import ast; from ast import *
in [2]: m = ast.parse('def at(): print("@")')
in [3]: m.body[0].name = "@"
in [4]: exec(compile(m, "<string>", 'exec'))
in [5]: globals()['@']
Out[5]: <function __main__.@>
in [1]: import ast; from ast import *
in [2]: m = ast.parse('def at(): print("@")')
in [3]: m.body[0].name = "@"
in [4]: exec(compile(m, "<string>", 'exec'))
in [5]: globals()['@']
Out[5]: <function __main__.@>
@zackmdavis
zackmdavis / slo.go
Created May 13, 2016 21:46
writing Static Large Objects to Swift from Go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
@zackmdavis
zackmdavis / svd.rs
Created May 6, 2016 04:35
naive singular value decomposition draft
pub fn singular_value_decomp(&self) -> (Matrix<T>, Matrix<T>, Matrix<T>) {
let ata = self.transpose() * self;
let (ata_eigenvals, ata_eigvecs) = ata.eigendecomp();
// (index, √λ) pairs (indices being order of return from `.eigendecomp`)
let mut enumerated_singular_vals = ata_eigenvals.iter()
.map(|s| s.sqrt())
.enumerate()
.collect::<Vec<_>>();
#/usr/bin/env python3
from enum import Enum
from random import choice, randint
from datetime import datetime
from operator import add, sub, mul # binary operations as functions!
# Enums were introduced in 3.4!
Operation = Enum('Operation', ('add', 'subtract', 'multiply'))
break
}
panic(err)
}
log.Printf("request is %#+v", req)
switch req := req.(type) {
case *fuse.StatfsRequest:
stats, err := mountHandle.Statfs()
import csv
import logging
import bleach
import textblob
import gensim
from sklearn.decomposition import PCA
from numpy import dot
from numpy.linalg import norm
@zackmdavis
zackmdavis / gist:bb4f1ea3b2b5ea11b31d
Created January 24, 2016 08:47
Less Wrong comments word vector exploration
in [200]: by_first_component[:100]
Out[200]:
[('u', -1.9398326),
('parameter', -1.8654854),
('1-p', -1.8631597),
('f', -1.8552135),
('T', -1.7352118),
('q', -1.6937695),
('F', -1.6872095),
('Pr', -1.6614704),