Skip to content

Instantly share code, notes, and snippets.

@spalger
spalger / index.js
Last active October 29, 2015 21:03
requirebin sketch
const url = require('url');
const rison = require('rison');
window.parseRison = function () {
var output = document.getElementById('risonOutput');
var input = document.getElementById('risonInput').value;
var j = function (v) {
return JSON.stringify(v, null, ' ');
};
{ "key": "value" }
{
"aggConfig": {
"type": "terms",
"schema": "split",
"params": {
"field": "agent.raw",
"size": 2,
"order": "desc",
"row": true
}
@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,
@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 / 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 / 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 / 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