Skip to content

Instantly share code, notes, and snippets.

@spalger
spalger / gist:6322190
Created August 23, 2013 18:00
get the branch name in the PS1
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
else
return 0
fi
echo -e ":$(branch_color)$gitver${c_plain}"
}
@spalger
spalger / gist:6417923
Created September 2, 2013 22:40
Inject jQuery and lodash into the current tab via a bookmarklet. To use, just create a new bookmark and use this as the URL.
javascript: (function () {
var el = document.createElement('pre'),
b = document.getElementsByTagName('body')[0],
otherjQuery = false,
msg = '',
libs = [
function loadjQuery() {
if (typeof jQuery != 'undefined') {
showMsg('This page already using jQuery v' + jQuery.fn.jquery);
} else {
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);
@spalger
spalger / git-restage
Last active August 29, 2015 13:56
Re-stages a staged file (courtesy of @esvinson)
gitFiles=$(git status --porcelain | grep "^[ADM\?][AMD] " | sed -e "s|^[ADM\?][AMD] ||")
if [[ -n "${gitFiles}" ]] ; then
for fname in $gitFiles ; do
git add --all -- "${fname}"
echo "Restaging ${fname}"
done
else
echo "No files changed"
fi
@spalger
spalger / scratch.js
Created March 14, 2014 15:33
Modified reproduction for elastic/elasticsearch-js#54, modified to comply with jshint and reports progress and success.
var elasticsearch = require('./src/elasticsearch');
var async = require('async');
var _ = require('lodash-node');
var client = new elasticsearch.Client({
host: 'localhost:9200'
});
async.eachSeries(_.range(100), function (value, done) {
async.eachSeries(_.range(500), function (value, done) {
client.create({ index: 'tests', type: 'test', body: {something: true, value: value} }, done);
@spalger
spalger / only_client_nodes.js
Last active August 29, 2015 13:58
nodesToHostCallback for the elasticsearch.js client that filters out nodes which are not in "client" mode.
var elasticsearch = require('elasticsearch');
var baseNodesToHostCallback = require('elasticsearch/src/lib/nodes_to_host');
var client = new elasticsearch.Client({
/* host seed list */
hosts: [ ... ],
// sniff every 5 minutes
sniffInterval: 1000 * 60 * 5,
{
"aggConfig": {
"type": "terms",
"schema": "split",
"params": {
"field": "agent.raw",
"size": 2,
"order": "desc",
"row": true
}