Skip to content

Instantly share code, notes, and snippets.

@tomgullo
tomgullo / use_stack_in_place_of_recur.js
Created August 5, 2013 23:56
use stack in place of recursion
function node(name, parent) {
return {
name:name,
parent:parent
}
}
root = node('root')
n2 = node('left', root)
root.left = n2
n3 = node('2left', n2)
@tomgullo
tomgullo / datamap.html
Created July 30, 2013 13:16
basic_datamap_based_on_example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="viewport" content="width=device-width">
<style>@media print, screen and (view-mode:minimized){#ghostery-purple-bubble{display:none}}</style>
<style>path {stroke: #FFFFFF; stroke-width: 1px;} .datamaps-legend dt,
@tomgullo
tomgullo / traverse_tree_nodes_in_js
Last active December 20, 2015 03:09
traverse_tree_nodes_in_js
function node(name, parent) {
return {
name:name,
parent:parent
}
}
root = node('root')
@tomgullo
tomgullo / get_most_popular_word_underscore.js
Last active December 19, 2015 16:29
get three words that appear most often in a string, using underscore
@tomgullo
tomgullo / javascript_prototype_testing.js
Created June 11, 2013 13:49
javascript_prototype_testing.js
function G(name, names) {
this.name = name;
this.players = {};
for (i=0; i < names.length; i++) {
this.players[ names[i] ] = {};
}
}
G.prototype = {
@tomgullo
tomgullo / q_promise.js
Created June 6, 2013 14:17
q promise example
function addAsync(data) {
var d = Q.defer();
setTimeout(function() {
console.log('data in ' + data);
if (data === 2) {
d.reject("rejected!");
} else {
d.resolve(data + 1);
}
},
@tomgullo
tomgullo / angular_js_promise.js
Last active December 17, 2015 10:18
angular_js_promise.js
$scope.getFakeStuff = function() {
timeoutTest(1)
.then(timeoutTest)
.then(timeoutTest)
.then(function(data) {
console.log("done " + data);
}, function(reason) {
console.log("error " + reason);
})
;
@tomgullo
tomgullo / BookController.groovy
Created April 24, 2013 12:31
nested REST with Grails
/*
"/book/$id?/$author?/$authorid?"(controller: "book") {
action = [GET:"show", PUT:"update", DELETE:"delete", POST:"save"]
}
*/
class BookController {
def beforeInterceptor = [action:this.&checkAuthor, except:'author']
def checkAuthor() {
@tomgullo
tomgullo / solr.xml
Created April 5, 2013 12:37
tomcat conf for solr
<tomcat>/conf/Catalina/localhost/solr.xml
<Context path="/solr" docBase="<location of solr war>" debug="0" crossContext="true">
<Environment name="solr/home" type="java.lang.String" value="<solr Home>" override="true"/>
</Context>
@tomgullo
tomgullo / allow_ip.sh
Created April 4, 2013 13:19
insert allow ip
iptables -A INPUT 4 -s x.x.x.x -m state --state NEW -p tcp --dport x -j ACCEPT