Skip to content

Instantly share code, notes, and snippets.

@bitdivine
bitdivine / install-nodejs.sh
Last active August 29, 2015 14:01
Install the latest stable nodejs
#!/bin/sh
set -eux
INSTALL_DIR=/opt/nodejs
CURRENT=$(node -v || true)
VERSION=$(curl -L -s http://nodejs.org/dist/latest/ \
| egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
| tail -n1)
PLATFORM="$(uname | tr 'A-Z' 'a-z')"
@bitdivine
bitdivine / install-mongodb.sh
Last active August 29, 2015 14:01
Install mongodb using just shell. No package managers needed.
set -eux
INSTALLTO="${INSTALLTO:-/opt/mongodb}"
INSTALLED="$(mongo --version 2>/dev/null | sed -n '1{s/.*[^0-9.]\([0-9.]*\)/\1/g;p};q')"
LATEST="${LATEST:-$(curl -s 'http://www.mongodb.org/downloads' | sed -n 's/.*Production Release (\([0-9.]*\)).*/\1/g;ta;b;:a;p')}"
PLATFORM="${PLATFORM:-$(uname | tr A-Z a-z)}"
ARCH="${ARCH:-$(uname -m)}"
if [ "x$INSTALLED" = "x$LATEST" ]
then
@bitdivine
bitdivine / gist:08763ed457dd04481f59
Created August 21, 2014 10:25
shell script to parse user@host:port into its constituent parts, with defaults.
# Parse user@host:port into its constituent parts, with defaults.
# Explode if there are errors:
set -eu
# The parser with defaults:
parse() {
target="$1"
hostssl replication replicator 5.6.7.8 md5
@bitdivine
bitdivine / gist:f040ba2f1507dac58455
Created October 20, 2014 12:00
apt-get update is SLOW (>1sec) so do it only if it hasn't been done in the last 10 hours.
(( ( $(date +%s) - $(date -d"$(stat -c %y /var/lib/apt/lists)" +%s) ) < 36000 )) || apt-get update
@bitdivine
bitdivine / gist:fd4d3a5e14dbe3758f02
Created October 24, 2014 19:14
Set HTML element content from URL
function setContentFromUrl(url, container, opt){
console.log("loading", url, "into", container);
opt = opt || {};
var data_filter = opt.filter;
var err_handler = opt.err_handler;
var xhr= new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange= function() {
if (this.readyState!==4) return;
if (this.status!==200){
@bitdivine
bitdivine / boston.json
Last active August 29, 2015 14:14 — forked from pprett/boston.json
{"error": 42716.2954, "samples": 506, "value": [22.532806324110698], "label": "RM <= 6.94", "type": "split", "children": [{"error": 17317.3210, "samples": 430, "value": [19.93372093023257], "label": "LSTAT <= 14.40", "type": "split", "children": [{"error": 6632.2175, "samples": 255, "value": [23.349803921568636], "label": "DIS <= 1.38", "type": "split", "children": [{"error": 390.7280, "samples": 5, "value": [45.58], "label": "CRIM <= 10.59", "type": "split", "children": [{"error": 0.0000, "samples": 4, "value": [50.0], "label": "Leaf - 4", "type": "leaf"}, {"error": 0.0000, "samples": 1, "value": [27.9], "label": "Leaf - 5", "type": "leaf"}]}, {"error": 3721.1632, "samples": 250, "value": [22.90520000000001], "label": "RM <= 6.54", "type": "split", "children": [{"error": 1636.0675, "samples": 195, "value": [21.629743589743576], "label": "LSTAT <= 7.57", "type": "split", "children": [{"error": 129.6307, "samples": 43, "value": [23.969767441860473], "label": "TAX <= 222.50", "type": "split", "children": [{"err
@bitdivine
bitdivine / gist:3366f3d21e025cac3b83
Created April 15, 2015 19:50
Reverse proxy InfluxDB on Apache
<VirtualHost *:80>
ServerName your.host.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Rewrite links to 8086 on the way out:
# start with your certificate:
cert=my.crt
# we will copy the individual certificates to 001.crt, 002.crt and so on:
counter=0
# Now, for each certificate:
link="$(printf "%03d.crt" $((++counter)))" # 001.cert, 002.crt, ...
# Check that the certificate is in the human readable PEM format.
# If not it needs to be converted. Then copy into 001/2/3.crt
if openssl x509 -in "$cert" -text -noout &>/dev/null
@bitdivine
bitdivine / grekify.js
Created August 10, 2015 14:20
2->di 3->tri 16->hexakaideca 20->dodeca ... git it?
// Language constants.
var x = ' hen di tri tetra penta hexa hepta octa ennea deca hendeca dodeca triskaideca tetrakaideca pentakaideca hexakaideca heptakaideca octakaideca enneakaideca icosa'.split(' ');
var y = ' ,,icosa,conta ,hecato,diacosio,cosioi ,chilia,diachilia,chilia'.split(' ').map(function(s){return s.split(',')});
var z = x.map(function(x){return x+(x[x.length-1]==='a'?'':'a')});
// Convert any number - up to a few thousand, to a numeric prefix.
function grekify(n){
n = String(n); // Greek numbers are deca-mal
return x[n] || n && [(n[0]>2?z[n[0]]:''),y[n.length][n[0]>2?3:n[0]],grekify(n.slice(1))].join('');
}