My Apprenticeship - Wednesday, July 14, 2004

Posted over 2 years back at Jake Scruggs

This summer I'm revisiting my short apprenticeship at Object Mentor. I'll be posting commentary on all my posts from the summer of 2004 exactly 5 years later to the day.

Wednesday 7-14-04

The problem with a 'five minute install' is that if you go beyond 5 minutes, you are screwed. A five minute install is doing a lot of things behind the scenes. If those hidden processes fail, then you don't have anything to look at. The configuration file for Word Press is very simple: You tell it the database's name, the user's name, the user's password, and where to look for the server. Once you've verified that the database does exist (by messing around in MySQL), the user has access, and the password is correct then only the server is left. Which is quickly crossed out by accessing the database through the server (which is running on the localhost). Now what? There's really nothing else to change.

After banging my head against this all day (Well not actually all day. When I arrived this morning the power was out and so I had no access to the Linux box. When the power came on, there was no internet until a number of things were restarted. Most of the mess got sorted out by 11am.) I have come to the conclusion, with Paul's help, that this Appache/PHP/MySQL bundle I've been using (which is called Xampp) may not be working correctly. There's also the issue of MySQL being installed in two places on the machine (I didn't know it was already there) so Word Press may be trying to access the wrong place. Or there's the fact that .php files aren't being recognized as PHP files unless I specifically run them by typing, for example: php install.php All this leads me to believe that I probably am going to have to uninstall Xampp and set up Apache, MySQL, and PHP the old fashioned way.

I better not have to re-re-re-install Linux.

Here's a bit of weirdness: Last night I woke up at 3:43 in the morning. As I blearily stared at the clock I thought "3:43, that should be public static."

Paul mentioned that he isn't allowed to use most of what he knows in his college programming classes. If he writes tests, he has to strip them out. And if he were to use a Visitor pattern and his professors didn't understand it he would be marked down. So he spends 9 months out of the year having to ignore what he learned in the other 3. That's not cool. Speaking of the Visitor pattern, it looks like I'm going to get to take a class at Object Mentor in advanced object programming and patterns. David is scheduled to teach this class, but since he's only taken it once, he wants to teach Paul and I first so that he can get his moves down and spot potential questions. Good for him and me because, although I've heard people talking about patterns in the office, I've only used the state machine pattern and not much else.

I wonder how test-friendly colleges have gotten in the past 5 years and if you make students write tests will they learn to hate them? I know a lot of students would ask me to teach them something about Quantum Physics because they had read a cool article or seen a 'Nova.' However, when they actually had to study about quarks and weak forces they were decidedly less enthusiastic.

So which one of the potential problems I outlined with the 5 minute install do you think is really the cause of its failure? The 2 databases? Xamp? The .php files not being recognized? An unsuccessful install of Linux? And how many more days before the 5 minute install draws to a close?

"public static" -- funny.

Remaining Ruby & Rails Conferences in 09

Posted over 2 years back at Riding Rails - home

The Ruby and Rails community is still growing strong and the sheer number of conferences coming up is proof of that. Below I’ve put together a list of all the conferences/events I could find before 2010 so you can hopefully make it out to at least one. ;-)

If you do attend one of these conferences, do me a favor and thank the organizer for taking the time to produce the event. Most of them spend a great deal of unpaid time making the event happen and most of them aren’t making a profit. Their passion and hard work helps keep our community strong.

Jul 17 – Jul 20 Rails Camp in Bryant Pond, Maine.

Cost: $120

Jul 17 – Jul 19 Ruby Kaigi 2009 in Tokyo, Japan.

Cost: Sold Out

Jul 24 – Jul 25 Rails Underground in London, UK

Cost: £240

Jul 31 – Aug 1 Rails Outreach Workshop for Women in San Francisco, CA

Cost: FREE

Jul 30 – Aug 1 RubyRx in Philadelphia, PA

Cost: $550

Aug 7 – Aug 9 eRubyCon in Columbus, OH

Cost: $299.00

Sep 10 – Sep 11 Ruby Rx in Washington DC

Cost: $550

Aug 7 – Aug 8 Oxente Rails in Natal, Brazil

Cost: R$ 200,00

Aug 27 – Aug 29 Lone Star Ruby Conf in Austin, TX

Cost: $250

Aug 28 – Aug 29 Ruby Hoedown in Nashville, TN

Cost: FREE

Sep 1 – Sep 2 Rails Konferenz in Frankfurt, Germany

