Posted by Nick Sieger
Thu, 01 Jun 2006 03:54:00 GMT
And now, a break from the tech- and ruby-related tidbits to add some
color to a local issue.
Today a news story of seemingly minor consequence passed through
the local news outlets on a proposal for a possible new Minneapolis
city ordinance:
The proposal would prohibit anyone from walking in an alley who
doesn’t live on that block or who isn’t a guest of someone who
does. Police, paramedics and firefighters would be exempt, as would
garbage haulers, meter readers, code inspectors and others whose
jobs take them there.
Before you call your councilperson and complain that your tax dollars
will be wasted, or you call the ACLU and complain that your civil
liberties will be infringed, consider this.
It strikes me as no small coincidence that my next-door neighbor was
shot at point-blank range last night by an assailant who was
attempting to car-jack him. He’s doing fine now, fortunately he had
his wits about him and the bullet only grazed his midsection before he
retreated back into his garage until the authorities arrived.
Would the ordinance have helped my neighbor in this case? Probably
not. But what it will do is give the police a legal reason to patrol
alleys and question conspicuous behavior. Fast-forward to a time in
the future where the ordinance has been in effect for a while and has
made Minneapolis neighborhoods safer, and maybe the environment for
the crime doesn’t even exist anymore.
One legitimate question is whether an ordinance like this would give
police more power to abuse and make it easier to profile and harass
people with no other probable cause.
For now, given my personal experience, I’ll gladly give up my right to
walk in other alleys in exchange for safety. Why would you want to be
back there anyway?
Posted in random | Tags crime, minneapolis | no comments | no trackbacks
Posted by Nick Sieger
Tue, 30 May 2006 16:57:00 GMT
Having trouble getting IRB to use a .irbrc file on Windows? The following seems to work:
- Create the .irbrc file in your
%USERPROFILE% directory.
- Create an environment variable in the System Properties->Advanced Tab->Environment Variables area called
HOME and set it to %USERPROFILE%.
An alternate approach is to create an environment variable called IRBRC and set it to the full path of the .irbrc file.
Perhaps IRB should be updated to look in %USERPROFILE% on Windows?
Plug: for handy .irbrc contents refer to this previous post.
Posted in ruby | Tags ruby | 1 comment | no trackbacks
Posted by Nick Sieger
Fri, 26 May 2006 03:32:00 GMT
Before my big blog drought at the beginning of the year, I had an
entry queued up talking about some success I’d experienced with Rails.
A lot in the Rails world has progressed since then, but I still think
the story is worth documenting. Also, the code to generate a PDF of
mailing labels may be useful to somebody out there.
I’ve had some Rails success lately building a home-use mailing list
manager/rolodex application. There are plenty of ways that such a
list could be maintained without resorting to a full web application
framework such as Rails, but what the heck! The mailing list
started life as an MS Access database; after my work computer was
re-imaged I no longer had “access to Access” so it had a temporary
layover in an Excel spreadsheet. Within the past couple of months I
had moved it to a MySQL database as a way to nurture my fledgling
Rails efforts.
Ok, so nothing real special so far, except that in order to print
mailing labels (one of the primary reasons for keeping such a list)
I’d have to export the names to a .csv file and do a mail merge with
Word. Until the most recent mailing.
On a Saturday night I had the brainstorm to use Austin Ziegler’s
PDF::Writer library to create a printable PDF directly from
the Rails app, thus skipping the need to go through the mail merge
rigamarole. Only a couple of hours of effort later, I had my
mother-in-law’s Christmas mailing list printed out! Anyone who has
ever done a mail merge with Word knows that clicking a single link
to create the printable versions of the mailing labels is a huge
improvement in usability. And finally, no MS bits were harmed in
the production of this mailing!
My starting point in building the code to generate PDFs was this page
in the Rails wiki. I decided to use the method that
describes installing an “rpdf” template handler. Nowadays, you may as
well use Josh Charles’ Rails PDF plugin, but for posterity
I’ve packaged up my effort as a simple plugin as well
(install into an existing Rails application with ./script/plugin
install http://svn.caldersphere.net/svn/main/plugins/pdfrender).
With the plugin in place, all that’s necessary is a controller method
to set up the data for the view, and the view code itself. The
controller is as straightforward as you’d expect:
class AddressController < ApplicationController
def pdf
@addresses = Address.find(:all, :order => 'last_name, first_name')
render :layout => false
end
end
The view code is a little more hairy but with a little thought the
dimensioning and layout code could easily be DRY’d out.
FONT = "Times-Roman"
FONT_SIZE = 12
COLS = 3
LABELS_PER_PAGE = 30
LABELS_PER_COL = 10
MARG_X = pdf.in2pts 0.19
MARG_Y = pdf.in2pts 0.5
CELL_Y = pdf.in2pts 1
CELL_X = pdf.in2pts 2.63
COL_PAD_X = pdf.in2pts 0.19
COL1_X = MARG_X
COL2_X = COL1_X + CELL_X + COL_PAD_X
COL3_X = COL2_X + CELL_X + COL_PAD_X
CELL_PAD_X = pdf.in2pts 0.13
CELL_PAD_Y = pdf.in2pts 0.25
CELL_LINE_Y = FONT_SIZE + 2
def cell_x(col)
[COL1_X, COL2_X, COL3_X][col] + CELL_PAD_X
end
def cell_y(row, line)
MARG_Y + ((LABELS_PER_COL - row) * CELL_Y) - CELL_PAD_Y - (line * CELL_LINE_Y)
end
def add_label(row, col, addr, pdf)
if addr
pdf.add_text_wrap(cell_x(col), cell_y(row, 0), CELL_X, addr.name, FONT_SIZE)
pdf.add_text_wrap(cell_x(col), cell_y(row, 1), CELL_X, addr.address, FONT_SIZE)
pdf.add_text_wrap(cell_x(col), cell_y(row, 2), CELL_X, "#{addr.city}, #{addr.state} #{addr.zip}", FONT_SIZE)
end
end
pdf.select_font(FONT)
pages = @addresses.length / LABELS_PER_PAGE
pages += 1 if (@addresses.length % LABELS_PER_PAGE) > 0
0.upto(pages - 1) do |page|
start = page * LABELS_PER_PAGE
address_page = @addresses[start..start+LABELS_PER_PAGE]
0.upto(LABELS_PER_COL - 1) do |row|
add_label(row, 0, address_page[row*COLS], pdf)
add_label(row, 1, address_page[row*COLS+1], pdf)
add_label(row, 2, address_page[row*COLS+2], pdf)
end
pdf.new_page unless page + 1 == pages
end
And that’s it! Avery labels in Rails!
Posted in ruby, rails | Tags pdf, ruby, rubyonrails | no comments | no trackbacks
Posted by Nick Sieger
Tue, 23 May 2006 03:59:00 GMT
My first trials in podcasting have been relatively enjoyable with
Typo. Although I wouldn’t recommend the approach I’ve taken for
someone who isn’t willing to get their hands pretty dirty.
I chose to save money at the expense of time and posted my podcasts
to ourmedia.org before realizing that Typo (svn rev 947) does not have
native support for externally-hosted enclosures. Following are the
hacks I’ve taken to work around that.
- In Typo Admin->Resources, upload a “blank” or dummy version of
the file you want to serve in your feed. Save the filename you
use for later (in the example below I use
minnebar20060506edwards.mp3).
- Upload the real file to the system that will be hosting the
file. Get the real length of the file, e.g., using
curl -I:
[22:48:37][~]$ curl -I http://www.archive.org/download/NickSiegerAgileDesign/minnebar20060506edwards.mp3
HTTP/1.1 302 Found
Date: Tue, 23 May 2006 03:47:54 GMT
Server: Apache/1.3.33 (Debian GNU/Linux) PHP/5.0.4-0.4
X-Powered-By: PHP/5.0.4-0.4
Location: http://ia301231.us.archive.org/3/items/NickSiegerAgileDesign/minnebar20060506edwards.mp3
Content-Type: text/html; charset=iso-8859-1
[22:48:51][~]$ curl -I http://ia301231.us.archive.org/3/items/NickSiegerAgileDesign/minnebar20060506edwards.mp3
HTTP/1.1 200 OK
Date: Tue, 23 May 2006 03:49:10 GMT
Server: Apache/2.0.54 (Ubuntu) PHP/5.0.5-2ubuntu1.2 mod_ssl/2.0.54 OpenSSL/0.9.7g
Last-Modified: Sat, 20 May 2006 03:39:32 GMT
ETag: "3c-1d8b320-46bc500"
Accept-Ranges: bytes
Content-Length: 30978848
Content-Type: audio/mpeg
- Now open up a Rails console in production mode on your server –
be careful! We need to patch in the real length of the file into
the resource record so that the actual length of the file appears
in the RSS and Atom feeds.
$ ./script/console production
Loading production environment.
>> r = Resource.find :first, :conditions => ['filename = ?', 'minnebar20060506edwards.mp3']
=> #<Resource:0xb747c2e4 ...>
>> r.size = "30978848"
=> "30978848"
>> r.save
=> true
>> quit
- Assuming you’re deployed on Apache (you are right?), put a
permanent redirect in your public/.htaccess file:
Redirect permanent /files/minnebar20060506edwards.mp3 http://www.archive.org/download/NickSiegerAgileDesign/minnebar20060506edwards.mp3
- Post your entry, and associate the resource to the post.
- Check your feed to verify the enclosure entry appears as
desired. Put your feed into a podcatcher and ensure the podcast
can be downloaded.
As you can see, not exactly the ideal scenario. I haven’t been
following recent Typo development closely but hopefully this can be
made to be super-easy in a future rev of Typo. If I was a hardcore
podcaster I would probably code up a patch but the above steps work fine for now.
Posted in random | Tags podcasting, typo | no comments | no trackbacks
Posted by Nick Sieger
Tue, 23 May 2006 02:44:00 GMT
In this podcast from minnebar 1, Ben Edwards presents on the topic of agile design. Using memes from the Agile Manifesto and 37 signals among others, Ben does a great job fostering a discussion.
Download the podcast here, or put my feed in iTunes or another podcatcher to have the podcast downloaded for you.
Posted in random | Tags minnebar, podcast | no comments | no trackbacks
Posted by Nick Sieger
Thu, 18 May 2006 02:48:00 GMT
Open source Java.
Who could possibly fork it
What? Not IBM!
Open source Java
Rather be hacking Ruby
Too late to matter
Open source Java
Need dynamic languages
Use JRuby now
Tags java, jruby, opensource | no comments | no trackbacks
Posted by Nick Sieger
Mon, 15 May 2006 03:12:00 GMT
Tom and Charlie have just experienced what can only be described as a watershed moment in the grand scheme of dynamic languages on the JVM. The Rails experience may soon be visiting a Java application server near you! Even though JRuby will be in perpetual catch-up mode with C Ruby, Tom and Charlie and the rest of the JRuby contributors have shown incredible perseverance in tracking the Ruby language despite the lack of any formal specification. Maybe Rails will never be mainstream, but the possibilities just got a whole lot more interesting. I agree with Obie that this could be a game-changer.
Now, a few comments about the ActiveRecord JDBC adapter. This code can still be considered alpha quality at best. It’s awesome that Tom and Charlie will be able to demo a top-to-bottom, working Rails app on JRuby, but don’t jump to conclusions yet that this will be anything like a write-once, deploy-to-any-database kind of experience. But you didn’t think it would, did you? We all learned that about Java a long time ago, right?
You can check out the code here. At the moment, I’ve only tried it with MySQL. Most of the problems with it come from the lossy mapping from ActiveRecord’s abstraction of the database to JDBC’s. (Although I suspect as more JDBC drivers are tried that there will eventually be compatibility issues with different implementations of the JDBC spec.)
Probably the thorniest issue is the one of type conversion. ActiveRecord has a fairly simple notion of types: :string, :text, :integer, :float, :datetime etc. Compare this to JDBC’s. What a mess! Right now there are arrays of procs for each AR type that try to guess the best JDBC type to use. This will certainly need improvement to become a more robust solution.
Probably the most promising approach may be to create a patch that refactors much of the AR adapters’ type conversion methods into separate modules that could be included into instances of the JDBC adapter depending on the underlying database. Then the JDBC types wouldn’t be needed at all – the existing AR database metadata could be reused. Presumably this would require some petitioning of the Rails core team to accept the changes even though the changes don’t buy AR itself any additional flexibility.
If you have a chance to try out the code or can think of any additional tricks that would help the ActiveRecord JDBC implementation along, let me know!
Tags java, jruby, rails, ruby | no comments | no trackbacks
Posted by Nick Sieger
Fri, 12 May 2006 03:25:00 GMT
In this podcast from minnebar 1, Jamie Thingelstad, CTO of
marketwatch.com, describes a real-world, scalable application of
asynchronous javascript that uses an event-driven model rather than
polling.
I enjoyed the session and think it’s worth a listen – there are some interesting approaches discussed, including a back-off strategy that helps give the server a chance to tell its javascript clients to not hit it so hard when it’s under duress.
Download the podcast here, or put my feed in iTunes or another podcatcher to have the podcast downloaded for you. I should be posting more minnebar podcasts in the coming days.
Posted in random | Tags minnebar, podcast | no comments | no trackbacks
Posted by Nick Sieger
Mon, 08 May 2006 03:17:00 GMT
It’s going to take me a while to recover from minnēbar. I met some great people, got motivated by some new noble ideas, and generally had a blast. A thousand kudos to Ben as well as the sponsors for making the event a smashing success.
But, let’s not stop there. We made some initial contact, hit it off well, vibed off of the energy in the venue. I’d be disappointed to say the least if I didn’t hear from anyone for another six months until the next event gets planned and scheduled.
So, can we make a concerted effort to keep in touch? May I suggest a monthly (or so) geek dinner, drinks or something similarly informal (e.g., the Friday night get together? I wasn’t there) where we can keep some momentum going and build our relationships? Find out where our own strengths are and how we complement each other?
If there’s one thing coming out of Saturday’s event where I hope we have a shared vision, it’s for increasing the amount of innovation in the technology sector in the Twin Cities. This group of people has the talent to make that real.
On a side note, I recorded four sessions of audio from Saturday, and at first listen they appeared to come out pretty well. I hope to post them in the coming days.
Another side note: the “ē” in minnēbar is represented in HTML as unicode entity ē. Don’t let your minnēbar posts suffer encoding issues on the highway!
Posted in random | Tags minnebar | 1 comment | no trackbacks
Posted by Nick Sieger
Fri, 05 May 2006 14:24:00 GMT
Spotted on ruby-talk today was this anecdote on a Ruby
hacker/father and son, and I just had to share here.
I trotted my 11 year old son over to the Poignant Guide and he
laughed like crazy at the Cartoon Foxes and did a little
programming, but soon got bored. Wait a minute Alex, let’s try one
more thing, Dwe.. Array. Wow, how do I make my R kill big time (He
knows all about cheats). I showed him the character’s values and he
promptly put in a hugh number for the Rabbit’s strength. He was
delighted to see the larger and larger negative life values appear
whenever he attacked. Dad, is this how all my Gameboy programs
work? Yes, son. Hey, dad I want to do 6dof animation too, can you
teach me? Yes son, here’s a few books for you – Computer Graphics,
Foley et al and Physics for Game Developers, Bourg. Not sure he’ll
read them right away, but the whole episode saved me another $49.95
Game Cube cartridge.
Posted in ruby | no comments | no trackbacks