Posts tagged on

Feb 28, 2010

Ruby whenever and day of month crontab syntax

Ruby cron | comments

Whenever by Javan Makhmali is an excellent way to manage the cron tasks that relate to your ruby app. It provides a very powerful and readable ruby syntax for planning a job schedule.

I had a hard time figuring out how to recreate the case of running a job on a specific day per month, however. The following crontab line is an example of running a job on the first day of month every month at 7:13am:

# .---------------- minute (0 - 59) 
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat 
# |  |  |  |  |
# *  *  *  *  *  command to be executed
  13 7  1  *  *  my_funky_command

The key to understanding the possible syntax is understanding that chronic is whenever’s underlying natural date and time parser. So the whenever syntax for the above cron definition is most elegantly:

every 1.month, :at => 'start of the month at 7:13am' do
  runner 'my_funky_command'
end

Running a job on days other than the beginning or ending of the month is not so straightforward. This GitHub issue explains it best. To running the same command every month at the same time, but on the 15th of the month:

every 1.month, :at => 'January 15th 7:13am' do
  runner 'my_funky_command'
end

‘January’ will be ignored as whenever parses the monthly job into its pieces.


Sep 02, 2009

JavaScript optional parameter hash with default values

default values javascript optional parameter hash | comments

I have dealt with optional parameters with default values in JavaScript plenty of times in the past. But for some reason it wasn’t immediately obvious to me how to create a nice options hash like I use so frequently when writing my Ruby code. It really is quite simple.

Here are the beginnings of a little function to handle the changing of a timeframe in a dropdown. The very obvious key is to default your options parameter to an empty hash if it comes through as null/undefined. I’m not sure why that eluded me for a while this afternoon. I’m defaulting the possible options in a couple different ways. I’m checking if boolean options are defined before defaulting them. For string options, I’m simply using an || operator.

function on_timeframe_change(options){
  options                     = options || {};
  var hide_selector_on_custom = typeof(options['hide_selector_on_custom']) == 'undefined' ? 
                                  false : 
                                  options['hide_selector_on_custom'];
  var prefix                  = options['prefix'] || '';
  var grab_focus              = typeof(options['grab_focus']) == 'undefined' ? 
                                  true : 
                                  options['grab_focus'];

  . . .

}

Sorry if you cannot handle ternary operators.


Aug 21, 2009

Five years old

consumption creativity work life balance | comments

This blog turns five today. Over the past year the blog has been relatively quiet, though I’ve put in a lot of time on a specific series of posts. I’m a little disheartened to see that the most frequently visited blog posts for the past year were all written in 2008 or 2007.

It appears most traffic to this little blog is through Google searches about specific programming problems. Other topics I write on are just not compelling enough to be passed around like a virus. That’s OK.

Do not let what you consume define you.
Rather, let what you create speak to your worth.

For the past few weeks I’ve been in a creative funk. Whenever I actively try to avoid working too much, it leads to over consumption of media. Not inspiring media like great books, great movies, or great photographs. I get stuck churning on RSS feeds I tried to bury long ago and checking Twitter and email. I’ve even picked up an addictive Scrabble game on my iPhone to while away the hours.

When it comes down to it, my creative outlets are my code and this blog. My code has led to some pretty fun projects, and a pretty fulfilling career. This blog has resulted in some nice compliments and introspective writing is not a waste even if it is not shared. It’s not a shame to keep investing time in code and this blog.

I’m not a workaholic. I don’t fear I’ll overreact to this funk by working all hours of the day. An alternative is to recognize other creative opportunities. There’s a kick-ass little camera sitting on my desk. There are some amazing slide photos from the 50‘s sitting on this computer, waiting to be cleaned up and shared. There is a nice kitchen in my home, and I enjoy cooking.

Spending most of the day creating sounds very tiring on its surface. But I know staying up until midnight diddling on an iPhone is tiring. Perhaps hitting the bed weary from activity and falling asleep quickly will be less taxing than nights of deafening insomnia. It’s worth a try.


Jul 14, 2009

So you're motivated by a tech conference. Now what?

blogging conference futureruby motivation oss technology | comments

Den Heinemeier Hansson
 
Photo by _heycarsten

