Skip to content

Instantly share code, notes, and snippets.

View revington's full-sized avatar
🎸
hey ho lets go!

Pedro Narciso García Revington revington

🎸
hey ho lets go!
View GitHub Profile
@revington
revington / jsdistance
Created June 13, 2012 13:02
Get distance between two points
var earth_radius = 6371;
function toRadian(x) {
return x * (Math.PI / 180);
}
function diffRadian(v1, v2) {
return toRadian(v2) - toRadian(v1);
}
@revington
revington / couchdb_delete_non_design_docs.js
Created July 2, 2012 12:07 — forked from ryankirkman/couchdb_delete_non_design_docs.js
Delete all non-design docs in CouchDB (using cradle)
var cradle = require('cradle');
var database = 'app';
cradle.setup({
host: '127.0.0.1',
port: 5984,
auth: { username: "YOUR_USERNAME", password: "YOUR_PASSWORD" }
});
module.exports.process = function () {
var f = arguments;
return function (initialContext) {
var ctx = initialContext || {},
i = 0,
walk = function () {
return f[i++] ||
function () {
throw new Error('can not "next()"');
};
@revington
revington / publisher.js
Created January 24, 2013 13:40
fanout amqp nodejs npm install amqp debug
var amqp = require('amqp'),
debug = require('debug')('master:' + process.pid), time= 10;
debug('hello');
var connection = amqp.createConnection({
host: 'localhost'
});
var exc;
connection.on('ready', function () {
exc = connection.exchange('my-exchange', {
type: 'fanout'
@revington
revington / ssh-tunnel-couchdb-aws
Created June 6, 2013 10:29
ssh tunnel to couchdb futon on aws
ssh -Ni ./my_key.pem -L 5984:127.0.0.1:5984 ec2-user@xxxxxxamazon-instance.compute.amazonaws.com
@revington
revington / launch-grid.sh
Last active April 12, 2018 17:59
launch selenium grid + phantomjs
#!/usr/bin/env sh
trap 'killall' INT
killall() {
trap '' INT TERM # ignore INT and TERM while shutting down
echo "**** Shutting down... ****" # added double quotes
kill -TERM 0 # fixed order, send TERM not INT
wait
echo DONE
}
@revington
revington / delete-test-db.sh
Created January 20, 2014 15:01
Delete all my test db from couch db
#!/bin/bash
while read -r line; do
curl -X DELETE http://localhost:5984/$line
done < <( curl http://localhost:5984/_all_dbs 2> /dev/null | node -e "
process.stdin.setEncoding('utf8');
process.stdin.resume();
var buf = '';
process.stdin.on('data', function(chunk){
buf += chunk;
@revington
revington / setup_upnp.sh
Last active March 24, 2018 18:15
upnp set up script
#!/bin/bash
export IP=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
echo "setting up ip ${IP}"
check_service(){
echo `upnpc -l | grep $1'->' | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"`
}
register(){
local service_name=$1
@revington
revington / app.js
Last active August 29, 2015 14:15
app bootstrap
"use strict";
var express = require('express'),
nano = require('nano'),
path = require('path'),
compression = require('compression'),
favicon = require('serve-favicon'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
bodyParser = require('body-parser'),
@revington
revington / System Design.md
Created April 18, 2016 07:31 — forked from vasanthk/System Design.md
System Design Cheatsheet

#System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

##Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?