I think this means it’s finally time for a new moleskine …

via tweetie

Posted via web from Scraps of Pan

On not rocking the MySQL Socket boat…

Update: This is, sadly, not the best advice. I’d recommend against it for now – at least, until I can come up with some way to accommodate for the fact that the tmp/ directory gets cleared out when the system does its cleanup – it being the tmp directory after all. Maybe I’ll craft a script that can be set to run on start up, or at least ahead of the attempt to access the database.

So, I’ve been working with a new group of folks lately, on a pretty exciting Rails project. However, as anyone who’s done this for more than a few months will know, not every development team works with the same basic setup.

My experience leads me to using package managers like Macports or Homebrew (I prefer the latter, but use both in tandem), to take care of things like Sphinx, or MySQL.

MySQL can prove especially tricky, since MacPorts puts everything in the /opt/local/etc/ directory. This doesn’t lend itself to being easily found by something like a Rails application, so in your database.yml file you couldd drop a line like this in:

socket: /opt/local/var/run/mysql5/mysqld.sock

Which is great … if you’re not using a database.yml file that’s being tracked in version control.

So, the simplest solution (that I’ve found, anyway) is to leave the YAML file alone, and just create a symbolic link in the /tmp directory (which, yeah, will probably get garbage collected at some point, but it’s easy enough to replace):

$ ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock

I’ll update as my experience with this moves on, and let you know if it’s too problematic a solution to maintain.

Short link: http://panpainter.com/p/11

Leave My Scrollbars Alone

One of my biggest pet peeves (right up there with re-sizing my browser), is when a designer changes the way that the scrollbar looks. I will admit that when I first started playing with CSS, this was one of the things that appealed to me. However, in addition to my own ignorance, web design principles still nascent at that point. It was awesome to be able to adjust the way that Internet Explorer’s scrollbars looked: I could adjust the aesthetic of the scrollbar to match the way that my site was designed. It didn’t work in that pesky up-start of a browser that the Mozilla folks were producing, but I was ok with that, because the majority of people weren’t using that browser (it pains me to think that I actively stuck by Internet Explorer at that point, but there it is. I’ve learned, and moved on from that horrendous browser).

Now, all of this reminiscing has a point: Tim Van Damme’s recent update to his blog. Normally I really admire his work, and he’s an exceptional interface designer. Recently, he launched an update to his blog, which, as expected, is fantastic. Except for one thing: he changed the scrollbars.

From an purely aesthetic point of view, it’s really well executed. It fits the updated design of the site, and it doesn’t vary too greatly from established scrollbar elements (it’s very much like the iPhone scrollbar). I do appreciate that it looks appropriate in that context.

However, there are some technical and accessibility issues with it, primarily that you can’t use the keyboard to progress down the page. Google has similar issues with their Javascript-driven scrollbars in Wave, though they get around it by enabling conversations to be selected with the keyboard, and the subsequent selections will let you progress down the page. However, with the technique that Tim’s using (and the context that it’s being used within) causes me the greatest concern because there’s really no way to navigate through his site using just the keyboard, which for me is inconvenient, but for others it basically makes his site very unusable.

Furthermore, from a usability standpoint, by doing this, he has fundamentally changed the viewing experience for his site’s visitors. No longer can they assume that the scrollbar will behave as expected, because it looks different (also, he’s removed the up/down arrows that some people still rely on). If nothing else, it takes the focus away from the content of his (very well written) articles, and places it on the scrollbars.

My biggest fear with this new implementation is that many of the copy-cat designers out there will see what he’s done (which is pushing the envelope, and usually a Very Good Thing) and will implement that without thinking about the impact. I think Tim can get away with it (although, again, I find it annoying) because his implementation is well executed, and his target audience is, for the most part, probably not restrained to their keyboard for navigation around the internet. Most importantly, the implementation he’s using only targets Webkit-based browsers.

So, while using these newer techniques is a wonderful thing, it’s best to proceed with caution when you’re doing something that will fundamentally change the user’s experience. I don’t want to seem like I’m warding off new advanced techniques, just that anyone choosing to use it should be wary of the impact of that implementation.

Short link: http://panpainter.com/p/11

P52

One of the things I’ve had on my to-do list for quite some time now is to spend more time writing (just look at my archives and you’ll see what I mean – I think I’ve been averaging one post per month, and that’s been an active couple of months for me!).

It’s not like I don’t have anything to say, but I get so stuck inside my own head that I never end up actually writing anything, and unfortunately that just makes it look like I have nothing to actually say. Which is bad.

Project 52

So, in an attempt to meet this goal, I’m participating in Project 52. The goal is simple: write one blog post per week. If you fail, then there are over 400 people that will know. It’s a bit scary, but I’m hoping that it will provide the motivation that I need in order to actually get writing.

