Saturday, February 9, 2008

Remember Basic Authentication passwords in Firefox without Roboform

If you like to save your passwords, you probably know that its a pain to save Basic Authentication passwords in Firefox. Basic Authentication comes up in a new window saying "Enter username and password for ..." and looks like this:

Prompt

There is no 'save this password' button. If you access this site every day, and close Firefox between sessions, you'd have to type your username/password every time. No longer!

It is possible, though seemingly undocumented, to save the username/password inside the HTTP URL (this long has been done with FTP). For example:

http://user:password@layer2.org

bookmark

Just put this into a bookmark, and you have an easy way to access your password-protected site. Of course, if the password is actually sensitive, you might think twice about saving it in plain text as a bookmark!

The only annoying thing that happens using this method is that you'll see this prompt the first time you try to log in (for any given Firefox session):

Log in

Just press OK. While not perfect, this is a heck of a lot easier to deal with than entering the password each and every time.

Saturday, January 12, 2008

Rails migration with a list of all United States

How many times have you created web applications that use addresses? Since I felt like I wasted the entire 10 minutes it took me to type out this state list, I figured I'd share it with everyone so that their time wasn't equally wasted. Enjoy.

Run this command:
ruby script/generate model State

And put this in db/migrate/XXX_create_states.rb:
class CreateStates < ActiveRecord::Migration
def self.up
create_table :states do |t|
t.column :name, :string
t.column :abbreviation, :string
end

State.create :name => 'Alabama', :abbreviation => 'AL'
State.create :name => 'Alaska', :abbreviation => 'AK'
State.create :name => 'Arizona', :abbreviation => 'AZ'
State.create :name => 'Arkansas', :abbreviation => 'AR'
State.create :name => 'California', :abbreviation => 'CA'
State.create :name => 'Colorado', :abbreviation => 'CO'
State.create :name => 'Connecticut', :abbreviation => 'CT'
State.create :name => 'Delaware', :abbreviation => 'DE'
State.create :name => 'District of Columbia', :abbreviation => 'DC'
State.create :name => 'Florida', :abbreviation => 'FL'
State.create :name => 'Georgia', :abbreviation => 'GA'
State.create :name => 'Hawaii', :abbreviation => 'HI'
State.create :name => 'Idaho', :abbreviation => 'ID'
State.create :name => 'Illinois', :abbreviation => 'IL'
State.create :name => 'Indiana', :abbreviation => 'IN'
State.create :name => 'Iowa', :abbreviation => 'IA'
State.create :name => 'Kansas', :abbreviation => 'KS'
State.create :name => 'Kentucky', :abbreviation => 'KY'
State.create :name => 'Louisiana', :abbreviation => 'LA'
State.create :name => 'Maine', :abbreviation => 'ME'
State.create :name => 'Maryland', :abbreviation => 'MD'
State.create :name => 'Massachutsetts', :abbreviation => 'MA'
State.create :name => 'Michigan', :abbreviation => 'MI'
State.create :name => 'Minnesota', :abbreviation => 'MN'
State.create :name => 'Mississippi', :abbreviation => 'MS'
State.create :name => 'Missouri', :abbreviation => 'MO'
State.create :name => 'Montana', :abbreviation => 'MT'
State.create :name => 'Nebraska', :abbreviation => 'NE'
State.create :name => 'Nevada', :abbreviation => 'NV'
State.create :name => 'New Hampshire', :abbreviation => 'NH'
State.create :name => 'New Jersey', :abbreviation => 'NJ'
State.create :name => 'New Mexico', :abbreviation => 'NM'
State.create :name => 'New York', :abbreviation => 'NY'
State.create :name => 'North Carolina', :abbreviation => 'NC'
State.create :name => 'North Dakota', :abbreviation => 'ND'
State.create :name => 'Ohio', :abbreviation => 'OH'
State.create :name => 'Oklahoma', :abbreviation => 'OK'
State.create :name => 'Oregon', :abbreviation => 'OR'
State.create :name => 'Pennsylvania', :abbreviation => 'PA'
State.create :name => 'Rhode Island', :abbreviation => 'RI'
State.create :name => 'South Carolina', :abbreviation => 'SC'
State.create :name => 'South Dakota', :abbreviation => 'SD'
State.create :name => 'Tennessee', :abbreviation => 'TN'
State.create :name => 'Texas', :abbreviation => 'TX'
State.create :name => 'Utah', :abbreviation => 'UT'
State.create :name => 'Vermont', :abbreviation => 'VT'
State.create :name => 'Virginia', :abbreviation => 'VA'
State.create :name => 'Washington', :abbreviation => 'WA'
State.create :name => 'West Virginia', :abbreviation => 'WV'
State.create :name => 'Wisconsin', :abbreviation => 'WI'
State.create :name => 'Wyoming', :abbreviation => 'WY'

end

def self.down
drop_table :states
end
end