Skip to content

Instantly share code, notes, and snippets.

View mpenet's full-sized avatar
🪲
breeding bugs

Max Penet mpenet

🪲
breeding bugs
View GitHub Profile
(apply str (map #(format "%02x" (bit-and % 0xff))
(.digest (doto (MessageDigest/getInstance "MD5")
(.update (.getBytes input))))))
(defprotocol PFoo
(foo [x]))
(extend-protocol PFoo
Keyword
(foo [x]
"Keyword")
js/Object
(defprotocol JSCodec
(clj->js [x])
(key->js [x])
(js->clj [x][x options]))
(extend-protocol JSCodec
default
(key->js [k]
(if (coll? k)
(prn-str k)
mpenet@thinkbox:~/gitmu/clojurescript(feature-codecs)$ ./script/test
Exception in thread "main" java.lang.NoClassDefFoundError: clojure/main
Caused by: java.lang.ClassNotFoundException: clojure.main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: clojure.main. Program will exit.
user> (scaffold clojure.lang.ISeq)
clojure.lang.ISeq
(next [this])
(cons [this G__30361])
(first [this])
(more [this])
clojure.lang.IPersistentCollection
(count [this])
(cons [this G__30362])
(empty [this])
@mpenet
mpenet / gist:4139088
Created November 24, 2012 10:01
monads! (kind of)
;; Examples based on code in https://github.com/ibdknox/jayq/tree/let-deferred
;; sugar for do-> ajax-m
(let-ajax [a {:url "http://localhost:8000/1.json"
:dataType :json}
b {:dataType :json :url "http://localhost:8000/2.json"}]
(utils/log a)
(utils/log b))
;; sugar for do-> deferred-m
(extend-type js/Object
IFn
(-invoke [this s]
(re-matches this s)))
java.lang.UnsupportedOperationException: nth not supported on this type: Symbol
(extend-type js/Object
@mpenet
mpenet / gist:5141349
Last active October 16, 2018 16:59
playing with hayt api
{:drop-index :foo}
{:drop-keyspace :foo}
{:drop-table :foo}
{:select (#qbits.hayt.cql.CQLFn{:name COUNT, :args (:*)}), :from :foo}
{:select (:*), :from :foo, :where {:ts #qbits.hayt.cql.CQLFn{:name now, :args nil}}}
{:select (#qbits.hayt.cql.CQLFn{:name WRITETIME, :args (:bar)}), :from :foo}
{:select (#qbits.hayt.cql.CQLFn{:name TTL, :args (bar)}), :from :foo}
{:select (#qbits.hayt.cql.CQLFn{:name unixTimestampOf, :args (bar)} #qbits.hayt.cql.CQLFn{:name dateOf, :args (:bar)}), :from :foo}
{:select (:*), :from :foo, :where {#qbits.hayt.cql.CQLFn{:name token, :args (:user-id)} [#<core$_GT_ clojure.core$_GT_@6177060f> #qbits.hayt.cql.CQLFn{:name token, :args (tom)}]}}
{:select (:*), :from :foo, :where {:ts #qbits.hayt.cql.CQLFn{:name now, :args nil}}}
(use 'clojure.core.typed)
;; I would like to only allow {:a 1} {:b 2} or {:a 1, :b 2}
(def-alias A '{:a '1})
(def-alias B '{:b '2})
;; naive version would be to use a Union
(ann foo [(U A B) -> (Value 1)])
(defn foo [x] 1)
(defn foo [x] (apply str x))
(ann foo [(U (Vector* String)
(Seq* String)
(List* String))
-> String])
user> (cf (foo ["a" "b"]))
>> java.lang.String