I’ll be writing on all sorts of topics, because I’m fascinated by a wide assortment of things. I will continue, of course, to use twitter for the more stream-of-consciousness type posts, and my tumblr site will continue to hold the things I find around the web that interest me, but this site will be the meat of all that content.

Here’s to new directions in 2010! I have high hopes that it’ll be a good year, and that this project will produce at least a few valuable posts.

nginx + PHP on Mac OS X

I’m a big fan of the nginx server (it’s lighter weight than Apache, and at this point I’m just more familiar with it, so it’s my server of choice). When trying to get it to play nicely with PHP, however … well, it leaves something to be desired.

But, with some persistence (and quite a bit of help), I got it up and running on my development machine. The one thing that I wasn’t ever able to find an answer for (at least, an answer that worked) was to have my system start up FastCGI on launch. I really dislike having to start these things by hand and feel that any performance trade-off (always having this run in the background) is well worth it for the productivity boost.

This article addresses using a plist that runs on load (utilizing launchd), but as the author notes, it works inconsistently. After doing some digging of my own (by reading the nginx plist that ships with my MacPorts install of the server), I came up with the following:

com.panpainter.php-fastcgi.plist


<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.panpainter.phpfcgi</string>
  <key>EnvironmentVariables</key>
  <dict>
    <key>PHP_FCGI_CHILDREN</key>
    <string>2</string>
    <key>PHP_FCGI_MAX_REQUESTS</key>
    <string>1000</string>
  </dict>
  <key>ProgramArguments</key>
  <array>
    <string>/opt/local/bin/daemondo</string>
    <string>--label=php-cgi</string>
    <string>--start-cmd</string>
    <string>/opt/local/bin/php-cgi</string>
    <string>-q</string>
    <string>-b</string>
    <string>127.0.0.1:8888</string>
  </array>
  <key>OnDemand</key><false/>
  <key>Debug</key><false/>
  <key>RunAtLoad</key><false/>
</dict>
</plist>

(Get the code here)

After adding this to the /Library/LaunchDaemons directory (or symlinking it in to there, if you’d rather it live somewhere else), don’t forget to run the following to ensure that it’ll run on load:

sudo launchctl load -w /Library/LaunchDaemons/com.panpainter.php-fastcgi.plist

Now, this probably is not the most elegant solution, and I’m relying on the MacPorts-depedent daemondo, but it works. If you know of a better way to do this, I’d be happy to hear it.

Shortlink: http://panpainter.com/p/10

960.gs TextMate Bundle

As part of the work I do every day, I use the 960.gs CSS framework, which means I spend a good portion of my day typing things like “grid_4″ and “container_16″ and “alpha” or “omega” a LOT.

This is stupid.

So I created a 960.gs Bundle for TextMate. Now, this doesn’t help with the CSS side of things (it won’t keep you from typing in .grid_4 for example), because there’s already a bundle that does that (and I did model some of my snippet structure off of his, so credit where credit’s due). I recommend installing both, since that Bundle also handles HAML (and, again, mine does not – just the HTML).

If you want to download it, you can grab it from here or you can grab the code from Github.

Also, if there are any problems that you run in to while using it (or if you have a request), please let me know! I’ll happily update the bundle.

Permalink: http://panpainter.com/p/9

Raising the Dead

If you run in to the situation where you (or someone you’re working with) has deleted files that shouldn’t have been deleted (like a stylesheet that gets used in only one place within a very large project, say), you can recover it easily (assuming you’re using Git, of course). Simply find when the file was deleted (this is just one way to do it, of course):

git log -- path/to/file

This method will show all commits for that file – sort of like a log-view of git blame

Then, when you have the commit you want, find a commit prior to that (it’s easiest if you use a tool like GitX or GitK, which comes with git, to view the tree’s history), grab that commit’s SHA, and run the following command:

git checkout [SHA] -- path/to/file

Then commit, and you’re good to go!

Note that you can solve this problem using git rebase, but that’ll flatten your tree. This adds a new commit at the head of your tree, and should be less likely to cause any conflicts or weird history issues.

Permalink: http://panpainter.com/p/8

Git Demote

I’m a big fan of Trevor Squires’ Git Promote script, but one thing that’s bothered me about it since I started using it is that it tends to clutter up my .git/config file. So, I made a counter-script for it that I’m calling, appropriately, “git demote”

    #!/bin/sh
    #
    # Counter-script to Travis Squires' git-promote script
    # (http://hoth.entp.com/2008/11/10/improving-my-git-workflow)
    # Removes a 'promoted' branch from the git config file.

