Skip to content

Instantly share code, notes, and snippets.

View ryansturmer's full-sized avatar

Ryan Sturmer ryansturmer

View GitHub Profile
@ryansturmer
ryansturmer / montyhall.py
Created July 30, 2012 04:48
Python Simulation of the Monty Hall Problem for N-Doors
#
# Monty Hall Problem Simulation
# Author: Ryan Sturmer
#
import random
def play_round(doors, switch):
# Choose the location of the car
@ryansturmer
ryansturmer / base64image.py
Created August 1, 2012 15:27
Convert Images to Base64 Encoded HTML
import base64
import os
def convert(infile):
with open(infile, 'rb') as fp:
data = fp.read()
b64 = base64.b64encode(data)
with open("%s.htm" % os.path.splitext(infile)[0], 'w') as fp:
@ryansturmer
ryansturmer / dov.py
Created August 2, 2012 15:01 — forked from anonymous/dov.py
The Dov problem
# Counting Squares Problem
# Code derived from original script by Keith Brafford
#
import itertools
coords = [(0,0), (1,0), (2,0), (3,0), (4,0),
(1.5,.5), (2,.5), (2.5,.5),
(0,1), (1,1),(1.5,1), (2,1), (2.5,1), (3,1), (4,1),
(1.5,1.5), (2,1.5), (2.5,1.5),
(0,2), (1,2), (2,2), (3,2), (4,2),
@ryansturmer
ryansturmer / get_sdk.py
Created August 21, 2012 02:04
Downloads, extracts, and installs the mozilla add-on SDK. Handy script to include in your add-on source tree.
import sys, os, urllib, shutil
from urlparse import urlparse
from zipfile import ZipFile
SDK_DIR = 'sdk'
TMP_DIR = os.path.join(SDK_DIR, 'tmp')
MOZILLA_SDK = 'https://ftp.mozilla.org/pub/mozilla.org/labs/jetpack/addon-sdk-1.9.zip'
VOLD_UTILS = 'https://github.com/voldsoftware/vold-utils-jplib/zipball/master'
VOLD_MENUITEMS = 'https://github.com/voldsoftware/menuitems-jplib/zipball/master'
@ryansturmer
ryansturmer / git_cheat_sheet.md
Last active October 12, 2015 14:48
Git Cheat Sheet

Git Cheat Sheet

This attempts to be a useful "cheat sheet" for git. I'm just writing git recipes down here as I find and use them.

Getting Code

Clone a repository (GitHub)

git clone git@github.com:username/repository.git
@ryansturmer
ryansturmer / .vimrc
Created November 28, 2012 21:54
My vimrc file
call pathogen#infect()
set nocompatible
set number
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
set diffexpr=MyDiff()
function MyDiff()
#!/bin/sh
# System Update
pacman --noconfirm -Syu
#The essentials
pacman --noconfirm -S base-devel vim git
# Packer (AUR Helper)
cd /tmp
@ryansturmer
ryansturmer / midi.py
Last active December 17, 2015 14:29
Some functions for dealing with MIDI and music data. Can't say how many times I've re-written these over the years. Bonus demo function written using pygame (poll a midi input device and print events to the console)
NOTES_SHARP = ["C", "C#", "D", "D#", "E", "F", "F#", "G","G#", "A","A#","B"]
NOTES_FLAT = ["C", "Db", "D", "Eb", "E", "F", "Gb", "G","Ab", "A","Bb","B"]
def generate_midi_event_map():
events = ['Note Off',
'Note On',
'Polyphonic Aftertouch',
'Control Mode Change',
'Program Change',
'Channel Aftertouch',
#!/usr/bin/env python
#coding:utf-8
# Purpose: Export 3D objects, build of faces with 3 or 4 vertices, as ASCII or Binary STL file.
# License: MIT License
import struct
ASCII_FACET = """facet normal 0 0 0
outer loop
vertex {face[0][0]:.4f} {face[0][1]:.4f} {face[0][2]:.4f}
@ryansturmer
ryansturmer / bbb-make-sdcard.sh
Last active August 29, 2015 14:02
Beaglebone Black SD Card Builder
#!/bin/sh
# This is a script for making a beaglebone SD card
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
read -p "This will obliterate the partition table on $1... Are you sure? (y/n)" -n 1 -r