Skip to content

Instantly share code, notes, and snippets.

Phil Calçado lernte ich bereits vor einiger Zeit auf einem Event in Berlin kennen und hatte daher hohe Erwartungen an seinen Vortrag APIs: The Problems with Eating your Own Dog food. Ich sollte nicht enttäuscht werden. Nachdem die Frage: "Was ist Soundcloud?" und die damit verbundenen Anforderungen an Performanz geklärt waren, wurde dargestellt wie sich die Soundcloud Architektur über die Zeit entwickelt hat.

Während dieser Evolution wurde zeitweise das Rendern der Webseite auf den Browser verlagert, was zu ungefähr 159 API-Anfragen pro Seitenanfrage führte. Nicht nur dem Publikum machte diese Zahl Angst sondern auch der Soundcloud Crew, jedoch war man zuversichtlich dass durch zusätzliche Server diese Last zu schaffen sei. Schnell lernte man, dass nach dem Zusammenbruch des HAProxy weitere Komponenten (memcached/Rails/MySQL) der Masse an Anfragen nicht gewachsen waren.

module Foo
end
initializer "iqvoc.load_migrations" do |app|
app.class.configure do
config.paths['db/migrate'] += Iqvoc::Engine.paths['db/migrate'].existent
end
end
puts RUBY_VERSION
class Foo
def info(*args)
puts args.inspect
end
end
@youngbrioche
youngbrioche / add_encoding_headers.sh
Created December 2, 2011 12:12
Add encoding headers to Ruby files
find -name "*.rb" | \
while read filepath; do \
{ echo -n "$filepath: "; head -n1 "$filepath"; } | \
grep -v encoding | sed -e "s#.*#$filepath#"; \
done | \
while read filepath; do \
{ echo "# encoding: UTF-8"; echo; } | \
cat - "$filepath" > "$filepath.tmp"; \
mv "$filepath.tmp" "$filepath"; \
done
test "unicode decoding" do
encoded_val = "\u00C4ffle"
decoded_val = JSON.parse("{\"x\": \"#{encoded_val}\"}")['x'].gsub("\\n", "\n")
assert_equal decoded_val, "Äffle"
end
# 1.9.2 passes
# 1.8.7
# <"u00C4ffle"> expected but was
e = Typhoeus::Easy.new
e.url = "http://example.com/"
e.method = :get
e.perform
@youngbrioche
youngbrioche / configuration.rb
Created February 15, 2011 11:11
Small configuration DSL
module Foo
module Configuration
require 'ostruct'
extend ActiveSupport::Concern
included do
#
end
module ClassMethods
# dynamically determining the MySQL socket in use
<% socket = ["/tmp/mysql.sock",
"/opt/local/var/run/mysql5/mysqld.sock",
"/tmp/mysqld.sock",
"/var/run/mysqld.sock"].detect { |socket| File.exist?(socket) } %>
development:
encoding: utf8
username: root
development:
encoding: utf8
username: user
password: foobar
database: foo_development
<% if defined?(JRuby) %>
adapter: jdbcmysql
hostname: localhost
<% else %>
adapter: mysql