About concept47

Ruby/Rails/Jquery/MySql/PostgresSQL hacker. Wannapreneur. Love to build beautiful things.

How to turn off Length Error messages on Password Confirmation fields in Authlogic

In Authlogic, if you use a password confirmation field (when creating a new user perhaps), there is an error message that shows up for that field if the User model does not validate.
Something like

is too short (minimum is 4 characters)

Seems simple enough to turn off, but I almost went mad trying to figure out how do this without completely turning off password authentication.

class User < ActiveRecord::Base
    acts_as_authentic do |c|
         c.merge_validates_length_of_password_confirmation_field_options  :allow_blank => true
    end
end

PS: It’d be nice to get all the configuration options for Authlogic in one place, with better documentation for each one.
Maybe I should get on that … it is open source software after all

Running thin instead of mongrel with script/server

Just go to the the rails directory that corresponds to this one on your computer (This is on a windows XP machine, but you should be able to figure out the right path on your machine)

C:\ruby\lib\ruby\gems\1.8\gems\rails-2.3.5\lib\commands

Open up server.rb

And edit the line that says

server = Rack::Handler::Mongrel

to say

server = Rack::Handler::Thin

enjoy

thin server logo

In the midst of crisis, opportunity … a counter-argument to “Free Kills”

Today I read this really insightful article about how giving away software can kill the market for it.

While I largely agree with the Andy, I think that he has missed one important point.

Giving away a really good product in a certain space can depress sales and stifle innovation, but there will always be that small percentage of users whose needs are not met by the free alternative. Because of this, niche users will be willing to pay top dollar for a product that goes beyond the free alternative.

What about the free alternative?
Won’t its developers be adding features too?
Sure. They might.
But its free, so its not a priority.
Your customers, on the other hand, will pay you good money to make adding features they want a priority … see the difference?

Case in point, Google Calendar added to-do lists, almost a year ago now … but despite cries for an api for it, nothing has happened.
2524 users (people requesting that feature) is not a large number to google, but if you’re a small development shop … and each of those users were paying you  … say $4.99 a month … you’d be doing okay.
Lots of motivation to bang out an api … yeah?

So, instead of looking at it as “Free” killing the market for your product.
Look at it as  …. “Free” doing you the favor of hand delivering the most passionate, keyed-in, highly motivated group of users in the market for your product, to your doorstep … for free 😀

You’re welcome.

Google Chrome adds RSS feed notification/preview/subscription via extension

This may have been around for a while, but I just learned of it today.

If you run the dev version of Google Chrome, you may already be aware that it supports extensions.

In fact when I first found out Google had published a few extensions for eager beta testers to try out, I went and got the rss feed extension.

Unfortunately, even though it showed the icon when a feed was present, clicking it only took you to Google Reader to subscribe to the feed (or so I heard, clicking it in my version of Chrome did nothing)

Google Chrome RSS feed Extension feed availability notification

Google Chrome RSS feed Extension feed availability notification

I am happy to report that with the new version of this extension (1.6.2), clicking on a feed allows you to actually preview the rss feed …
<sound of angels singing HALLEJUYAH />

I can finally test rss feeds I’m coding in Chrome without having to fire up IE8 or Opera (Firefox doesn’t preview either, just tries to subscribe you to live bookmarks … I hate that) and unstar this bug ticket!

Image of Google Chrome RSS feed extension previewing a feed

Image of Google Chrome RSS feed extension previewing a feed

Don’t hit the business growth accelerator just yet Joel!

Yesterday, Joel Spolsky posted an article about why growing steadily but slowly might not be such a good idea.

When I read it, I had my reservations about it, but I couldn’t express them … the whole idea just sounded wrong?

Well, the guys over at 37Signals issued a rebuttal of Mr Spolsky’s argument, and I have to say … I agree.

The main thing that drives the use of software like Fogz bugz (a bug tracking web application), is how good it is, and how much buzz it generates. The size of your company doesn’t matter if people that matter (developers in this case) are talking about the other guy’s software on twitter, facebook, digg or reddit, and recommending it to every other developer they can find.

