Skip to content

Instantly share code, notes, and snippets.

View gartenfeld's full-sized avatar

David Rosson gartenfeld

View GitHub Profile
@gartenfeld
gartenfeld / app.js
Last active April 27, 2016 03:16
Maze Explorer Draft
var app = require('express')();
var puzzle = require('./flipboard/maze');
app.get('/maze/new', puzzle.init);
app.get('/maze/update/:id', puzzle.update);
app.listen(3000, 'localhost');
@gartenfeld
gartenfeld / yql_cors.js
Last active April 22, 2016 22:32
YQL CORS jQuery Plugin
// http://james.padolsey.com/snippets/cross-domain-requests-with-jquery/
// enableCORS();
var enableCORS = function() {
jQuery.ajax = (function(_ajax){
var api = 'http://query.yahooapis.com/v1/public/yql',
query = 'select * from html where url="{URL}"';
return function(o) {
var q = query.replace('{URL}', o.url);
o.url = api;
o.dataType = 'json';
@gartenfeld
gartenfeld / introrx.md
Created April 21, 2016 00:40 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@gartenfeld
gartenfeld / python_server.sh
Created April 18, 2016 20:33
Simple HTTP Server
# Invoke Python with -m to use the server module
python -m SimpleHTTPServer 3000
@gartenfeld
gartenfeld / mock_users.sh
Created February 20, 2016 00:17
Generate a number of users and directories in HDFS
USERNAMES=("aada" "aaro" "aino" "aleksi" "anni" "eeli" "eemil" "eetu" "eevi" "eino" "elias" "ella" "elsa" "emil" "enni" "helmi" "joona" "kerttu" "lauri" "leevi" "lenni" "lilja" "lotta" "luka" "lumi" "matias" "mikael" "mila" "nella" "niilo" "niklas" "olivia" "onni" "oona" "peetu" "pihla" "siiri" "veera" "veeti" "venla" "vilho" "vilma");
RAND_BASE=8;
RAND_POWER=3;
GROUP_NAME="demo";
DUMMY_FILE_SIZE=4096;
TMP_DUMMY_DIR="/tmp/dummy";
time_in_ms() {
date +"%s"
@gartenfeld
gartenfeld / method_loading.js
Created February 11, 2016 22:23
An Illustrative Tale of JavaScript Behaviours
function setLoader(store) {
// Now `store` is imported into the closure scope
return function set(val) {
/**
* To update a value, reassign a property, not a variable
* For example, `store = { value: 'new value' };` would NOT
* work. It just reassigns the scope variable `store` to
* point to something else, rather than going to the memory
* spot of what `store` points to and alter the value there
*/
@gartenfeld
gartenfeld / debounce.min.js
Last active February 10, 2016 02:19
Extends the global window with Lodash's debounce method
!function(){function t(t,e,r){function a(){b&&clearTimeout(b),v&&clearTimeout(v),x=0,s=v=g=b=w=void 0}function u(e,n){n&&clearTimeout(n),v=b=w=void 0,e&&(x=T(),m=t.apply(g,s),b||v||(s=g=void 0))}function c(){var t=e-(T()-d);0>=t||t>e?u(w,v):b=setTimeout(c,t)}function f(){return(b&&w||v&&$)&&(m=t.apply(g,s)),a(),m}function l(){u($,b)}function p(){s=arguments,d=T(),g=this,w=$&&(b||!h);var n=!1,i=!1;if(j===!1)n=h&&!b;else{v||h||(x=d);var o=j-(d-x);i=0>=o||o>j,i?(v&&(v=clearTimeout(v)),x=d,m=t.apply(g,s)):v||(v=setTimeout(l,o))}return i&&b?b=clearTimeout(b):b||e===j||(b=setTimeout(c,e)),n&&(i=!0,m=t.apply(g,s)),!i||b||v||(s=g=void 0),m}var s,v,m,d,g,b,w,x=0,h=!1,j=!1,$=!0;if("function"!=typeof t)throw new TypeError(o);return e=i(e)||0,n(r)&&(h=!!r.leading,j="maxWait"in r&&y(i(r.maxWait)||0,e),$="trailing"in r?!!r.trailing:$),p.cancel=a,p.flush=f,p}function e(t){var e=n(t)?m.call(t):"";return e==a||e==u}function n(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function i(t){if(n(t)){var i=e(t.valueOf)?t
@gartenfeld
gartenfeld / search_and_open.sh
Created January 9, 2016 01:26
Search for files containing a pattern, then open those files
alias gg="git grep -n"
# -n: show line numbers
function ggl {
RESULTS=$(gg -l "$*" | tr "\n" " ");
# -l: file name (path included) only
# tr: replace $1 with $2
if [ -z "${RESULTS// }" ]; then
# "${VAR// }" removes whitespace in $VAR
# -z: not empty
@gartenfeld
gartenfeld / xhr_base_64.js
Created October 27, 2015 14:13
Load an image and convert it to a string.
var xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
if (this.status == 200) {
var buffer = new Uint8Array(this.response);
var i = buffer.length;
var binary = new Array(i);
while (i--) {
binary[i] = String.fromCharCode(buffer[i]);
}
@gartenfeld
gartenfeld / async_closure.js
Created October 27, 2015 07:49
Since JSHint says not to make functions inside a loop..
var delay = function(i) {
setTimeout(function() {
console.log(i);
}, i * 100);
};
for (var i = 1; i <= 10; i++) {
delay(i);
}