Skip to content

Instantly share code, notes, and snippets.

View shepting's full-sized avatar

Steven Hepting shepting

View GitHub Profile
@shepting
shepting / print_db.py
Created January 27, 2011 21:13
Prints out all table and column names for an SQLite db
import sqlite3
import sys
try:
FILENAME = sys.argv[1]
except IndexError:
print "You must pass in a valid sqlite db."
sys.exit(1)
print FILENAME
@shepting
shepting / fast_fib.py
Created March 9, 2011 01:53
Using caching (pseudo dynamic programming) to remove all the redundant calls of a regular recursive Fibonacci program.
"""Calculate the Fibonacci sequence caching the
values after each call.
"""
dp = {}
dp[0] = 0
dp[1] = 1
def fib(n):
@shepting
shepting / pi.py
Created March 29, 2011 02:07
Finding pi by Monte Carlo sampling
from random import uniform
# Variables
inside = 0
outside = 0
radius = 3
total = 1000000 # Number of runs
for i in xrange(total):
x = uniform(-radius, radius)
@shepting
shepting / backtrack.py
Created August 29, 2011 03:23
A skeleton framework for implementing a backtracking algorithm.
finished = False
def backtrack(a, k, input_data):
pass
def is_a_solution(a, k, input_data):
pass
def process_solution(a, k, input_data):
@shepting
shepting / fizzbuzz.js
Created October 7, 2011 00:09
FizzBuzz in Javascript
for (j=1;j<100;j++) {
if (!(j%3) && !(j%5)) {
console.log("FizzBuzz");
} else if (!(j%3)) {
console.log("Fizz");
} else if (!(j%5)){
console.log("Buzz");
} else {
console.log(j);
}
@shepting
shepting / test.html
Created October 25, 2011 23:52
Module Pattern
<html>
<script type="text/javascript">
// Test of the module pattern from Douglas Crockford's
// "Javascript: The Good Parts" pages 41 & 42
console.log("Starting module test...")
var serial_maker = function () {
var prefix = '';
var seq = 0;
@shepting
shepting / objc_random.m
Created October 26, 2011 20:02
Good Random Numbers in Objective C
#import <stdlib.h>
for (int i=0; i<20;i++) {
NSLog(@"%i", arc4random_uniform(74));
}
@shepting
shepting / nested_dispatch_async.m
Created January 20, 2012 17:39
Nested Dispatch Async Calls
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Company *company = [self createCompanyForIndexPath:indexPath];
dispatch_async(dispatch_get_main_queue(), ^{
[self createNewViewWithCompany:company];
});
});
}
@shepting
shepting / logs.m
Created January 24, 2012 22:32
Handy Log Variables
// 2012-01-24 16:33:29.836 MacKenzie[28439:10703] -[DetailViewController viewDidLoad] 198 viewDidLoad
NSLog(@"%s %d %@", __PRETTY_FUNCTION__, __LINE__, NSStringFromSelector(_cmd));
@shepting
shepting / VerticalAlign+UILabel.m
Created February 8, 2012 20:09
Vertical Aligned UILabel
Code.