Just my 2 cents.

cropper_capture_11-05-200911-05-14 AM

From the books: Exceptions to Ruby’s standard variable assignment by reference behavior

The un-reference: immediate values
Some objects in Ruby are stored in variables as immediate values. These include integers, symbols (which look like :this), and the special objects true, false and nil. When you assign one of these values to a variable (x = 1), the variable holds the value itself, rather than a reference to it

— From page 54 of The Well Grounded Rubyist by Robert Black

Filed under Things I did not know about Ruby 😀

41A+B9T4yGL._SS500_

WordPress creator Matt Mullenweg on staying in the ‘zone’ as a developer

“Music helps me when I’m coding, which is still my priority. When you’re coding, you really have to be in the zone. I’ll listen to a single song, over and over on repeat, like a hundred times. And I turn off instant message and email. If you are taken out of the flow, if that little toaster pops up that says you’ve got mail — and you look at it, you’ve lost it. You’re juggling variables and functions and layouts. The moment you look away, it all falls to the ground, and you spend 10 minutes getting it all back in the air again.”

— Matt Mullenweg
June 2009 issue of  Inc. Magazine

Passenger dying … too many apache processes

I encountered this problem when I first started working with Passenger, and have run into it repeatedly over the last year, so I thought I’d just throw out the fix I have for it.

Usually people having these problems are usually running the prefork MPM and have a section in their apache config file that looks like this

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers          5
MinSpareServers       5
MaxSpareServers      10
MaxClients          150
MaxRequestsPerChild   0
</IfModule>

#Aside: To find out if  what multi processing module (mpm) you are runing (worker or prefork) just run this command.
apache2 -l
(it may also be httpd/httpd2/apache/apache2ctl/apachectl -l)

The apache processes themselves don’t usually take up a lot of memory, I’ve seen anywhere from 0.2MB – 14MB … but they usually lie in the range of 2 – 6MB.
The problem comes if you get a traffic spike and Apache spawns up to 150 process to handle the traffic.

You can see that you can easily have 300MB – 1GB of memory allocated to the processes and, consequently, run out of memory so that your server is now unresponsive.

The fix for this is to set MaxClients to, at minimum, your StartServers + Min Spare Servers. But you also want to take into consideration the Max Instances of your app that you’ve set for passenger and how many requests you want to be able to serve at a time.

From Apache documentation

The MaxClients directive sets the limit on the number of simultaneous requests that will be served. Any connection attempts over the MaxClients limit will normally be queued, up to a number based on the ListenBacklog directive. Once a child process is freed at the end of a different request, the connection will then be serviced.

Be sure to increase this number if you are running php apps on your server as well.

Hope this helps.


rake aborted! development database is not configured.

You might have been happily running migrations on your development box for weeks and go to get the application set up on a production server.
And all might even have been going well until you ran

rake db:migrate

only to see it crash and burn like this.

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
development database is not configured

Fear not ye intrepid developer!
This happens when you leave out the development specifications in your database.yml.
(If you don’t define development.rb, you’ll get a weirder “No such file or directory – …../development.rb” error)

Apparently rake db:migrate runs in development mode no matter what environment you’re in (still looking into the reason for this).
So what you have to do is call migrate like this

rake db:migrate RAILS_ENV=production <—- or whatever your environment is

That should get you back on the path to true happiness.

Real programmers write in Fortran!

And oldie-but-goodie …

Mel’s job was to re-write the blackjack program for the RPC-4000. (Port? What does that mean?) The new computer had a one-plus-one addressing scheme, in which each machine instruction, in addition to the operation code and the address of the needed operand, had a second address that indicated where, on the revolving drum, the next instruction was located. In modern parlance, every single instruction was followed by a GO TO! Put *that* in Pascal’s pipe and smoke it.

Mel loved the RPC-4000 because he could optimize his code: that is, locate instructions on the drum so that just as one finished its job, the next would be just arriving at the “read head” and available for immediate execution. There was a program to do that job, an “optimizing assembler”, but Mel refused to use it.

“You never know where it’s going to put things”, he explained, “so you’d have to use separate constants”.