Archive for October, 2008
Deconstructing software to find bugs
by Frank Kim on Oct.27, 2008, under Tools
In the September/October 2008 Technology Review I read a short article on Seth Hallem, one of the TR35. The subtitle of this article was “Deconstructing software to find bugs.”
As a graduate student at Stanford, Seth Hallem perfected an improved approach to finding bugs, called static analysis… Hallem developed algoritems to … examine only the most important combinations, allowing millions of lines of code to be examined quickly and efficiently. He cofounded Coverity in San Francisco.
Using Helpers with Email Templates
by Frank Kim on Oct.14, 2008, under Ruby on Rails
To use helpers with email templates specify in the model the helpers you want to use.
class FooMailer < ActionMailer::Base helper :Foo, :Application
Formatting Text
by Frank Kim on Oct.14, 2008, under Ruby on Rails
For text fields one typically wants to allow some HTML tags, add support for link breaks and even auto link URL’s and emails.
This method which I got from this forum thread, Adding a line break … safely, does all of this and is a must add to my application_helper.rb.
def format_content(content) # allow only tags specified in tags options, likewise in attributes content = sanitize(content, :tags => %w(b strong i em img), :attributes => %w(src)) # add support for line breaks content = simple_format(content) # auto link URL's and emails content = auto_link(content, :all, :target => '_blank') return content end
rake db:migrate hangs
by Frank Kim on Oct.09, 2008, under Ruby on Rails
Recently I tried running my RoR applications on Oracle.
I noticed that when I ran rake db:migrate it would hang. Specifically it would hang during the schema dump phase.
E:\work\sandbox>rake db:migrate --trace -v (in E:/work/sandbox) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump
I realized later that this was because the schema dump phase is very slow and the database I was using had many other tables from other applications. When I left it running it finally completed after 10 minutes.
You can see the slow progress of the schema dump phase by tailing schema.rb in the db directory.
Ruby on Rails and Oracle
by Frank Kim on Oct.08, 2008, under Oracle, Ruby on Rails
- Get the Ruby OCI8 driver. Download the file that ends with “mswin32.rb” and install like this:
E:\ruby>ruby ruby-oci8-1.0.3-mswin32.rb Copy OCI8.rb to e:/ruby/lib/ruby/site_ruby/1.8/DBD/OCI8 Copy oci8.rb to e:/ruby/lib/ruby/site_ruby/1.8 Copy oci8lib.so to e:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt OK? Enter Yes/No: Yes Copying OCI8.rb to e:/ruby/lib/ruby/site_ruby/1.8/DBD/OCI8 ... done Copying oci8.rb to e:/ruby/lib/ruby/site_ruby/1.8 ... done Copying oci8lib.so to e:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt ... done OK
You can test the driver by running a query using Ruby.
E:\>ruby -r oci8 -e "OCI8.new('foo','12345','sid').exec( 'SELECT * from users') do |r| puts r.join(' | ') ; end" - Install the ActiveRecord Oracle adapter.gem
E:\ruby>install activerecord-oracle-adapter --source http://gems.rubyonrails.org
- Update config/database.yml to connect to Oracle
development: adapter: oracle database: sid username: foo password: 12345 timeout: 5000
- Test by doing a rake db:migrate.
- Test by running the Ruby on Rails server and making sure there are no errors upon startup.
This article is based on these articles.
Perforce Adding a Directory Tree
by Frank Kim on Oct.08, 2008, under Perforce
This article, Adding a Directory Tree, shows how to add a directory tree to your perforce repository.
- On UNIX, run:
find . -type f -print | p4 -x - addThe above
findcommand will find files, but will not find symlinks. Nevertheless, you can add symlinks to Perforce using a similar method. Be aware, however, that symlinks are read-only entites, and that editing a symlink is not the same as editing the file it references.To discover the symlinks that exist in your client workspace and assess whether or not you want to version them, run the following command from your client workspace root:
find . -type l -print (That's an "el" as in "l" for link)To add symlinks, run:
find . -type l -print | p4 -x - add -t symlink- On Windows, using the MS-DOS command shell, run:
dir /b /s /a-d | p4 -x - add
smush.it
by Frank Kim on Oct.02, 2008, under Web
Image optimization is an art that not many people master. There are many good image editing tools that allow us to get the best visual result for a certain file size but “under the hood” a lot more optimization can be done.
Smushit.com is a service that goes beyond the limitations of Photoshop, Fireworks & Co. It uses image format specific non-lossy image optimization tools to squeeze the last bytes out of your images – without changing their look or visual quality. You’ll get a report of how many bytes you can save by optimizing your images and all the changed images as a single zip for download.
Smush it comes in different flavours:
- You can upload a bunch of pictures in your browser
- You can provide us with a list of image urls or
- You can get a Firefox Extension to optimize the images found on any web page
Saving bytes has never been so easy – you point us in the right direction, and we’ll do the rest for you. A ZIP archive with optimized images will be generated for you.
New from the Yahoo Performance team.
Takes your image(s) and makes their file size as small as possible: converts GIF to PNG8, throws out JPG metadata, etc. Does not make JPGs more lossy; the results look exactly the same.
Install the Firefox plugin and you can hand it a URL — and when it’s done, it’ll give you a ZIP file of all the images from that URL in reduced form.
Our Travel page, for instance:
Smushed 12.97% or 30.14 KB from the size of your image(s).
I’m actually pretty pleased we are “only” 30KB over. I’d have thought it’d be more.Our visitor HIW page:
Smushed 30.48% or 51.16 KB from the size of your image(s).
