Skip to content

Instantly share code, notes, and snippets.

@ta
ta / fire_and_forget.rb
Created October 24, 2012 11:51
Fire and Forget in Ruby
# -*- encoding: utf-8; mode: ruby; tab-width: 2; indent-tabs-mode: nil -*-
def fire_and_forget &block
raise ::LocalJumpError, "No block given" unless block_given?
Process.detach(fork &block)
end
# Demo
puts "main"
@ta
ta / unicornctl
Created September 9, 2011 18:46
unicornctl manages your app's unicorn server in an easy manner
#!/usr/bin/env ruby
require "getoptlong"
module UnicornCTL
class Controller
def initialize(args, argv)
@args = args
@argv = argv
end
@ta
ta / update_all_returning.rb
Last active October 30, 2018 12:30
Add Postgresql RETURNING <column> to ActiveRecord when updating more than a single row
# USAGE:
#
# class SomeModel < ActiveRecord::Base
# include ActiveRecord::PostgresqlExtensions
# end
#
# SomeModel.update_all_returning("count = count + 1", nil, ["id", "count"])
#
module ActiveRecord
module PostgresqlExtensions