Skip to content

Instantly share code, notes, and snippets.

View halgari's full-sized avatar

Timothy Baldridge halgari

View GitHub Profile
(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
(def ^:dynamic *counters*)
(defn new-counter [name]
"Creates a pair of LongAdders"
...)
(defn get-counter [name]
(if-let [ctr (get *counter* name]
ctr
;;;
(->> actors
(map (partial get-data server-pool))
(filter #(> (:age %) 42))
(map :name)
set)
(into #{}
(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))
(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 March 2, 2017 23:57
Word Count (MMap)
;; 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))
(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 May 11, 2024 02:23
What I want from a Type System
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
(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))
(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))