Attending a great tech conference is a singularly motivating experience. If you have been to a few conferences you realize the motivation wanes alarmingly fast once you sit down in that old office chair and get back to work. While disturbing, this is a natural experience. No matter how swell your work environment, it is very difficult to recapture that “all things are possible with code” vibe the conference provided. Better to admit this and deal with it.

The most difficult conference lightning for me to bottle is the motivation for self improvement. I walk away from a conference wanting nebulous things like “build a software as a service site”, “build a mobile application” or “contribute more to open source.” I honestly get depressed when time and again I fail to execute on these goals. My hyper-motivated attitude sets me up for failure.

First, get the most out of attending the conference

Working the conference floor has been discussed frequently. I’m just going to bullet point these things and get to the meat.

  • Be prepared to talk about yourself
  • Be prepared to talk about a variety of other people and companies
  • Be prepared to be uncomfortable
  • If you are an introvert, head to a conference room and strike up a conversation with someone sitting alone. Avoid people making love to their laptops.
  • Be prepared to ask someone to lunch
  • Take notes, like with pen and paper. Put down the laptop from time to time.

Things I like to note down:

  • Information pulled directly from the talk
  • Unrelated ideas that pop into my head during the talk
  • Audience reactions to the talk
  • Good and bad aspects of the presentation and presenter
  • Information about people I meet

Capture conference motivation by reliving it

A conference wears you out, particularly if it has very good, or very bad, parties. When you get home, get some sleep, eliminate the pile of emails, and then get some more sleep. Then sit down and process the information you gathered and emotions you experienced during the conference. Plan to do this within a few days of returning from the conference, or you simply will not do it. After a week, you probably will not have much ingrained recollection of the event save for a general label of “it was great” or “it was OK”. (Note: The less great the conference, the more quickly you will complete this process.)

The simplest bits to capture from a conference are to-do items like books to read, software to trial, etc. Just get them in your to-do listing app of choice. Put them near the top as they are currently as relevant as they will ever be.

Follow up with folks you met. Don’t be a networking whore; get in touch with people you truly connected with. Follow those people you met in passing on Twitter, if you must.

Share your thoughts about the conference. Consider not only informational aspects of the event, but also the emotion of both you and the audience. Maybe this is a blog post, though I prefer to share the info with colleagues or journal it for my own benefit. My thoughts are usually too personal and scattered for an interesting blog post.

Let your experience generate something useful to share with others. For me this is typically when I put together a blog post. I might write about a single aspect of the conference itself, or more likely I’ll write on a subject I was motivated to research. You may wish to pay it forward by working on an OSS project or putting together a presentation for your local users group. It is entirely possible your reflections will generate multiple projects with which you can put your motivation into action.

Rather than set an impractical dream as a goal, be motivated by bringing the things that opened your eyes to others. Through blog posts, software contributions and local presentations you will explore your own ability to learn and you may just inspire the next guy. And everyone’s dream will become a little more possible.


Jun 30, 2009

Security of ignorance

career corporate world passion | comments

Ignorance is Bliss Road
  
Photo by parl

In college, I would add bells and whistles to my coding assignments. As any computer science degree-holder knows, most college projects are not incredibly applicable to the Real World (tm). But I like to think I was adding features to make the software work as a user expected it to work. I was learning unassigned lessons about user interface. I think the word for this is “passion” - I really loved programming during college.

Shortly after entering the corporate world, I quit my experimentation. There was no encouragement from within; no extra time offered for experimentation and growth. There was little tolerance for false starts and giving things a try. Strict up front planning was rampant. Annual education allotments were 24 hours, but I learned that gaming the system was preferred. Education options provided were a mix of Microsoft Word for Business, pursuing insurance and financial services designations, and a little morsel of technical stuff thrown in. All technical options were job-applicable to a fault. Again, experimentation was discouraged and deemed of very low value.

This is not to say I was forced into my ambivalence. New to the world of employment, I was easily swayed from the path I was on. Somehow I forgot what I loved about programming in order to “learn the ropes.” It was my responsibility to remain engaged in my career, and I failed for a long time to own up to that responsibility.

