Skip to content

Instantly share code, notes, and snippets.

Something something = object.getSomething();
if (something != null) {
SomeType[] someArray = something.getSomeArray();
if (someArray != null) {
for (SomeType some : someArray) {
// call f(some)
}
}
@fdaoud
fdaoud / TimeTypeConverter.java
Created April 30, 2012 17:11
TimeTypeConverter
public class TimeTypeConverter extends DateTypeConverter {
private static final String[] TIME_FORMAT = { "HH:mm" };
@Override
protected String[] getFormatStrings() {
return TIME_FORMAT;
}
}
@fdaoud
fdaoud / gist:1339865
Created November 4, 2011 17:07
Clojure - generating a random password
(defn random-letter []
(-> (rand-int 26) (+ 97) char))
(defn random-digit []
(rand-int 10))
; for example, (generate-random-password "a1aa1a11") returns something like "z5qr9s42"
(defn generate-random-password [spec]
(-> #(if (= % \a) (random-letter) (random-digit)) (map spec) (apply str)))
(defn swap-keys [map key1 key2]
(assoc map key1 (map key2) key2 (map key1)))
public Map swapKeys(Map map, Object key1, Object key2) {
Object val1 = map.get(key1);
map.put(key1, map.get(key2);
map.put(key2, val1);
return map;
}
(fn [init & args]
(reduce
(fn [a [f b]] (f a b))
init (partition 2 args)))
@fdaoud
fdaoud / gist:1320378
Created October 27, 2011 18:25
Ball of mud
(let [
rnd (send-command "status" "getPredictionRnd")
latest-rnd (send-command "prediction" "getLatestPredictionRnd" {:pooler_id pooler_id :sheet rnd})
preds (send-command "prediction" "getPredictionsForMatchups" {:pooler_id pooler_id :sheet rnd :rnd latest-rnd})]
(if (or (nil? rnd) (= rnd 0))
{:errors "rnd_is_nil_or_zero"}
(get-matchups
(cond
(seq preds) preds
(= rnd 1) (.query persistence "team_playoffs" {})
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.8</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>