Cost: €215

Sep 12 Windy City Rails in Chicago, Il

Cost: $99

Oct 5 – Oct 6 Aloha on Rails in Waikiki, HI

Cost: $199

Oct 13 – Oct 14 Rails Summit Latin America in São Paulo, Brazil

Cost: R$ 400

Oct 16 – Oct 19 Rails Camp UK in Margate, UK

Cost: £50

Nov 7 – Nov 8 Rupy 2009 in Pozna?, Poland

Cost: ? (registration not open yet)

Nov 19 – Nov 21 Rubyconf in San Francisco, CA

Cost: ? (registration not open yet)

Nov 20 – Nov 23 Rails Camp Australia in Melbourne, Australia

Cost: $180

Let me know if I forgot any events, I’ll be happy to add them to this list.

Remaining Ruby & Rails Conferences in 09

Posted over 2 years back at Riding Rails - home

The Ruby and Rails community is still growing strong and the sheer number of conferences coming up is proof of that. Below I’ve put together a list of all the conferences/events I could find before 2010 so you can hopefully make it out to at least one. ;-)

If you do attend one of these conferences, do me a favor and thank the organizer for taking the time to produce the event. Most of them spend a great deal of unpaid time making the event happen and most of them aren’t making a profit. Their passion and hard work helps keep our community strong.

Jul 17 – Jul 20 Rails Camp in Bryant Pond, Maine.

Cost: $120

Jul 17 – Jul 19 Ruby Kaigi 2009 in Tokyo, Japan.

Cost: Sold Out

Jul 24 – Jul 25 Rails Underground in London, UK

Cost: £240

Jul 31 – Aug 1 Rails Outreach Workshop for Women in San Francisco, CA

Cost: FREE

Jul 30 – Aug 1 RubyRx in Philadelphia, PA

Cost: $550

Aug 7 – Aug 9 eRubyCon in Columbus, OH

Cost: $299.00

Sep 10 – Sep 11 Ruby Rx in Washington DC

Cost: $550

Aug 7 – Aug 8 Oxente Rails in Natal, Brazil

Cost: R$ 200,00

Aug 27 – Aug 29 Lone Star Ruby Conf in Austin, TX

Cost: $250

Aug 28 – Aug 29 Ruby Hoedown in Nashville, TN

Cost: FREE

Sep 12 Windy City Rails in Chicago, Il

Cost: $99

Oct 5 – Oct 6 Aloha on Rails in Waikiki, HI

Cost: $199

Oct 13 – Oct 14 Rails Summit Latin America in São Paulo, Brazil

Cost: R$ 400

Oct 16 – Oct 19 Rails Camp UK in Margate, UK

Cost: £50

Nov 7 – Nov 8 Ruby 2009 in Pozna?, Poland

Cost: ? (registration not open yet)

Nov 19 – Nov 21 Rubyconf in San Francisco, CA

Cost: ? (registration not open yet)

Nov 20 – Nov 23 Rails Camp Australia in Melbourne, Australia

Cost: $180

Let me know if I forgot any events, I’ll be happy to add them to this list.

Apologies for Invalid Emails involving CC Issues

Posted over 2 years back at entp hoth blog - Home

Last night you may have received an email claiming that your credit card information was incorrect on your Lighthouse account. We moved to a new payment system and inadvertently sent out emails during the migrations. You can safely ignore these emails.

If you have any problems please let us know by filing an ticket and we'll get you taken care of.

Presentation:Building Context Aware Services using Identity as Foundation

Posted over 2 years back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

This presentation explores the issue of context automation, the forces driving it (clouds, extensible browsers, internet identities) and then focuses on issues of identity and how identity services augment context and facilitate using features of the cloud and extensible browsers to provide a richer and more secure user experience. By Phil Windley

SexpPath: A Ruby DSL for Pattern Matching S-Expressions

Posted over 2 years back at Ruby Inside

With people occasionally talking about "Code vs. Data", it only makes sense that you should be able process over code as you would a string. Sexp Path is a code processing tool that allows you to search over and process Ruby code in the form of S-Expressions.

For those who don't know, an S-Expression (or simply, a "sexp") is an iterable way of representing code or data. Using Ryan Davis' Parse Tree, you can parse Ruby files and process over them using Sexp Path. It's a bit like like XPath or regular expressions for your code.

