Navigation Menu

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 / boolean_char.rb
Created January 27, 2014 16:43
The things we do for legacy databases
require 'dm-core'
class BooleanChar < DataMapper::Property::String
def primitive?(value)
super || value == true || value == false
end
# prepare for model use
def load(value)
@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
@tpitale
tpitale / Notes.txt
Created December 9, 2013 17:36
Notes on "complex" nested routes/urls/views in Ember
In order to to add a new task for Problem 3 in the UI above, I'm hoping for a route that's something like `/problems/3/tasks/new`. This style is, of course, very much like what Rails uses.
Below is a cut down version of the router setup I'm using to to try to accomplish this URL structure. It seems strange to have a resource "problem" inside of a resource "problems", but the edit for that problem is ouside the individual problem, but inside of problems (plural).
Either way, all of this is structured in such a way as to give me the UI above, and the URL I'd like to use. To couple the UI and the URL together feels like it makes things very brittle in the router, and makes me fight against Embers' conventions.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
setup_window
end
def window
@window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
end
private
@tpitale
tpitale / gist:7359235
Created November 7, 2013 18:11
Reading the header info from a whisper (.wsp) file with ruby.
irb(main):003:0> pp Wisp.info(File.expand_path('~/Dropbox/Projects/created_or_updated.wsp'));nil
{:aggregation_method=>"average",
:max_retention=>94608000,
:x_files_factor=>0.5,
:archives=>
[{:offset=>64,
:seconds_per_point=>10,
:point_count=>241920,
:retention=>2419200,
:size=>2903040},
@tpitale
tpitale / czmq-test.rb
Created October 9, 2013 04:15
Celluloid-zmq PubSub messing about.
#!/usr/bin/env ruby
gem 'celluloid-zmq', '0.15.0'
require 'celluloid'
require 'celluloid/zmq'
class Publisher
include Celluloid::ZMQ
@tpitale
tpitale / gist:6152948
Created August 5, 2013 01:54
Give Ruby 1.9 OpenStruct [] and []= like in Ruby 2.0
options = OpenStruct.new({a: 1, b: 2})
# make options[] work in 1.9 like 2.0
unless options.respond_to?(:[])
options.extend(Forwardable)
options.def_delegators :@table, :[], :[]=
end
# now I can do
options[:a]
@tpitale
tpitale / standup_email
Created July 31, 2013 17:20
Ruby script to deliver standup email. Requires ruby and the mail gem.
#!/usr/bin/env ruby
require 'mail'
today = Time.now.strftime('%Y-%m-%d')
options = { :address => "smtp.gmail.com",
:port => 587,
:domain => '<your domain>',
:user_name => '<your full email>',
@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',