Skip to content

Instantly share code, notes, and snippets.

@peterkeen
peterkeen / Dockerfile
Created Jun 27, 2013
My very first Dockerfile! It installs Ruby 2.0 from scratch, installs bundler, and then vendors in my app and installs dependencies.
View Dockerfile
MAINTAINER Pete Keen "pete@petekeen.com"
# Use Ubuntu 12.04 as the base image
FROM ubuntu:precise
# Install a bunch of prerequisites
RUN apt-get update
RUN apt-get install -y git-core curl wget libssl1.0.0 python-yaml build-essential libssl-dev
# Install ruby-build
@peterkeen
peterkeen / 20121108220000_add_budget_tables.rb
Created Jan 8, 2013
This is how I implement budgets for ledger web
View 20121108220000_add_budget_tables.rb
Sequel.migration do
up do
create_table(:budget_periods) do
String :account
BigDecimal :amount
Date :from_date
Date :to_date
end
create_or_replace_view :budget_months, "select xtn_month, account, amount from (select distinct xtn_month from accounts_months) x cross join budget_periods where xtn_month between budget_periods.from_date and (coalesce(budget_periods.to_date, now()::date))"
View do_backup.sh
#!/bin/bash
# This depends on a file named `/root/backup_dirs` containing a list of directories to backup
# one per line. All directories in that file, plus a database dump, will be archived together.
#
# Further, if you have a gitolite installationn, this will backup every repo in an individual archive.
set -e
set -x
set -o pipefail
@peterkeen
peterkeen / ward.txt
Created Nov 29, 2012
Ward Cunningham on Pair Programming to the pdxruby mailing list
View ward.txt
Subject: Re: [pdxruby] Re: Complex return value anti-pattern?
From: Ward Cunningham <ward.cunningham@gmail.com>
Date: Thu, 29 Nov 2012 08:23:26 -0800
Pair programming is often misunderstood.
To understand pairing one must examine the world views of programmers. For
many (perhaps all programmers historically) programming is difficult and re
quires skill and concentration to be successful. For others, and here we fi
nd roots in dynamic languages, programming is easy but requires imagination
View gist:3177415
/^(?:Expenses:(Cable|Utils))/
* $account -0.5
* Assets:Receivable:GF 0.5
= /^Expenses:Rent$/
* $account -0.2968
* Assets:Receivable:GF 0.2968
View gist:3062758
<table class="table table-striped table-bordered">
<col class="span2"></col>
<col class="span8"></col>
<col class="span2"></col>
<thead>
<tr>
<th>From</th>
<th>Subject</th>
<th>Date</th>
</tr>
View built.coffee
foo = () ->
a = 17
40
foo()
View example transfer
2012/02/29 * Medical Fund Transfer To Savings
[Assets:Checking] $4,000.00
[Assets:Funds:Medical]
2012/02/29 * Savings Deposit
Assets:Savings $4,000.00
Assets:Checking
2012/02/29 * Medical Fund Transfer To Savings
[Assets:Medical] $4,000.00
@peterkeen
peterkeen / query.sql
Created Mar 4, 2012
Complicated ledger query
View query.sql
-- Count the number of months where the 12 month moving average of after-tax expenses excluding travel (basically, normal ordinary expenses) went up, down, or didn't change
select
sum(case when pct_change > 0 then 1 else 0 end) as up,
sum(case when pct_change < 0 then 1 else 0 end) as down,
sum(case when pct_change = 0 then 1 else 0 end) as no_change
from (
select
xtn_month,
((expenses - prev) / prev) * 100 as pct_change
@peterkeen
peterkeen / gist:1548326
Created Jan 1, 2012
python "anonymous" functions
View gist:1548326
def some_anonymous_function(arg1, arg2):
print "%s %s" % (arg1, arg2)
def some_named_function(func, arg1, arg2):
func(arg1, arg2)
some_named_function(some_anonymous_function, arg1, arg2)