Over time I no longer even knew what technologies I could explore if I wanted to explore. Programming became a job in the sense that collecting money at a parking ramp or pounding nails is a job. I would leave work at work, which is something I encourage. But eventually I found leaving the tools for work at work was leading to a hole in my career. Something I was formerly so passionate about was becoming a negative, job-is-a-job part of my life.

Programming is a field where passion translates to practice and practice translates into success. One passionate at building eventually needs to stop pounding nails in order to progress in his career. In programming, you can have a very rewarding, and growing, career while writing code the whole time. In that sense, programming is more analogous to artistic and sports fields. It has been theorized that it takes 10 years just to get started in programming. The easy choice is to save tech learning for work hours. It’s an unfortunate decision because if one’s job does not provide enough time for practice, one misses the opportunity for success and fulfillment.

I entered this field precisely because of the changes inherent in the industry, an industry that grows and evolves somehow faster than I ever could. The rewarding choice was to embrace constant learning and position myself to benefit from it.


Jan 07, 2009

Hardware and software

office workarea workstation | comments

John Nunemaker at RailsTips recently asked the Tubes what hardware and software was being used to complete work. Here’s my rundown.

Hardware

My workspace


(annotated version)

My deck is a MacBook 2.4 GHz Core 2 Duo with 4GB RAM. I’ve been using an Apple Wireless keyboard for a while. I loved typing on my Microsoft Ergo 4000 board, but it’s so damn wide. My shoulder thanks me for the Wireless even while my wrists are slapping me.

I also have an auxiliary computer, a Mac Mini. It serves a slave purpose most of they day, playing music from iTunes and providing API docs on the second monitor. It has saved my bacon as an emergency work machine in the past. Behind the BenQ 24“ monitor sits a 250GB Western Digital Passport drive for backup. More about that later.

Shure E2c headphones provide complete aural privacy when needed. However I have grown tired of these as in-ear headphones bother me rather quickly. Even though the Shures provide about 9 different pieces of in-ear hardware, none of them quite work for me. I’ll probably move on to an over-ear solution soon.

Software

Let me get the basics out of the way. TextMate, iTerm, Safari for speed, FireFox for developing, Skitch, CocoaMySQL (which has apparently disappeared), and Quicksilver.

Time tracking is Harvest country. Actually, I interact with my time almost exclusively through Co-op‘s integration with Harvest. I do visit Harvest for reporting and such.

For email, I pretty much use Gmail with Mailplane exclusively.

I don’t have a lot of calendaring needs, so I mostly use Google Calendar (watch out, still in beta). At some point I set up an unholy sync to iCal so I get PING reminders every so often. But honestly, I don’t trust the sync at all. If I ever have greater need for strict calendaring I’ll get it all figured out. (My personal email is also sort of on Gmail, though I don’t have Apps for [My] Domain set up or anything. Just an auto-forward.)

I work on a completely distributed team, yet I hardly never use the phone, audio chat, or video chat. On occasion I’ll use Google Chat to have a quick conversation with my team. For the most part, Co-op and email keep us connected. Oh, and we’re using an internal app to deal with our tickets and plans. Not sure if I’d call it a project management app, though. Project management is a bit too highfalutin for us. :)

I’m pretty sure Things is my thing for personal task management. Will have to decide within a few days.

Big point. Get a backup system. A bootable backup is preferred if you depend on working hours to make money (i.e. you’re not salaried). I have partitioned my Western Digital 250GB Passport such that it can hold to entire bootable mirrors of my MacBook. I then use SuperDuper! on a schedule to create a mirror on alternating partitions each day (except Sunday). In the end, this gives me two days worth of bootable partitions at any one time. I have used this to work for a week on my Mac Mini (booted from the Western Digital drive as if my MacBook) while my MacBook was in the shop. Saved my bacon, I say!

Wait, now that isn’t so much a backup system as a recovery system. I also send all of my important files, as well as every family photo, nightly to Amazon S3 via Jungle Disk. I can’t recommend it enough.

