Skip to content

Instantly share code, notes, and snippets.

@jqr
jqr / reader.rb
Created February 24, 2012 01:53
Locking log rotation for processing
require 'fileutils'
class Reader
def self.read(filename, processing_filename)
return [] unless File.exists?(filename)
FileUtils.move(filename, processing_filename)
lines = []
File.open(processing_filename, 'r') do |f|
f.flock(File::LOCK_EX)
while !f.eof?
#
# Created by Eric Lindvall <eric@sevenscale.com>
#
class KestrelMonitor < Scout::Plugin
OPTIONS=<<-EOS
host:
label: Host
notes: Kestrel host
default: localhost
port:
@eric
eric / bundle-outdated-github.rb
Created March 8, 2012 06:11
Annotate your "bundle outdated" with GitHub compare URLs
#!/usr/bin/env ruby
#
# Annotate your "bundle outdated" with GitHub compare URLs
#
require 'open-uri'
require 'json'
def rubygems_gem_info(gem_name)
@justindossey
justindossey / gist:2063267
Created March 17, 2012 17:38
MongoMapper-- check that replicas are within a minute of primary
def all_replicas_in_sync?(verbose=false)
in_sync = true
# connect to the primary
mongo = Mongo::Connection.new(*MongoMapper.connection.primary)
db = mongo.db('local')
last_op=db.collection('oplog.rs').find.sort([['$natural',-1]]).limit(1).to_a[0]
db.collection('slaves').find().to_a.each do |slave|
opdiff = last_op['ts'].increment - slave['syncedTo'].increment
diff = (last_op['ts'].seconds - slave['syncedTo'].seconds)/1000.0
in_sync = false if diff > 60
@ryandotsmith
ryandotsmith / worker-pattern.md
Created April 11, 2012 20:15
The Work Pattern

The Worker Pattern

2011-05-22

Introduction

This article is the accumulation of a tutorial that was given as a training session at Red Dirt Ruby Conf (2011) and a formal talk given at Rails Conf (2011). To understand the theory behind The Worker Pattern, read over the slides and the slide notes. From there, you can follow the instructions in the Tutorial

@ryandotsmith
ryandotsmith / process-partitioning.md
Created April 13, 2012 06:40
Process Partitioning

Process Partitioning

The Problem

When working with large, high volume, low latency systems, it is often the case that processing data sequentially becomes detrimental to the system's health. If we only allow 1 process to work on our data we run into several challenges:

  • Our process may fall behind resulting in a situation which it is impossible for our process to catch up.
  • Our singleton process could crash and leave our system in a degraded state.
  • The average latency of data processing could be dramatically affected by outlying cases.
module Resque
module Plugins
# If you want only one instance of your job queued at a time,
# extend it with this module.
#
# For example:
#
# require 'resque/plugins/zookeeper_lock'
#
# class UpdateNetworkGraph
@panthomakos
panthomakos / benchmark.rb
Created May 3, 2012 20:06
Benchmark Your Bundle
#!/usr/bin/env ruby
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@paulmillr
paulmillr / active.md
Last active May 15, 2024 02:25
Most active GitHub users (by contributions). http://twitter.com/paulmillr

Most active GitHub users (git.io/top)

The count of contributions (summary of Pull Requests, opened issues and commits) to public repos at GitHub.com from Wed, 21 Sep 2022 till Thu, 21 Sep 2023.

Only first 1000 GitHub users according to the count of followers are taken. This is because of limitations of GitHub search. Sorting algo in pseudocode:

githubUsers
 .filter(user =&gt; user.followers &gt; 1000)
@camertron
camertron / measure.rb
Created June 15, 2012 22:48
Measure the memory taken by a Ruby object (by Robert Klemme)
#!/bin/env ruby
# lazy hack from Robert Klemme
module Memory
# sizes are guessed, I was too lazy to look
# them up and then they are also platform
# dependent
REF_SIZE = 4 # ?
OBJ_OVERHEAD = 4 # ?