mencoder rotates video files

So I made a video with my cell phone camera held wrong, and to fix it I used this:

mencoder -o OUTFILE.dv \
    -vf-add rotate=1 \
    -vf-add scale=640:480 \
    INFILE.dv \
    -oac copy -ovc lavc \

Winff can convert 3gp files to raw DV, but it's a GUI application.

Cloned from Satya's website (post comment)


Rails 3 upgrade on ubuntu

Spent several hours yesterday upgrading an Ubuntu running Ruby on Rails 2.x to Rails 3.

Starting with an Apache running passenger, ruby from Ubuntu repositories, and Rails 2.x from gems, we'll end with a fully rvm'd system, bundler, etc.

First upgrade rubygems to 1.6.2 by downloading, because ubuntu rubygems packages are hopelessly outdated:

wget http://production.cf.rubygems.org/rubygems/rubygems-update-1.6.2.gem
sudo gem install rubygems-update-1.6.2.gem
sudo /var/lib/gems/1.8/bin/update_rubygems

Verify with gem -v, which should produce 1.6.2.

Install rvm and other dependencies. You need readline, and the dev libs to compile it. Install it now, save headaches later.

sudo apt-get install git-core tig libreadline-ruby \
    libncurses-dev libreadline-dev

Install rvm via git:

mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm \
    -rf ./rvm/ && git clone \
    git://github.com/wayneeseguin/rvm.git && cd \
    rvm && ./install

Add this line to the end of .bashrc. See the rvm web site for details on why and how.

 -s "~/.rvm/scripts/rvm"  && source "~/.rvm/scripts/rvm"

Install ruby 1.9.2, passenger, and the rails upgrade checker plugin, and set up Gemfile. The first step, i.e. the ruby 1.9.2 install, takes time. This sets the new ruby as the default, installs newest rails and passenger, goes back to old ruby to install the rails upgrade helper plugin, sets 1.9.2 as the default for everyone plus passenger, pulls new Rails skeleton into your app, and installs bundler.

rvm install 1.9.2
rvm 1.9.2 default
gem install rails passenger
rvm system
script/plugin install git://github.com/rails/rails_upgrade.git
rake rails:upgrade:backup 
rvm 1.9.2 --default --passenger
rails new .
# (bunch of fiddling with environment.rb, application.rb, routes.rb)
gem install bundler

Add required gems to Gemfile in RAILS_ROOT, so you get non-broken mysql and rake:

gem 'mysql2', '< 0.3'
gem 'rake', '0.8.7'

Set the Gemfile.lock file with correct permissions. Then install the gems.

touch Gemfile.lock
sudo chown www-data.YOURUSERLOGIN Gemfile.lock
sudo chmod 664 Gemfile.lock
bundle install

Run `bundle check` in a rails application's directory (RAILS_ROOT) to find out what gems to install. It'll tell gem name and version number.

Thanks to http://basedotextend.com/, I found out how to compile openssl support in order to install passenger properly. Compile readline while you're at it:

cd ~/.rvm/src/ruby-1.9.2-p180/ext/openssl
ruby extconf.rb
make install

cd ~/.rvm/src/ruby-1.9.2-p180/ext/readline
ruby extconf.rb
make install

Now the actual passenger install. This will ask to install some development libraries, so install them using "sudo apt-get install list of packages that it gives" and run it again (i.e. run once to find out what it wants, install the dev libs, run again):

~/.rvm/src/rvm/binscripts/rvmsudo  passenger-install-apache2-module

It should eventually spit out the right Apache config, something like this:

LoadModule passenger_module \

PassengerRoot ~/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7
PassengerRuby ~/.rvm/bin/passenger_ruby

The LoadModule line should go in /etc/apache2/mods-enabled/passenger.load and the other two will go in /etc/apache2/mods-enabled/passenger.conf. It doesn't matter, both files are loaded, but that's how Apache is organized on Ubuntu.

Remove passenger and readline compilation libraries:

sudo apt-get remove build-essential libcurl4-openssl-dev libssl-dev \
    zlib1g-dev libopenssl-ruby apache2-prefork-dev libapr1-dev \
    libaprutil1-dev libncurses-dev libreadline-dev

If you're using calendar_date_select on Rails3, there's a gotcha. Some weird interaction between git and bundler on rails 3 causes issues, so you have to muck with the Gemfile. First put this in the Gemfile (all one line):

gem 'calendar_date_select', :git =>
:branch => 'rails3test'

Then install the source, compile the gem and inject the gem into rvm:

bundle install
cd ~/.rvm/gems/ruby*/bundler/gems/calendar_date_select*
gem build calendar_date_select.gemspec
gem install ./calendar_date_select
# Change Gemfile to:
gem 'calendar_date_select'

You have to switch the gemfile around every time you run bundle install. Ugh.

