Skip to content

Instantly share code, notes, and snippets.

View alandotcom's full-sized avatar

Alan Cohen alandotcom

View GitHub Profile
@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
@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 / 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 / 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 / gist:4142405
Created November 25, 2012 04:31
SuperFeedr PubSubHubbub API inside a Rails App

Structure of the JSON response from SuperFeedr

When working with the SuperFeedr REST API it is important to understand the notifications that SuperFeedr will send to your server.

I am using th JSON response here, as the format is familiar and easy to parse using the Ruby API.

Receiving feed updates

After successfully subscribing to a feed, SuperFeedr will send notifications to the callback URI specified during the subscription process.

@alandotcom
alandotcom / fizzbuzz.rb
Created November 16, 2012 00:56
fizzbuzz
=begin
Write a program that prints the numbers from 1 to 100.
But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz".
For numbers which are multiples of both three and five print "FizzBuzz".
(http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html)
=end
module FizzBuzz
def self.fizzbuzz(n)
case
@alandotcom
alandotcom / jq.konami.js
Created November 6, 2012 02:05 — forked from adamcbrewer/jq.konami.js
JS: Konami Code
// Konami code with jQuery.
// Source: http://paulirish.com/2009/cornify-easter-egg-with-jquery/
var kkeys = [],
konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(evt) {
kkeys.push( evt.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ){
$(document).unbind('keydown',arguments.callee);
@alandotcom
alandotcom / gist:4013119
Created November 4, 2012 19:05
Internal state is not cloned
class Obj
attr_accessor :first, :second
def initialize
@first = {:one => 'x',:two => 'y',:three => 'z'}
@second = {[1,2]=>'x',[3,2]=>'o'}
end
end
# Using either dup or clone doesn't make a difference, they both make shallow copies
obj1 = Obj.new
@alandotcom
alandotcom / card.rb
Created October 21, 2012 18:52 — forked from dbc-challenges/card.rb
FlashCardinator
class Card
attr_reader :term, :definition
def self.load(filename,cards = [])
File.new(filename).each do |card|
card = card.split("\t")
cards << Card.add_card(card)
end
cards
end
require './binary'
describe 'binary_search' do
let(:int_ary) { (100..200).to_a }
let(:strg_ary) { %w{ swedish\ chef miss\ piggy scooter gnu animal foo-foo }.sort }
let(:one_elemnt_ary) { [0] }
it 'returns correct index' do
binary_search(135,int_ary).should eq 35
binary_search('miss piggy',strg_ary).should eq 3