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
// bind to change the function scope and send arguments for the functions | |
Function.prototype.bind = function(context) { | |
var __method = this, | |
args = Array.prototype.slice.call(arguments, 1); | |
return function() { | |
var a = Array.prototype.concat(Array.prototype.slice.call(arguments), args); | |
return __method.apply(context, Array.prototype.slice.call(a)); | |
} | |
}; |
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
sudo mkdir /var/mysql | |
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock |
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 linearSearch(values, target) { | |
for(var i = 0; i < values.length; ++i){ | |
if (values[i] == target) { return i; } | |
} | |
return -1; | |
} |
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 ArrayList(initialLength) { | |
this.length = 0; | |
this.array = new Array(initialLength); | |
this.add = function(value) { | |
if (this.length == this.array.length){ | |
this.grow(); | |
} | |
this.array[this.length++] = value; | |
}; |
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 LinkedList() { | |
this.head = null; | |
this.tail = null; | |
this.add = function(value) { | |
var node = new Node(value); | |
if (this.head == null) { this.head = node; } | |
if (this.tail != null) { this.tail.next = node; } | |
this.tail = node; | |
}; |
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 HashTable(size) { | |
this.size = size; | |
this.buckets = new Array(size); | |
this.add = function(value) { | |
var index = this.hash(value); | |
this.buckets[index] = value; | |
}; | |
this.hash = function(value) { | |
var sum = 0; |
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 binSearch(values, target) { | |
return binarySearch(values, target, 0, values.length - 1); | |
}; | |
function binarySearch(values, target, start, end) { | |
if (start > end) { return -1; } //does not exist | |
var middle = Math.floor((start + end) / 2); | |
var value = values[middle]; |
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 bubbleSort(values) { | |
var length = values.length - 1; | |
do { | |
var swapped = false; | |
for(var i = 0; i < length; ++i) { | |
if (values[i] > values[i+1]) { | |
var temp = values[i]; | |
values[i] = values[i+1]; | |
values[i+1] = temp; | |
swapped = 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 insertionSort(values) { | |
var length = values.length; | |
for(var i = 1; i < length; ++i) { | |
var temp = values[i]; | |
var j = i - 1; | |
for(; j >= 0 && values[j] > temp; --j) { | |
values[j+1] = values[j]; | |
} | |
values[j+1] = temp; | |
} |
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 getDayDelta(incomingYear,incomingMonth,incomingDay){ | |
var incomingDate = new Date(incomingYear,incomingMonth-1,incomingDay), | |
today = new Date(), delta; | |
// EDIT: Set time portion of date to 0:00:00.000 | |
// to match time portion of 'incomingDate' | |
today.setHours(0); | |
today.setMinutes(0); | |
today.setSeconds(0); | |
today.setMilliseconds(0); |
OlderNewer