Skip to content

Instantly share code, notes, and snippets.

;;from http://stackoverflow.com/questions/502753/programmatically-convert-a-video-to-flv
(defn readerRecurse
"calls .readPacket until there's nothing left to do2"
[reader]
(if (not (nil? (.readPacket reader))) ; here .readPacket actually does the processing as a side-effect.
true ; it returns null when it has MORE ro process, and signals an error when done...
(recur reader)))
(defn make-coll [x]
(cond
(coll? x) x
(nil? x) nil
:else (list x)))
(defn dragdrop [source-nodes target-nodes & {:keys [source-listeners target-listeners]}]
(let [source-group (goog.fx.DragDropGroup.)
target-group (goog.fx.DragDropGroup.)]
(doseq [source-node (make-coll source-nodes)]
;;Not an amazing name
(defn partition*
"Given a function that takes an input and returns a count n, will take an item from a sequence,
call f on it to get count n, add that input to a partition along with the next n items from the coll"
([f]
(fn [rf]
(let [part (volatile! [])
size (volatile! ::not-set)]
(fn
([] (rf) )
(defn zipmap+
"Like zipmap, except `tags` can contain the following:
keywords: treated like zipmap
A vector with a boolean value for it's first element:
the boolean dictates weather the rest of the values in the vector should put
into the parent map and processed.
A vector containing a function f followed by a single keyword k:
Unstaged
modified src/hoplon/core.cljs
@@ -23,6 +23,8 @@
(enable-console-print!)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Declare Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(declare elem! do! on! ->node $text add-children! attribute?)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Benchmarking [1 2]
hoplon 7.2 x 440,307 ops/sec ±3.15% (58 runs sampled)
array x 728,639 ops/sec ±3.30% (59 runs sampled)
transient x 565,336 ops/sec ±3.71% (56 runs sampled)
non-transient x 688,109 ops/sec ±4.14% (57 runs sampled)
Fastest is  #js [array]
=====================================================
Benchmarking [1 2 3 4 5]
hoplon 7.2 x 217,633 ops/sec ±3.22% (59 runs sampled)
(defn- child-vecV0
[this]
(let [x (.-childNodes this)
l (.-length x)]
(loop [i 0 ret (transient [])]
(or (and (= i l) (persistent! ret))
(recur (inc i) (conj! ret (.item x i)))))))
(defn- child-vecV1
[this]
(ns shadow-hoplon.perf
(:require [hoplon.core :as h]
[javelin.core :as j :refer [defc defc= cell cell=]]
[hoplon.jquery]))
(defc total-count 10000)
(defc change-count 100)
(defn get-color [n]
(cond
(def elems
["html" "head" "body"
"a" "abbr" "address" "area" "article" "aside" "audio" "b" "base" "bdi" "bdo" "blockquote" "br" "button" "canvas" "caption" "cite" "code" "col" "colgroup" "data" "datalist" "dd" "del" "details" "dfn" "dialog" "div" "dl" "dt" "em" "embed" "fieldset" "figcaption" "figure" "footer" "form" "h1" "h2" "h3" "h4" "h5" "h6" "header" "hgroup" "hr" "i" "iframe" "img" "input" "ins" "kbd" "keygen" "label" "legend" "li" "link" "main" "html-map" "mark" "menu" "menuitem" "html-meta" "meter" "multicol" "nav" "noframes" "noscript" "html-object" "ol" "optgroup" "option" "output" "p" "param" "picture" "pre" "progress" "q" "rp" "rt" "rtc" "ruby" "s" "samp" "script" "section" "select" "shadow" "small" "source" "span" "strong" "style" "sub" "summary" "sup" "table" "tbody" "td" "template" "textarea" "tfoot" "th" "thead" "html-time" "title" "tr" "track" "u" "ul" "html-var" "video" "wbr"])
(defmacro def-all-hoplon-elems!!! [& {:keys [exclude rename]}]
`(do
~@(for [el# (remove (set (map nam
@jjttjj
jjttjj / core.clj
Last active December 14, 2018 19:35
A minimum viable Interactive Brokers client from clojure with no dependencies!
(ns iboga.core
(:require [clojure.string :as str])
(:import [java.io BufferedReader DataInputStream DataOutputStream IOException]
[java.net InetSocketAddress Socket SocketException]
java.nio.ByteBuffer
java.nio.charset.StandardCharsets))
(defn socket-open? [socket]
(not (or (.isClosed socket) (.isInputShutdown socket) (.isOutputShutdown socket))))