Skip to content

Instantly share code, notes, and snippets.

View scotthaleen's full-sized avatar
λ

スコット scotthaleen

λ
View GitHub Profile
@scotthaleen
scotthaleen / vimium-emacs.md
Created January 8, 2016 17:50
Emacs-Style Key Bindings for Vimium

My Vimium Key Bindings (Emacs-Style)

This is a full set of key bindings (as of Vimium v1.45); covering all Vimium functionality. I have tried to map all Vimium functionality to comparable Emacs functionality (whenever possible). In cases where there is no equivalent, those commands are prefixed by <c-g> (indicating <c-g>oogle Chrome; and because <c-g> does not conflict with other Emacs shortcuts at all).

Commented Shortcuts: There are a few Emacs-style shortcuts that are simply not possible in Vimium. All of my shortcuts (including those which were not possible; i.e. where I used a decent alternative) have been commented below. This should help to clarify my rationale.

_Compatibility: All of these shortcuts were tested on Mac OS X (Mavericks). Please note that all of my shortcuts operate under the assumption that your Emacs Meta key is the Alt/Option key. This really was my only choice, because the key is already used in Chrome for shortcuts that c

@scotthaleen
scotthaleen / ConsCarCdr.js
Created February 10, 2016 16:31
JavaScript implementation of cons, car and cdr
function cons(x, y) {
return function(w) { return w(x, y) };
};
function car(z) {
return z(function(x, y) { return x });
};
function cdr(z) {
return z(function(x, y) { return y });
@scotthaleen
scotthaleen / GIF-Screencast-OSX.md
Created March 14, 2016 14:55 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@scotthaleen
scotthaleen / curry.clj
Created August 11, 2016 21:31 — forked from sunilnandihalli/curry.clj
a macro to create fixed-arity curryable function in clojure
(defmacro def-curry-fn [name args & body]
{:pre [(not-any? #{'&} args)]}
(if (empty? args)
`(defn ~name ~args ~@body)
(let [rec-funcs (reduce (fn [l v]
`(letfn [(helper#
([] helper#)
([x#] (let [~v x#] ~l))
([x# & rest#] (let [~v x#]
(apply (helper# x#) rest#))))]
@scotthaleen
scotthaleen / cut.clj
Created August 12, 2016 21:59 — forked from ghoseb/cut.clj
Cut macro from SRFI-26 in Clojure
;;; http://srfi.schemers.org/srfi-26/srfi-26.html
(defn ^:private cut*
[[a f] form]
(cond
(nil? form) [a f]
(seq? (first form))
(let [[arg-list xform] (cut* [[] '()] (first form))]
(recur [(reduce conj a arg-list) (concat f (list xform))] (next form)))
@scotthaleen
scotthaleen / parsing_json.clj
Created September 9, 2016 19:44
json to clojure keyword map
(ns clean.json
(:require
[clojure.data.json :as json]
[clojure.string :as s])
(:refer-clojure :exclude [read read-string]))
(defn key->keyword [key-string]
(-> key-string
(s/replace #"([a-z])([A-Z])" "$1-$2")
(s/replace #"([A-Z]+)([A-Z])" "$1-$2")
@scotthaleen
scotthaleen / clojure_classpath.clj
Created September 15, 2016 20:46
Get a list of what is on the classpath
(->> (ClassLoader/getSystemClassLoader)
.getURLs
(map #(.getFile %)))
;; Add a filter
(->> (ClassLoader/getSystemClassLoader)
.getURLs
(map #(.getFile %))
(filter #(clojure.string/includes? % "resources")))
@scotthaleen
scotthaleen / stream_to_bytes.clj
Created October 20, 2016 21:15
Clojure: read an io/stream to a byte array
(require '[clojure.java.io :as io])
(def fp "/path/to/file")
(defn stream->bytes [is]
(loop [b (.read is) accum []]
(if (< b 0)
accum
(recur (.read is) (conj accum b)))))
@scotthaleen
scotthaleen / smallest_jpg_bytes.txt
Last active February 21, 2026 01:54
Smallest Valid JPG
# http://web.archive.org/web/20111224041840/http://www.techsupportteam.org/forum/digital-imaging-photography/1892-worlds-smallest-valid-jpeg.html
FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 00 48 00 48 00 00 FF DB 00 43 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF C2 00 0B 08 00 01 00 01 01 01 11 00 FF C4 00 14 10 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF DA 00 08 01 01 00 01 3F 10
# Base64 Encoded
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wgALCAABAAEBAREA/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxA=
@scotthaleen
scotthaleen / flatten_html.clj
Created November 5, 2016 19:28
Flatten HTML
;;include [clj-tagsoup "0.3.0"]
(require '[pl.danieljanus.tagsoup :as tags])
;; each node's structure is as such
;; [:tag attr-map node node ....]
(defn flatten [x]
(tree-seq (comp keyword? first) (partial drop 2) x))