Croppr, ready for primetime

Posted April 11th, 2007 in Javascript, Projects, Rails and or Ruby

It’s been a long time coming… Croppr has grown out of it’s infancy. Sparked recently by the release of Gravatar 2.0 and the Ruby on Rails podcast Camping II, I dove back into the code and cleaned it up. Croppr now adheres to the minimalistic principles of Camping. RMagick was thrown out in favor of ImageScience. The javascript was tweaked for performance and readability using the ever so light and powerfull MooTools. The magic is really in the javascript, I encourage you to check it out. All the pieces come together as a living tutorial of how to implement Croppr on your own. Go play with my vain demo! If you want to get sneaky and upload your own image tag /new to the end of the URL, but keep it clean… Here’s an overview on how to get her up and running on your own machine:

sudo gem install mongrel
sudo gem install camping
sudo gem install json
sudo gem install sqlite3-ruby (you need to have sqlite3 installed) 
sudo gem install image_science (you need to have freeimage installed)

svn co http://svn.vandev.com/croppr/trunk croppr
cd croppr

ruby croppr.rb

It’s that easy. You should be able to follow the documentation in the javascript and the implementation example in the camping app to get her working yourself. Goodluck, and let me know of any crazy browser issues. I half-assed tested it in IE 6 and 7… Safari and Firefox are golden.

Kinda like: | | | |

Mephisto is finally up and running

Posted January 12th, 2007 in Rails and or Ruby, The Rest

Dang, procrastination is a terrible terrible thing. I had been doing allot of traveling prior to the Holidays and just didn’t have the motivation needed to put the time into setting up Mephisto. I finnaly got around to doing it, and it went pretty well. The Typo conversion didn’t happen as smoothly as I had hoped and I had to hack the Flickr plugin a bit to get her up and going, but she’s finally here. This time around I shouldn’t rank as #1 on Google for a series of absurdly explicit terms describing grotesque sexual actions… Thank you Akismet. I also decided to drop the blog from blog.vandev.com. From now on, this is vandev.com.

I’ve got a couple new little projects that I’ll release in the near future. Merb has entertained me as of late, as well as MooTools. Anyway, I’ll get them up and I’ll finish polishing the site. Polishing it until it shines.

Kinda like: | | |

MaxMind GeoLite on Rails with PostGIS

Posted October 15th, 2006 in Mapping, Programming, Rails and or Ruby, Tutorials

Ughhhh, many hours of frustration have been spent trying to push the MaxMind GeoLite City CSV files into a database configured with PostGIS. Anyway, I figured I would document the process that I went through incase someone else wants some free IP based geocoding in there Rails app.

MaxMind gives you two CSV files for the city database. One has an assload (2,783,434) of IP blocks that map to the id of a row in the other table containing location data. The location data is pretty rich. It contains a postal code, area code, dma code, country, region (state in US), and a latitude and longitude. Because I wanted to be cool and more efficient, I decided to store the lat / lon as a point in PostGIS format. Using PostGIS along with Guilhem Vellut’s Spatial Adaptor plugin for Rails, makes doing geo-spatial operations sexier and easier than ever. You can use the Spatial Adaptor with MySQL, but you’ll never be as cool as the guy using it with PostgreSQL.

First off I had to create my tables.

create_table "geo_ip_locations" do |t|
  t.column "country", :string, :limit => 2
  t.column "region", :string, :limit => 2
  t.column "city", :string
  t.column "postal_code", :string, :limit => 7
  t.column "dma_code", :integer, :limit => 3
  t.column "area_code", :integer, :limit => 3
  t.column "geom", :point, :null => false, :srid => 4269, :with_z => false
end

add_index :geo_ip_locations, :geom, :spatial => true

create_table "geo_ips" do |t|
  t.column "start_ip", :integer, :limit => 10
  t.column "end_ip", :integer, :limit => 10
  t.column "geo_ip_location_id", :integer
end

add_index :gep_ips, :start_ip
add_index :geo_ips, :end_ip
add_index :geo_ips, :geo_ip_location_id

A few things to note:

  • The geom column has the srid set to 4269, this threw me for a loop for way too long. Make sure you have the spatial_ref_sys table populated. I’m also assuming that the MaxMind data is mapped to the WGS 84 standard.
  • The limit’s on the start and end ip’s are set to 10. This creates bigint columns in my DB. I’m not sure what version of Rails started doing this (I’m on Edge), but the columns have to be bigints for the IP block information to be imported.
  • Remember to create a couple models for the tables
  • You may want to add an index on postal_code or anything else you’ll be using in a SQL WHERE clause

Now because the CSV file with the blocks of IP addresses in it is so large I went with an importing tool to get it into the table. I was going to use PostgreSQL’s COPY command, but it doesn’t seem to support CSV’s with double quotes. I went with Navicat and took advantage of my 30 day trial. The CSV with the locations in it is another story. We need to convert the lat / lon pairs into points for PostGIS. Not only that, but if we want to be really cool we need to convert the city names into UTF-8. The file that MaxMind gives us has ISO-8859-1 encoding. Iconv comes to the rescue. You can either convert the entire file from the command line, or just use the ruby library to do it in the import script below.

require "#{File.dirname(__FILE__)}/../../config/environment"
require 'fastercsv'
require 'iconv'
ICONV = Iconv.new( 'UTF-8', 'ISO-8859-1' )

FasterCSV::HeaderConverters[:underscore] = lambda { |h| h.underscore }

FasterCSV.foreach('geo_ip_locations.csv', {:headers => :first_row, :col_sep => ",", :header_converters => :underscore}) do |row|
  begin
    row['id'] = row.delete('loc_id')[1]
    row['geom'] = Point.from_x_y(row.delete('longitude')[1].to_f, row.delete('latitude')[1].to_f, 4326)
    row['city'] = ICONV.iconv(row['city'])
    cool = GeoIpLocation.new(row.to_hash)
    cool.id = row['id']
    cool.save!
    $stdout.print '.'
  rescue
    puts $!.message
    $stdout.print 'f'
  end
  $stdout.flush
end

Things to note:

  • You need FasterCSV for this to work gem install fastercsv
  • You need to delete the first line (with the copyright info in it) in the CSV for this script to work.
  • If you converted the file from the command line, comment out the three lines referencing iconv to improve performance.
  • I created a directory called transform in my db directory, renamed and moved the location CSV there, and created a file with the above code in it.
  • Always remember to put the srid in the Point.from_x_y call, otherwise you’ll be very very frustrated.
  • You’ll need to specify encoding: unicode Postgres, encoding: utf8 MySQL in database.yml to use UTF-8 with the DB. See the Rails wiki
  • The id is set this way to preserve it.

That’s it! There you have it, the possibilities are now endless. As I said before, I set this up on PostgreSQL, but this should work the same on MySQL. The one main difference will be the srid’s. MySQL doesn’t support them, so you don’t need to specify them. Goodluck!

QuickPresent

Posted October 6th, 2006 in Programming, Projects, Rails and or Ruby

I threw together a quick and simple way to make a presentation on a mac using Quicksilver and Camping a while back. Well, I finally got around to refining it and putting it into a both tiny and awesome package. This puppy is made of two files, and makes presenting dead simple. You just outline your thoughts in a text file, and QuickPresent smacks it onto your screen using Quicksilver’s largetype feature. Not only that, but it also gives you a slick little web interface to show you what you’ve said, and what you’re about to say. Let me show you…

A few other slick features include automatically opening URL’s and Files from your hard drive. All you need is Camping and Quicksilver (with the command line tool (qs) plugin installed). Just type camping quickpresent.rb from the command line and your up running. If you want to try something cheaper than Keynote or Powerpoint, play with QuickPresent. Let me know what you think.

Get it from my SVN Repo: http://svn.vandev.com/presenter

Croppr podcast... a little late

Posted September 22nd, 2006 in Javascript, Rails and or Ruby, Tutorials

The SDRuby podcast site is filling up with great episodes. One of which being my little talk on camping and Croppr (Episode 002 on the bottom). The thing has been up for a couple of monthes now, but my posting consistency has been miserable lately. I’ve had more pressing issues, but today is a new day. My next project will be pushing this thing over to Mephisto. I should also spend some time fixing the Rails date_select helper, but that’s another post all together. The next time I speak, the entire back end of this puppy will be different… totally awesome.

Croppr is born... perhaps pre-mature

Posted July 5th, 2006 in Javascript, Rails and or Ruby