Cloned from Satya's website (post comment)


Password storage security

I have a system that stores passwords encrypted, with a one-way algorithm (meaning that in most cases, it's nigh-impossible to get the password back from what is stored).

e.g. "password" becomes 286755fad04869ca523320acce0dc6a4i (the "hash"), but given what's stored in the database: 286755fad04869ca523320acce0dc6a4, it's almost impossible for anyone to know that the password is "password". So if the database is stolen, no one can read the passwords. (That hash was possibly generated with a newline.)

When someone registers their account, the password they type is stored as a hash. When they log in, the password they type is hashed and compared (along with the login) with the database. Match, means they are who that database record says they are, and can log in.

Problem: there are available "rainbow tables". These are huge computer-generated lists of common words and phrases that people use as passwords. All an attacker has to do is compare the tables with the database, and see that the database contains 286755fad04869ca523320acce0dc6a4 and the table maps that to "password". The username and email are there already, so now they can try this info at a banking site. Most people use the same or similar passwords everywhere.

These attacks have happened on other sites.

A solution: instead of hashing "password", combine it with something else like "s3cret". This is called a salt. So now we hash "s3cretpassword". If someone's password is swordfish, we hash "s3cretswordfish". The hash for both of these is:
dba68374e08f8757483a58fa7550d803 s3cretpassword
8a8e32bdfe2504db405cb0fa004d0026 s3cretswordfish
and also:
286755fad04869ca523320acce0dc6a4 password

Of course we choose something a little more complicated than s3cret. So generating rainbow tables using all possible salts is impossible, so we're back to storing in the database an impenetrable string, which is also unique to our site. So someone who has stolen our database (it happens, not to us because we don't leave our database on thumb drives and laptops) will not be able to decrypt even lame passwords like "password". Our password checker does not even allow "password" but now there is an extra and better layer of security.

So, we have:

  • salted passwords against rainbow table attacks
  • password strength requirement (which security experts say is lame, and I agree, because it actually reduces the number of possible passwords, making automatic guessing easier. And also encourages people to use the same password everywhere, and write it down, etc.)
  • and password guess throttling (you get locked out temporarily after a small number of bad logins) to defend against automatic guessing.

Cloned from Satya's website (post comment)


How to reset your Linux mouse

Based on http://fixunix.com/x/343094-mouse-dying-me-ubuntu.html: if your mouse pointer gets stuck (because your KVM switch screwed up, as mine did) and you don't want to reset because you're in the middle of a non-saveable game, you can do this in a terminal:

sudo rmmod psmouse
sudo modprobe psmouse

While you don't have a mouse, here are some handy shortcuts for use with Ubuntu and Gnome:

Switch windows. Hit once to alternate between two windows. Hold down alt and keep pressing tab to reach other windows.
Run command. You can run gnome-terminal from here to get a command line. alt-1 etc switch terminal tabs. ctrl-shift-t opens new tab.
(Firefox) search bar
(Firefox) address bar. In Firefox, Ctrl-w closes current tab, ctrl-t opens new tab, ctrl-tab cycles through tabs.

Cloned from Satya's website (post comment)


Gemfile.lock in Rails 3

[Error: Irreparable invalid markup ('<p.>') in entry. Owner must fix manually. Raw contents below.]

<p. I followed the instructions at <a href="http://gembundler.com/rails23.html">http://gembundler.com/rails23.html</a> so that my Rails 2 apps can run in a Rails 2 + Rails 3 environment (I run Ubuntu, apt-get ruby, and gem install rails). </p> The instructions amount to: 1. put this code in environment.rb above the Rails.boot! line: <pre> class Rails::Boot def run load_initializer Rails::Initializer.class_eval do def load_gems @bundler_loaded ||= Bundler.require :default, Rails.env end end Rails::Initializer.run(:set_load_path) end end </pre> 2. put this in config/preinitializer.rb: <pre> begin require "rubygems" require "bundler" rescue LoadError raise "Could not load the bundler gem. Install it with `gem install bundler`." end if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24") raise RuntimeError, "Your bundler version is too old for Rails 2.3." + "Run `gem install bundler` to upgrade." end begin # Set up load paths for all bundled gems ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__) Bundler.setup rescue Bundler::GemNotFound raise RuntimeError, "Bundler couldn't find some gems." + "Did you run `bundle install`?" end </pre> 3. This'll do for your Gemfile: <pre> source :gemcutter gem "rails", "~> 2.3.5" gem "sqlite3-ruby", :require => "sqlite3" </pre> <p> (reproducing the instructions here mostly for myself.) </p> <p> That Gemfile goes in your application's rails root, i.e. the parent of app/ and config/. Okay, fine. So I set up an application that way, and it worked. I then commented out the 2.3.5 and it continued working. So I set up another application the same way and it failed. After 2 hours of headbanging, I realised that the Gemfile.lock was being used instead. Symptom: rails fails to start with: </p> <pre> no such file to load -- initializer </pre> <p> Now if you start it at least once with the 2.3.5 NOT commented out, it'll keep working even after you do comment it out. Might be a weird permissions interaction, though. </p> <p> The rant here is, .lock files are a *nix convention for, well, locking. As in concurrency control. Transient files. This Gemfile.lock isn't that kind of file. And it needs to be writable by the web server, unlike all the other files in your rails root. Ugh. </p> <p><a href="http://www.thesatya.com/blog/2011/03/gemfile_lock.html">Cloned</a> from <a href="http://www.thesatya.com/blog/">Satya's website</a> (<a href="http://www.thesatya.com/cgi-bin/blogcomm.pl?url=/blog/2011/03/gemfile_lock.html">post comment</a>) </p>

