Skip to content

Instantly share code, notes, and snippets.

View joelittlejohn's full-sized avatar

Joe Littlejohn joelittlejohn

View GitHub Profile
@zentrope
zentrope / number-format.cljs
Created December 22, 2016 03:07
A comma for thousands separator in Clojurescript using goog closure libs.
(ns client.ui
(:require
[goog.i18n.NumberFormat.Format])
(:import
(goog.i18n NumberFormat)
(goog.i18n.NumberFormat Format)))
(def nff
(NumberFormat. Format/DECIMAL))
@joelittlejohn
joelittlejohn / staqueue.clj
Last active August 29, 2015 13:56
The Staqueue, Coding for Interviews Issue #20
;; Building a functional queue using two stacks
;; We'll use vectors for our stacks, 'push' == conj
(def ^:private push conj)
;; We'll need be able to fill one stack from another
(defn ^:private refill
[s1 s2]
(if (empty? s1)
s2
@Timmmm
Timmmm / lastfm_to_gmusic.py
Last active June 1, 2018 12:43
Convert Last.fm loved tracks to your Google Play Store Music Play All Access Subscription Service by Google™. It creates a new playlist rather than adding the tracks to your library willy-nilly. See code for more details.
#!/usr/bin/env python
# Lastfm loved tracks to Google Music All Access playlist. As noted in the comments you do need the All Access subscription thing otherwise it will always find 0 songs.
#
# Written by Tim Hutt, tdhutt@gmail.com, based on this script:
#
# https://gist.github.com/oquno/3664731
#
# Today is the 15th of September 2013.
#
@joelittlejohn
joelittlejohn / merge_ascii.clj
Created July 31, 2013 19:02
Merge two ascii (art) files like image layers, treating spaces as transparent.
(ns merge-ascii
(:require [clojure.java.io :refer [reader writer]]))
(defn choose-char [a b]
(cond (nil? a) b
(nil? b) a
(not= b \space) b
:else a))
(defn merge [a b out]
@joelittlejohn
joelittlejohn / generate-changelog.sh
Last active March 4, 2021 18:50
Instant CHANGELOG.md from your GitHub issues
#!/usr/bin/env bash
# Generates this kind of thing:
# https://github.com/joelittlejohn/jsonschema2pojo/blob/master/CHANGELOG.md
#
# If your issue has 'breaking' label, the issue will be shown in the changelog with bold text
#
# All versions of this script are dedicated to the Public Domain, no rights reserved,
# as per https://creativecommons.org/publicdomain/zero/1.0/
#
if [ "$#" -ne 2 ]; then
@joelittlejohn
joelittlejohn / trie.clj
Last active May 25, 2020 14:59
Trie for auto-complete (or: how to implement auto-complete in 4 lines of Clojure)
(def t
"trie containing the 100,000 most common english words"
(with-open [r (clojure.java.io/reader "/tmp/words-100000")]
(reduce #(assoc-in %1 %2 (sorted-map \0 nil)) (sorted-map) (line-seq r))))
(defn search [p m]
"return a sorted sequence of all words in the trie m that start with the given prefix p"
(let [n (get-in m p)
next (mapcat #(search (str p (key %)) m) (dissoc n \0))]
(if (contains? n \0) (cons p next) next)))
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active April 2, 2024 15:59
shell/bash generate random alphanumeric string
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs