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.

firefox

Comments (1)

Permalink

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 migration 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

rails
ruby

Comments (2)

Permalink

Use ffmpeg to extract first image out of FLV

I found at least one other person trying to find a way to extract a JPG snapshot out of a flash video using ffmpeg.

The above article suggests using ffmpeg to extract a PNG, and then convert that to a JPG (since the JPG will be much smaller). Instead, just use the correct arguments to ffmpeg:

ffmpeg -i movie.flv-vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 movie.jpg

With -vcodec mjpeg the important argument.

linux
web

Comments (0)

Permalink

Rails’ attachment_fu, :thumbnail_class and you

I was having a bit of trouble with attachment_fu that took a while to figure out, so I thought I’d post my solution for the next person.

I have a Photo model that I’m using to store pictures. Since attachment_fu will automatically resize, create thumbnails, and store pictures on the file system, it was an easy choice to use it. The things I found I didn’t like about it:

  1. It stores thumbnails as separate records inside the photos table. This means you have to check if thumbnail.nil? each time you display the pictures, and you’ll have to check parent_id.nil? to count your photos.
  2. You can’t use your own model validations. For example, I wanted to use
validates_presence_of :name
validates_presence_of :description

But I’d always get validation errors because attachment_fu tries to save the thumbnail attributes when it creates or resizes a thumbnail. As you can imagine, this is a major problem.

:thumbnail_class to the rescue

Mike Clark’s attachment_fu blog post mentions that you can use the :thumbnail_class argument to separate your model validations and attachment_fu’s validations. Here’s how to do it:

class Photo < ActiveRecord::Base
  has_many :thumbnails, :foreign_key => 'parent_id'
 
  has_attachment  :storage => :file_system,
                          :content_type => :image,
                          :max_size => 10.megabytes,
                          :resize_to => '640x480',
                          :thumbnails => { :thumb => '100x100' },
                          :thumbnail_class => Thumbnail
 
  # Validations
  validates_presence_of :name
  validates_presence_of :description
end
 
class Thumbnail < ActiveRecord::Base
  belongs_to :photo, :foreign_key => 'parent_id'
 
  has_attachment  :storage => :file_system,
                  :content_type => :image
end

The killer for me initially was that I wasn’t specifying has_attachment in the Thumbnail model. I always got this error:

undefined method `temp_path=' for #thumbnail:0xb69a9514

So save yourself by putting has_attachment in both models. Make sure to define any attachment_fu arguments in your Photo model, and leave the Thumbnail model bare. You’ll also want to make sure you have the normal attachment_fu schema in both models:

      t.column :parent_id,  :integer
      t.column :content_type, :string
      t.column :filename, :string
      t.column :thumbnail, :string
      t.column :size, :integer
      t.column :width, :integer
      t.column :height, :integer

I’ve found that everything seems to be working as normal going this route. My model validations work and the thumbnails are not polluting the photos table. If you want to find the Photo for a particular Thumbnail, keep in mind that parent_id now refers to the id in the Photo model:

t = Thumbnail.find ....  # find your thumbnail
p = Photo.find(t.parent_id)

And for the ultimate ease-of-use relationship, just use:

t = Thumbnail.find ....  # find your thumbnail
p = t.photo               # get a photo
p.thumbnails              # get all thumbnails

This works since we defined the has_many relationship in the model.

Let me know if you have any problems with this method or if it helped you!

rails
ruby

Comments (6)

Permalink

Serve home directories to internal IPs only with lighttpd

Recently, I decided I wanted to share home directories via HTTP to everyone on my home network. This is an easy way to share files with Windows machines where you don’t have any type of sshfs-like support. The problem was that this file/web server also faces the Internet. Obviously I don’t want to share our personal files to anybody who cares to look. After a bit of playing, I came up with this configuration:

$HTTP["remoteip"] != “192.168.1.0/24″ {
  $HTTP["url"] =~ “^/~” {
    url.access-deny = ( “” )
    dir-listing.activate = “disable”
  }
}

This allows any host with an IP in the 192.168.1.1-254 range view any URL that begins with /~username. It denies everyone else with a 403 - Forbidden message. Note that for some reason, listing the conditions in the opposite order (url first, remoteip second) did not produce the correct results.

Finally, make sure that you have both the appropriate modules enabled:

server.modules += ( "mod_access", "mod_userdir" )

network
web

Comments (0)

Permalink

Google IMAP will be a Yahoo mail killer!

If you haven’t heard already, Google with be and is offering IMAP for their Gmail service! You might not have it available on your account immediately, but it should be within a few days or a week.

I’m one of the lucky ones that already has IMAP set up. I tried it out in Thunderbird and the setup was quite smooth. The only problem I ran into is that some of my old chats came up with a timestamp of 2:33am this morning. So, they were out of order and weird, but it wasn’t that big of an issue.

The real point I wanted to make in this post is that this will be a killer (imo) for Yahoo mail. Back in the day when I signed up for Yahoo mail, they were on the leading edge for features and interface. I remember when they moved to the interface they have which they now call their ‘classic’ interface, and I have saved HTML pages that show what their REAL classic interface looks like.

But until now I have not had a reason to move to Gmail. While I do have a Gmail account, I don’t use it as my primary account because there was no real advantage to switch to it. Some of the features might be nicer and sexier, but webmail is still webmail. Now that Gmail offers IMAP along with a host of other features that set it apart from other webmail clients, there is a huge reason to move to Gmail. For this reason, Yahoo will lose many ‘techie’ customers it hasn’t already lost unless it offers the same feature.

In case you’re curious, here are the settings:

Incoming: imap.gmail.com
Outgoing: smtp.gmail.com
Username: username@gmail.com
SSL: yes

Have fun!

mail

Comments (0)

Permalink

LDS General Conference Podcast RSS feed

LDS General Conference audio and video is available via podcast!

After watching conference the LDS General Conference at the beginning of October, I really wanted to download all the talks via an RSS feed. I didn’t see one available right away, so I considered making my own. Fortunately, I found that an official podcast does exist. Its just not publicized well by the Church.

MP3 audio: http://feeds.lds.org/ldsgccomplete_eng

Video: http://feeds.lds.org/ldsgccomplete_eng_mp4

This should get you the most recent General Conference. If you haven’t used RSS before, you just need to give either (or both) of the above feed URLs to a podcast downloader (such as iTunes). The downloader will download all the current talks, and theoretically, will download the new talks next conference.

As an unrelated side note, feeds.lds.org is actually hosted by feedburner. Thanks to ldswebguy for originally posting these podcast feeds.

Uncategorized

Comments (0)

Permalink

Verizon FIOS and running a Linux operating system

Despite the well known fact that Verizon Can’t Do Math, I have to say that I am surprised to find that their FIOS service is pretty good. I’ve had it for over a month, and haven’t noticed it go down or have any speed problems.

More interestingly, I’ve actually found that they are pretty Linux-friendly. Actually, Linux-friendly might be too strong - lets just say that they have not locked me into using Windows for their service. I did have to use activatemyfios.verizon.net, which has a Windows/OS X only Firefox extension. But other than that, I haven’t felt the vendor lock-in blues.
Here are some good points:

  • As far as I can tell, Verizon only blocks port 80. I run both SSH and HTTPS from my home box.
  • Once I spoofed the correct MAC address, I was able to use my own non-Verizon router
  • There is no PPPoE authentication or the like
  • My IP address has not changed since I started the service
  • Latency is very low (about 12ms to Google)
  • Service has not gone down

I don’t use their phone or TV services, so I can’t comment on those. My guess would be that services like Vonage or Skype would work pretty well on my FIOS connection.

Bad points:

  • The backup battery is supposedly pretty weak. It only provides voice service during a power outage, not Internet. For that, you’d have to use a UPS. Fortunately, I haven’t had the power go out.
  • It took forever to get the service installed. Even though the previous house owner already had FIOS installed, they couldn’t come out for 2.5 weeks.

Verizon does pretty well here. So if you’re thinking about switching - I would recommend it.

fios
linux
network

Comments (0)

Permalink

How to create a lookup table in Ruby on Rails

I’m a big fan of the Rails way, but sometimes the simple things get you. I like to set up “lookup tables” in Rails, ie. tables in the database that hold commonly used, (often) fixed values. For example, if I have a Car model, I might want to define a Car type model. This would have two purposes:

  1. Give me the ability to associate a type with the Car model (ie. Car.type => ’sport’)
  2. Pre-load common values into the database (ie. sport, coupe, sedan, etc)

Continue Reading »

rails
ruby

Comments (0)

Permalink

New version of Rails available

If you didn’t know already, there is a new version of Rails out there.

And I’m not referring to the Rails 2.0 preview. This is Rails 1.2.5, which contains fixes for a JSON XSS (cross-site scripting) vulnerability. I’m not horribly familiar with the details, but the site does say that you don’t have to worry about it if you’re not using JSON. Probably a good idea to upgrade anyway.

rails

Comments (0)

Permalink