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 / mergeSort.js
Last active August 23, 2016 09:53
JavaScript Merge Sort
//Merge Sort
Array.prototype.mergeSort = function() {
var thiz = this;
if (this.length <= 1) {
return this;
}
//split left and right
var left = [], right = [];
//JS QuickSort
Array.prototype.quickSort = function() {
var r = this;
if(this.length <= 1) {
return this;
}
var less = [], greater = [];
/* 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
@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/
@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) {
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;
}
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 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 = ["","",""];
@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 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);