Skip to content

Instantly share code, notes, and snippets.

View Xorlev's full-sized avatar

Michael Rose Xorlev

View GitHub Profile
@Xorlev
Xorlev / gzip chain
Created August 30, 2013 02:54
Fast GZIP copy, credit the smart guys at Tumblr. You can use this to replicate data from one machine to another, and without decompressing send the data to the next server in the chain until the terminal link in the chain. pigz is a parallel gzip. With this you can copy data at (almost) gigabit line speed. Great for seeding read slaves.
On the last machine in the chain:
nc -l 1234 | pigz -d | tar xvf -
On each intermediate machine, you use a fifo to copy the data to the next machine as well as decompressing.
mkfifo myfifo
nc $NEXT_SERVER 1234 <myfifo &
nc -l 1234 | tee myfifo | pigz -d | tar xvf -
@Xorlev
Xorlev / load_file.rb
Created December 10, 2011 09:10
Naive data loading
# Not the most efficient method...
File.open('track1/albumData1.txt').each do |line|
album, artist, *genres = split_and_filter(line)
genres.map! { |g| Genre.find(g) }
Album.create! :id => album, :artist_id => artist, :genres => genres
end
@Xorlev
Xorlev / models.rb
Created December 10, 2011 09:08
AR Models
require 'active_record'
class Album < ActiveRecord::Base
belongs_to :artist
has_many :tracks
has_and_belongs_to_many :genres
attr_accessible :id, :artist_id, :genres
def to_s