Skip to content

Instantly share code, notes, and snippets.

View andrewle's full-sized avatar

Andrew Le andrewle

View GitHub Profile
@andrewle
andrewle / a.rb
Created May 30, 2014 17:13 — forked from ahoward/a.rb
#! /usr/bin/env ruby
# this script can create a static build from virtually any rails' project. it
# has two simple requirements.
#
# 1) you have
#
# gem 'passenger'
#
# in your Gemfile
@andrewle
andrewle / leader-election.md
Created April 16, 2012 02:06 — forked from ryandotsmith/process-partitioning.md
Leader Election With Ruby & PostgreSQL

Leader Election With Ruby & PostgreSQL

The Problem

I have a table with millions of rows that needs processing. The type of processing is not really important for this article. We simply need to process some data with Ruby --or any other user-space programming language.

A Solution

#!/usr/bin/env ruby
require 'rubygems'
require 'chef'
require 'chef/client'
require 'chef/run_context'
Chef::Config[:solo] = true
Chef::Config[:log_level] = :info
Chef::Log.level(:info)
require 'net/http'
require 'uri'
# POST /api/v1/:format/new
# GET /api/v1/:format/gists/:user
# GET /api/v1/:format/:gist_id
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'),
{ 'files[file1.ab]' => 'CONTNETS',
'files[file2.ab]' => 'contents' })