Skip to content

Instantly share code, notes, and snippets.

@adambard
adambard / gist:9844556
Created March 28, 2014 22:46
keybase.md
### Keybase proof
I hereby claim:
* I am adambard on github.
* I am adambard (https://keybase.io/adambard) on keybase.
* I have a public key whose fingerprint is D7B0 3610 4BA0 86AA 366A 2733 2E89 85DE 39A5 2FFC
To claim this, I am signing this object:
// Chart.redraw
redraw: function (animation) {
var chart = this,
//...
series = chart.series,
//...
;
// ...<snip>...
import csv
from collections import defaultdict
with open('/Users/adam/Downloads/languages-2014.csv', 'r') as f:
results_2014 = [row for row in csv.reader(f)][1:]
with open('/Users/adam/Downloads/languages-2013.csv', 'r') as f:
results_2013 = [row for row in csv.reader(f)][1:]
with open('/Users/adam/Downloads/languages-2012.csv', 'r') as f:
@adambard
adambard / core.clj
Last active August 29, 2015 14:11
I'm so shit at parsers.
(ns parsley.core
(:require [net.cgrand.parsley :as p]))
(def parse (p/parser {:main :blat*} :blat #{["{{" #"[a-zA-Z_\-]*" "}}"]}))
(defmulti render-node (fn [node _] (:tag node)))
; Pull out the middle bit and look it up in the context
(defmethod render-node :blat [node context]
(get context (nth (:content node) 1) ""))
@adambard
adambard / gist:9800b29fcecbc977a0ac
Last active August 29, 2015 14:13
analysis.clj
(ns redditlater.analysis
(:import
java.util.Date
java.util.Calendar
java.util.TimeZone
java.util.SimpleTimeZone
)
(:require
[somnium.congomongo :as mongo]
[redditlater.reddit-api :as api]
import random
from collections import deque
class Card(object):
def __init__(self, cost):
self.cost = cost
def __eq__(self, other):
return isinstance(other, self.__class__) and self.cost == other.cost
def __cmp__(self, other):
@adambard
adambard / hearthstone_stats.clj
Created September 11, 2015 22:59
Just neckbeard things.
(ns hearthstone-stats
(:require [clojure.data.json :as json]
[clojure.java.io :as io]
[clojure.string :as s]))
(defn get-results []
(json/read-str (slurp "results.json") :key-fn keyword))
(def uncounted-cards #{"Reinforce", "Lesser Heal", "Shapeshift", "The Coin", "Armor Up!", "Totemic Call", "Steady Shot", "Life Tap", "Dagger Mastery", "Fireblast"})
@adambard
adambard / development.py
Created December 27, 2010 01:53
Sample django development.py settings.
from base import *
DEBUG = True
TEMPLATE_DEBUG = DEBUG
PROJECT_DIR = "/path/to/project/directory/"
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
"""
A simpler pivot table for non-python people.
Pythonisms present:
1. You can iterate over a list of tuples using `for ... in` and map each tuple to a variable.
2. Dicts exist and are great.
3. Iterating over a dict returns the key.
4. Attempting to access a variable that doesn't exist in a dict raises a KeyError.
def find_largest_contiguous_region(countsarray):
"""
Find the contiguous regions in countsarray using the modified
flood count algorithm described in get_flood_count
"""
Q = countsarray.copy()
points_checked = []
rows, cols = Q.shape