Skip to content

Instantly share code, notes, and snippets.

@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
CREATE OR REPLACE FUNCTION update_notify() RETURNS trigger AS $$
DECLARE
channel text;
BEGIN
channel := TG_ARGV[0];
NOTIFY channel;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
@tpitale
tpitale / spec_helper.rb
Created May 24, 2014 01:31
Disable "should" syntax
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
@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 / 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>',