FE dev setup

# Guide to create package.json
npm init

# install version of npm package
npm install --save react@0.14.7

# browserify
npm install -g browserify

# Babel + browserify
npm install --save-dev babelify

# npm build
npm run build

# sass
npm install --save-dev node-sass
Posted in node

elastic search decommission node

Remove node:

curl -v -XPUT localhost:9200/_cluster/settings -d '{"transient" :{"cluster.routing.allocation.exclude._ip" : "xxx.xxx.xxx.xxx"}}'

Add node back after maintenance:

curl -v -XPUT localhost:9200/_cluster/settings -d '{"transient" :{"cluster.routing.allocation.exclude._ip" : ""}}'
Posted in Elastic Search

fast linux delete for large directories

Found this to be faster than rm -rf

mkdir blank
rsync -a --delete blank/ dir-to-delete/
Posted in linux

elasticsearch test analyzer

curl 'localhost:9200/_analyze?text=the+quick+brown+fox+jumps+over+the+lazy+dog&pretty&analyzer=snowball'
Posted in Elastic Search

trace webmachine resource

1> dbg:tracer().
2> dbg:p(all,[c]).
3> dbg:tp({my_resource, '_', '_'}, []).
Posted in erlang

hmac

#!/usr/bin/perl
 
use strict;
use warnings;
use Digest::SHA qw(hmac_sha1_hex);
 
print hmac_sha1_hex("my data", "secret key") . "\n";
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <openssl/hmac.h>
 
int main() {
 
  char* key = "secret key";
  char* data = "my data";
  char tmp[3];
  unsigned int result_len, i;
  unsigned char* result = malloc(sizeof(unsigned char) * result_len);
 
  HMAC_CTX ctx;
  HMAC_CTX_init(&ctx);
  HMAC_Init_ex(&ctx, (unsigned char*) key, strlen(key), EVP_sha1(), NULL);
  HMAC_Update(&ctx, (unsigned char*) data, strlen(data));
  HMAC_Final(&ctx, result, &result_len);
  HMAC_CTX_cleanup(&ctx);
 
  char* output = malloc(sizeof(char) * result_len);
  for (i = 0; i != result_len; i++)
  {
    //printf("Got %02X at byte %d\n", result[i], i);
    sprintf(tmp, "%02x", result[i]);
    strcat(output, tmp);
  }
 
 
  printf("output  : %s\n", output);
  printf("expected: %s\n", "97a62219092f3ddab3707cc9e85e63e926f45c87");
 
  return 0;
}
$ perl hmac.pl
97a62219092f3ddab3707cc9e85e63e926f45c87
 
$ gcc -Wall -lcrypto hmac.c -o hmac  && ./hmac
output  : 97a62219092f3ddab3707cc9e85e63e926f45c87
expected: 97a62219092f3ddab3707cc9e85e63e926f45c87
Posted in bash, c, hmac, perl

sqlite index

sqlite> CREATE TABLE dogs (dog_id INTEGER PRIMARY KEY AUTOINCREMENT, dog_name VARCHAR(100), state CHAR(2));
sqlite> CREATE INDEX dog on dogs(state);
sqlite> .indices dogs
dog
sqlite> EXPLAIN QUERY PLAN SELECT dog_name FROM dogs WHERE state='FL';
0|0|TABLE leagues WITH INDEX league
Posted in sqlite
Follow

Get every new post delivered to your Inbox.