Skip to content

Instantly share code, notes, and snippets.

View alandotcom's full-sized avatar

Alan Cohen alandotcom

View GitHub Profile
@alandotcom
alandotcom / UnicornMetrics
Created June 26, 2013 00:43
Example of some new middleware for gathering metrics for Ruby web apps running on Unicorn
{
"responses.2xx": {
"type": "counter",
"value": 1
},
"responses.3xx": {
"type": "counter",
"value": 19
},
"responses.4xx": {
@alandotcom
alandotcom / commit-msg
Created August 26, 2013 15:20
A commit-msg shell function to insert hyper-links to JIRA issues directly into the commits that are related. We use Gerrit for code-review, so this also takes into account that a changeID may exist in the commit message. Adding the link is simply a matter of putting the JIRA issue tag in the commit message header surrounded by brackets. Multiple…
#!bin/bash
MSG="$1"
# Add JIRA hyperlinks to the end of the commmit message
# Using ggrep (gnu grep) and
add_JiraUrl() {
# Get all the JIRA numbers from the commit heading e.g., [AIP-2024][APPS-2000]
JIRA=$(cat $MSG | head -n 1 | ggrep -Po '(?<=\[)[A-Z]*[\-]\d*(?=\])')
@alandotcom
alandotcom / gist:6766423
Last active December 24, 2015 07:49
Watching long running commands in OSX

Install terminal-notifier

$ gem install terminal-notifier

Then add a new function into your .bashrc or .zshrc

function watch { 
 $* 
@alandotcom
alandotcom / .vimrc
Created April 24, 2014 03:10
.vimrc
set nocompatible " choose no compatibility with legacy vi
set synmaxcol=120 " limit syntax highlighting to first 120 col
set number " line numbers
set colorcolumn=80
"" Set cursor lines in current window
au WinLeave * set nocursorline nocursorcolumn
au WinEnter * set cursorline cursorcolumn
"" Recognize Markdown files

Keybase proof

I hereby claim:

  • I am lumberj on github.
  • I am 0x00 (https://keybase.io/0x00) on keybase.
  • I have a public key whose fingerprint is 4633 F361 A0D4 9653 A019 6F3B BD00 2615 CC77 8356

To claim this, I am signing this object:

@alandotcom
alandotcom / powerset.rb
Last active August 29, 2015 14:09
Power Set
def power_set(set)
# Base Case: The power set of the empty set is a set with only the empty set [ [] ]
return [set] if set.empty?
# General Case: PS(set): PS(set - element) UNION [ element UNION for each subset in PS(set-element) ]
ps = power_set(set[1..-1])
ps | ps.map { |subset| [set[0]] | subset }
end
@alandotcom
alandotcom / promiseLoop.js
Created December 10, 2014 03:00
Async promise loop
var Promise = require('bluebird');
var _ = require('lodash');
function promiseA() {
return Promise.resolve([1]);
}
function promiseB(prevResult) {
prevResult.push(2)
return Promise.resolve(prevResult);
@alandotcom
alandotcom / paginate_offers.js
Created December 12, 2014 20:47
Paginating offers from ripple-rest
#!/usr/bin/env node
var http = require('http');
var concat = require('concat-stream');
var address = 'rQE5Z3FgVnRMbVfS6xiVQFgB4J3X162FVD';
var url = 'http://localhost:5990/v1/accounts/' + address + '/orders?limit=10';
function getOrders(url, cb) {
var req = http.get(url, function(res) {
res.pipe(concat(function(body) {
@alandotcom
alandotcom / pagination_streams.js
Last active August 29, 2015 14:11
Paginating ripple-rest responses with streams
#!/usr/bin/env node
var oboe = require('oboe');
const address = 'rQE5Z3FgVnRMbVfS6xiVQFgB4J3X162FVD';
const baseUrl = 'http://localhost:5990/v1/accounts/' + address + '/orders?limit=10';
const stream = process.stdout;
stream.write('[\n');
streamOrders(baseUrl,true)
@alandotcom
alandotcom / functions.js
Created December 23, 2014 17:31
Function declaration vs. statement
a();
b();
var a = function() {
console.log("hello world");
};
function b() {
console.log("hello, again");
}