Satya's blog - 2009/

Dec 27 2009 17:02 Rails code profiler

At last, a simple easy to use profiling option:

require 'profiler'

Yay! Bog-slow, though. Without the profiling, the code ran in about 15 seconds. With profiling, 8 minutes! And then all I get is a dump of internal ruby functions getting called. I need to know which of *my* functions are slow. Oh, well.

Tag: rails

Dec 27 2009 17:00 Rails, everything is not the web

Suppose you you Rails fragment caching. Fast and easy right? Now you have a model method which you call from cron to update your data. So you want to expire those fragments from cache. Well, according to this post it's next to impossible to cause the cached data to expire without breaking MVC. Solutions/workarounds involve instantiating controller objects or calling a controller method via HTTP. Rails Fail. Some things do NOT need to run via HTTP.

Either that, or I'm doing the wrong after_update method.

Or, it's a permissions issue. (Hint: this is the correct answer. after_update was being triggered but couldn't delete the cache files in /tmp.)

The point stands, though: advising people to muck with the controller, for a cron job to expire cached data, is wrong.

Tag: rails rant

Dec 27 2009 16:57 Tell postfix to send by port 587

The Postfix SASL documentation says:

The "submission" destination port tells Postfix to send mail via TCP network port 587, which is normally reserved for email clients. The default is to send mail to the "smtp" destination port (TCP port 25), which is used for receiving mail across the internet.

So when my Postfix was trying to send to my (non-ISP) smart host on port 25, and my DSL provider was blocking 25, I had to add the port in

relayhost =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_map

And in my sasl password map file, instead of just, I needed to add the ":587" part, and then regenerate the db file:

postconf /etc/postfix/sasl_map

Tag: howto postfix

Nov 03 2009 16:35 Why blog?

Someone I know said recently, "I tweeted once. Maybe twice. Then, I thought... Who in the world cares what I'm doing?". (Hi, Shaun!) I've heard similar comments from others. (Hi, Jason!)

I blog or microblog (tweet/dent) because I've got something to say. I don't care if anyone reads it. Others keep a journal or diary. Some say that a blog is totally public (true), unlike a diary. "Why should the whole world know my personal thoughts?", some say. For me, it's about the transmission -- I don't care if anyone is listening, as long as anyone *can* listen. And then there are some things I want to get out there. My soapbox, or my lectern. Variously.

As for micro-blogging, that's for more ephemeral thoughts, and to direct people to other locations such as my blog or photo album. For stuff that need not be preserved (even though it may be, I'm not the one doing it, so don't care -- stuff I care about, I try to preserve by myself). Sometimes I need to talk, for the sake of talking, for getting the thought out there. If not for microblogging, I'd be yelling over the cube walls. At least this way you can not follow me, and not be bothered.

So to those who don't want to blog, I say that's great for you. Don't stop me. Don't put me down either. (And no, this isn't directed at you, Shaun, or anyone else in particular.)

I've actually posted about this before, in "Why I blog".

Last updated: Nov 03 2009 16:44

Tag: hmm

Oct 31 2009 18:03 Insect through peehole
My picture of an insect through a door peephole is now up in the CHS section of my albums. It was taken in April 2009.

Tag: picture

Oct 15 2009 10:56 Ruby is a ghetto

Like Zed Shaw, I'm mildly disillusioned by Ruby and Rails. Here's why:

So many things in Ruby and Rails seem half-assed, in a "we're more interested in this cool new thing, so we're not going to bother to implement language features that are well-established and people would be relying on having". Like XML parsing.

To which, Matthew says: what are you doing with libxml? REXML might be enough. Core ruby isn't like that, lots of modules are.

My response is, core Ruby isn't enough to do anything non-toy. That is, to do anything serious (more than "hello world"-level stuff), you need libraries.

More than that, Matthew's comment (mind, I respect his opinion, and this wasn't an an argument, just a discussion) leads me to think, I don't need to be ripping out the guts of my program. That's what I'd have to do to switch parsers. Possibly. Depending on how the parsers work (stream versus ... non-stream, I guess).

(I use libxml-ruby (debian/ubuntu), which gives me XML::Parser, for the record.)

Which is another thing. The ruby/rails community always expects you to be doing stuff from scratch, and really I'm interfacing with existing systems/data and tweaking existing rails projects. (This is where the "ghetto" epithet comes in.)

I don't feel like playing roulette with XML parsers. But whichever I pick, there will be a problem. And when i ask about it, i'll be told use this other one instead. Ruby/rails expects everything to be in a vacuum, and it isn't!! I can't just go swicth out parsers. Yeah, maybe that's what unit tests are for, but does anyone actually use those? (I should be using cucumber or rspec, I know, but there's more pressure to just do the project any half-assed way than to do it right behind the scenes.)

Here's a conversation snippet, following the above discussion on #barcampchs:

LabThug: what's the new hip thing this week?
satyap: lisp
mcg: rails has always been a ghetto
satyap: lisp again, i mean
satyap: next week we'll be doing fortran
LabThug: yeah, but that ghetto has a lot of bling in it
mcg: yup
LabThug: satyap: F#
satyap: forth by november do we will
satyap: Fthat, i say
mcg: #!F
satyap: haaaah, LabThug and mcg, i'd like to quote you guys on my blog
LabThug: Go ahead

Another source of disillusionment: the whole gem/apt thing I posted earlier.

Tag: rant ruby

