Skip to content

Instantly share code, notes, and snippets.

(let [f (future (do (Thread/sleep 1200) 2))]
(or (deref f 1000 nil) (.cancel f true)))
if(someObject instanceOf someClass){
// specific behaviour for someClass
} else if (someObject instanceOf someOtherClass) {
// specific behaviour for someOtherClass
} // ... ad nauseam
(defn some-fn [some-param]
some-param)
(map seq [(.getBytes (String. "12") "UTF-8") (.getBytes (String. "12") "ISO-8859-1") (.getBytes (String. "12") "US-ASCII")])
-> ((49 50) (49 50) (49 50))
@mknoszlig
mknoszlig / gist:3497499
Created August 28, 2012 11:53
Tying protocols together via the generated java interface...
(ns my.behavior)
;;
;; implementing SupportMyBehavior (3 args) is sufficient to also have
;; support for the behavior given some config record MyConfig.
;;
;; Protocols
;;
(for [v value-list]
(map #(apply % v) fn-list))
>> dt = DateTime.parse('Tue, 03 Jul 2012 14:13:16 CEST +02:00')
=> Tue, 03 Jul 2012 14:13:16 +0200
>> tz = Time.zone.parse('Tue, 03 Jul 2012 14:13:16 CEST +02:00')
=> Tue, 03 Jul 2012 16:13:16 CEST +02:00
>> tz2 = Time.zone.parse('Tue, 03 Jul 2012 14:13:16 CEST +02:00')
=> Tue, 03 Jul 2012 16:13:16 CEST +02:00
>> dt <=> tz
=> -1
>> tz <=> tz2
=> 0
2012-06-06 21:10:09
Full thread dump OpenJDK 64-Bit Server VM (19.0-b09 mixed mode):
"Attach Listener" daemon prio=10 tid=0x000000000282b800 nid=0x238d waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Swank REPL Thread" prio=10 tid=0x00007faa18013000 nid=0x2080 waiting on condition [0x00007faa1ed56000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x0000000784710bf8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
java.lang.RuntimeException: who is using this????
at org.jruby.RubyGlobal$NonEffectiveGlobalVariable.get(RubyGlobal.java:421)
at org.jruby.Ruby$3.getValue(Ruby.java:2287)
at org.jruby.internal.runtime.GlobalVariables.get(GlobalVariables.java:111)
at org.jruby.embed.variable.LocalGlobalVariable.retrieve(LocalGlobalVariable.java:94)
at org.jruby.embed.variable.VariableInterceptor.retrieve(VariableInterceptor.java:157)
at org.jruby.embed.internal.BiVariableMap.retrieve(BiVariableMap.java:373)
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:122)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:90)
at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:153)
@mknoszlig
mknoszlig / gist:2659381
Created May 11, 2012 12:39
cascalog - joining and filtering at the same time...
;given the following data:
(def users
; [id, name]
[[1, "amy"]
[2, "doug"]
[3, "ben"]])
(def messages
; [row-id, user-id, medium]