Skip to content

Instantly share code, notes, and snippets.

Avatar

Timothy Baldridge halgari

View GitHub Profile
View truffle-in-clojure.clj
(ns morel.core
(:import (com.oracle.truffle.api.nodes RootNode NodeInfo Node$Child))
(:require [clojure.interop :refer [defclass]]
[clojure.reflect :as reflect]))
(defclass
^{NodeInfo {:language "SL"
:description "The root of all SL execution trees"}}
SLRootNode [language
frame-descriptor
View gist:71dd5cfd8234a982a11e48d2aac003b0
(def ^:dynamic *counters*)
(defn new-counter [name]
"Creates a pair of LongAdders"
...)
(defn get-counter [name]
(if-let [ctr (get *counter* name]
ctr
View xducer.clj
;;;
(->> actors
(map (partial get-data server-pool))
(filter #(> (:age %) 42))
(map :name)
set)
(into #{}
View gist:a874b5e8e281c3e4afe51c0249b31811
(defn unordered-pmap [threads f in-c out-c]
(let [remain (atom threads)]
(dotimes [x threads]
(go-loop []
(if-some [v (<! in-c)]
(do (>! out-c (f v))
(recur))
View join.clj
(def data {:cards
[{:id "card-1", :idList "list-id-1", :name "Task 1"}],
:lists
[{:id "list-id-1", :name "List 1"}
{:id "list-id-2", :name "List 2"}]})
(vec (o/for-query
(o/and
(d/query-in data _ [:lists _] ?list-item)
(d/query data ?list-item :id ?list-id)
@halgari
halgari / word-count.clj
Created Mar 2, 2017
Word Count (MMap)
View word-count.clj
;; On my box, wc processes the 11GB JSON file in 50sec
;; This code does it in 11sec
;; Compiled with lein uberjar, and run with java -server -jar word-count-STANDALONE.jar
(ns word-count.core
(:import (java.io RandomAccessFile File)
(java.nio.channels FileChannel$MapMode)
(java.nio ByteBuffer))
(:gen-class))
View gist:ac93675c26109e5604057b9de3da85d3
(defn my-dsl-fn
([mp]
... do stuff with map ...
([k v & {:as mp}]
(my-dsl-fn (assoc mp k v))))
@halgari
halgari / gist:f431b2d1094e4ec1e933969969489854
Last active Aug 29, 2019
What I want from a Type System
View gist:f431b2d1094e4ec1e933969969489854
The question was asked why I (as a programmer who prefers dynamic languages) don't consider static types "worth it". Here
is a short list of what I would need from a type system for it to be truely useful to me:
1) Full type inference. I would really prefer to be able to write:
(defn concat-names [person]
(assoc person :full-name (str (:first-name person)
(:second-name person))))
And have the compiler know that whatever type required and produced from this function was acceptible as long as the
View fn-fx-3d.clj
(ns other-examples.shapes-3d
(:require [fn-fx.fx-dom :as dom]
[fn-fx.diff :refer [component defui render should-update?]]
[fn-fx.controls :as ui]))
(def red (ui/color :red 1 :blue 0 :green 0))
(def green (ui/color :red 0 :blue 0 :green 1))
(def blue (ui/color :red 0 :blue 1 :green 0))
(def grey (ui/color :red 0.5 :blue 0.5 :green 0.5))
View gist:9b83e28b180e32d003380db94f4d1744
(ns other-examples.shapes-3d
(:require [fn-fx.fx-dom :as dom]
[fn-fx.diff :refer [component defui render should-update?]]
[fn-fx.controls :as ui]))
(def red (ui/color :red 1 :blue 0 :green 0))
(def green (ui/color :red 0 :blue 0 :green 1))
(def blue (ui/color :red 0 :blue 1 :green 0))
(def grey (ui/color :red 0.5 :blue 0.5 :green 0.5))