The foundation of Sexp Path is the query, formed with Q?{ ... }, which is applied to the sexp via the / method. These methods can be chained, and the results processed via the each method. Using this as an example, Sexp Path also supports named captures like Q?{ s(:class, atom % 'class_name', _, _) } in line 16 so that the second atom is accessible via the class_name attribute in line 25.

The code is stored on GitHub. Unclear of where the project is headed, Adam Sanderson, the creator, encourages forking and feedback.

Recent code - FastImage resize, Scrooge and Read From Slave

Posted over 2 years back at Pennysmalls

A roundup of some of my projects that may be of interest:

1. FastImage Resize

This builds on my work on FastImage to provide an image resize facility.  The resize code calls libgd to do the work of resampling and resizing the image - this is a library that is very likely to be already installed on your system if it is some flavour of unix / linux or even OSX.  And if not, it is very easy to install.  This is a light and simple option if you don’t wish to install heavier libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).

2. Scrooge

This is a plugin and gem to optimise queries to the database based on a learning algorithm that looks at how the results of each query are used.  I worked on this with Lourens Naudé earlier this year, and I will shortly make a minor release with a few further optimisations and tests.  Try this if your database is slowing you down, but also see slim-attributes if you are using MySQL.

3. Read From Slave

A gem to force your database reads to a slave database while your writes go to the master.  It’s fast and simple, it works a treat, and we have it in production use.

Double Shot #495

Posted over 2 years back at A Fresh Cup


Time to get back on the daily sales and marketing wagon.

  • Build Guild – Spreading social/technical gathering of web folks. I’d be tempted to start an Evansville/Newburgh chapter if I actually knew any other web folks around here.
  • wikicloth – Mediawiki markup for Ruby.
  • flickr_fu – I may need a flickr interface in Ruby soon. This one looks promising.

Bacondrop Libraries

Posted over 2 years back at ones zeros majors and minors

Bacondrop uses two third party libraries that are quite good.

The first is ChocTop, Dr Nic’s library for generating DMGs and managing Sparkle. The documentation is great and the gem is dead simple to use: all I had to do was run rake dmg (after installing it and running install_choctop path/to/project) to get a DMG ready for distribution. It even included an Applications shortcut in the DMG for easier installation. Though Bacondrop doesn’t use Sparkle, I already know I’ll use ChocTop in any and all Cocoa apps I write in the future.

The second library is ASIHTTPRequest. It’s an Objective-C wrapper for the CFNetwork API which makes it dead simple to issue HTTP requests. The file uploading support in particular is ridiculously good:

def beginUpload(url, path, username, password)
  request = ASIFormDataRequest.requestWithURL(url)
  request.username = username
  request.password = password
  request.uploadProgressDelegate = progressBar
  request.didFinishSelector = "uploadFinished:"
  request.didFailSelector = "uploadFinished:"  
  request.setFile(path, forKey:"file")

  @networkQueue.addOperation(request)
  @networkQueue.go
end

This’ll POST a file to the url of my choosing, authenticate with HTTP basic auth, hit the uploadFinished: method with the request object upon completion, and even update a progress bar for me along the way. Naturally it’s all done asynchronously – I can fire off as many as I want using the queue.

(It’s not the exact code I use in Bacondrop, but it gives you an idea of how easy it is to use this library.)

The documentation is fantastic and it even works on the iPhone. Ben Copsey really knocked this one out of the park.

metric_fu graphing, 1.9, and 'awesome' templates

Posted over 2 years back at Jake Scruggs

So there have been a bunch of metric_fu releases since I announced 1.0.0 on this here blog. It's now up to version 1.1.4 and we've added:

  • Flog, Flay, Reek, Roodi, and Rcov now have graphs over time (thanks Édouard Brière).
  • Cool, dare we say 'Awesome,' templates for the metrics (thanks Nick Quaranto and Edouard Brière).
  • Flog report now tracks average Flog score per method and the average of the worst 5% of your methods.
  • MetricFu is now works with Ruby 1.9.1 (thanks to Robert E. Rouse for his help).
On to the pics:

flog

main metric_fu

stats

saikuro

roodi

reek

rcov

flay

churn

Homepage
Google Group
Github Repo

Enjoy!

Exploring Tuple Spaces Persistence In Ruby With Blackboard

Posted over 2 years back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

