Skip to content

Instantly share code, notes, and snippets.

var DATASTORES = [
"PostgreSQL",
"MySQL",
"MariaDB",
"MongoDB",
"RethinkDB",
"Elasticsearch",
"Redis",
"Cassandra",
"CouchDB"
@adambard
adambard / core.clj
Last active January 29, 2016 12:12
(ns failjure.core
(:require [clojure.algo.monads :refer [domonad defmonad]]))
; Public API
; failed, message part of prototype
(declare fail)
(declare attempt-all)
(declare if-failed)
(declare attempt->)
(declare attempt->>)
@adambard
adambard / passwords.py
Last active December 7, 2015 15:09
Recover passwords from Filezilla 2.x (Filezilla.xml)
from xml.etree import ElementTree
import csv
class CircularLookup(object):
key = "FILEZILLA1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def __len__(self):
return len(self.key)
@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"})
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 / 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]
def multi(dispatch_fn):
def _inner(*args, **kwargs):
return _inner.__multi__.get(
dispatch_fn(*args, **kwargs),
_inner.__multi_default__
)(*args, **kwargs)
_inner.__multi__ = {}
_inner.__multi_default__ = lambda *args, **kwargs: None # Default default
return _inner
@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) ""))
(ns whatlang.core
(:require [clojure.java.io :as io]
[clojure.string :as str]
[clojure.set :as sets]
))
(defn load-data
"Read the country data file from the resource. The data has been
mangled in to lines like so:
@adambard
adambard / user.clj
Last active December 17, 2015 22:07
(require '[schema.core :as s])
(require '[myproject.helpers :refer [uuid hash-password ]])
(require '[myproject.errors :refer [attempt-all fail]])
; Actual code
(s/defrecord User
[id :- s/Str
email :- s/Str
password_hash :- s/Str])