Oct 14 2009 10:20 Apt and Gem

If you use Ubuntu and Rails, you may have run across this already: the apt system and the gem system will fight like cats, or as someone called ReinH put it, like Kirk and Spock in Amok Time.

To use ruby stuff, install the ruby packages like "ruby", and rubygems only. Then install all other ruby stuff using the gem command. Slight problem, on 9.10 you get these:

rubygems - package management framework for Ruby libraries/applications
rubygems-doc - package management framework for Ruby libraries/applications
rubygems1.8 - package management framework for Ruby libraries/applications
rubygems1.9 - package management framework for Ruby libraries/applications
rubygems1.9.1 - package management framework for Ruby libraries/applications

Old Ubuntu hands will know that the 'rubygems' package should install the "best" rubygems<version> package. Nope.

The main problem is that gems, and the ruby world in general, make it hard to twist into the mind-space of apt-based systems. See for more than you ever want to know about this stuff. In short, all Rails apps want to be in one directory, and all Debian-based ssytems want you config in /etc, your code in /usr/local (or whatever), etc. and that's just not compatible with what Rails likes. And the Ruby/Rails people don't see the problem.

Tag: ruby rails

Sep 30 2009 10:39 JRuby on Rails with Sybase

Got Sybase*? Got Rails? You're skewered. But you can do it with JRuby and jTDS. Assuming Ubuntu 9.04, but any deb-based system should do.
*(or MSSQL, or SQLServer, whatever the heck it's called)

Get jruby1.1 (or whatever the latest is). This also might drag in 90+ other dependencies. You don't have a choice. Get libjtds-java. Get the following gems: activerecord-jdbc-adapter jruby-openssl

sudo apt-get install jruby1.1 libjtds-java
sudo jruby -S gem install rails activerecord-jdbc-adapter jruby-openssl 

jruby -S: installs the gems into the jruby system instead of the ruby (or cruby, for C) system.

Start a jrails (my term for JRuby on Rails) app by doing: jruby -S rails jdbctestapp

Edit config/database.yml to read something like:

  adapter: jdbc
  url: jdbc:jtds:sybase://server:4100/;TDS=5.0
  database: mydatabasename
  username: foo
  password: bar
  driver: net.sourceforge.jtds.jdbc.Driver

Assuming you know how to handle the database.yml file. For MSSQL, change 'sybase' to 'sqlserver' and set TDS=8.0 (or remove the TDS thing altogether, including the semi-colon).

And then, the best-kept secret of the internet: Add this line, or similar, to your environment.rb file:

require '/usr/share/java/jtds.jar'

That's right, the full path to the jtds jar file (you can find it with dpkg -L libjtds-java|grep jar).

Tag: rails

Sep 27 2009 16:52 James in MSTS
If you've got a kid who is into Thomas the Tank Engine, and you have Microsoft Train Simulator, you can go grab the James (or any other steam engine) model from the web. But to get it into MSTS, you need a consist file (James.con) which contains the following. Paste into Notepad, and save it with the other consist files.

Train (
	TrainCfg ( james
		Name ( "James, 10 passengers" )
		Serial ( 4 )
		MaxVelocity ( 58.11520 0.20534 )
		NextWagonUID ( 19 )
		Durability ( 0.10500 )
		Engine (
			UiD ( 0 )
			EngineData ( james5 james )
		Wagon (
			WagonData ( ScotsCar1 Scotsman )
			UiD ( 12 )
		Wagon (
			WagonData ( ScotsCar1 Scotsman )
			UiD ( 11 )
		Wagon (
			WagonData ( ScotsCar1 Scotsman )
			UiD ( 18 )
		Wagon (
			WagonData ( ScotsCar1 Scotsman )
			UiD ( 17 )
		Wagon (
			WagonData ( ScotsCar1 Scotsman )
			UiD ( 16 )
		Wagon (
			WagonData ( ScotsCar3 Scotsman )
			UiD ( 15 )
			Flip ( )

Tag: trains

Sep 27 2009 15:56 LDAP/Kerberos login with local accounts

Suppose your organization uses LDAP authorization, and maybe kerberos, and you have a Debian-based box with PAM (Pluggable Authentication Modules). Then, in /etc/pam.d/, you need:

# /etc/pam.d/common-auth :
auth    sufficient nullok_secure
auth    sufficient use_first_pass
auth required

# /etc/pam.d/common-password :
password   required nullok obscure min=8 max=16 md5

# /etc/pam.d/common-session :
session required

Only the pam_krb5 line is required, the rest are provided for completeness.

Tag: geeky sysadmin

Sep 02 2009 10:32 Rails with Shibboleth headers

Phusion Passenger 2.2.3 (although I'm running 2.2.4 or 2.2.5, via gem) has a mis-feature where it sets the environment variables on startup only. This means every request to Rails gets the same set of environment variables.

Shibboleth recommends not turning on request headers (don't do ShibUseHeaders On), as that's slightly insecure. They say use the environment variables instead. In Rails terms, ENV['Shib-EduPerson-Principal-Name'].

But these two things together means every Rails request thinks it's being made by the same person!

So, turn Shibboleth headers on (ShibUseHeaders On) and use request.env['HTTP_SHIB_EDUPERSON_PRINCIPAL_NAME'] instead. Sigh.

Update: I almost wish I could do Rails-style simple_format in Perl.

Last updated: Sep 02 2009 10:38

Tag: geeky bug