Some other apps I find myself using throughout the day: RapidoWrite, Twitter, Twitterific on the iPhone, Google Reader (for personal feeds), Fluid (for app instances of Twitter, Google Reader and Co-op), NetNewsWire (for work feeds), growl, jing (for quick videos to share with the team), Flickr (for quick photo shares), SmugMug (to share photos with my family), Don’t Break the Chain (to keep me exercising, reading, writing, and sleeping), VueScan, PDFMergeX (for reassembling scanned documents), FuzzyClock (who needs to know the exact time?), SpiritedAway (auto-hide unused apps), iPhoney, NeoOffice, Pixelmator, Fusion, github, and gitx. When I need to take a note, I do it in text files which I can search with Spotlight. To ease the sorting pain, I use some Automator scripts.

Hopefully this quick rundown has given you some ideas for things you can improve in your work environment. Keep in mind, home office workers, watch out for bling creep. If you have an idea where I can improve, please do share!


Dec 22, 2008

Educating software developers

bjarne stroutstrup computer science software development software education | comments

knuth
 
Photo by bitmask

My brother recently shared with me an interview with C++ designer Bjarne Stroutstrup, speaking about educating software developers. Stroustrup recently entered the world of teaching after decades as a Bell Labs researcher. As you can imagine, Stroustrup had lots of good things to say.

The highlights for me tended to relate to my own career trajectory, as well as places where I see a reflection of my deficiencies. Stroustrup’s thoughts on the dissatisfaction corporations have with the current crop of computer science students:

Robert Dewar made an essential point. The companies are complaining because they are hurting. They can’t produce quality products as cheaply, as reliably, and as quickly as they would like. They correctly see a shortage of good developers as a part of the problem. What they generally don’t see is that inserting a good developer into a culture designed to constrain semi-skilled programmers from doing harm is pointless because the rules/culture will constrain the new developer from doing anything significantly new and better.

Lowest-common-denominator developer management is both lazy and antithetical to creativity. I’ve experienced this, as I’m sure most reading this have. Providing a hospitable environment for quality developers would lead to less cost for greater productivity, as a result of having fewer, better developers.

On a vital missing piece in most CS programs:

The aim is to instill a degree of professionalism; to get to the point where the students can write software suitable for the use by others than themselves.

This one, simple concept was missing from my CS education. Other than the occasional pair project, there was never any real consideration for maintainability and readability of code.

On what high school education is best to prepare the future developer:

What should high schools do to prepare students for university-level software development? When I entered a Math course as a 1st year student, the department head said something like this in his welcoming lecture: “I don’t care if you know math – we’ll teach you that from scratch – but I hope you know how to work hard and to read & write English, because you’ll need that to keep up.” I think he had an important point: current freshmen appear to have been spoon fed and many find it hard to adjust to independent work and to shake the impression that you work only to improve your grades.

With only anecdotal evidence, I can’t imagine the latest crop of high school students experiencing a renaissance of advanced communication skills. At the very best, I’d guess they are at the same, deficient level as I was exciting high school. While I won’t go so far as to suggest all high school students should complete speech and/or debate coursework, it’s pretty clear to me that any college-bound kids should be sent down that route. And this is coming from someone who works in an environment that uses 99.9% written communication.

On teaching the art of programming, as opposed to the craft:

I think aesthetics can be taught to many. Mostly it is a case of repeatedly showing students good examples and explaining why those examples are good. This takes time, years. I would like for programmers to present portfolios of their work, much in the way artist (including architects) have to. I don’t think everyone is cut out to be a programmer, just as not everybody is cut out to be a musician. Thus, we should not claim that program aesthetics is teachable to everybody. Drawing from the experience of crafts and arts, we should consider instituting a system of apprenticeships.

It will be interesting to see if all of this CS “apprenticeship” discussion coming from the thought leaders in our industry ever comes to fruition in the next decade. I personally find the concept to be intriguiing and I’d love to see a more in-depth description on how such a program would be built.

Stroustrup also talks about the much maligned “Java universities” and how their high-level teaching method is spitting out subpar developers. This is where I wince a bit. While my education was definitely skewed to the low-level, I have not even skimmed an entire data structures and algorithms book since graduation. Bad developer!

What do you take away from Stroustrup’s interview? Does it cause a lot of self-inspection, or do you think more about the changing CS education landscape?


Nov 11, 2008

Announcing time warp ruby gem

change time gem rails ruby time manipulation time warp | comments

