Skip to content

Instantly share code, notes, and snippets.

View jasonkeene's full-sized avatar
:shipit:

Jason Keene jasonkeene

:shipit:
View GitHub Profile
@jasonkeene
jasonkeene / life.py
Created March 20, 2012 19:33
Python implementation of Conway's Game of Life
"""Python implementation of Conway's Game of Life
Somewhat inspired by Jack Diederich's talk `Stop Writing Classes`
http://pyvideo.org/video/880/stop-writing-classes
Ironically, as I extended the functionality of this module it seems obvious
that the next step would be to refactor board into a class with advance and
constrain as methods and print_board as __str__.
"""
@jasonkeene
jasonkeene / notes.rst
Created May 12, 2012 15:58
Introduction to Python Notes

Installing Python

Mac OSX
Binary installation from python.org
Windows
Binary installation from python.org
Ubuntu/Debian
sudo apt-get install python2.7
@jasonkeene
jasonkeene / placeholder_shim.js
Last active October 5, 2015 07:08
Placeholder Text Shim
// placeholder text fallback
// requires modernizer and jQuery
$(function () {
if (!Modernizr.input.placeholder) {
var placeholder_text_color = '#999999';
function hide_placeholder_fake(real, fake) {
real.show();
real.focus();
@jasonkeene
jasonkeene / gist:3019590
Created June 29, 2012 17:50 — forked from jglenes/gist:3018166
Bash Git Branch
function parse_git_dirty {
[[ `git status --porcelain` ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1="\n\[$BPurple\][\w]\n\[$BCyan\]\u@\h \[$BGreen\]\$(parse_git_branch)\n$\[$Color_Off\] "
@jasonkeene
jasonkeene / uber_pass.py
Last active October 7, 2015 20:08
Generate and check password hashes for Ubersmith DE (salted sha1)
r"""Generate and check password hashes for Ubersmith DE (salted sha1).
Example use:
>>> my_new_hash = generate_hash('my_new_pass', 'salt')
>>> my_new_hash # store this in the database
'{ssha1}W77amZWRUSWjDLh04P/dlfsCvYdzYWx0\n'
>>> check_password('my_new_pass', my_new_hash)
True
>>> check_password('not_my_new_pass', my_new_hash)
@jasonkeene
jasonkeene / monte_carlo_pi.py
Created September 3, 2012 21:19
Naive Monte Carlo approximation of pi
#!/usr/bin/env python
"""Naive Monte Carlo approximation of pi."""
from __future__ import division
import math
from random import random
from itertools import repeat
@jasonkeene
jasonkeene / notes.rst
Last active December 15, 2015 09:28
Getting started with testing in Python

Why Test

  • Tells you when your code is broken
  • Manual testing sucks
  • Prevent against regressions
    • Upgrading dependencies
    • Refactoring
  • Documentation
    • Other devs can read your tests to see how you intended your code to be used
@jasonkeene
jasonkeene / alert.coffee
Last active December 30, 2015 20:39
A simple bookmarklet to add an alert feature to bitcoinwisdom.com :)
interval_id = high = low = null
ticker = $ '#price'
alert_url = 'http://www.angelfire.com/ut/jlpicard/images/picalert.wav'
start = ->
do nodes.stop.show
do nodes.start.hide
interval_id = setInterval ->
current_price = parseFloat do ticker.text
unless high > current_price > low
@jasonkeene
jasonkeene / counter.js
Created January 10, 2014 20:54
JavaScript Counter Implementation
function Counter() {
this.elements = {};
}
Counter.prototype.lookup = function (element) {
var el, i;
el = this.elements[element] || [];
for (i = 0; i < el.length; i++) {
if (el[i][0] === element) {
return el[i][1];
}
@jasonkeene
jasonkeene / calc.html
Last active August 29, 2015 13:56
Testing Calculator
<!DOCTYPE html>
<html>
<head>
<title>Testing Calculator</title>
<style type="text/css">
#display {
width: 180px;
border: 1px solid black;
padding: 5px 7px;