So, I finally got around to testing TextMate’s new blogging bundle. It’s dead simple… Anywho, I figured I would use it to give a sneak peek of my newest invention Croppr, which I will be revealing in it’s full glory tomorrow night at SDruby.

All right, so Croppr was born out of a desire to make a better way to crop images online. Specifically the need came from my buddy Tom Werner’s pet project, Gravatar. The inspiration came from iChat’s avatar cropper:

iChat Cropper

After days of arduous JavaScript hacking with the help of Prototype and eventually Prototype Lite with moo.fx I had a lightweight browser equivalent. Have a peek and play around.

What good is a lightweight JavaScript cropper without a lightweight back end to actually do the cropping? Enter camping. In just 225 lines of sexy Ruby code I have a fully functional image cropping machine. I hope to have a running demo available in the near future. As far as licensing goes, I’m still working on it so hold your shorts. Until than, come to the SDruby meetup (start driving now if you have to) and see all the awesomeness that is Croppr!

RMagick on Mac OS X 10.4 Tiger

Posted June 6th, 2006 in Rails and or Ruby, Tutorials

Recently I needed Rmagick installed on my Mac OS X 10.4 system. This turned out to be nearly impossible, until I got down and dirty and just went for a fresh compile from source. Actually it became more impossible until I found enlightenment on the long and arduous journey. The following is a pretty bare-bones install. It leaves out excess functionality like exporting to TIFF, working with PostScript or PDF files, color management, EXIF headers, SVG images, or MSWord documents. All of this functionality can be added by downloading the source from the links above, and compiling them before you run ./configure for ImageMagick. You can also install GraphicsMagick if you like, it shouldn’t make a difference which one you use.

The following instructions will have you up and running in no time (actually about 30 minutes depending on the speed of your system ImageMagick takes forever). These instructions assume you have installed Ruby according to the instructions at HiveLogic. If you have not, make sure you atleast follow the steps up to the point of installing ruby. This makes sure your path is correct and your build environment is in place.

X11:

10.4 Tiger install DVD or http://www.apple.com/downloads/macosx/apple/x11formacosx.html

Freetype2:

curl -O http://umn.dl.sourceforge.net/sourceforge/freetype/freetype-2.2.1.tar.gz
tar zxvf freetype-2.2.1.tar.gz
cd freetype-2.2.1
./configure && make && sudo make install
cd ..

Jpeg:

curl -O ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
ln -s `which glibtool` ./libtool
export MACOSX_DEPLOYMENT_TARGET=10.4
./configure --enable-shared && make && sudo make install
cd ..

PNG:

curl -O http://umn.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.10-no-config.tar.gz
tar zxvf libpng-1.2.10-no-config.tar.gz
cd libpng-1.2.10
cp scripts/makefile.darwin Makefile
make && sudo make install
cd ..

ImageMagick:

curl -O http://umn.dl.sourceforge.net/sourceforge/imagemagick/ImageMagick-6.2.8-0.tar.gz
tar zxvf ImageMagick-6.2.8-0.tar.gz
cd ImageMagick-6.2.8
./configure && make && sudo make install
cd ..

RMagick (finally and thankfully):

sudo gem install rmagick

That’s it, goto RMagick’s web site for information on using RMagick in your apps. Be on the look out for an incredible little Camping app that uses the power of RMagick to appear on VD soon!

Introducing AjaxSpy

Posted May 4th, 2006 in Javascript, Programming, Rails and or Ruby

While playing with the new RJS templates in rails, I found it difficult to know what was actually being returned from my requests. Thus, AjaxSpy was born. It’s a simple JavaScript and CSS file. All you need to do is include the js file in the header of your document, the css is automagically included (must be in the stylesheets directory). The script relies on Prototype 1.5.0rc0, and for it to be sexy you need the Scriptaculous effects library. You can include it conditionaly based on params in the query string, or do some fancy session stuff. That’s all up to you. This is what I’ve been doing

<%= javascript_include_tag "prototype", "effects" %>
<%= javascript_include_tag "debugger" if params["debug"] %>

The script is currently only working with Firefox and Safari, I’ll work on the bastard child that is IE down the road. Here’s what it looks like, syntax highlighting and all:

AjaxSpy Preview

I present to you, AjaxSpy:

Again, to install simply include the js in the layout, it automagically includes the css (as long as it’s in a directory named “stylesheets” relative to the site route). Let me know if you have any problems.