Skip to content

Instantly share code, notes, and snippets.

@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)))
@auramo
auramo / gist:5689544
Created June 1, 2013 07:10
Multi-line comprehension
new_list = [number for row in numbers
for number in row]
#!/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: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")
}
@auramo
auramo / Event delegation version of textFieldValue
Last active December 28, 2015 20:39
textFieldValue based on event delegation
function textFieldValue(parentElement, inputFieldSelector) {
return parentElement.asEventStream("keyup input").filter(isNotEnter).
merge(parentElement.asEventStream("cut paste").delay(1)).
merge(autofillPoller()).
map(getValue).toProperty(getValue()).skipDuplicates();
function getValue() {
var inputField = parentElement.find(inputFieldSelector)
return _.isEmpty(inputField) ? "" : inputField.val();
}
@auramo
auramo / gist:8182955
Created December 30, 2013 14:50
All for the lack of a horseshoe nail
For the lack of a nail,
throw new HorseshoeNailNotFoundException("no nails!");
For the lack of a horseshoe,
EquestrianDoctor.getLocalInstance().getHorseDispatcher().shoot();
For the lack of a horse,
RidersGuild.getRiderNotificationSubscriberList().getBroadcaster().run(
new BroadcastMessage(StableFactory.getNullHorseInstance()));
@auramo
auramo / gist:8347434
Created January 10, 2014 05:31
Command line flags for bash
#!/bin/bash
set -e
command="$1"
eka() {
local use_x_flag=false
while getopts ":x:" o; do
case "${o}" in
class WeeksAdapter(activity: Activity, dimensions: ScreenParameters) extends BaseAdapter {
val nowIndex = Integer.MAX_VALUE/2
val nowDateTime = new DateTime().withTimeAtStartOfDay
val nowWeek = nowDateTime.getWeekyear
def positionOfNow: Int = nowIndex
override def getCount: Int = Integer.MAX_VALUE
fi/allacca/WeeksAdapter;
I/System.out(20532): getView call with pos 0 count 1
I/System.out(20532): getView call with pos 1 count 2
I/System.out(20532): getView call with pos 2 count 3
I/System.out(20532): getView call with pos 3 count 4
I/System.out(20532): getView call with pos 4 count 5
I/System.out(20532): getView call with pos 5 count 6
I/System.out(20532): getView call with pos 6 count 7
I/System.out(20532): getView call with pos 7 count 8
I/System.out(20532): getView call with pos 8 count 9
D/ALLACCA (26924): elapsed time readEvents: 3716771 ns (3.716771 ms)
D/ALLACCA (26924): elapsed time groupBy: 7391823 ns (7.391823 ms)
D/ALLACCA (26924): elapsed time getDays: 4553697 ns (4.553697 ms)
D/ALLACCA (26924): elapsed time create daysWithEventsMap: 4560521 ns (4.560521 ms)
D/ALLACCA (26924): elapsed time filter which contents are new: 461042 ns (0.461042 ms)
D/ALLACCA (26924): elapsed time concatenating: 211146 ns (0.211146 ms)
D/ALLACCA (26924): elapsed time Id array creation: 2030520 ns (2.03052 ms)
D/ALLACCA (26924): elapsed time Fast(?) sort: 190313 ns (0.190313 ms)
D/ALLACCA (26924): elapsed time Construct new contents: 2500313 ns (2.500313 ms)
D/ALLACCA (26924): elapsed time Update model: 7531979 ns (7.531979 ms)