Skip to content

Instantly share code, notes, and snippets.

View yabberyabber's full-sized avatar
🐐

Andrew Nelson yabberyabber

🐐
  • Arista Networks
  • San Luis Obispo, California
  • 23:23 (UTC -07:00)
View GitHub Profile
;;function lis-length returns the length of a list
;;list -> number
(define (lis-length lis)
(cond [(empty? lis) 0]
[else (add1 (lis-length (rest lis)))]))
(check-expect (lis-length (list 1 2 3 4 5)) 5)
(check-expect (lis-length empty) 0)
(check-expect (lis-length (list 1)) 1)
@yabberyabber
yabberyabber / bach-notes.rkt
Last active December 30, 2015 20:49
Markov chains with custom degrees
#lang racket/base
(require rsound)
(require rsound/piano-tones)
(require racket/list)
(require "markov.rkt")
;; a note is (make-note note-num frames frames)
(define-struct note (pitch time duration))
(define (note->note* old)
@yabberyabber
yabberyabber / gist:7922169
Created December 12, 2013 02:09
Wouldn't it be fun to write a lisp interpretor in python?
def car(x):
return x[0]
def cdr(x):
return x[1:]
#define some things that we can do in our arithmatic language
def plus(x):
if x == []:
return 0
else:
@yabberyabber
yabberyabber / 2048
Last active August 29, 2015 14:03
almost complete 2048 implemtation... can only shift tiles one direction (left), but compensates for that by rotating the grid before and after shifting.
#lang racket
(require rackunit)
(require racket/list)
(define board (list (list 0 0 0 0)
(list 0 2 0 0)
(list 0 0 0 0)
(list 0 0 0 2)))
@yabberyabber
yabberyabber / estimate_total_cat_facts.py
Last active September 10, 2015 19:51
Every day at work we get a random cat fact in our slack chat, each fact has a number on it. Assuming those numbers start at 1, are unique, and are consecutive, how many cat facts total would you guess there are?
import math
def frequentist(facts):
m = max(facts)
k = len(facts)
return m + (float(m) / k) - 1
def bayesian(facts):
m = float(max(facts))
k = float(len(facts))
rgfdlj rjgrldj,xlarjcrgsrgllj;rsrr
import numpy, math
from scipy import linalg
# Let |terms| be a list of lambdas... one for each term
# the result is a linear combination of them applied to x
terms = [
lambda x: 1,
lambda x: math.log( x ),
lambda x: math.log( x ) ** 3
]
@yabberyabber
yabberyabber / .bashrc
Last active July 15, 2016 18:12 — forked from anonymous/.bashrc
if [ -z "$WP" ]; then
# $WP is empty... you are not in a chroot workspace
export PS1="\[\033[0;31m\]"$PS1"\[\033[0m\]"
else
# $WP contains the name of the project you're currently in
export PS1="\[\033[0;37m\]"$WP": "$PS1"\[\033[0m\]"
fi
@yabberyabber
yabberyabber / mutex.py
Created July 20, 2016 00:23
for when you wanna run a bunch of commands in serial but each in a different terminal and you don't care what order they run in
import sys, os, subprocess, errno, time
class BadArgsException( Exception ):
pass
class FileLock:
def __init__( self, lockfile, delay=1.0 ):
""" Acquire the lock, if possible. If the lock is in use, it check again
every `wait` seconds. It does this until it either gets the lock or
exceeds `timeout` number of seconds, in which case it throws
@yabberyabber
yabberyabber / mutex.py
Last active July 20, 2016 00:34
for when you wanna run a bunch of commands in serial but each in a different terminal and you don't care what order they run in
import sys, os, subprocess, errno, time
class FileLock:
def __init__( self, lockfile, delay=1.0 ):
self.is_locked = False
self.lockfile = lockfile
while True:
try:
self.fd = os.open( self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR )
break;