Skip to content

Instantly share code, notes, and snippets.

View slagyr's full-sized avatar

Micah Martin slagyr

  • Clean Coders, LLC
  • Scottsdale, AZ
View GitHub Profile
one.rb -------------------
Java::Main.thing = "thing1"
two.rb -------------------
thing = Java::Main.thing
puts "thing: #{thing}"
puts "thing.class: #{thing.class}"
one.rb -------------------------------------
$GLOBAL = "ONE"
class Foo
def global
return "#{__FILE__}:GLOBAL = #{$GLOBAL}"
end
end
foo = Foo.new
(defproject lein_issue "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.1.0"]
[org.clojure/clojure-contrib "1.1.0"]
[compojure "0.4.0-SNAPSHOT"]
[ring/ring-jetty-adapter "0.2.0"]]
:main lein_issue.core)
(ns lein_issue.core
(:use compojure.core
ring.adapter.jetty))
(defroutes silly-routes
(ANY "*" []
"<h1>Howdy</h1>"))
(run-jetty silly-routes {:port 8080})
Output when run from command line:
......................................................................
Finished in 0.69600 seconds
70 examples, 0 failures
Output when run through eval-in-project:
......................................................................
Finished in 0.69600 seconds
bludgeon:speclj micahmartin$ lein javac
Exception in thread "main" java.lang.ClassCastException (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:5440)
at clojure.lang.Compiler.eval(Compiler.java:5391)
at clojure.core$eval.invoke(core.clj:2382)
at clojure.main$eval_opt.invoke(main.clj:235)
at clojure.main$initialize.invoke(main.clj:254)
at clojure.main$script_opt.invoke(main.clj:270)
at clojure.main$main.doInvoke(main.clj:354)
at clojure.lang.RestFn.invoke(RestFn.java:458)
bludgeon:speclj micahmartin$ lein jar
Exception in thread "main" java.lang.ExceptionInInitializerError (NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:5440)
at clojure.lang.Compiler.eval(Compiler.java:5415)
at clojure.lang.Compiler.eval(Compiler.java:5391)
at clojure.core$eval.invoke(core.clj:2382)
at clojure.main$eval_opt.invoke(main.clj:235)
at clojure.main$initialize.invoke(main.clj:254)
at clojure.main$null_opt.invoke(main.clj:279)
at clojure.main$main.doInvoke(main.clj:354)
@slagyr
slagyr / gist:950574
Created May 1, 2011 15:22
Game of Life in 8 lines of Clojure
(defn neighbors-of [cell]
(set (for [dx [-1 0 1] dy [-1 0 1] :when (not (= [dx dy] [0 0]))]
[(+ dx (first cell)) (+ dy (second cell))])))
(defn alive? [[cell freqs] world]
(or (and (= 2 freqs) (contains? world cell)) (= 3 freqs)))
(defn tick [world]
(let [frequencies (frequencies (reduce #(concat %1 (neighbors-of %2)) [] world))]
(set (keys (filter #(alive? % world) frequencies)))))
@slagyr
slagyr / gist:967151
Created May 11, 2011 19:36
Prime Factors in Ruby
module PrimeFactors
def self.of(n)
factors = []
divisor = 2
while n > 1
while n % divisor == 0
factors << divisor
n /= divisor
end
@slagyr
slagyr / gist:967161
Created May 11, 2011 19:39
Prime Factors in Clojure
(ns prime-factors)
(defn factors-of [n]
(loop [factors [] divisor 2 n n]
(if (<= n 1)
factors
(if (= 0 (rem n divisor))
(recur
(conj factors divisor)
divisor