Skip to content

Instantly share code, notes, and snippets.

@peterkeen
peterkeen / gist:79a9d7b9f068f8a199de
Created January 30, 2015 21:41
A silly torturous PG plan
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------
Append (cost=1124.07..1134.09 rows=201 width=136) (actual time=13.030..13.052 rows=13 loops=1)
CTE months
-> Function Scan on generate_series x (cost=0.00..25.00 rows=1000 width=4) (actual time=0.042..0.064 rows=12 loops=1)
CTE monthly_income
-> HashAggregate (cost=293.73..293.74 rows=1 width=42) (actual time=12.623..12.625 rows=10 loops=1)
-> Seq Scan on ledger (cost=0.00..293.52 rows=12 width=42) (actual time=10.223..12.497 rows=27 loops=1)
Filter: ((account ~ 'Income:Consulting'::text) AND ((jtags ->> 'Client'::text) IS NOT NULL))
Rows Removed by Filter: 2741
if Rails.env.production?
resp = HTTParty.get(@sale.product.file.url)
filename = @sale.product.file.url
send_data resp.body,
:filename => File.basename(filename),
:content_type => resp.headers['Content-Type']
else
filename = File.expand_path(Sale.last.product.file_file_name, Rails.root)
send_data File.open(@sale.product.file_file_name),
echo "hi there"
@peterkeen
peterkeen / about.md
Last active August 29, 2015 13:59
Email courses as state machines.

This is a first draft of an idea I had in the shower this morning.

Email courses (aka sequences of email autoresponders) can be trivially modeled as finite state machines. Each state is the last email they were sent (or queued to receive) and each transition queues an email to be sent.

This example implementation builds on top of AASM for the state machine and ActsAsTaggableOn to keep track of states. In a production-ready implementation, likely the state machine implementation would be wrapped in a DSL that streamlines the process a little more.

@peterkeen
peterkeen / gist:7591428
Created November 21, 2013 23:02
microsoft.com is down
$ dig microsoft.com @4.2.2.2
; <<>> DiG 9.7.6-P1 <<>> microsoft.com @4.2.2.2
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 15309
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
@peterkeen
peterkeen / gist:6017752
Last active December 19, 2015 21:08 — forked from idan/gist:3135754

Hello there! This is a sample post for gist.io, a super-lightweight writing soapbox for hackers.

Now look up. Further. Above the post title. See that grey text with the gist ID?

Now back to me. That grey text is a link! Open that sucker in a new tab to see the source for this post. Also, I'm on a horse.

This is a SUPER major heading

If you peek at it with a web inspector, you'll see that it is a second-level heading. You can use first level headings, but they'll look just like the second level ones, and the gods of the HTML5 outlining algorithm will frown upon you.

@peterkeen
peterkeen / Dockerfile
Created June 27, 2013 05:43
My very first Dockerfile! It installs Ruby 2.0 from scratch, installs bundler, and then vendors in my app and installs dependencies.
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 January 8, 2013 05:44
This is how I implement budgets for ledger web
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))"
@peterkeen
peterkeen / ward.txt
Created November 29, 2012 16:50
Ward Cunningham on Pair Programming to the pdxruby mailing list
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
/^(?:Expenses:(Cable|Utils))/
* $account -0.5
* Assets:Receivable:GF 0.5
= /^Expenses:Rent$/
* $account -0.2968
* Assets:Receivable:GF 0.2968