Skip to content

Instantly share code, notes, and snippets.

View christopherhill's full-sized avatar

Christopher Hill christopherhill

  • 01:06 (UTC -05:00)
View GitHub Profile
@christopherhill
christopherhill / Value Watcher
Created October 19, 2013 04:59
Value Watcher class for JS
function ValueWatcher(value, callback, prequel) {
var that = this;
this.value = value;
this.onBeforeSet = prequel || function(){};
this.onAfterSet = callback || function(){};
this.setValue = function(newVal) {
that.onBeforeSet(that.value, newVal);
that.value = newVal;
that.onAfterSet(newVal);
}
@christopherhill
christopherhill / Sudoku Validation Class
Last active December 29, 2015 21:19
Sudoku Validation Class
var testCases = new Array();
testCases[0] = "751843926893625174642179583425316798176982345938754612364297851289531467517468239";
testCases[1] = "751843927893625174642179583425316798176982345938754612364297851289531467517468239";
testCases[2] = "571843926893625174642179583425316798176982345938754612364297851289531467517468239";
testCases[3] = "851743926693825174142679583425316798976182345738954612364297851289531467517468239";
testCases[4] = "223275461161885667779964198782134691447868986543883499854252274298641511551153988";
testCases[5] = "398126745471293685394287156874539162173982456973681245163759248927864531498612375";
var SudokuValidator = function() {
@christopherhill
christopherhill / URLPatternParser
Last active December 30, 2015 08:09
URL Pattern Parser
// We need to write a function in JavaScript that parses all the variable parts of a
// url, and any url parameters, into a hash. The function should take two arguments:
// 1. A "url format" string, which describes the format of a url that can contain
// constant parts and variable parts (where "parts" of a url are separated with "/").
// All variable parts begin with a colon. Here is an example "url format" string:
// "/v6/:collecton/:id"
// 2. The second argument is a particular url that is guaranteed to have the format
// specified by the first argument. It may also contain url parameters. For instance,
// given the example url format string above, the second argument might be:
// "/v6/photos/3?size=large&res=high
@christopherhill
christopherhill / gist:7836660
Created December 7, 2013 02:44
Javascript Classic Inheritance
var Automobile = function() {
this.automobile = true;
}
var Car = function() {
this.car = true;
}
var Bus = function() {
@christopherhill
christopherhill / fibonacci.js
Created December 16, 2013 04:29
Fibonacci Generator
var fibonacci = function(arrLength) {
var offset = 1;
var result = [0, 1];
for (var i = offset; i < arrLength + offset; i++) {
result.push(result[i] + result[i-1]);
}
return result;
}
h1, h2, h3, h4, h5, h6 {
font-weight: normal;
}
form, input, button {
border: none;
margin: 0;
padding: 0;
}
.container {
/* removed width here */
border: 1px solid black;
height:80px;
overflow-x:auto;
overflow-y:hidden; /* turns off y-scrollbar */
display:block;
}
.image-container {
background: blue;
class Automata():
'Represents a cellular automata with configurable params:'
' - number of columns, defaults to 64'
' - number of iterations, defaults to 32'
' - true symbol, defaults to *'
' - false symbol, defaults to -'
entries = []
rows = 0
cur_row = 0
<!DOCTYPE html>
<html>
<head>
<title>MJ Test</title>
<style>
.passed { color: green; }
.failed { color: red; }
@christopherhill
christopherhill / gist:da7e45c198cbad2d76e6
Last active August 29, 2015 14:06
Exercise (get second degree connections from graph data)
var graph = {
nodes:
[{
userId: 'chill',
city: 'Sonoma' },
{
userId: 'sjobs',
city: 'Mountain View' },
{
userId: 'bgates',