Skip to content

Instantly share code, notes, and snippets.

View joaodrp's full-sized avatar

João Pereira joaodrp

View GitHub Profile

Developing a RubyGem using Bundler

Bundler is a tool created by Carl Lerche, Yehuda Katz, André Arko and various superb contributors for managing Rubygems dependencies in Ruby libraries. Bundler 1.0 was released around the same time as Rails 3 and it's the Rails project where Bundler is probably most well-known usage occurs. But remember, Bundler isn't just for Rails!

Did you know that you can use Bundler for not only gem dependency management but also for writing our own gems? It's really easy to do this and Bundler provides a couple of things to help you along this path.

But first, why?

Why should we create a gem? Can't we just throw in some code into our other library and use that instead? Sure, we can do that. But then what if we want to use the code elsewhere, or we want to share it? This is why a gem is perfect. We can code our library and a gem separately from each other and just have the library require the gem. If we want to use the gem in another library, then it's just a tiny modificati

@joaodrp
joaodrp / benchmark.sh
Created October 28, 2011 14:11 — forked from emersonmoretto/benchmark.sh
Apache bench + Gnuplot Script with custom line titles and cleaning *.out files
#!/bin/bash
echo -e "\nbenchmark.sh -n<number of requests> -c<number of concurrency> <line tittle>:<URL1> <line tittle>:<URL2> ..."
echo -e "\nEx: benchmark.sh -n100 -c10 google:http://www.google.com/ bing:http://www.bing.com/ \n"
## Gnuplot settings
echo "set terminal png
set output 'benchmark_${1}_${2}.png'
set title 'Benchmark: ${1} ${2}'
# Simple web service that looks for an image metadata record on a MySQL db given its ID and sends it back in JSON
#
# Ruby 1.9.3
# All gems updated to the most recent version
# MBP i5 8gb Lion
#
# See source code above, combo is:
# Sinatra + Thin:
# - mysql_db.rb # mysql2 api class
# - sinatra_thin_server.rb
#
# Inside Config file
#
backend_map = {'mongodb' => MyProject::Backends::MongoDB,
'mysql' => MyProject::Backends::MySQL}
conf = load_some_yaml_file_with_a_backend_URI_parameter()
uri = conf[:backend]
backend_name = uri.split(':').first
# server.rb
require 'goliath'
module MyApp
class Server < Goliath::API; end
end
# ----------------
# api.rb
require 'em-synchrony'
require 'uri'
module Store
class FileSystem
CHUNKSIZE = 65536
def initialize(uri)
@uri = uri
@path = uri.path
end
module Backend
CHUNKSIZE = 65536
def self.save(tmp_file, new_file)
md5 = Digest::MD5.new
STDERR.puts "COPYING!!"
open(tmp_file, "rb") do |tmp|
open(new_file, "wb") do |new|
until tmp.eof?
#
# s3_store.rb
#
require "em-synchrony"
require "em-synchrony/em-http"
class S3Store
def initialize(uri)
@uri = uri
end
$ docker history hello-world-go
IMAGE CREATED CREATED BY SIZE
89f4b3330c9d 14 minutes ago /bin/sh -c #(nop) CMD ["./hello-world"] 0B
214fd4f5ac0c 14 minutes ago /bin/sh -c go build -o hello-world 1.86MB
2e3c915dc835 14 minutes ago /bin/sh -c #(nop) COPY file:2d548923cbd267... 72B
320edf382c83 14 minutes ago /bin/sh -c #(nop) WORKDIR /src/app 0B
ed119d8f7db5 2 days ago /bin/sh -c #(nop) COPY file:ea7c9f4702f94a... 2.48kB
<missing> 2 days ago /bin/sh -c #(nop) WORKDIR /go 0B
<missing> 2 days ago /bin/sh -c mkdir -p "$GOPATH/src" "$GOPATH... 0B
<missing> 2 days ago /bin/sh -c #(nop) ENV PATH=/go/bin:/usr/l... 0B
$ docker history hello-world-go-multi
IMAGE CREATED CREATED BY SIZE
ea51dd184d58 2 minutes ago /bin/sh -c #(nop) CMD ["./hello-world"] 0B
10ba0619b65c 2 minutes ago /bin/sh -c #(nop) COPY dir:0369fffbae7eaf4... 1.86MB
d82070a626fa 2 minutes ago /bin/sh -c #(nop) WORKDIR /src/app 0B
76da55c8019d 3 days ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 3 days ago /bin/sh -c #(nop) ADD file:4583e12bf5caec4... 3.97MB