This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Parallelize the execution of a command | |
###### | |
CHUNK_COUNT=0 | |
parallel_configure () { | |
if [ $# -eq 0 ]; then | |
echo "usage: <tmp dir> <tmp prefix> <num chunks>" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// space complexity: O(n) -- the hashmap | |
// time complexity: ~O(2n); iterate both strings once | |
// worse case: O(2n) | |
function areAnagrams(a, b) { | |
var len = a.length, chars = {}, i = 0; | |
if (len !== b.length) return false; | |
for(; i < len; i++) { | |
chars[a[i].toLowerCase()] = true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function (window) { | |
if (window.top !== window.self) { | |
killFrame(); | |
} | |
var _frame_ = "<html><head><title>Not Allowed</title>\ | |
</head><body><h1>We don't allow This</h1></body></html>"; | |
function killFrame() { | |
document.open(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Just define a simple is_a fn and populate it with functions | |
* that correspond to the primary JS objects; interface is | |
* | |
* is_a.array([]) >> true | |
*/ | |
;(function (window, undefined){ | |
var upFirst = /^(\w)/, | |
toS = Object.prototype.toString, | |
builtIns = ['Array', 'Object', 'Number', 'String', 'Window', 'RegExp', 'Function']; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function (window, document, undefined) { | |
var m = window.micro = {}, | |
whiteSpaceRxp = /[\r\n\t\s]/g, | |
quotesRxp = /['"]/g, | |
attrRxp = /<%=\s*([\w_\$\.]+)\s*%>/ig; | |
// Convert template to use consistent quotes, remove unnecessary whitespace | |
// returns: the normalized template string | |
function normalizeTemplate(tpl) { | |
return tpl.replace(whiteSpaceRxp, ' ').replace(quotesRxp, "'"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function safe_eval(code, ctx) { | |
return (new Function (["window", "undefined"], "try { " + code + " } catch (e){ return e; }"))(ctx); | |
} | |
function restrict (base, perm) { | |
var out = {}, k = null, | |
READ = 'read', | |
WRITE = 'write', | |
RW = 'readwrite'; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function label_stream() | |
{ | |
perl -sne '$|=1; print "[$cmd]\t$_"' -- -cmd="$1" | |
} | |
# example use | |
ls -lafh . | label_stream "ls" | |
# output | |
[ls] drwxr-xr-x 6 nickjacob staff 204B Nov 11 2012 Processing/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# get coinbase price | |
### | |
require 'coinbase' | |
require 'optparse' | |
# your API key - https://coinbase.com/docs/api/authentication | |
COINBASE_API = '' | |
UP_ARROW = "\u25B2".encode('utf-8') | |
DOWN_ARROW = "\u25BC".encode('utf-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Tie::LevelDB; | |
sub foreach_key { | |
my ($db_name, $block) = @_; | |
my $db = new Tie::LevelDB::DB($db_name); | |
my $it = $db->NewIterator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# upgrade starcluster | |
#### | |
mute_run () | |
{ | |
$* >/dev/null 2>&1 | |
} | |
cecho () | |
{ |