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 / 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 / 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 / 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"
require 'rubygems'
require 'eventmachine'
require 'evma_httpserver'
require 'event_utils'
require 'singleton'
require 'syslog'
require 'trollop'
require 'yaml'
class Syslogger
@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
#
# 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 / 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)
@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
# Redis configuration file
daemonize no
pidfile /var/run/redis-picor.pid
port 12430
bind 0.0.0.0
timeout 3000
save 900 1
save 300 10
save 60 10000
dbfilename redis-picor_state.rdb
@octplane
octplane / test-case.rb
Created October 20, 2010 14:42
Test case for /redis-rb/issues#issue/63
#!/usr/bin/env ruby
require 'rubygems'
require 'redis'
class Subscriber
def initialize
end
def redis
Redis.new(:host => "redis.fotonauts.net", :port => 12430)