Skip to content

Instantly share code, notes, and snippets.

View favila's full-sized avatar

Francis Avila favila

View GitHub Profile
@favila
favila / git-squash.sh
Created February 24, 2014 05:40
git-squash: script to create a squashed patch from a branch.
#! /bin/sh
# Produce a squash-commit patch from a branch of changes
MASTER=$1
PATCHBRANCH=$2
SQUASHBRANCH="$PATCHBRANCH-squash"
MESSAGE=$3
git checkout -b $SQUASHBRANCH $MASTER &&
git merge --squash $PATCHBRANCH &&
git commit -a -m "$MESSAGE" &&
@favila
favila / murmur3_32.js
Last active August 29, 2015 13:56
Port just enough of Murmur3 32bit to javascript for clojurescript. Goal is to produce identical results and capabilities as this class: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Murmur3.java
/**
* Javascript port of Clojure's flavor of Murmur3.
* See https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Murmur3.java
*
* Find at: https://gist.github.com/favila/9088146
* By favila (Francis Avila) 2014-02-19
*/
goog.provide('cljs.lang.murmur3');
goog.require('cljs.core');
@favila
favila / breeze.util.uuid.clj
Created February 17, 2014 03:27
Generate version 5 (sha1-based) uuids in clojure.
(ns breeze.util.uuid
"Utilities for generating version 5 (SHA-1 hashing) uuids.
This implementation should conform to RFC 4122, section 4.3.
Includes shortcuts for generating uuids for breeze rule hashes."
(import java.security.MessageDigest
java.util.UUID
java.nio.ByteBuffer
java.nio.charset.StandardCharsets))
(def rule-namespace-uuid
@favila
favila / unique.py
Created January 28, 2014 05:29
Various ways to test if all members of a collection are unique in Python 2.7, with timing harness.
import re
import array
import collections
import bisect
re_dup_g = re.compile(r'(.).*\1', re.DOTALL)
re_dup_ng = re.compile(r'(.).*?\1', re.DOTALL)
def isunique_reg(s, search=re_dup_g.search):
@favila
favila / defenum.clj
Last active December 29, 2015 01:29
Macro to define a google closure compiler enum from clojurescript.
(ns defenum
(:require [clojure.string :as str]
cljs.compiler))
(defn unzip
([s] (unzip 2 s))
([n s] (apply map vector (partition n s))))
(defmacro jso
"Like js-obj, except the keys are emitted as unquoted munged symbols. Keys
@favila
favila / git-archive-branch.sh
Created October 2, 2013 20:22
git-archive-branch.sh Replace a git branch with an archived tag.
#!/bin/sh
# git-archive-branch.sh
#
BRANCHNAME=
PUSH=
usage() {
cat 1>&2 << EOF
usage: $(filename $0) [-p] [-h] BRANCHNAME
@favila
favila / parallel-chan-map.clj
Created September 19, 2013 14:32
parallel-chan-map: Read in-chan and put result of `(apply f in-chan-value args)` on out-chan, running items in "parallel" and yielding results out-of-order. Works with Clojure or Clojurescript.
(ns parallel-chan-map
(:require-macros [cljs.core.async.macros :refer (go alt!)])
(:require [cljs.core.async :refer (>! close! put! chan )]))
(defn parallel-chan-map
"Read in-chan and put result of `(apply f in-chan-value args)` on out-chan,
potentially running items in parallel and yielding results out-of-order.
Function f must return something takeable (e.g. a go-block, channel, promise),
in essence spawning a \"subprocess\" which this function manages as a pool
@favila
favila / subclass.cljs
Last active December 20, 2015 20:19
Attempts at creating clean subclasses (with closure compiler annotations) in clojurescript with macros
(ns subclass
(:require [clojure.string :as string]))
;;TODO: definterface
; :closure/const
; :const
; :closure/constructor
; :closure/depreciated
@favila
favila / b64longs.clj
Created August 7, 2013 02:12
Encode and Decode java.lang.Long as a web-safe, identically-sortable Base64 string. I.e., the Long and the string will both sort exactly the same way, and none of the characters of the string ever need to be escaped in a web context (e.g. in html, in xml, in any part of a url). Requires net.iharder.Base64 class which is Public Domain. See http:/…
(ns b64longs
"Encode and Decode java.lang.Long as a web-safe, identically-sortable Base64 string.
I.e., the Long and the string will both sort exactly the same way, and none of
the characters of the string ever need to be escaped in a web context (e.g. in html,
in xml, in any part of a url).
Requires net.iharder.Base64 class which is Public Domain.
See http://iharder.sourceforge.net/current/java/base64/
Add this as a leinigen dependency.
@favila
favila / imgmeta.java
Created May 13, 2013 04:17
Sample code demonstrating how to parse the XMP metadata in an image using javax.imageio.metadata. Written to answer this stackoverflow question: http://stackoverflow.com/a/13748517/1002469
import java.io.*;
import java.util.*;
// for imageio metadata
import javax.imageio.*;
import javax.imageio.stream.*;
import javax.imageio.metadata.*;
// for xml handling
import org.w3c.dom.*;