Skip to content

Instantly share code, notes, and snippets.

function f() {
console.log('with local arguments');
console.log(f.arguments === arguments);
console.log(f.arguments === f.arguments);
}
function f2() {
console.log('without local arguments');
console.log(f2.arguments === f2.arguments);
}
node-browserify [master] $ npm test
> browserify@2.35.4 test /Users/spenceralger/dev/node-browserify
> tap test/*.js
ok test/args.js ......................................... 2/2
ok test/backbone.js ..................................... 4/4
ok test/bin.js .......................................... 4/4
ok test/bin_entry.js .................................... 4/4
ok test/buffer.js ..................................... 14/14
@spalger
spalger / gist:7661636
Last active December 29, 2015 11:09
Default methods in place in the elasticsearch-js client. Keep in mind, JS does not support request bodies with HTTP GET.
bulk (POST/PUT) [POST] -> http://elasticsearch.org/guide/reference/api/bulk/
count (POST/GET) [POST] -> http://elasticsearch.org/guide/reference/api/count/
create (POST/PUT) [POST] -> http://elasticsearch.org/guide/reference/api/index_/
explain (GET/POST) [POST] -> http://elasticsearch.org/guide/reference/api/explain/
index (POST/PUT) [POST] -> http://elasticsearch.org/guide/reference/api/index_/
indices.analyze (GET/POST) [POST] -> http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze/
indices.clearCache (POST/GET) [POST] -> http://www.elasticsearch.org/guide/reference/api/admin-indices-clearcache/
indices.create (PUT/POST) [POST] -> http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index/
indices.flush (POST/GET) [POST] -> http://www.elasticsearch.org/guide/reference/api/admin-indices-flush/
indices.optimize (POST/GET) [POST] -> http://www.elasti
@spalger
spalger / console.graph
Last active December 31, 2015 11:59
Started as https://github.com/adamschwartz/chrome-console-grapher but didn't find it to actually work. Brought in a touch of https://github.com/dunxrion/console.image and presto! Just pass an array of measurements to console.graph and it will graph them in that order.`console.graph(points, [height=150, [width=400]]);`
(function(){
var barColor = '#333';
var defaultHeight = 150;
var defaultWidth = 400;
window.console.graph = function (points, height, width) {
var height = height || defaultHeight;
var width = width || Math.max(defaultWidth, points.length);
var barWidth = Math.floor(width / points.length);
var maxPoint = Math.max.apply(Math, points);
#!/usr/bin/env bash
# call this with the pr number you want to apply and the base branch of that pr
#
# backport pr 5805, which was submitted against master, to 4.4:
# git co 4.4
# git cherry-pick-pr 5805
#
# backport pr 5840, which was submitted against 4.x, to 4.4:
# git co 4.4
@spalger
spalger / gulpfile.babel.js
Last active January 25, 2016 00:10
babel transform that unlinks deleted/renamed files
import gulp from 'gulp'
import babel from 'gulp-babel'
import combiner from 'stream-combiner2'
import sourcemaps from 'gulp-sourcemaps'
import watch from 'gulp-watch'
import gulpif from 'gulp-if'
import del from 'del'
import vinylPaths from 'vinyl-paths'
gulp.task('default', function () {
/*
* SystemJS v0.19.17
*/
!function(){function e(){!function(e){function t(e,t){var n;return e instanceof Error?(n=new Error(e.message,e.fileName,e.lineNumber),M?(n.message=e.message+"\n "+t,n.stack=e.stack):(n.message=e.message,n.stack=e.stack+"\n "+t)):n=e+"\n "+t,n}function n(e,n,r){try{new Function(e).call(r)}catch(a){throw t(a,"Evaluating "+n)}}function r(){}function a(t){this._loader={loaderObj:this,loads:[],modules:{},importPromises:{},moduleRecords:{}},z(this,"global",{get:function(){return e}})}function o(){a.call(this),this.paths={}}function s(e,t){var n,r="",a=0;for(var o in e){var s=o.split("*");if(s.length>2)throw new TypeError("Only one wildcard in a path is permitted");if(1==s.length){if(t==o)return e[o];if(t.substr(0,o.length-1)==o.substr(0,o.length-1)&&(t.length<o.length||t[o.length-1]==o[o.length-1])&&"/"==e[o][e[o].length-1])return e[o].substr(0,e[o].length-1)+(t.length>o.length?"/"+t.substr(o.length):"")}else{var i=s[0].length;i>=a&&t.substr(0,s[0].length)==s[0]&&t.substr(t.length-s[1].l
@spalger
spalger / partial.js
Created February 8, 2016 08:31
A version of _.partial that caches functions so that `partial(fn, 1, 2, 3) === partial(fn, 1, 2, 3)`.
var partial = (function () {
'use strict';
const caches = new WeakMap()
return function partial(fn, ...args) {
let toApply = fn
while (args.length) {
if (!caches.has(toApply)) caches.set(toApply, [])
@spalger
spalger / eswait.js
Last active April 11, 2016 21:19 — forked from rrva/eswait.js
(function checkForConnection() {
esClient.ping(function (err, pong) {
if (pong) {
console.log("Ping got pong!");
} else {
console.log("Ping did not get pong, trying again in 3sec.");
setTimeout(checkForConnection, 3000);
}
})
}());
@spalger
spalger / .js
Created October 18, 2016 21:14
const get = require('lodash.get')
const vars = { first: 'spencer', last: 'alger', age: 28 }
return 'Mr. { first } {last }, age {age}'.replace(/\{\s*(.+?)\s*\}/g, (_, name) => get(vars, name))