curr_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')

git config --remove-section "branch.${curr_branch}"

To install it, simply create a file called $HOME/bin/git-demote (assuming you have $HOME/bin in your PATH, otherwise place it somehwere that does exist in your PATH), then run the following from the terminal:

chmod 755 $HOME/bin/git-demote

Now, when you’re done with a branch, you can clean up your .git/config file by running:

git checkout topic-branch
git demote

And you’re good to go.

You can fork the Gist, if you don’t want to type all that.

Shortlink: http://panpainter.com/p/7

Stubbing/Mocking for ThinkingSphinx and will_paginate using Flexmock

One of the things that I love about Rails development is the emphasis on Test Driven Design (and BDD, but that’s another topic entirely). As someone relatively new to Rails, however, it’s occasionally frustrating to attempt to build tests when you don’t full know what to expect back (not knowing what to expect as a returned value, being dependent on an outside resource like an API, whatever).

Nothing has been as frustrating for me as learning about mocking/stubbing.  It’s one of those things that everyone else just seems to know, but rarely talks about.  Maybe I’m just looking in the wrong places; I’m not sure.  Either way, I was recently working on adding in ThinkingSphinx to a project that I was working on, and I wanted to make sure that my implementation of the plugin was being tested (not, of course, testing ThinkingSphinx itself, because it’s already tested in its own right).

Of course, anything that runs through the plugin is eventually going to want to hit the search daemon, which is a dependency that our test suite shouldn’t have.  This is easy enough to overcome with a quick mock (if you know the right magic incantation, that is).

After some searching, I settled on Flexmock as the framework of choice, if for no more reason than the fact that it has better documentation than some of the others I’ve found.  Here’s the test that I wrote that just made sure that search would occur given a few different situations. (Note that this is done using Test/Unit.)

First I had to make sure that will_paginate would cooperate with me, so I created a view_helper.rb file in /test/mocks/test/ to set the total_pages_for_collection method to just return “1″ (because we really don’t care how many pages there are in the collection, and running anything against a view without this being set throws an error):

# /test/mocks/view_helpers

require 'will_paginate/core_ext'

module WillPaginate
  module ViewHelpers
    def self.total_pages_for_collection(collection) #:nodoc:
      return 1
    end
  end
end

The only slightly odd thing here is the #:nodoc: statement; we just don’t want to have this method show up in any of the documentation (probably not really necessary, but I feel better having it in place). Now that will_paginate is getting pre-empted, we can test the SearchController:

# /test/functional/search_controller_test.rb

require 'test_helper'
require 'flexmock/test_unit'
require 'mocks/view_helpers'

class SearchControllerTest < ActionController::TestCase

  test "should search events" do

    flexmock(Location).should_receive(:search).once.with_any_args.and_return([locations(:one)])
    flexmock(Event).should_receive(:search).once.with_any_args.and_return([events(:one)])

    get :index, :q => 'hello world'
    assert_response :success

    assert_match '<p>There is 1 result for "hello world"</p>', @response.body
end

test "get with no query paramter searches everything" do

    flexmock(Event).should_receive(:search).once.with_any_args.and_return([events(:one)])

    get :index
    assert_response :success
    assert_match 'There is 1 result for ""</p>', @response.body
  end
end

I’ve got two tests here, one that tests that search works if a query is passed to the search daemon, and one that tests what happens if no query is actually passed (the expected function for the latter test is that all Events would be displayed).

I also like Flexmock because of the readability of the tests – the method names are quite literally what they seem to be. The really important thing to note though, and what took me forever to find, was the .once.with_any_args.and_return(#...) phrasing. That’s what’s really key here – I was getting all manner of weird errors back until I set up my stub this way. What I’m doing is short-circuiting the search function – I’m telling my tests that the search parameters and responses are unimportant, all that we really want is to make sure that the search method is getting invoked.

Hopefully this will help save someone else time. If there are better ways to solve this problem, I would love to hear about it – like I mentioned above, mocking/stubbing seems to be one of those topics that no one really discusses at any length, so the more discussion we can have, the better.

Shortlink: http://panpainter.com/p/6

A High Point

Last weekend I participated in Rails Rumble ‘09 (along with some really awesome teammates), and today we found out that we made it in to the Public Voting stage!

It really makes that weekend of hard work worth it (although we all really wanted to build Quippopotamus anyway). Congrats to my teammates, and to everyone else – go vote for us! :)

You’ll also notice that I’ve added something new to the sidebar (over there on the right) – that would be the by-product of last weekend’s endeavors, an embedded widget from Quippopotamus cycling through a collection of quips that I’ve started to build.

Shortlink: http://panpainter.com/p/5

« Older Entries |