Skip to content

Instantly share code, notes, and snippets.

@skolf
skolf / process.rb
Created June 19, 2014 22:28
An extension to the Ruby Process module for checking if a given process is running.
# usage: Process.alive? 1
# > true
module Process
class << self
def alive?(pid)
return false if pid.nil?
begin
Process.kill(0, pid.to_i)
status = true
rescue Errno::ESRCH
@skolf
skolf / Gemfile
Created June 19, 2014 22:10
A Rake task for precompiling assets in a Sinatra app using Sprockets.
source 'http://rubygems.org'
# app base
gem 'logger'
gem 'rack'
gem 'sinatra'
gem 'sinatra-assetpack'
gem 'sprockets'
gem 'sprockets-helpers'
@skolf
skolf / row-striping.rb
Last active August 29, 2015 14:02
This is an extension for any MySql-backed ActiveRecord model. It provides a convenient method for filtering results by row number on the database side.
# extend any ActiveRecord model with a fast method
# for selecting rows.
#
# this is useful for parallel processes that work on
# subsets of large tables.
#
# ex:
# process A needs to work on all odd numbered Posts,
# process B needs to work on all even numbered Posts.
#
@skolf
skolf / backbone-data-queue.js
Last active August 29, 2015 14:02
This is a simple extension to the base Backbone Router class to provide batch loading of models and collections. It's useful in single-page apps when multiple models/collections need to be loaded before transitioning to a different view.
// backbone-data-queue.js 1.0.0
// extends the base Backbone Router class with a helper method to
// perform a batch data load.
//
// call this with an array of Backbone models/collections. it returns
// a function that accepts success and error callbacks. the appropriate
// callback will be fired when the batch operation is complete.
//
// usage (in a Backbone router):