Installing Cucumber

Cucumber, the last time I installed it, was a pain. This time I put some more effort into it, and the steps boil down to:

sudo apt-get install libxslt-dev libxml2-dev ruby1.8-dev

sudo gem install gherkin webrat cucumber cucumber-rails database_cleaner --no-rdoc --no-ri 

Add config.gem to the config/envirnments/test.rb and config/envirnments/development.rb file (why not production, or environment.rb? because it's a *testing* framework):

config.gem "cucumber"
config.gem "webrat"

This is for Rails 2.x.

(Cucumber is a Behavior-Driven Development (BDD) testing framework for Ruby on Rails.)

References: https://rspec.lighthouseapp.com/projects/16211/tickets/235-couldnt-fnd-cucumber-generator

Cloned from Satya's website (post comment)


Wizard of Oz, Star Wars compared, and other crossovers

I was watching Suite Life on Deck (don't judge, with a little boy around those channels are the safest things to watch) and realised:
Star Wars Wizard of Oz
Luke Dorothy
C3PO Tin Man
Chewbacca Cowardly Lion
Han Solo Scarecrow
Obi-wan The Wizard
Emperor Any wicked witch
R2-D2 Toto

Can you hear "I'll get you my pretties, and your little Artoo!" in Vader's rasp? How about "It's a trap!" for the poppy fields?

"Pay no attention to the man behind the curtain... from a certain point of view."

On a completely different crossover:
"You want answers?"
"I want the truth!"
"You can't handle the truth! Now witness the firepower of this fully armed and operational battle station..."

Cloned from Satya's website (post comment)


Backups on Amazon EC2

If you like to rsync/rdiff your backups to an EBS volume on Amazon, this script will spin up a spot instance, attach the volume, run your backup, detach, and cleanup. A little bash knowledge and EC2 knowledge is required.

Original from http://roeeb.blogspot.com/2010/03/backup-to-amazon-ec2-using-spot.html (who seems to have got it from http://blog.blackpepper.co.uk/black-pepper-blog/Using-Amazon-EC2-EBS-S3-for-automated-backups.html ) but I cleaned it up a bit... a lot. And I've added micro-instance support as of Sep 10 2010.


Update: Here's a script that'll snapshot a given volume, keeping N snapshots, deleting older ones. http://www.thesatya.com/code/ec2-snapshot.bash-dist

Cloned from Satya's website (post comment)


Moonbase Alpha

Moonbase Alpha released for free on Steam this week. I tried it.

Over a gig for a relatively simple game? Sigh.

Two to five gigs of hard drive space? What?

4 gigs RAM? *What*? (okay, so maybe it said 2 gigs. Still: *what*?)

And then I ran it.

Slow. Sloooow. Laggy. Too laggy to play. Sorry, NASA, you lose the game development badge.

I mean it even lags on the *MENU* screen. It's always a bad sign when the menu screen lags.

I mean, good god, I'm on low-end hardware that was new in late 2009. This game is supposed to be from 2005. And it *lags*? Even Battlefield 2 is playable on this hardware.

This is about moon-walking and fixing-things with wrenches and robots. Shouldn't lag. The graphics aren't even that special; they look worse than BF2. So why does it lag? Must be something wrong in the code somewhere.

What a waste. Looked like it could have been fun.

Cloned from Satya's website (post comment)


Youtube on Roku

Assuming you have a local web server.

Step 1. Get Roksbox

Step 2. Go to Youtube, login, create a playlist (as many as you want).

Step 3. Get the alphanumeric ID of the playlist.

Step 4. Go to http://www.thesatya.com/cgi-bin/rry/get_playlists.pl and plugin the ID.

Step 5. Add the resulting URL to the roksbox videoqueue.xml file. (See roksbox docs for info.)

Step 6. Add whatever you want to the playlist.

Step 7. Enjoy!

From that link, you can also get the code.

Cloned from Satya's website (post comment)