Skip to content

Instantly share code, notes, and snippets.

View jasondscott's full-sized avatar

Jason Scott jasondscott

  • San Francisco, California
View GitHub Profile
@jasondscott
jasondscott / pre-commit
Last active June 6, 2017 20:05
pre-commit hook
echo "Running debugger check"
FILES=$(git diff --cached --name-only HEAD)
RED='\x1B[0;31m';
DEBUG_COMMANDS='debugger|console\.log|binding\.pry'
# Adding /dev/null so that grep reports file name when only one file is given
ERRORS=$(grep -E --line-number $DEBUG_COMMANDS $FILES /dev/null)
if [ -n "$ERRORS" ]; then
lon lat zip
-122.412 37.776 94103
-122.402 37.791 94104
-122.396 37.790 94105
-122.728 37.785 94106
-122.394 37.769 94107
-122.409 37.791 94108
-122.421 37.795 94109
-122.416 37.749 94110
-122.405 37.774 94111
function mergeSort(arr) {
for (var n = 1; n < 4 ; n++){
var seg_size = Math.pow(2, n);
for (var seg = 0; seg < Math.ceil(arr.length/seg_size); seg++) {
var before = arr.slice(0, seg * seg_size);
var cur = arr.slice(seg * seg_size, (seg+1) * seg_size);
var after = arr.slice((seg+1) * seg_size);
var left = cur.slice(0, seg_size/2);
@jasondscott
jasondscott / SimpleCal.css
Last active August 29, 2015 13:57
Simple Calendar
.slot {
padding: 3px;
text-align: center;
border: 0;
}
.available {
background-color: #eee;
}
function Stack() {
var data = [];
var stackPtr = [0,0,0];
this.push = function(stackNumber, d) {
var index = stackNumber + stackPtr[stackNumber] * 3;
data[index] = d;
stackPtr[stackNumber]++;
};
this.print = function() {
var strs = ["","",""];
function Node(d) {
this.next = undefined;
this.data = d;
this.appendToTail = function(d) {
var end = new Node(d);
var n = this;
while (n.next !== undefined) { n = n.next; }
n.next = end;
function allUnique(str) {
var a = [];
for (var i = 0; i < str.length; i++) {
var char = str.charAt(i);
if (!a[char]) {
a[char] = true;
} else {
return false;
}
@jasondscott
jasondscott / Deferreds.js
Last active December 30, 2015 12:29
Javascript Deferred implementation
function Deferred () {
var rand = Math.random();
var dones = [];
var is_resolved = false;
return {
promise: function () {
},
resolve: function(str) {
@jasondscott
jasondscott / gist:7664333
Created November 26, 2013 19:16
Git Command to sort your branches by most recently changed.
git for-each-ref --sort=-committerdate refs/heads/
/* Rotate an array n positions
* if n is positive - rotate to the left
* if n is negative - rotate to the right
*/
Array.prototype.rotate = function(n) {
//Make a copy of the current array
var newArray = this.slice(0);
//Handle a number greater than the length so that it loops around