Skip to content

Instantly share code, notes, and snippets.

View jamesmoriarty's full-sized avatar
🔮
0xc0000005

James Moriarty jamesmoriarty

🔮
0xc0000005
View GitHub Profile
CREATE OR REPLACE FUNCTION calculate_dialup(
hours real,
service_dialup_id int
) RETURNS real as $$
DECLARE
dialup service_dialups%ROWTYPE;
excess_usage_charge real := 0;
BEGIN
SELECT * INTO dialup FROM service_dialups WHERE id = service_dialup_id;
-- ...
class Trie
def initialize
@root = {}
end
def build(string)
node = @root
string.chars.each do |char|
node[char] ||= {}
require "benchmark"
trie = Trie.new
dictionary = IO.read("/usr/share/dict/words").split("\n")
puts "/usr/share/dict/words has #{dictionary.size} words."
Benchmark.bm(15) do |benchmark|
benchmark.report("build (iterative)") do
trie = Trie.new
PATH=/usr/local/bin:$PATH
@jamesmoriarty
jamesmoriarty / git_bash_editor.sh
Created July 3, 2012 00:08
There was a problem with the editor 'vi'.
$ git commit
error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.
$ echo $?
1
$ git config --global core.editor /usr/bin/vim
$ git commit
[feature/tag-search 0167ee2] Merge branch 'master' of github.com:jamesmoriarty/project-x into feature/tag-search
$ echo $?
0
@jamesmoriarty
jamesmoriarty / one.js.coffee
Created July 4, 2012 02:15
Coffeescript Ternary Statements
# toggle order
order = ( order == "desc" ? "asc" : "desc" )
# var order, _ref;
#
# order = (_ref = order === "desc") != null ? _ref : {
# "asc": "desc"
# };
class Account
attr_reader :balance
def initialize(balance)
@balance = balance
end
def receive(amount)
@balance += amount
end
@jamesmoriarty
jamesmoriarty / kernel.rb
Created September 18, 2012 06:45
require_relative
# File lib/extensions/kernel.rb, line 38
def require_relative(path)
require File.join(File.dirname(caller[0]), path.to_str)
end
@jamesmoriarty
jamesmoriarty / redis.markdown
Created November 1, 2012 01:48 — forked from bdotdub/redis.markdown
Running redis using upstart on Ubuntu

Running redis using upstart on Ubuntu

I've been trying to understand how to setup systems from the ground up on Ubuntu. I just installed redis onto the box and here's how I did it and some things to look out for.

To install:

# Twilio HTTP HAProxy Configuration
# Version: 0.1
global
daemon
log 127.0.0.1 local0 info
maxconn 60000
spread-checks 3