Skip to content

Instantly share code, notes, and snippets.

10dc9e228e633f7c0645ab4301a3c1f36315187a HEAD
8bc2fca90b6a1378bc3731fc58111f7e3df40f63 refs/heads/dev
10dc9e228e633f7c0645ab4301a3c1f36315187a refs/heads/master
@matthewp
matthewp / gist:1748027
Created February 5, 2012 21:29
Homebrew tmux
==> Downloading http://sourceforge.net/projects/tmux/files/tmux/tmux-1.6/tmux-1.6.tar.gz
File already downloaded in /Users/matthew/Library/Caches/Homebrew
/usr/bin/tar xf /Users/matthew/Library/Caches/Homebrew/tmux-1.6.tar.gz
==> ./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/tmux/1.6 --sysconfdir=/usr/local/etc
./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/tmux/1.6 --sysconfdir=/usr/local/etc
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... etc/install-sh -c -d
checking for gawk... no
checking for mawk... no
@matthewp
matthewp / gist:2036428
Created March 14, 2012 13:23
Object.is polyfill
// Blatantly stolen from ES6 specs. Kept here for reference.
// http://wiki.ecmascript.org/doku.php?id=harmony:egal
if(!Object.is) {
Object.defineProperty(Object, 'is', {
value: function(x, y) {
if (x === y) {
// 0 === -0, but they are not identical
return x !== 0 || 1 / x === 1 / y;
@matthewp
matthewp / gist:2324447
Created April 7, 2012 01:43
String Split in Scheme
;;; str-split : Apr 2006 Doug Hoyte, hcsw.org.
;;; ----
;;; Splits a string 'str into a list of strings
;;; that were separated by the delimiter character 'ch
;;; ----
;;; Efficient as possible given that we can't count on
;;; 'str being an immutable string.
(define (str-split str ch)
(let ((len (string-length str)))
@matthewp
matthewp / soundex.clj
Created April 17, 2012 17:19
Soundex algorithm in Clojure
(defn soundex [data]
(let [ contains-char? (fn [the-string the-char]
(some #(= the-char %) the-string))
find-first-map-val (fn [m v]
(last (first (filter #(contains-char? (first %) v) m))))
compress (fn [xs]
(reduce #(if (= (last %1) %2) %1 (concat %1 (list %2))) '() xs))
fill (fn [x l w]
(if (> l (.length (str x))) (recur (str x w) l w) (.substring (str x) 0 l)))
code-gen { "BFPV" "1"
@matthewp
matthewp / rel-template.js
Created June 19, 2012 19:08
Synchronous loading of templates in a link tag.
(function() {
"use strict";
Object.defineProperty(HTMLLinkElement.prototype, 'template', {
get: function() {
if(!/template/i.test(this.rel)) {
return "";
}
var req = new XMLHttpRequest();
@matthewp
matthewp / gist:3099268
Created July 12, 2012 16:50
XMLHttpRequest wrapped into a promise
function xhr(options) {
var deferred = Q.defer(),
req = new XMLHttpRequest();
req.open(options.method || 'GET', options.url, true);
// Set request headers if provided.
Object.keys(options.headers || {}).forEach(function (key) {
req.setRequestHeader(key, options.headers[key]);
});
@matthewp
matthewp / gist:4142184
Created November 25, 2012 02:43
Reset powershell colors

This function is useful when a program jacks up your colors. Change to what you use.

function Reset-Colors ()
{
	$HOST.UI.RawUI.BackgroundColor = "DarkMagenta"
	$HOST.UI.RawUI.ForegroundColor = "DarkYellow"
}
@matthewp
matthewp / gist:5609985
Last active December 17, 2015 12:29
Array flatten
function flatten(array, isShallow, callback, thisArg) {
var index = -1,
length = array ? array.length : 0,
result = [];
// juggle arguments
if (typeof isShallow != 'boolean' && isShallow != null) {
thisArg = callback;
callback = !(thisArg && thisArg[isShallow] === array) ? isShallow : undefined;
isShallow = false;
@matthewp
matthewp / node-debug
Created July 16, 2013 14:15
Simple script for launching node-inspector and node --debug in one. Kills the inspector when you ctrl+c
#!/bin/bash
INSP_PID=0
function ctrl_c() {
echo "Killing process" $INSP_PID
kill $INSP_PID
exit 0
}
trap ctrl_c INT