Skip to content

Instantly share code, notes, and snippets.

@zackmdavis
zackmdavis / firstbornnumsibs.py
Created December 5, 2011 04:18
Not-firstbornness vs. number of siblings
from scipy.stats import pearsonr
from random import choice
def experiment(max_family_size, trials_per_family_size):
number_of_sibs = []
not_firstborn = []
for num_sibs in range(1,max_family_size+1):
for subject in range(trials_per_family_size):
birthrank = choice(range(num_sibs))
number_of_sibs.append(num_sibs)
@zackmdavis
zackmdavis / gist:1829487
Created February 14, 2012 19:32
Mandelbrot Turtle v.0.8
from turtle import *
from cmath import phase
# TODO: use _multiple turtles_ to trace points with different escape times (awesome)
# TODO: optimize sort order to avoid awkward radial lines
def z_n_escape_time(c, n):
z = 0
for i in range(n):
z = z**2 + c
@zackmdavis
zackmdavis / gist:2760987
Created May 21, 2012 07:39
Stokes intrigue
#!/usr/share/sage-4.8-linux-64bit-ubuntu_10.04.3_lts-x86_64-Linux/sage
from math import cos, sin, exp, pi, e
from sage.all import *
# Terrible ad hoc code follows
x1 = var('x1')
x2 = var('x2')
x3 = var('x3')
x4 = var('x4')
@zackmdavis
zackmdavis / lwuser.rb
Created May 31, 2012 00:50
Less Wrong karma histogram creator (author unknown)
require 'rubygems'
require 'nokogiri'
require 'open-uri'
#Change this to your username to run this script for you.
#Make sure it makes the name in the 'lesswrong.com/user/USERNAME/comments/ url.
username = "Will_Newsome"
def parse_page url
puts $pages
@zackmdavis
zackmdavis / years.py
Created December 30, 2012 19:54
looking for tuples of n consecutive years with exactly n prime factors which are all distinct (turns out n>=4 is impossible because out of every four consecutive numbers, one must have 2**2 in its factorization, but I didn't realize this until the code was already written)
from subprocess import check_output
def factorize(n):
if n == 0 or n == 1:
return {}
output = check_output(["factor", str(n)]).decode('utf-8')
factors = list(map(int, output.split(": ")[1].split(' ')))
factorization = {(f, factors.count(f)) for f in set(factors)}
return factorization
@zackmdavis
zackmdavis / serp_rev.py
Created October 28, 2013 04:39
proposed revisions to SerpentineRecord
def has_many(self, association, class_name, foreign_key = None, primary_key = "id"):
foreign_key = foreign_key or self.__class__.__name__.lower()+"_id"
search = lambda: eval(class_name).where({foreign_key: self.__dict_[primary_key]})
setattr(self, association, search)
def belongs_to(self, association, class_name, foreign_key = None, primary_key = "id"):
foreign_key = foreign_key or class_name.lower()+"_id"
search = lambda: eval(class_name).where({primary_key: self.__dict__[foreign_key]})
setattr(self, association, search)
@zackmdavis
zackmdavis / terminal_output.txt
Last active January 1, 2016 06:08
Swift CLI utility troubles
# using cURL works fine ...
Jons-MacBook-Pro:deploy zmd$ curl -X GET -H "X-Auth-Token: $TOKEN" $SERVER/v1/$USER/Storage_Container_A/ -i
HTTP/1.1 200 OK
Content-Length: 58
X-Container-Object-Count: 3
Accept-Ranges: bytes
X-Timestamp: 1387591147.17947
X-Container-Bytes-Used: 47428
Content-Type: text/plain; charset=utf-8
X-Trans-Id: tx9b60e656fed54149a21b0-0052b88667
@zackmdavis
zackmdavis / gist:8151551
Created December 27, 2013 19:35
failed swiftstack.com dev environment boot
(ssdc)Jons-MacBook-Pro:swiftstackdotcom zmd$ vagrant up
Bringing machine 'dev' up with 'virtualbox' provider...
[dev] Setting the name of the VM...
[dev] Clearing any previously set forwarded ports...
[dev] Creating shared folders metadata...
[dev] Clearing any previously set network interfaces...
[dev] Preparing network interfaces based on configuration...
[dev] Forwarding ports...
[dev] -- 22 => 2222 (adapter 1)
[dev] -- 8000 => 8888 (adapter 1)
@zackmdavis
zackmdavis / gist:8151727
Created December 27, 2013 19:51
/etc/init.d/vboxadd
vagrant@precise64:/etc/init.d$ ./vboxadd
Usage: ./vboxadd {start|stop|restart|status|setup}
vagrant@precise64:/etc/init.d$ sudo !!
sudo ./vboxadd
Usage: ./vboxadd {start|stop|restart|status|setup}
vagrant@precise64:/etc/init.d$ sudo ./vboxadd setup
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules
The make utility was not found. If the following module compilation fails then
@zackmdavis
zackmdavis / jobs.js
Created January 17, 2014 01:26
apparently I don't understand scope in JavaScript
$(document).ready(function() {
var job_postings_data = JSON.parse($("#job_postings_data").html());
for (var job in job_postings_data) {
var job_item_selector = "#" + job + "-item";
$(job_item_selector).on("click", function(e) {
var this_job = job;
e.preventDefault();
$(".job-post-item").removeClass("selected");
$(this).addClass("selected");