Saturday, May 22, 2010

Running an rssh chroot on Ubuntu Lucid 10.04

I had some trouble getting a chroot running for rssh on Ubuntu Lucid 10.04. I ran the script below:

/usr/share/doc/rssh/examples/mkchroot.sh /var/chroot

It created most of the files, but didn't include the right libraries. Here's the minimum file listing I've been able to use:



libnsl was the tricky one that I found by trial and error. I installed bash inside the chroot and tested running each binary. Everything runs without libnsl, but its required if you want it to work with rssh.

Saturday, May 30, 2009

How to replace your iPod Touch 2nd gen digitizer / outer glass and bezel frame

If you're like me, you recently had a small accident with your iPod touch... you broke the screen! In our case, the iPod had slipped from a pants pocket into the recliner. It got caught between a few internal recliner arms and pinched to the point where the upper portion of the glass was broken.

[gallery link="file"]

In the case where your outer glass (called the digitizer) is broken but the LCD underneath is still perfect, you can replace the glass for $50-$75 in parts and tools. If you just want someone to fix it for you, it'll run $100+ for a 2nd gen from a parts store. Much better than the $200+ I've heard about from the Apple store.

I found a few video tutorials and other articles about replacing parts on the iPod Touch 2nd gen, but nobody described a few issues that I ran into. First, a few good resources:

Things you'll need



  1. Plastic opening tools (these often accompany digitizer replacements on ebay)

  2. A new digitizer. Available from eBay or a parts shop like http://www.pdaparts.com

  3. Most likely you'll also need a new front bezel or frame. For best results, get one with rubber gasket around the edge and double-sided tape on the inside

  4. A thin knife with a strong blade (mostly optional)

  5. A small pair of wire cutters (optional)

  6. Intermediate skill if you buy a new front bezel / frame, and advanced skill if you salvage the old one . I took the easier route and bought a new front bezel. Either way, you still need the button seat from the old bezel.


Unfortunately most of the part stores and eBay sellers that advertise replacement digitizers for 2nd generation iPod touches don't mention that the front bezel is extremely difficult to remove without damage. The front bezel and digitizer are attached through buttons around the digitizer edges. My broken digitizer was also glued down to the front bezel. Additionally, there is a thin rubber gasket that runs around the length of the digitizer. Even with careful prying with my fingers and plastic tools I tore the gasket in several places.

Take it apart


The youtube video linked above gives very good information about the location of the clips and how to pull the digitizer off without damaging it. Be careful that you press the plastic tool on the outside of the rubber gasket (closest to the metal backing) rather than the inside of the rubber gasket (closest to the actual glass). This is especially important if you don't want to damage the bezel. I found that I accidentally separated the bezel from the digitizer because I didn't realize the distinction.

Once you have the digitizer off, you can put the rest of the iPod aside and focus on separating the glass from the bezel. It is a pain, and assuming your digitizer is cracked, is likely to drop pieces of glass. You only need to separate the glass from the lower portion of the bezel (near the home button).

The goal is the grab the home button and its seat. I haven't seen any parts stores that sell the seat, so don't mess it up! The button just fails out.

The edges around the button seat are raised. After bending the plastic various ways, I found the easiest way to retrieve it is to use a small wire cutter and snip off the edges to the right and left, removing the raised edges. This will allow you to take a small, thin knife and slide it under the tiny plastic buttons that hold it on. Keep the knife away from the center of the button seat because that might sever the electrical connection.

Attach the new digitizer and bezel


Since I didn't know that I needed a bezel to do the replacement, I just ordered it tonight. I will post more information and pictures when the part arrives.

Slide in the new assembly


After you have the new digitizer and bezel together, complete with home button, you can put it back together! Don't forget to attach the digitizer ribbon to the rest of the iPod.

Thats it! Post a comment about how your replacement goes.

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

Sunday, December 2, 2007

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.

Monday, November 19, 2007

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!

Sunday, November 4, 2007

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" )