When writing tests, it is often desirable to bend time to test limits and edges of the day. It is especially useful to warp time to test results across the timezones of the world. Manipulating time is also useful to assure a day of the week, month or year every time the test runs.

Some may say “Why not just mock Time#now?” I see the point, but I find mocking around with baseline Ruby classes to be asking for trouble. Eventually unusual behavior will rear its head and a day will be lost debugging tests - the most excruciating debugging one can be subjected to.

For all of your time manipulation needs, give time warp a try in gem or plugin form.


Nov 03, 2008

Filter unwanted tweets from your Twitter stream

filter filtering fluid greasemonkey twitter | comments

Ever find yourself annoyed by frequent talk of elections, memes and kitty-cats on Twitter? I have created a user script to apply to your Twitter Fluid instance or Firefox Greasemonkey install to enable regex whitelists and blacklists for filtering out tweets in your Twitter stream.

With this script installed, you will see whitelist and blacklist entry fields at the bottom of your sidebar:

The filter only applies to twitter.com/home* URL’s, so you will always see the entirety of a user’s tweets when visiting her homepage or browsing elsewhere within Twitter. As long as cookies are retained, the filter will remember your selections. Change your selection and hit enter or click away from the field to see immediate updates to your Tweet filtering.

Go ahead and install it.


Sep 17, 2008

Security of income

career corporate world employment income generation | comments

Book : How To Use Internet To Earn A MAssive PassivBook : How To Use InBook : How To Use Internet To Earn ternet To Earn e Income In Your Pyjamas
 
Photo by mohdzarki

My corporate job did not provide an extravagant income. It was probably less than industry average. This was not a realization over time - getting rich was never a reason to take the job in the first place. Budgeting and planning was made easy due to this consistent monthly income. Yet that simple fact was a poor reason to continue in an unhappy situation.

As my job satisfaction diminished, I began plugging scenarios into a spreadsheet, using various hourly rates and annual hours worked. I asked myself what expenses I could cut to make my budget lower profile. At first the resulting numbers concerned me. The largess of my necessary expenses surprised me.

A bit of a depression phase ensued. I wished I had never worked corporately, that I had never become accustom to living with two cars, a house, and piles upon piles of Stuff. I imagined prison walls built out of stacked DVD’s, furniture, and electronics, with framed equity and debt statements as the only decorative flourishes.

Since my responsibilities necessitated a certain level of income generation, the task of leaving corporate life required analysis of my (and my wife’s) risk tolerance and testing of my ability to predict the future. While I carried debt in the form of a mortgage, car payments, and student loans, I found our situation better than bad.

First, I had recently established an emergency fund. This offered me protection in the form of tide-me-over money in case of disaster while my income dipped below the norm. Second, I carried no credit card debt. Zero credit card debt was obviously helpful in that I had zero credit card debt to pay, nor interest to incur. Less obvious is if money ever became tight I basically had pre-approved loans up to my credit limits to keep my family in house and home (and car and diapers and ramen noodles and so on).

I am not recommending a dip in the ice-cold waters of one’s emergency funds as a means to make a corporate departure possible. Nor am I suggesting incurring credit card debt is the way to go. But this bit of buffer, this bit of protection, eased my mind as I considered the possibilities for my career. If the budget does not work, it simply does not work! There is no shame in working on the side to establish oneself in an alternative career. I would probably recommend the moonlighting route as opposed to the route I took.

After taking my risk tolerance temperature, I was at a point where I preferred tightening the purse strings to delaying a career change. To be sure, I needed to secure paid employment at some juncture over the next six months. I calculated the lowest possible amount I could make in the remainder of the year in order to cover my needs. The scenarios I devised were plausible, and even allowed me to develop a pecking order for potential work. At this point I was fairly secure in my abilities to get another corporate job if the “real world” became too difficult.

I was only able to make this jump into the freelance world by taking the time to research my budget, address my risk tolerance, understand the income I truly required, and consider ways to reduce my required income. Once I truly understood all of these factors, leaving the every-two-weeks checks behind was not all that scary. Growing confidence in my abilities did not hurt my comfort level, either.

Here’s where I share my secret, my ace-in-the-hole. I had another safety net. My wife was working a good-paying job with options to increase her hours if the need arose. It really helped me to have a supportive (in more ways than one) spouse!

