Skip to content

Instantly share code, notes, and snippets.

@auramo
auramo / gist:7359846
Last active December 27, 2015 17:09
MONGOHQ_URL regex (Scala) which works with username containing dashes
val regex = """mongodb://(\w+):([\w|-]+)@([\w|\.]+):(\d+)/(\w+)""".r
url match {
case Some(regex(u, p, host, port, dbName)) =>
ConnectionParams(host, port.toInt, dbName, u, p)
case None => {
ConnectionParams("127.0.0.1", 27017, "mylocaldb")
}
#!/usr/bin/env python
import json
import fileinput
def compact(raw):
parsed = json.loads(raw)
compacted = json.dumps(parsed, separators=(',',':'))
return compacted
@auramo
auramo / gist:5689544
Created June 1, 2013 07:10
Multi-line comprehension
new_list = [number for row in numbers
for number in row]
@auramo
auramo / clj-resource
Created October 10, 2011 08:30
Loading resource file in clojure
(defn load-resource
[name]
(let [rsc-name (str "somefolder/" name)
thr (Thread/currentThread)
ldr (.getContextClassLoader thr)]
(.getResourceAsStream ldr rsc-name)))