Skip to content

Instantly share code, notes, and snippets.

View sunilnandihalli's full-sized avatar

Sunil S Nandihalli sunilnandihalli

  • Sunnyvale
View GitHub Profile
(defn h [x] (map-indexed #(into [%1] %2) (partition 1 (shuffle x))))
(def win-ids (h [0 1 1 2 3 4]))
(def impression-ids (h [0 0 0 1 1 1 3 3 5 6 6]))
(def click-ids (h [0 1 2 5 2 2]))
(defaggregatefn safe-sum
([] 0)
([total val] (+ total (or val 0)))
([total] [total]))
(defn tt1 []
(let [wins-q (<- [?bid-id ?wins] (win-ids _ ?bid-id) (c/count :> ?wins))
Hello, This is a test gist...!
Hello everybody,
I am trying to get a simple java code (about 10 lines in clojure )
which uses jReality ported to clojure. This is my attempt has been
kind of half way successfull. The corresponding github-repo link is
git://github.com/sunilnandihalli/jRealityTutorial.git
The project is nicely set up to work with leiningen .. so simple
"lein deps && lein native-deps" should get it started. after that I
just execute the sexp in the emacs editor. When the code runs, it
opens the ui and shows what is intended in a rather unpleasing way
with the flickers and all. when I look at the terminal output it tells
(ns giws-clj.core
(:require [clojure.contrib.lazy-xml :as xml])
(:use [clojure.contrib.trace :as trace]))
(defn emit-giws-xml [c]
(let [package (.getPackage c)
methods (map #(hash-map :name (.getName %)
:returnType (str (.getName (.getReturnType %)))
:params (map (fn [p] {:name (.getName %)})
(.getParameterTypes %)))
(.getMethods c))]
sunil@eagle ~/work/clojure/expcake#cake deps
/var/lib/gems/1.9.1/gems/cake-0.4.18/bin/cake:399: warning: Insecure world writable dir /home/sunil in PATH, mode 040777
[pom] creating pom.xml
[deps] Fetching dependencies...
[deps] Copying 1 file to /home/sunil/work/clojure/expcake/build/lib
[deps] Deleting directory /home/sunil/work/clojure/expcake/lib
[deps] Attempting to rename dir: build/lib to lib
[deps] Restarting project jvm.
[deps] /bin/cake:9:in `require': no such file to load -- rubygems (LoadError)
[deps] from /bin/cake:9
(mathematica-eval "D[x*x+y*x,x]") returns => (+ (* 2 x) y)
(math (Variables (+ (* 2 x) y))) returns => [x y]
(math (Variables (mathematica-eval "D[x*x+y*x,x]")))
it is a combination of first and second sexps...
-> gives an error ...
I guess I need to do so me macro and symbolic thing .. bu I am unable to figure it out.. can anybody help?
(defmacro hello [x]
`(sayhello ~x))
(macroexpand-1 (apply-macro hello [10]))
@sunilnandihalli
sunilnandihalli / letd.clj
Created November 25, 2010 07:44
a macro to help in debugging code in let form...
(ns letd
(:require [clojure.contrib.macro-utils :as m]))
(defmacro with-seperator [& body]
(let [line '(println (apply str (repeat 61 "-")))]
`(m/symbol-macrolet [sep ~line]
(m/with-symbol-macros
(do sep (let [x# (do ~@body)] sep x#))))))
(defmacro display-local-bindings []
@sunilnandihalli
sunilnandihalli / symbol-macro-problem.clj
Created November 26, 2010 04:53
a small example demonstrating the problem with symbol macros..
(ns symbol-macro-problem
(:require [clojure.contrib.macro-utils :as m]))
(defmacro sym-macro [& body]
`(m/symbol-macrolet [begin :begin
end :end]
(println begin)
~@body
(println end)))
@sunilnandihalli
sunilnandihalli / debug-macros.clj
Created November 28, 2010 08:30
a few macros to help in debugging
(defmacro print-and-return
([x]
`(let [x# ~x]
(println x#) x#))
([flag x]
`(let [flag# '~flag
x# ~x]
(println flag#)
(println x#)
x#)))