Skip to content

Instantly share code, notes, and snippets.

View octplane's full-sized avatar
👨‍💻
I came here for the javascript jokes and was disappointed

Pierre Baillet octplane

👨‍💻
I came here for the javascript jokes and was disappointed
View GitHub Profile
@octplane
octplane / client.rb
Created October 27, 2010 16:38
Redis Monkey Patch to get custom exception handling for redis
class RedisException < Exception
attr_accessor :original_exception
end
class Redis
class Client
def call(*args)
begin
process(args) do
read
end
@octplane
octplane / mongo_pubsub.rb
Created November 9, 2010 16:17
Simple Pub/Sub system using MongoDB, capped collections and tailable cursors in ruby
require 'rubygems'
require 'mongo'
module MongoPubSub
QUEUES_COLLECTION = 'queues'
class EndSubscriptionException < Exception; end
class Publisher
def initialize(queue_name, mongo_connection)
# Initialize queue collection as a capped collection
if not mongo_connection[QUEUES_COLLECTION].collection_names.include?(queue_name)
#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which
# are not shown in this example
#
# Some options that are often worth tuning have been included as
@octplane
octplane / test_caller.rb
Created November 26, 2010 12:28
caller_for_all_threads fails to work in a multithread program using sleep conditions
#!/usr/bin/env ruby
Thread.new do
sleep(15)
puts "dumping stacks"
puts caller_for_all_threads.inspect
puts "done."
end
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
require 'event_utils'
require 'singleton'
require 'syslog'
require 'trollop'
require 'yaml'
class Syslogger
@octplane
octplane / net_http_write_timeout.rb
Created January 26, 2011 08:24
enforce a 3s timeout when writing to the network, monkey-patch against 1.8 ruby net/http
module Net
class HTTP < Protocol
def connect
D "opening connection to #{conn_address()}..."
s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }
D "opened"
if use_ssl?
unless @ssl_context.verify_mode
warn "warning: peer certificate won't be verified in this SSL session"
@octplane
octplane / changes.sh
Created April 19, 2011 15:54
Quickly upload changes to a chef server (0.8)
#!/bin/sh
diff -x .gitignore -x .DS_Store -x metadata.json -x "README" -qr cookbooks/ /srv/chef/cookbooks/ | grep -v "Only in
/srv/chef/cookbooks/" | sed -e "s/.*cookbooks\/[ :]*//;s/\/.*//;s/:.*//" | sort | uniq | xargs knife cookbook upload
for a in `diff -x .gitignore -x metadata.json -x "README" -qr cookbooks/ /srv/chef/cookbooks/ | grep "Only in /srv/
chef/cookbooks/" | sed -e "s/.*cookbooks\/[ :]*//;s/\/.*//;s/:.*//" | sort | uniq`; do
echo "y" | knife cookbook delete $a
done
@octplane
octplane / palm.rb
Created April 20, 2011 23:40
SuperUnpack sample code
require 'superunpack'
class Category < Complex
Blong :index
Blong :identifier
Blong :dirty
CString :long_name
CString :short_name
@octplane
octplane / firstrecipe.rb
Created August 11, 2011 12:15
First Recipe. Creates the empty monitoring registry and also store the new key
# This recipe should be called at the beginning of the run_list
# If we are not the last item of the run_list break
order = node.recipes
if order[0] != "firstrecipe"
Chef::Log.error("First Recipe should be the first recipe to run; current run list is "+order.inspect)
raise "Please refactor my runlist"
end
@octplane
octplane / lastrecipe.rb
Created August 11, 2011 12:21
Last Recipe that populates the registry
order = node.recipes
if order[-1] != "lastrecipe"
Chef::Log.error("Last Recipe should be the last recipe to run")
raise "Please refactor my runlist"
end
# This recipe is tightly integrated with monitored in fotonauts and recipe
# firstrecipe