Oh, and one other thing. My potential income is now much greater than it ever was in the corporate world.


Aug 29, 2008

Windy City Rails

conference rails ruby | comments

I am all registered for Windy City Rails, taking place in Chicago on September 20th. Looking forward to a shorter conference, along with an interesting drive with fellow Minnesota Rubyists. Come join us - only $99!


Jul 15, 2008

Fixing slow rake on Leopard

mysql rails rake ruby ruby on rails | comments

Hay Rake Third Version
 
Photo by JBAT

Update: I highly recommend going with Ruby Enterprise Edition and Evan Weaver's Ruby GC settings for much improved Ruby speed.

In the past few months, as a result of my clumsiness, I’ve been working on a new, Leopard-enabled MacBook. When replacing my wet and dying Tiger MacBook of yore, my one hope was that my daily executions of rake to test Harvest would execute a little faster. A 20% increase in processor speed doesn’t buy one a whole lot when web programming. The one place I figured I’d see a bump is the constant processor use of rake.

Wrong. So, so, wrong.

After moving to a new MacBook with Leopard installed, I experienced a test suite that ran 2-3 times slower than on my old machine. This became the difference between testing frequently and hardly at all; the difference between using and not using autotest. Pain to the max.

This post is going to get long, so I’m going to reveal now. For me, the issue was resolved by leaving the canonical Hivelogic world and reverting to the default Leopard installation of Ruby. Test speed returned to better-than-normal, and all at the price of only 6 hours of troubleshooting!

MySQL: Like shooting fish in a Superior-sized barrel

As always, my first suspicion was MySQL. I looked through my local Rails logs for particularly slow calls into MySQL. The initial thought was that a few bad-apple tests were not tuned very well for my environment. What I found was everything was slow and there were too many noticeably poor speeds to point to a few SQL calls as the culprits.

Next I compared my my.cnf file to my compadre‘s. I noticed no major smells in my file. Since I’m a DB dummy, more important was Dee’s estimation that indeed my configuration file looked alright. We even went so far as comparing MySQL variables from within the MySQL shell:

mysql> show variables;

Finally, I upgraded MySQL from 5.0.51 to 5.0.51b and reinstalled the ruby-mysql gem. No dice.

Sanity check: Benchmark the MacBook

Dee suggested I verify that my new MacBook itself wasn’t a lemon. I was doubtful since I’d noticed no other areas where it performed worse than its predecessor. Still, this was a great place to regroup. Benchmarking each MacBook put my mind in the right place to finish off my troubleshooting and uncover my problem.

I used Xbench to compare the general performance of my new and old MacBooks. Benchmark results favored the new machine everywhere except OpenGL. After reading the FAQ, it’s pretty clear OpenGL is a false positive for the old MacBook.

Rails: A general comparison between two machines

So I knew Rails was running slow when hitting the DB, but what about all by itself? I simply ran rake environment on both laptops and took a mental count. The command took ~3 seconds on the old machine and 6-7 seconds on the new one.

This was really enough, but I did run some model finders in each environment as a sort of sanity check. Performance results were in line with everything you’ve read so far.

Ruby: ActiveRecord-less and slow as ever

To hit the real meat-and-potatoes, I executed some Ruby-only code on both systems, benchmarking the whole way. Old Tiger:

$ ruby script/performance/benchmarker "(1..100).inject(1){|sum, n| sum*n}" 
            user     system      total        real
#1      0.000000   0.000000   0.000000 (  0.000217)

New Leopard:

$ ruby script/performance/benchmarker "(1..100).inject(1){|sum, n| sum*n}" 
            user     system      total        real
#1      0.000000   0.000000   0.000000 (  0.001347)

Over six times slower. New shit has come to light!

Sanity check II: Another system test

I wanted to run something from the command line that proved the new hotness was outperforming the old hoopty. Enter a little shell script built to copy an empty file to and from a folder 10,000 times:

#!/bin/sh
echo "start at `date +%s`" 
touch ./file.txt
mkdir ./fileholder

LIMIT=1000

for ((a=1; a <= LIMIT ; a++))
do
  mv ./file.txt fileholder/
  mv ./fileholder/file.txt ./
