Autorenarchiv: Daniel

No Log to STDOUT from Sinatra / Thin in development?

Today logging broke in my environment ( Rack 1.4 & Sinatra 1.4 (GIT) & Thin 1.3.1 ). Don’t know why exactly (I refreshed all my Gems) – but somehow it got fixed by adding: use Rack::CommonLogger

Veröffentlicht in Ruby | Getagged: , , , | Kommentieren

Sinatra Streaming + nginx Proxy

Fairly easy. The important line here is: proxy_buffering off; I think this one works at least for most Rack based applications. The application itself runs on thin ( besides that, I only know Unicorn and Rainbow(s?) that have Streaming Support. Webrick won’t do that (yet)) My vhost config. upstream stream { server 127.0.0.1:4800; server 127.0.0.1:4801; [...]

Veröffentlicht in Ohne Kategorie, Ruby, Server / Deployment | Getagged: , , , | Kommentieren

Map Scale: Distance in Meters to Pixels depending on Zoom level

Took me a while to wrap my head around this: I tried to draw a circle around a specific coordinate (latitude & longitude) on a (google maps like) map. My first attempt was: EARTH_CIRCUMFERENCE / 2 ^ ZOOM_LEVEL / TILE_SIZE which resulted in a circle whose radius was off by about 20% in my tests. [...]

Veröffentlicht in Ohne Kategorie | Getagged: , | Kommentieren

memcached gem 1.3.5 on Lion 10.7.2

Maybe Xcode 4.2 and its compiler change (LLVM) is the reason I couldn’t install the darn thing. This helped: $ export CC=gcc-4.2 $ gem install memcached

Veröffentlicht in Ohne Kategorie, Ruby | Getagged: , , , , , | Kommentieren

Ubuntu – RVM – Error?

RVM Installation seems pretty simple, worked flawlessly almost every time I used it on OSX. On my new production machine I couldn’t install it. mkdir: cannot create directory `/usr/local/rvm’: Permission denied Every Tutorial or Snippet I tried looked liked this: bash < ~/.rvmrc $ echo 'export rvm_path="$HOME/.rvm"' >> ~/.rvmrc Then rerun the above bash/curl line.

Veröffentlicht in Ohne Kategorie, Ruby | Getagged: , , | Kommentieren

Rake Tasks for non-Rails application

put in your Rakefile: Load seeds: namespace :db do task :seed => :environment do seed_file = File.join(File.dirname(__FILE__), ‘db’, ‘seeds.rb’) load(seed_file) if File.exist?(seed_file) end end run Migrations & Rollback namespace :db do desc "Migrate the database through scripts in db/migrate." task :migrate => :environment do ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true ActiveRecord::Migrator.migrate("db/migrate/", ENV["VERSION"] [...]

Veröffentlicht in Ohne Kategorie, Ruby | Getagged: , , , | Kommentieren

ActiveRecord: Add Comments to Migrations and Schemas

For my most recent project I created some kind of “auto-documentation”. I thought the most easy way was to simply use MySQLs comments. Turns out, ActiveRecords doesn’t support this comments at all. Neither in schema dumping nor in migrations. ( used also for recreating database from a schema.rb ). This ain’t bound to Rails; It [...]

Veröffentlicht in Database, Ruby | Getagged: , , | Kommentieren

Global ActiveRecord Observers

Have you ever tried to get ActiveRecord Observers working in a Sinatra environment? I spent hours crawling trough the Rails sources but eventually gave up. Plus: My goal anyway was to have some kind of global observer through all models in my application. So, easy decision – I build my one solution – as always: [...]

Veröffentlicht in Ohne Kategorie, Ruby | Getagged: , , , , , | Kommentieren