Ruby has long been criticized for 1.8's limited green threads. Luc Castera gave a presentation at RubyNation about Concurrent Programming with Ruby and Tuple Spaces. He introduces 2 ways of implementing TupleSpaces in Ruby: Rinda and Blackboard using Redis (with plans to porting it to Erlang). By Sebastien Auvray

My Apprenticeship - Tuesday, July 13, 2004

Posted over 2 years back at Jake Scruggs

This summer I'm revisiting my short apprenticeship at Object Mentor. I'll be posting commentary on all my posts from the summer of 2004 exactly 5 years later to the day.

Tuesday 7-13-04

What was supposed to take a half hour yesterday actually did take 30 minutes today (after we got yesterday sorted out). Email problems turned out to be mostly a matter of restarting Outlook a few times. With the SMCCSharp compiler taken care of, I could go back to my other project: getting Word Press, MySQL, and PHP running on the Linux box.

Although Micah and I had downloaded, installed, and successfully used Mozilla (a web browser -- like Internet Explorer) I couldn't find it today. Paul came over and he couldn't find it. And he's been using Linux for years! It was somewhere on the hard drive, but after wasting about an hour looking for it I decided to stop throwing good time after bad and just re-install Linux (for a third time) and this time make sure I installed almost everything. While that was chugging away, I used my laptop to look up Word Press, MySQL, and PHP. Word Press claims you can set it up in five minutes. The hidden assumption is that you know how to use MySQL and PHP. Here's what I knew about MySQL as of this morning: It's a database. Here's what I know about PHP: it's a scripting language. I did, despite my ignorance, manage to get an local Apache server up and running using MySQL and PHP. I even got to look at some sample databases using the local host (what all this means is that I set up the computer to be a server and then I had another part of that same computer start talking to that server using Mozilla -- kinda weird but real useful when you want to get all the bugs out prior to opening your server up to the world wide web). After digging around on the internet for awhile I still wasn't sure how to get a basic database up and running. I'm pretty hopeful about tomorrow because David found a book in the OM library entitled 'MySQL and PHP for Web Development. Which sounds more than a little helpful.

Somewhere in the middle of the day, Paul said that he thought our SMCCSharp compiler might have some bad dependencies. Hmm.

I remember, during one of my first days at Object Mentor, being flabbergasted that David had a server running on his laptop. Weren't servers huge things that hosted cnn.com? How could he possibly have one on that little laptop? I'm pretty sure I kinda didn't believe him when he mentioned it in passing. Now here I was a few weeks later setting up a server my own self. Crazy talk.

4 days since distant-past-jake started the 5 minute WordPress install -- how long will it take? Stay tuned.

Paperclip file rename

Posted over 2 years back at WyeWorks Blog - Home

While developing an application with Sebastián that allow users to upload videos with some file name restrictions, meaning that it must contain only A-Z and 0-9 digits, underscores (_) as a valid component as well, and also the name must be preceded by it’s own #id, we came up with the need of applying this custom filter to each uploaded video. After doing some research on paperclip source code and internet tutorials, we suggest the following solution:

class Video < ActiveRecord::Base
  has_attached_file :video,
    :path => ":rails_root/public/system/:attachment/:id/:style/:normalized_video_file_name",
    :url => "/system/:attachment/:id/:style/:normalized_video_file_name" 

  Paperclip.interpolates :normalized_video_file_name do |attachment, style|
    attachment.instance.normalized_video_file_name
  end

  def normalized_video_file_name
    "#{self.id}-#{self.video_file_name.gsub( /[^a-zA-Z0-9_\.]/, '_')}" 
  end
end
What are we doing here? Easy, in has_attached_file we edit the way paperclip returns the path and url by default, the most relevant components when saving and loading the file in order to display it. Paperclip default values are:
path default => ":rails_root/public/system/:attachment/:id/:style/:filename" 
url default => "/system/:attachment/:id/:style/:filename"

Values preceded by ’:’ are the standard interpolations paperclip has. For further information on this visit http://wiki.github.com/thoughtbot/paperclip/interpolations.

What we did was change * with *:normalized_video_file_name in both path and url, being the second a custom interpolation and then added the ‘normalized_video_file_name’ method to video.rb.

By doing this we not only achieve a way for paperclip to handle the file by this normalized way, but also have a method to access the normalized file name, plus being able to access the original file name through paperclip video_file_name method.

So remember on video_file_name you have the uploaded filename and on normalized_video_file_name you have the server filename.

TwitterAuth Integration Testing

Posted over 2 years back at zerosum dirt(nap) - Home

