Skip to content

Instantly share code, notes, and snippets.

@tpitale
tpitale / group_and_count_to_date.sql
Last active August 29, 2015 13:56
Group count by creation date and sum of count-to-date.
SELECT created_on, note_count, sum(note_count) OVER (ORDER BY created_on ASC)
FROM (
SELECT date_trunc('day', created_at) AS created_on, count(1) AS note_count
FROM notes
GROUP BY created_on
ORDER BY created_on DESC
) AS note_counting;
-- WHERE created_on >= '2013-01-01'
@tpitale
tpitale / wait_for_notify.rb
Last active August 29, 2015 14:01
Implementation of wait_for_notify with PG and Celluloid::IO
def wait_for_notify(&block)
io = pg_connection.socket_io
while @listening do
Celluloid::IO.wait_readable(io) # blocks execution, but unblocks this actor
pg_connection.consume_input # fetch any input on this connection
# read the NOTIFY messages off the socket
while notification = pg_connection.notifies do
block.call(
@tpitale
tpitale / data.tsv
Created May 29, 2014 15:23
Minimally responsive (flexible width) D3 Bar Chart
letter frequency
A .08167
B .01492
C .02782
D .04253
E .12702
F .02288
G .02015
H .06094
I .06966
@tpitale
tpitale / gist:93428db182dd44ec52e5
Created June 11, 2014 03:50
SideBarEnhancement for ST2
import os; path=sublime.packages_path(); (os.makedirs(path) if not os.path.exists(path) else None); window.run_command('exec', {'cmd': ['git', 'clone', 'https://github.com/titoBouzout/SideBarEnhancements', 'SideBarEnhancements'], 'working_dir': path})
import os; path=sublime.packages_path(); window.run_command('exec', {'cmd': ['git', 'checkout', '37429739a0452a2dc36343fb7875ba7fcbeb88a9'], 'working_dir': os.path.join(path, 'SideBarEnhancements')})
@tpitale
tpitale / gist:2037000
Created March 14, 2012 14:51
Handy little script to run a glob directory of test/unit tests
#!/usr/bin/env ruby
$: << 'test' << 'lib'
Dir.glob(ARGV).each {|f| load f unless f =~ /^-/}
# Usage: ruby_test test/unit/**/*.rb
@tpitale
tpitale / demo.rb
Created July 15, 2013 15:43
Test/demo script for Legato Issue #34
#!/usr/bin/env ruby -Ilib
require 'pp'
require 'oauth2'
require 'legato'
module OAuth2Helpers
def build_client(id, secret)
opts = {
:authorize_url => 'https://accounts.google.com/o/oauth2/auth',
@tpitale
tpitale / ruby-example-upstart.conf
Created January 3, 2014 04:09
Basic start/stop upstart init conf for a ruby script. May require modification to run in /bin/bash or if you need to source rbenv or chruby.
# /etc/init/ruby-example-upstart.conf
description "Ruby example upstart conf"
# change to the user you want to run this ruby script as
setuid deploy
setgid deploy
# This starts upon bootup and stops on shutdown
# check runlevel of running system with `runlevel` command
dm-migrations
dm-do-adapter
dm-yaml-adapter
dm-mysql-adapter
dm-postgres-adapter
dm-sqlite-adapter
dm-sqlserver-adapter
dm-oracle-adapter
dm-rest-adapter
dm-ferret-adapter
@tpitale
tpitale / reel_ws_pg_example.rb
Last active March 23, 2017 13:03
Reel Websocket Server using PG Listen/Notify for crude pubsub
require 'rubygems'
require 'bundler/setup'
require 'reel'
require 'celluloid/io'
require 'pg'
module PGNotifications
def self.included(actor)
actor.send(:include, Celluloid::IO)
end