This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; based on the discussion at https://groups.google.com/d/msg/netty/mcGswAZ5NeQ/ivG9snRSFy4J | |
(ns netty4.core | |
(:import [io.netty.bootstrap AbstractBootstrap ServerBootstrap] | |
[io.netty.channel ChannelFuture ChannelInitializer ChannelOption | |
ChannelHandlerContext ChannelInboundHandlerAdapter ChannelHandler] | |
[io.netty.handler.logging LogLevel LoggingHandler] | |
io.netty.buffer.ByteBuf | |
io.netty.channel.socket.SocketChannel | |
io.netty.channel.nio.NioEventLoopGroup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def c (finite-frame (prefix :int16) | |
[:uuid :int32 (repeated (finite-frame (prefix :int16) (string :utf8)) :prefix :none)])) | |
(def p (encode c [:uuid 1000 ["ass" "hole"]])) | |
(let [fp (contiguous p) | |
s (.limit fp) | |
arr (.array fp)] | |
(doseq [i (range s)] | |
(print (aget arr i) " "))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def chopped-codec | |
(finite-frame | |
(prefix :int32) | |
[:uuid :int32 (repeated (finite-frame (prefix :int16) (string :utf8)) :prefix :none)])) | |
(def response-chopped-codec | |
(finite-frame | |
(prefix :int32) | |
[:uuid :int32 (repeated :int64 :prefix :none)])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(run | |
"let count = proc(val) -(0, -(-1, val)) % perform the actual counting on church-numerlas | |
in let to-num = proc(n) ((n count) 0) % convert from church numerals to num-val | |
in let next = proc(n) proc(f) proc(x) (f ((n f) x)) % standard church numerals implementations using LC | |
in let mult = proc(m) proc(n) proc(x) (m (n x)) % multiplication in terms of CN | |
in let zero = proc(f) proc(x) x % some constants | |
in let one = proc(f) proc(x) (f x) | |
in let two = proc(f) proc(x) (f (f x)) | |
in let three = (next two) | |
in let four = ((mult two) two) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defroutes app-routes | |
(GET "/" [] ) | |
(GET ["/shlomi/:id/:name" :id #"[0-9]+" :name #"[a-zA-Z]+"] [id name] (str id name)) | |
(GET "/test" [] (html5 [:head | |
[:title "YO"] | |
[:body | |
[:h1 "Yo!"] | |
(text-field "test" "whats in here")]])) | |
(route/resources "/") | |
(route/not-found "Not Found")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn first-out [& fns] | |
(let [fs (atom []) | |
terminate (fn [] (println "cancling..") (doall (map future-cancel @fs)))] | |
(reset! fs (doall | |
(map (fn [x] (future-call #((x) (terminate)))) fns ))))) | |
(defn wait-for [n s] | |
(fn [] (print "start...") (flush) (Thread/sleep n) (print s) (flush))) | |
(first-out (wait-for 1000 "long") (wait-for 500 "short")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn first-out [& fns] | |
(let [fs (atom []) | |
ret (promise) | |
terminate (fn [x] (println "cancling.." ) (doall (map future-cancel @fs)) (deliver ret x))] | |
(reset! fs (doall | |
(map (fn [x] (future-call #(terminate (x)))) fns ))) | |
@ret | |
)) | |
(defn wait-for [n s] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load the entire file, and call it fs (all lazy) | |
val fs = sc.textFile("/data01/fs.txt") | |
// lets find all lines that contains the string "song", and cache that data source | |
val songs = fs.filter(x=>x.toLowerCase.contains("song")).cache | |
// now that we are trying to count, all the previous lazy computations will have to get realized, so this will take about 85 | |
// seconds to complete, but then it will be completly cached. | |
songs.count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '(criterium [core :as q])) | |
(def ranges [-1 2 5 10 20 40 80 500 1500 Long/MAX_VALUE]) | |
(defn create-partitioner | |
"returns a function that accepts a number, and returns i if the number is between h(igh) and l(ow) | |
otherwise returns nil" | |
[l h i] (fn [v] (if (and (<= v h) (> v l)) i nil) )) | |
(defn part |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns netty4.core | |
(:import [io.netty.bootstrap AbstractBootstrap ServerBootstrap] | |
[io.netty.channel ChannelFuture ChannelInitializer ChannelOption | |
ChannelHandlerContext ChannelInboundHandlerAdapter ChannelHandler] | |
[io.netty.handler.logging LogLevel LoggingHandler] | |
io.netty.buffer.ByteBuf | |
io.netty.channel.socket.SocketChannel | |
io.netty.channel.nio.NioEventLoopGroup | |
io.netty.channel.socket.nio.NioServerSocketChannel | |
java.util.concurrent.atomic.AtomicInteger) |
OlderNewer