done

rm ./file.txt
rm -rf ./fileholder

echo "end at `date +%s`" 
exit 0

Rejoice! The new machine took 32 seconds to execute. The old one executed in 78 seconds. The winnowing process was imperfect, but I believe a winner has been crowned: Ruby.

Ruby: From source to simple

I pwnd Ruby
 
Photo by tychay

Both machines in question were on Ruby 1.8.6. The new one on patchlevel 114, the old one on 0. I attempted to install Ruby from source for patchlevel 230 (ACK!) and 111. No rake performance improvements were achieved. I also own a Leopard Mac Mini, installed from the Hivelogic instructions, and experienced the same rake downfalls (Sanity check III). Time to try Leopard’s default Ruby (patchlevel 114).

I did not want to remove /usr/local/bin from my path because I have other wonderful things installed there. Advisable or not, I simply renamed key binaries:

mv /usr/local/bin/ruby /usr/local/bin/ruby.bak
mv /usr/local/bin/rake /usr/local/bin/rake.bak
mv /usr/local/bin/irb /usr/local/bin/irb.bak

From there, all my gems needed reinstalled. gem install failed on my first try, but worked thereafter. The ruby-mysql gem had special needs (assuming a Hivelogic-style install of MySQL), which were addressed with:

sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

rake clean. Barry happy.

I can’t say I’m comfortable browsing my filesystem for gem source like I was with /usr/local, but I imagine that will come with time. My suspicion is the Hivelogic instructions can still work in Leopard given the appropriate compilation switches. I’m not the person to provide such information - perhaps someone already has?


Jun 01, 2008

Presentation: an audience perspective

rails railsconf railsconf08 RailsConf RailsConf ‘08 Rails | comments

Baked NYC
 

This weekend I attended RailsConf. This was my first multi-day conference. It was a great experience that I’m sure to repeat over the coming years. Met a lot of great Rails developers, working on interesting and disparate projects. Met a good number of Harvest users who spoke to me using words like “enjoy,” “love,” and, most surprisingly, “famous.” Even met people doing Important Stuff (tm) who didn’t particularly care to hear about my story.

Watching speaker after speaker is terribly motivating. Soon the realization that this blog has pretty well been dormant in 2008 came to mind. The realization that I’ve not prepared a proper presentation…ever…entered my thoughts. As I sat in sessions, I found myself, with a wide sliver of irony, writing down presentation techniques that pleased and bothered me.

Humor

You have to include humor in your talk. Most presenters are aware of this. However, many presenters front-load their humor. It’s difficult to lace the entire flow of information with engaging humor, but this is one of the most outstanding ways to provide a positive experience for the audience - one that causes them to pursue the topic after the fact.

In the case of technical talks, one must be careful not to make the humor the focus. But generally speaking, presenters tend to err on the opposite end of the spectrum.

A consistent metaphor

Several sessions included an interesting, nerdy metaphor. Don’t meticulously introduce the Star Wars comparison and then drop it for the rest of the presentation. Lace that damn B-wing throughout the slides.

Know your environment

Your super-sexy, light-on-dark TextMate theme is most likely going to cause the audience fits. They will yell at you, especially if it is the cranky third day.

Greater than 15 lines of code is unlikely to be readable by the audience. Know how to zoom or bigify your code or think of other creative ways around the problem.

Slide titles should be mid-screen or higher. Cool MTV banner titles along the bottom of the screen are likely difficult for most of the audience to read, save for the most ideal conference situations.

Unless the presentation calls for frequent interaction with your computer, stand up. Give yourself the air of authority and the confidence that you are qualified to share information with the group. Don’t pace, and get yourself some sleep the day before.

Timing

Don’t hope your talk will fit into the given time slot, know it will fit. Err on the side of too short, please. Don’t promise time for questions unless you’re certain you can deliver. Plan for interruptions (technical issues, in-presentation questions, rambling, etc). You will be refreshing and set yourself apart if you deliver a well-tuned, concise message.

Tell them what they want to hear

Or Pander to the crowd.

Or Tell them what they already know, in a new way.

Or Inspire them to pursue what you know they want to pursue.

