Skip to content

Instantly share code, notes, and snippets.

@joho
joho / gzip_net_http.rb
Created September 19, 2012 04:12
Handling gzip responses in Ruby Net::HTTP library
# from http://pushandpop.blogspot.com.au/2011/05/handling-gzip-responses-in-ruby-nethttp.html
# i wanted syntax highlighting
require 'net/http'
debug = Proc.new{|msg| STDERR.puts "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}] #{msg}" }
page = nil
http = Net::HTTP.new( "www.google.com", 80 )
req = Net::HTTP::Get.new( "/search?num=20&hl=en&noj=1&q=test&btnG=Search", { "Accept-Encoding" => "gzip", "User-Agent" => "gzip" } )
@zaccari
zaccari / workers.rake
Created October 12, 2012 17:15 — forked from karmi/workers.rake
Rake taks to launch multiple Resque workers in development/production with simple management included
# Rake task to launch multiple Resque workers in development/production with simple management included
require 'resque/tasks' # Require Resque tasks
namespace :workers do
# = $ rake workers:start
#
# Launch multiple Resque workers with the Rails environment loaded,
# so they have access to your models, etc.
@miketheman
miketheman / zook_grow.md
Created July 22, 2013 21:36
Adding nodes to a ZooKeeper ensemble

Adding 2 nodes to an existing 3-node ZooKeeper ensemble without losing the Quorum

Since many deployments may start out with 3 nodes and so little is known about how to grow a cluster from 3 memebrs to 5 members without losing the existing Quorum, here is an example of how this might be achieved.

In this example, all 5 nodes will be running on the same Vagrant host for the purpose of illustration, running on distinct configurations (ports and data directories) without the actual load of clients.

YMMV. Caveat usufructuarius.

Step 1: Have a healthy 3-node ensemble

@sauloperez
sauloperez / signal_catching.rb
Last active December 14, 2024 13:43
How to catch SIGINT and SIGTERM signals in Ruby
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
end
puts "I have PID #{Process.pid}"
# Trap ^C
Signal.trap("INT") {
@dallasmarlow
dallasmarlow / gist:6978574
Created October 14, 2013 16:47
jruby hdfs client
#!/usr/bin/env jruby
include Java
options = {
hdfs_uri: 'hdfs://0.0.0.0:8020/',
hadoop_config_path: '/etc/hadoop/conf',
hadoop_config_files: ['core-site.xml', 'hdfs-site.xml'],
}
hdfs_conf = org.apache.hadoop.conf.Configuration.new
@shawnjgoff
shawnjgoff / snmp4jruby_trap_listener.rb
Created December 21, 2013 17:57
Using snmp4jruby to receive traps and informs...
#!/usr/bin/env jruby
require 'snmp4jruby'
class TrapListener
def initialize()
@transport = SNMP4JR::Transport::DefaultUdpTransportMapping.new
@address = SNMP4JR::SMI::GenericAddress.parse("udp:127.0.0.1/1162")
@snmp = SNMP4JR::Snmp.new(@transport)
@callbacks = []
@snmp.addNotificationListener(@address, self)
@stephancom
stephancom / stripe_customer.rb
Created March 21, 2014 03:54
Stripe Customer rails concern
# _ _
# __| |_ _ _(_)_ __ ___
# (_-< _| '_| | '_ \/ -_)
# /__/\__|_| |_| .__/\___|
# |_|
# __ _ _ __| |_ ___ _ __ ___ _ _
# / _| || (_-< _/ _ \ ' \/ -_) '_|
# \__|\_,_/__/\__\___/_|_|_\___|_|
#
# (c) 2013 stephan.com
@dfletcher
dfletcher / tsws
Last active July 21, 2018 12:47
Totally simple web server using Bash and netcat (nc)
Moved to a proprer repositoy, TSWS is a real boy now!
https://github.com/dfletcher/tsws
PRs welcomed.
@datakurre
datakurre / .gitignore
Last active December 29, 2022 10:29
Minimal Nix Docker
*.tar.gz
.sentinel.*