Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
hughfdjackson / example
Last active December 14, 2015 20:09 — forked from andyhd/maybe-monad.js
var peeps = { hugh: { name: 'hugh jackson' } }
var titleCase = function(str){
return str.split(' ').map(function(str){ return str.substr(0, 1).toUpperCase() + str.substr(1) }).join(' ')
}
var val = maybe(peeps)
.map(function(peeps){ return peeps.tahir })
.map(function(peep){ return peep.name })
.map(titleCase)
.getOrElse('couldn\'t find person')
$(function()
{
$.ajax({
url: 'check.php', //the script to call to get data
success: function(data) {
$('#count').html(data); //Set output element html
}
});
});
core.register('myModule', function(sandbox){
sandbox.subscribe('init', function(){
//do stuff
});
});
function deepClone(o) {
return (typeof o !== 'object' || o === null) ? o
: (o instanceof Array) ? o.map(deepClone)
: Object.keys(o).reduce(function (result, key) {
result[key] = deepClone(o[key])
return result
}, Object.create(Object.getPrototypeOf(o))) }
function attachEvent(el, action, callback){
if (el.addEventListener) {
el.addEventListener(action, callback, false);
} else if (el.attachEvent) {
el.attachEvent('on' + action, (function (ele) { return callback; })(el) );
}
}
inputKeyup: function (courseType){//event that's triggered on the input keyups
var currentRequest;
return function (e){
var client = new XMLHttpRequest();
client.open('GET', 'maxid.php', false);
client.send(null);
maxid=client.responseText;
JSON.parse(maxid);
return maxid;
for (var i = 0; i < 10; i++) {
process.nextTick(function (i) { console.log(i); }.bind(this, i));
}
// Prints 10 x 10 times
// I want it to print 1 - 10 without using an external array to store i
/*
In browser test edition
var MyClass = function() {
this.cosa = 0;
console.log('constructor');
};
(function() {
var func1 = function() {
console.log('func1');
console.log(this.cosa);
};
@hughfdjackson
hughfdjackson / gist:2725819
Created May 18, 2012 15:17 — forked from yorickvP/gist:2725801
Simple (regex) routing in JavaScript
module.exports = function router() {
function router(method, url) {
var r = get_routes(method), rl = r.length
for (var i = 0; i < rl; ++i) {
if (r[i].type == 'string') {
if (r[i].url == url)
return [[url], r[i].callback] }
else {
var route = r[i]
@hughfdjackson
hughfdjackson / FXYnVZaZ
Created April 28, 2012 12:42 — forked from anonymous/FXYnVZaZ
a guest on Apr 28th, 2012 - JSON
{
"cmd": "init",
"payload": {
"blackboard_id": 2,
"data": [
"{\"id\":1,\"z\":1,\"class\":\"Rectangle\",\"x\":234.5,\"y\":130.5,\"width\":297,\"height\":147,\"style\":{\"fillColor\":\"#FFFFFF\",\"strokeColor\":\"#000000\",\"strokeSize\":\"1\"},\"minWidth\":10,\"minHeight\":10,\"text\":\"Test\",\"font\":\"verdana\",\"fontSize\":\"16px\",\"fontStyle\":{\"bold\":false,\"italic\":false},\"boundingBox\":{\"x\":[234.5,383,531.5],\"y\":[130.5,204,277.5]}}",
"{\"id\":1,\"z\":1,\"class\":\"Rectangle\",\"x\":234.5,\"y\":130.5,\"width\":297,\"height\":147,\"style\":{\"fillColor\":\"#FFFFFF\",\"strokeColor\":\"#000000\",\"strokeSize\":\"1\"},\"minWidth\":10,\"minHeight\":10,\"text\":\"Test\",\"font\":\"verdana\",\"fontSize\":\"16px\",\"fontStyle\":{\"bold\":false,\"italic\":false},\"boundingBox\":{\"x\":[234.5,383,531.5],\"y\":[130.5,204,277.5]}}"
]
}
}