Skip to content

Instantly share code, notes, and snippets.

View eigenhombre's full-sized avatar

John Jacobsen eigenhombre

View GitHub Profile
(ns instaparsexample.core
(:require [instaparse.core :as i]))
(let [p (i/parser (slurp "example.bnf"))]
(for [ex ["1234"
"a"
"aab"
"nil"
"()"
"(())"
@eigenhombre
eigenhombre / core.clj
Created January 21, 2019 23:08
Histogramming stuff, e.g. from Sumo
(ns timings.core
(:gen-class)
(:require [com.hypirion.clj-xchart :as c]))
(defn bin-value
"
Convert value from xmin to xmax to a bin number (0..nbins-1)
"
[xmin xmax nbins x]
(int (Math/floor (* nbins
@eigenhombre
eigenhombre / core.clj
Last active January 24, 2019 15:40
WIP Minor Planets
(ns ephem.core
(:require [clj-http.client :as http]
[clojure.java.io :as io]
[clojure.string :as s]
[logplots.histo :as h]))
(def local-planet-file-name "planets.dat")
(defn cache-planets! []
(let [planets-url "https://minorplanetcenter.net/iau/MPCORB/MPCORB.DAT"
@eigenhombre
eigenhombre / buildings.clj
Created November 1, 2018 18:56
Parsing all buildings in the Microsoft US Building Footprint dataset (https://github.com/Microsoft/USBuildingFootprints/)
(ns buildings.core
(:require [clojure.java.io :as io]
[cheshire.core :as json])
(:gen-class))
(defn read-buildings-from-geojson [statefile]
(->> statefile
io/file
io/reader
line-seq
@eigenhombre
eigenhombre / README.md
Created August 5, 2018 12:38
Exporting your Mac addressbook to JSON using Python

You should pip install pyobjc first.

Keybase proof

I hereby claim:

  • I am eigenhombre on github.
  • I am eigenhombre (https://keybase.io/eigenhombre) on keybase.
  • I have a public key ASDwbU1xCvJguJP-Rlw_qEzhcN_1l3Sh4TaOX9T4AouEzwo

To claim this, I am signing this object:

@eigenhombre
eigenhombre / properties.clj
Last active November 13, 2023 14:53
Temporarily set Java System properties (Clojure macro)
(defmacro with-properties [property-map & body]
`(let [pm# ~property-map
props# (into {} (for [[k# v#] pm#]
[k# (System/getProperty k#)]))]
(doseq [k# (keys pm#)]
(System/setProperty k# (get pm# k#)))
(try
~@body
(finally
(doseq [k# (keys pm#)]
@eigenhombre
eigenhombre / lazystuff.clj
Created April 24, 2018 21:18
Teaching lazy sequences, etc. ... examples from Clojurepalooza
(def xs (vector 1 2 3))
(type xs)
(type (map str xs))
(type (map odd? xs))
(type (filter odd? (list 1 2 3)))
(first (map str (range)))
(take 10 (range))
(take 10 (map str (range)))
@eigenhombre
eigenhombre / perd2.clj
Last active May 3, 2018 20:59
Another simple in-progress counter/timer
(require '[clj-time.core :as t]
'[clj-time.coerce :as tc])
(defn perd2
"
Another in-progress timer, showing remaining time. Gradually reports
less and less often, with a maximum time between reports of one
minute.
@eigenhombre
eigenhombre / kinesis.clj
Last active October 26, 2023 21:10
AWS Kinesis example in Clojure: feeding and consuming streams using Amazonica
(ns example.kinesis
(:require [amazonica.aws.kinesis :as k]
[cheshire.core :as json]
[clj-time.coerce :as tc]
[clj-time.core :as t])
(:import [java.nio ByteBuffer]
[java.nio.charset Charset]))
(def my-stream-name "my-neato-stream")