Skip to content

Instantly share code, notes, and snippets.

View dtjm's full-sized avatar

Sam Nguyen dtjm

  • Twilio SendGrid
  • Pacific Northwest
View GitHub Profile
@dtjm
dtjm / time.pl
Created September 9, 2013 22:01
AnyEvent->time vs Time::HiRes::time
use strict;
use AnyEvent;
use Time::HiRes;
use Data::Dumper;
my $iterations = 10000000;
my $start = Time::HiRes::time;
for ( my $i = 0; $i < $iterations; $i++ )
{
$REPO=`git svn info | grep "Repository Root: " | sed -e 's/Repository Root: //'`
git branch -r | sed 's|^[[:space:]]*||' | grep -v '^tags/' > git-branch-list
svn ls $REPO/branches | sed 's|^[[:space:]]*||' | sed 's|/$||' > svn-branch-list
diff -u git-branch-list svn-branch-list | grep '^-' | sed 's|^-||' | grep -v '^trunk$' | grep -v '^--' > old-branch-list
for i in `cat old-branch-list`; do git branch -d -r "$i"; rm -rf .git/svn/refs/remotes/"$i"; done
rm -v old-branch-list svn-branch-list git-branch-list
@dtjm
dtjm / awssigner.js
Last active December 11, 2015 18:49
// Copyright 2007 Amazon Elena@AWS
// http://aws.amazon.com/code/developertools/1137
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
@dtjm
dtjm / fuzzy_string_match.js
Created October 26, 2012 21:00
Fuzzy string matching function for JavaScript
// Fuzzy matching algorithm
var fuzzyMatch = function(needle, haystack) {
if(needle === "" || haystack === "") return true;
needle = needle.toLowerCase().replace(/ /g, "");
haystack = haystack.toLowerCase();
// All characters in needle must be present in haystack
var j = 0; // haystack position
for(var i = 0; i < needle.length; i++) {
@dtjm
dtjm / to_base_n.js
Created October 5, 2012 16:42
Convert text to base 2-65536 using Unicode characters
(function(){
var toBaseN = function(n, base) {
if(base < 2 || base > 65535) {
throw "Base must be between 2 and 65535 inclusive"
}
var str = "";
var sign = "";
if(n < 0) {
@dtjm
dtjm / jsonpp.go
Created August 23, 2012 19:33
JSON pretty printer
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"os"
)
@dtjm
dtjm / http_wai_fib.hs
Created July 19, 2012 17:01
HTTP Fibonacci service in Haskell
{-# LANGUAGE OverloadedStrings #-}
import Char
import Control.Monad (join)
import Network.Wai
import Network.HTTP.Types
import Network.Wai.Handler.Warp (run)
import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance
import Control.Monad.IO.Class (liftIO)
import Data.Conduit
import Data.String.Utils ()
@dtjm
dtjm / cat.hs
Created July 13, 2012 16:49
The Cat in the Haskell
import Control.Monad as Monad
import System.Exit
import System.IO as IO
import System.Environment as Env
main :: IO ()
main = do
-- Get the command line arguments
args <- Env.getArgs
@dtjm
dtjm / gist:1641807
Created January 19, 2012 18:51
Phlaya - PHP micro middleware stack [Relocated to https://github.com/dtjm/phlaya]
We couldn’t find that file to show.
@dtjm
dtjm / cramfs-osx.diff
Created September 9, 2011 20:52
cramfs patch for OS X
--- cramfs-1.1/cramfsck.c 2011-09-09 13:39:01.000000000 -0700
+++ cramfs-dtjm/cramfsck.c 2011-09-09 13:39:02.000000000 -0700
@@ -47,14 +47,17 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
-#include <sys/sysmacros.h>
#include <utime.h>
#include <sys/ioctl.h>
#define _LINUX_STRING_H_