Michael Bleigh’s TwitterAuth gem is truly full of awesome. It’s a complete OAuth authentication and API access solution for building Twitter apps with Rails. It uses familiar conventions borrowed from the Restful Authentication plugin, too. If you’re building a Rails-based app and you want to allow your users to Sign in with Twitter there’s just no better way to go.

For this particular app, I’m using the dynamic duo of Cucumber and Webrat to whip up integration tests. Since I initially stumbled a little bit when thinking about how to test integrated authentication against an external source like Twitter, I thought I’d doc the solution here in case other people were having the same issue.

Ready? Let’s do it.

Setup

First, install the TwitterAuth gem and use the provided generator to whip up the appropriate facilities. You’ll need to register your Twitter application accounts too. Or you know what? Screw it. If you want to make this super easy on yourself, Mike wrote a really great Twitter app Rails template that does all the setup for you, including walking you through getting the dev accounts. It’s nice, try it out. You’ll be up and writing Twitter apps in no time.

For the rest of this I’m going to assume that you have all of that working, and have installed Cucumber too. Don’t have Cucumber? Install it using RubyGems and then just run script/generate cucumber inside your Rails app.

Authentication Feature

So let’s write a Cucumber feature to test authentication in our boilerplate Twitter template application. Put the following in features/authentication.feature:

Feature: Authentication
In order to create and edit games
As a user
I want to sign in with Twitter

  Scenario: Login via Twitter
    When I go to "the homepage"
    And I follow "Login via Twitter"
    And Twitter authorizes me
    Then I should see "Logged in as"

  Scenario: Checking login status
    Given I am signed in
    When I go to "the homepage"
    Then I should see "Logged in as"

  Scenario: Log out
    Given I am signed in
    When I go to "the homepage"
    And I follow "Log out"
    Then I should see "Login via Twitter"

Step Definitions

Next, you’ll need to write step definitions to satisfy the missing steps. Do that by creating a file called features/step_definitions/auth_steps.rb. The content of the file should define the following two steps:

Given /^I am signed in$/ do  
  visit login_path
  visit oauth_callback_path
end  

When /^Twitter authorizes me$/ do
  visit oauth_callback_path
end

Fake Style

The secret sauce here is FakeWeb. We’ll use it to fake out responses from the Twitter auth service so that your integration tests stay local (and reliable). Make sure to gem install fakeweb, and add the following to tests/environments/cucumber.rb:

config.gem "fakeweb", :version => ">= 1.2.5"

Now edit Cucumber’s features/support/env.rb file:

FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:post, 'http://twitter.com/oauth/request_token', :body => 'oauth_token=fake&oauth_token_secret=fake')
FakeWeb.register_uri(:post, 'http://twitter.com/oauth/access_token', :body => 'oauth_token=fake&oauth_token_secret=fake')
FakeWeb.register_uri(:get, 'http://twitter.com/account/verify_credentials.json', :response => File.join(RAILS_ROOT, 'features', 'fixtures', 'verify_credentials.json'))

Here we’re stubbing out the interaction with Twitter auth, and responding to all outbound authorization attempts with canned data. Note that this references a fixture file, containing a sample verify_credentials API response from Twitter. You can obtain a copy using curl from the comfort of your terminal prompt (substitute your own username and password):

curl -i -u user:pass "http://twitter.com/account/verify_credentials.json" > verify_credentials.json

And We’re Done

Alright that should do it. Go ahead and run rake features. Everything should be green. And green is good. If you need to write other features that are dependent on a login requirement, you can reuse the same “Given I am signed in” step that we created earlier.

Thanks to b.kocik, whose original post on using FakeWeb to stub Twitter auth was 80% of the solution I needed here.

Windy City Rails Deadline Approaching Fast

Posted over 2 years back at Softies on Rails - Home

Many of us in the Midwest are looking forward to the Windy City Rails Conference on September 12, 2009.

The deadline is very rapidly approaching for the early bird rates ($99 conference only, or $199 for the conference plus a complete 3-hour tutorial session).

I’m doing the morning tutorial called REST 101: Best Practices for Rails Developers for those of you who are relatively new to Rails or trying to get a handle on what the whole REST thing is all about.

So register now for the conference and/or tutorial. Profits from the tutorials/conference go to charity. So we’ll learn a lot, have fun, and support a good cause all in one day.

Questions? Leave a comment below and I’ll try to respond quickly.

Thanks! See you there!