Littering your presentation with known community mores will give you at least a knee-jerk positive reaction. The audience wants to laugh, nod, clap, and feel assured in their own choices. Be a catalyst.

Ideally your whole presentation shouldn’t be comprised of such a message. But if you don’t have anything nice to say, reflecting your audience is probably your safest option.

If all else fails, blow their minds

Announce a product, process, tuning, enhancement, iteration or whatever that carries along with it jaw-dropping statistics. The nice thing about this is you don’t have to necessarily give the product in question to anyone to prove your statements - at least not right away. Plan on delivering something within a few months, and deliver something within 50% of the improvements originally touted, or you will be blasted.

This talk can be combined with telling people what they want to hear to make a powerful concoction. It is workable to describe utopian worlds where downfalls are leveled with a Sim-City-like ease. Again, any improvements will be welcomed, and the army of supporters from announcement-time will do all of you defense for you when the rubber meets the road.

It’s not about you

Indeed, some speakers enjoy well-attended presentations due to their niche fame. Still, it is not about them. It is about what the speaker can do for me, the audience member. How do you help me to relate to you? How do you help me fit your perhaps only tangentially applicable message into my situation? How can you generalize the information you have for public consumption? How can you make it all about me?


May 28, 2008

RailsConf '08

rails railsconf railsconf08 RailsConf RailsConf '08 | comments

Just wanted to drop a note in my blog, here, that I will be attending RailsConf from Friday through Sunday. If any lurkers out there are gonna be in attendance, do drop me a note. Let’s meet each other!

If you want to stay up-to-date on any Barry-meets-RailsConf information, please check me out on Twitter.


Mar 29, 2008

ActiveResource HTTP basic auth with email address

ActiveResource Rails authorization | comments

As I’ve started to play around here and there with ActiveResource, I’ve noticed lots of complaints about how ActiveResource’s implementation of HTTP basic auth leaves a lot to be desired. Specifically with regard to its lack of support for email addresses as usernames. This won’t work:

class Expense < ActiveResource::Base
  self.site = "https://barry@bjhess.com:password@website.com"
end

Turns out it’s fairly simple to authorize via email address in ActiveResource. Just send the header:

class Expense < ActiveResource::Base
  self.site = "https://website.com"
  @headers  = { 'Authorization' => "Basic (#{Base64.encode64('barry@bjhess.com:password').strip})" }
end

Jan 02, 2008

Integrating Rails and WordPress

WordPress Ruby on Rails | comments

Mad code rewrite
 
Photo by zhartley

Scrawlers, an online writing workshop I helped build, includes a blog. Rather than build the blog from scratch, or even use a Rails solution, I chose to stick with the familiarity of WordPress. I’d read enough about Rails-lovers switching to a Rails-based engine and back to WordPress that I wasn’t even going to bother leaving The WP.

Scrawlers sits on an Ubuntu server with Apache and Mongrel running. Unfortunately I have little to no server admin skill, and that includes Apache mod_rewrite. Ilya Grigorik posted an excellent HOWTO on integrating WordPress and Rails. Unfortunately it didn’t quite work for Scrawlers, and I put off figuring out my special mod_rewrite secret sauce for quite a while.

Eventually I figured out what I needed beyond Ilya’s original technique and posted it in the comments section of his blog. The completist in me needs to post the solution on my blog as well. What follows is pretty much word-for-word from Ilya’s comment section. Be sure to read his post. It’s an easier solution, if it works for you, and it provides background information for what follows.

I’m dealing with Apache configuration that I do not understand. So it turns out I have AllowOverride disabled on my server, even explicitly in my app-specific Apache configuration for the public directory. This is why .htaccess wasn’t working for me.

After reading up a bit on .htaccess/AllowOverride, I decided there was really no reason to turn it on and eat the overhead involved. Instead I made a Directory directive in my app-specific config file and placed it before my initial WordPress redirects.

Once these things were in place, the one-line RewriteRule worked in every instance except one. The URL http://www.scrawlers.com/blog (or /blog/) failed with an access denied error. Looking at the rules it sure appeared like it should work. In the end I needed to include a couple rules specific to these situations. Here is, essentially, the bit of configuration code I needed to make my blog start working naturally: