Double Shot #475
Just a couple of odds and ends.
- Don’t kill your app when using ActiveRecord in Rails Metal, release your database connections - Probably better is "Don't use Active Record in Metal."
- Searchlogic v2 officially released - Dynamic named scopes and search support by magic.
Double Shot #474
Well, I don't know about you, but clearly some people had busy weekends.
- comma - Nice-looking little DSL to add CSV output to ruby and Active Record objects.
- Ruby Hoedown - Regional (and free) Ruby conference for the US South, coming August 28 this year.
- Cleaning up your act, with a little handsoap - A look at using the handsoap library to replace soap4r action.
- JRuby - The JRuby site has had a facelift, and it's looking good.
- rubaidhstrano - A collection of Capistrano recipes that will make your life easier.
- Agilebuddy - An online scrum tool that integrates with GitHub, among other things.
- Zombie Operating Systems and ASP.NET MVC - Why ASP.NET MVC cannot handle routing /aux1.
- RightSignature - Online document signing that works better than the others I've seen in that niche.
- Working on it - A sign of life on the TextMate 2 front.
- Mike's Idiosyncratic Rails FAQ - Recently revised, so I figured I'd plug it again.
- Ruby Tidbits: Spork - Look at some software to speed up RSpec runs.
- rubyrep - Ruby-based database replication.
- Fat Free CRM - Rails-based open source CRM platform.
- Radiant 0.8.0 - New release of this CMS with a new extension system.
- IronRuby 1.0 - To be announced at OSCON at the end of next month.
Double Shot #473
Looking forward to the weekend, when I can actually be productive.
- rip - New ruby packaging system that was all the sexy yesterday. Personally, the thought of having to deal with yet another packaging system does not fill me with joy, no matter how good it is.
- Rails Edge Architecture - An explanation of the big round of refactoring that's been going on in Rails.
- Anonymous Pro - Free fixed-width font for coders.
- Webbynode - Another VPS host with Rails plans and some nice-looking management tools. (via Rails Inside)
- Need a Job? Come Work with Pivotal Clients and We've got several positions open (Developers, Designers, and Intern) - There are some nice full-time job opportunities in Railsland these days.
- Ruby at ThoughtWorks - Bottom line: it's working for them.
- Prude or Professional? - The Flash community has seen a conference presentation eerily reminiscent of the GoGaRuCo nonsense that provoked the founding of RailsBridge. The conference organizer is on top of it.
- relevance/rcov - Reportedly this is the hot (i.e., working) fork of rcov these days.
Double Shot #472
After a rough start with rubyforge, github, and lighthouse all being down, yesterday saw the release of a batch of software:
- ConfigToolkit - Extensive and flexible code for reading file-based configuration information in ruby.
- Programmers: Before you turn 40, get a plan B - As a programmer about to turn 50, I'm a bit leery of the notion that age discrimination in the field is as pervasive as some people say, but this blog post does a reasonable job of laying out the issues.
- RubyGems 1.3.4 - Another point release.
- Google Quick Search Box - Looks like Google wants to replace QuickSilver.
- Wagn 1.0 - Milestone release for this slick-looking wiki. I need to find some time to dig in.
- RedCloth 4.2.0 - New release with some formatting changes. Check the changelog before you update if you use bulleted or numbered lists.
- Devver - Run tests in the cloud and get them back faster. Looks interesting.
- Blocky - Crowdsourced spammer blocking for Twitter.
Finding Visitor Locations in Rails
I've got an application that I work on where the client wants to track which countries they're seeing click-throughs from. They want this in real time and in the application's UI, not in an external package such as Google Analytics. There are various ways to guess at country, but for the purposes of this application, basing it on the IP address and where its range is assigned proves to be good enough.
There are various services that will let you geolocate based on IP just by making an API call. But there's no particular reason to go outside your own application for this; it's pretty trivial to set up in Rails:
1) Download the "Complete (Country) One Table" SQL file from IPInfoDB. This is the raw data necessary to do the lookups. Decompress it and then run the resulting SQL file in your application's database. This will give you an
2) In this particular application, we're maintaining an Event model that holds, among other things, the IP address of the request. So the easy answer is to geolocate instances of that model when they're created or updated:
[sourcecode language='ruby']
class Event < ActiveRecord::Base
before_save :get_country_info
def get_country_info
segments = remote_ip.split('.')
ip_atom = ((segments[0].to_i * 256 + segments[1].to_i) * 256 + segments[2].to_i)*256
result = connection.execute("SELECT * FROM `ip_group_country` where `ip_start` <= #{ip_atom} order by ip_start desc limit 1;")
row = result.fetch_row
self.country_code = row[2]
self.country_name = row[3]
end
end
[/sourcecode]
3) There is no #3. That's it!
There are various services that will let you geolocate based on IP just by making an API call. But there's no particular reason to go outside your own application for this; it's pretty trivial to set up in Rails:
1) Download the "Complete (Country) One Table" SQL file from IPInfoDB. This is the raw data necessary to do the lookups. Decompress it and then run the resulting SQL file in your application's database. This will give you an
ip_group_country
table. There's no need to set up a matching model; we're just going to hit it with raw SQL.2) In this particular application, we're maintaining an Event model that holds, among other things, the IP address of the request. So the easy answer is to geolocate instances of that model when they're created or updated:
[sourcecode language='ruby']
class Event < ActiveRecord::Base
before_save :get_country_info
def get_country_info
segments = remote_ip.split('.')
ip_atom = ((segments[0].to_i * 256 + segments[1].to_i) * 256 + segments[2].to_i)*256
result = connection.execute("SELECT * FROM `ip_group_country` where `ip_start` <= #{ip_atom} order by ip_start desc limit 1;")
row = result.fetch_row
self.country_code = row[2]
self.country_name = row[3]
end
end
[/sourcecode]
3) There is no #3. That's it!
Double Shot #471
Had a fun evening of patching Rails sites. Hope you did too.
- Dos Vulnerability in Ruby - Worth patching on your deployed Rails applications. Here's the official Ruby announcement. There's also a patched Ruby Enterprise Edition that fixes this.
- Searchlogic v2 beta released - Instant named scopes on the fly via method_missing.
- Firebug 1.5a3 - New round of alpha testing releases for those of us on Firefox 3.5.
Double Shot #470
I'm sure something happened in Rails-land yesterday, but I didn't see it, so just one link today. More tomorrow, I expect.
- Firefox 3.5 Preview - If you haven't been seduced away by Safari, here's the latest Firefox, now nearing release candidate status and plenty stable enough for daily browsing.
Double Shot #469
Yup, Monday again. Keeps happening for some reason.
- Introducing Trample: A Better Load Sampler - James Golick wants to help you beat up your application.
- Freelancing: Writing Estimates - Advice for not losing your shirt when bidding a development project.
- sham_rack - FakeWeb for Rack, sort of: a way to stub out external sites via Rack for testing.
- CUPS - Huh, browser-based printer management on OS X, just visit http://127.0.0.1:631/printers/ - more unixy goodness.
- Lynxlet - Lynx on OS X. Useful if you ever need to visit a gopher site, I guess.
Double Shot #468
And some days, the bugs eat you.
- request-log-analyzer - Nice little tool for crunching through Rails logs and finding performance issues.
- Sprinkle: the provisioning tool for people who don't have huge server clusters - Luke Franci points to a lower-complexity alternative to Chef and Puppet.
- Introducing Page Speed - Google gets into the Firebug optimization add-on business.
- activegroonga - Ruby bindings for yet another full-text search engine.
Double Shot #467
Back on a reasonably early morning schedule. Hopefully I can catch more than worms.
- Adobe BrowserLab - Adobe hosted service for cross-browser testing. It didn't work on the test page I threw at it, but maybe you'll have better luck.
- ClickTale - Serious in-page web analytics. I might have some use for this in the future.
- Joe - Thor scripts to simplify releasing gems to RubyForge.
- Auto timeout sessions in Rails - Just like banks and stuff use to turn off your browser session.
- Security Problem with authenticate_with_http_digest - Yeah, Rails had another security issue. It's hardly the worst one ever. I'm very amused by Hacker News trying to get the mob together with pitchforks for this one. (Full disclosure: I'm partially responsible because I passed on the original documentation to the blog entry without spotting the error. Guess I'd better go shoot myself for that.)
Double Shot #466
-
GitHub Firewall Install - Commercial private GitHub installations. - Introducing Contest - Simple nested contexts for Test::Unit.
- hoe version 2.0.0 has been released! - A major refactoring of this gem builder (with other goodies).
- Hemlock - XMPP + Flash framework for multiuser real-time web applications.
- attachment_fu - Rails 2.2 and 2.3 compatible fork.
Double Shot #465
Birds can apparently consume an unlimited amount of seed.
- How to monitor server load on GNU/Linux - File under "stuff I should know more about."
- Web Applications Should Be Compiled - This one was going around yesterday. It's not as outrageously stupid an idea as some people seem to think.
Double Shot #464
June...I hope to have some news in June...for now, I just have a load of email to deal with. Enjoy some links.
- apidock-tmbundle - Hook TextMate up to APIdock for help on Ruby and Rails keywords.
- Comparing Ruby Mock Object Libraries - More good stuff from Noel Rappin.
- Cerberus 0.6 - New release of this command-line CI tool. I've got a tiny bit of code in the release.
- yui_compressor_fu - Automatic minimization of CSS/JavaScript for Rails applications.
- Ruby on Rails on Google App Engine - Demo and cheatsheet.
Double Shot #463
Bird feeders in this neighborhood attract bunnies.
- Cross-Domain Data with Rack and Rails - Encoding data into CSS rules to get around cross-domain security policies is certainly one of the nastier perversions of web standards I've seen lately.
- Meet the Command Line - Remedial Unix from Peepcode.
- Prey - Software to help track stolen laptops.
- Is It JRuby? _ Gem compatibility tracking for JRuby.
- How to Facebook Connect your Rails app - Some guidance into deep and treacherous waters.
- sortable - A fresh descendant of acts_as_list.
Double Shot #462
I've got more open hours on my dance card for June than I expected. That makes it the perfect time to hire me. :)
- Mac-friendly Autotest - New gem that makes autotest nicer to your Mac's CPU.
- handsoap - Lower-level (and hopefully better) alternative to soap4r.
- Git Up! 10 Reasons to Upgrade Your Old Git Installation - Some of the things that have happened recently in git-land. If you're on OS X, the Git for OS X installer is updated to the latest version.
- Ruby Enterprise Edition third sponsorship campaign - Phusion is raising money for another round of REE updates.
- SuperDeploy - Collection of Capistrano recipes to make development easier.
- Querious - New MySQL client for OS X.
- mcinsight - Graphical memcached version for OS X to help in development and debugging.
- WRESTLE: Aggressive and Unprincipled Agile Development in the Small - A new contribution to the wide range of agile methodologies.
Double Shot #461
A little flotsam from my browser.
- Scaling Memcached: 500,000+ Operations/Second with a Single-Socket UltraSPARC T2 - Apparently memcached does scale.
- Hardening MacOSX against the Java vulnerability - If you want to go poking around in the Java source yourself, you can make your Mac safe for Java again.
- Stories - Another option for natural language-ish BDD.
Double Shot #460
Hoping to deploy new code to staging tonight. We'll see.
- The Male Programmer Privilege Checklist - For those who don't see an issue here.
- Hammock - "Radically RESTful Rails", a scheme for squeezing out controller code by specifying some more conventions on your models.
- System-wide script/console logging - An old tip but still a good one: how to get the Rails log messages to write in your script/console sessions.
Double Shot #459
Working hard for an end-of-the-month deployment on one big project.
- Rails plugin directory revamp - Ben Curtis has added Github integration, among other things, to the plugin directory.
- Cerberus 0.5 - New release of this continuous integration alternative.
- JsTestDriver - JavaScript test runner for TDD and CI use.
- MooTools on Rails - Helpers to replace the default Rails javascript with MooTools.
Building Rails with Cerberus and multiruby
I've been poking at various continuous integration software lately. Most recently I gave Cerberus a spin, and I must say, even though the project is a bit immature, I like its approach. My test for CI is generally "can I use it on the Rails source" as I think that provides a level of complexity beyond what I'm likely to need for my own projects. Well, I had to contribute a bit of code to get Cerberus to that point, but it works. I also set up the box so that I can build with different ruby versions, thanks to multiruby. Here's my notes on getting all the ducks in a row, starting with a bare-metal Debian Lenny installation.
Note: the italicized installs currently fail on ruby 1.9.1.
Note: Currently, you'll need to either pull and build cerberus from my fork or from the ruby_builder branch in the official repo. With the next release after 0.5.0, you should be able to use the gem install method.
Note: Some of this depends on having pulled a copy of Rails to the box; the easiest way is to let Cerberus do a failing build and then create the databases.
Now you can run
Root Tasks
- log in as root
- adduser webadmin
- visudo - set webadmin up with sudo rights
webadmin Tasks
- log in as webadmin
Prerequisites for Ruby Compiles
- sudo apt-get install autoconf
- sudo apt-get install bison
- sudo apt-get install zlib1g-dev
- sudo apt-get install libzlib-ruby
- sudo apt-get install ruby-dev
rubygems install
- mkdir sources
- cd sources
- wget http://rubyforge.org/frs/download.php/56227/rubygems-1.3.3.tgz
- tar -xvzf rubygems-1.3.3.tgz
- cd rubygems-1.3.3/
- sudo ruby setup.rb
- sudo ln /usr/bin/gem1.8 /usr/bin/gem
fastcgi (we'll need fcgi gem later)
- cd ~/sources
- wget http://www.fastcgi.com/dist/fcgi.tar.gz
- tar -xvzf fcgi-2.4.0.tar.gz
- cd fcgi-2.4.0/
- ./configure
- make
- sudo make install
- sudo apt-get install libfcgi-dev
Databases
- sudo apt-get install mysql-server-5.0 libmysqlclient15-dev
- sudo apt-get install sqlite sqlite3 libsqlite-dev libsqlite3-dev
- sudo apt-get install postgresql postgresql-server-dev-8.3
- sudo su - postgres -c 'createuser -s webadmin'
- sudo su - postgres -c 'createuser -s rails'
memcached
- sudo apt-get install memcached
- sudo /etc/init.d/memcached start
multiruby Install
- sudo gem install ZenTest
- sudo multiruby_setup mri:svn:tag:v1_8_6_368
- sudo multiruby_setup mri:svn:tag:v1_8_7_160
- sudo multiruby_setup mri:svn:tag:v1_9_1_129
- sudo multiruby_setup update:rubygems
Gem Installs
- sudo multiruby -S gem install --no-ri --no-rdoc --development test-unit
- sudo multiruby -S gem install --no-ri --no-rdoc --development fcgi
- sudo multiruby -S gem install --no-ri --no-rdoc --development memcache-client
- sudo multiruby -S gem install --no-ri --no-rdoc --development mocha
- sudo multiruby -S gem install --no-ri --no-rdoc --development mysql
- sudo multiruby -S gem install --no-ri --no-rdoc --development pg
- sudo multiruby -S gem install --no-ri --no-rdoc rack
- sudo multiruby -S gem install --no-ri --no-rdoc thin
- sudo multiruby -S gem install --no-ri --no-rdoc --development rake
- sudo multiruby -S gem install --no-ri --no-rdoc --development sqlite-ruby
- sudo multiruby -S gem install --no-ri --no-rdoc --development sqlite3-ruby
- sudo multiruby -S gem install geminstaller
- sudo multiruby -S gem install SystemTimer
- sudo multiruby -S gem install json
Note: the italicized installs currently fail on ruby 1.9.1.
git
- sudo apt-get install git-core
Cerberus
- sudo gem install cerberus
Note: Currently, you'll need to either pull and build cerberus from my fork or from the ruby_builder branch in the official repo. With the next release after 0.5.0, you should be able to use the gem install method.
Create the Cerberus project and build it
- cerberus add http://github.com/rails/rails/tree/master APPLICATION_NAME=rails_master_187 SCM=git
- Edit the file ~/.cerberus/config.yml to include your own notifier information
- Edit the file ~/.cerberus/config/rails_master_187.yml to put in the custom build info:
---
publisher:
mail:
recipients: you@yourdomain.com
scm:
url: git://github.com/rails/rails.git
type: git
# branch: 2-3-stable
builder:
ruby:
task: ci/ci_build.rb
ruby_path: /home/webadmin/.multiruby/install/v1_8_7_160/bin/
success: Rails build finished sucessfully
failure: Rails build FAILED
brokeness: (\d+) failures, (\d+) errors
- cerberus build rails_master_187
Build databases for ActiveRecord
Note: Some of this depends on having pulled a copy of Rails to the box; the easiest way is to let Cerberus do a failing build and then create the databases.
- cd ~/.cerberus/work/rails_master_187/sources/activerecord/
- mysql -uroot -e 'grant all on *.* to rails@localhost;'
- mysql -urails -e 'create database activerecord_unittest;'
- mysql -urails -e 'create database activerecord_unittest2;'
- rake postgresql:build_databases
Ready to Go
Now you can run
cerberus build rails_master_187
to run a single build, or cerberus build rails_master_187 force=TRUE
to build even if nothing has changed in the repo, or cerberus buildall
to build everything you've defined. Hook it up to cron if you want periodic checks of the repo.
Double Shot #458
A quiet morning in Rails-land.
- Typus - Admin scaffolding generator for Rails.
- Ruby 1.8.6 Maintenance Transition - Engine Yard is taking over.
- Dear Railsists, Please Don’t be Obtrusive - Peter Szinek argues for UJS techniques in Rails.
subscribe via RSS