Dumping Ground

In a cube in the city there worked a programmer.

Using Vimdiff with Git Diff

While perusing the post, "A few of my Git tricks, tips and workflows" I saw the author output his git diff information to an external tool. I wanted to do the same thing, but to vimdiff. After a very short googling, I ran across the following solution on StackOverflow:

git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.d difftool

Setting it up this way allows you to use "git diff" as normal, but if you want see the diff in Vim, use "git d" instead of "git diff".

Further Reading:

 

 

 

 

Filed under  //   git   vim  
Posted April 7, 2011

David Chelimsky's Answer to Testing Named Scopes

I was looking for the best way to test named scopes in Rails using
Rspec and I ran across the following answer by David Chelimsky (Rspec's
creator) in the Rspec Google Group:

 
describe User, ".admins" do 
  it "includes users with admin flag" do 
    admin = User.create! :admin => true 
    User.admin.should include(admin) 
  end 
 
  it "excludes users without admin flag" do 
    non_admin = User.create! :admin => false 
    User.admin.should_not include(non_admin) 
  end 
end 
 
class User < ActiveRecord::Base 
  named_scope :admins, :conditions => {:admin => true} 
end 

Read the entire thread for context.

Filed under  //   activerecord   rspec   ruby on rails   scopes  

Parallel Programming with Dropbox

Dropbox is one of the greatest web applications in use today: it’s simple, it’s accessible, it’s ubiquitous, and it has a myriad of uses. I’ve written about using Dropbox as a remote Git repository in the past, and other authors have compiled lists of unique and interesting ways to get the most out of it. The best explanation for it’s popularity and prolific use was probably given on Quora.com: Why is Dropbox more popular than other programs with similar functionality?

At a recent KC Ruby Meetup, in which we were duscussing code retreats, I had the idea of using Dropbox as a bridge to enable Test Driven Development between two (or more) developers. Here’s how it might work:
  • The developers work in a shared dropbox folder
  • One developer writes the tests
  • The other developer writes code to make the tests pass
  • Each developer has some sort of autotesting suite running in order to pick up recent changes.
  • As changes are made and as Dropbox syncs the folders, the autotesting suite(s) picks up the changes, runs the tests, and provides success/failure messages to the developers.
  • Each developer then responds according to the the test outputs: writing more tests, writing code to make the tests pass, or refactoring.
  • The developers can switch roles as needed.
I could see how two developers wouldn’t necessarily even need to talk as long as the tests written well enough (but that would kinda suck.) But seriously, as long as the tests tell you what they are expecting, there’s no real need to communicate.

This might not be the ideal environment to work in if you were building a serious project, but as a learning tool and as a playground, I think it could be a lot of fun. And honestly, I can imagine an entire site being built around the idea of programmers coming together to mentor each other and learn from one another.

Further Reading:

Filed under  //   TDD   dropbox   parallel programming   programming  

Installing the Command-T VIM Plugin on Ubuntu

I ran into an issue while installing the Command-T VIM plugin on my Ubuntu box. Once installed, I received this ever so helpful message which trying to launch VIM: 

Vim: Caught deadly signal SEGV
Vim: Finished.
Segmentation fault

If you've run into the problem too, chances are you're running RVM and your default Ruby is something other than the version used by VIM. Since I installed vim through apt, it's using the default Ruby provided by Ubuntu.

Here's the fix:
  1. Go back into your .vim/ruby/commnd-t directory.
  2. Type: make clean
  3. Type: rvm system
  4. Type: ruby extconf.rb
  5. Type: make
That fixed it for me, hopefully it fixes it for you too.

Filed under  //   linux   ubuntu   vim  

Github Gists and Google SEO

My boss, Wes asked me the other day if Google was able to read embedded code from Pastie or Github's Gist. According to this thread from Github, they (Github) don't believe search engines can render JavaScript. I think they're wrong though. In an interview with searchnewz, Matt Cutts (Google's webspam chief) made the following two points:

For a while, we were scanning within JavaScript, and we were looking for links. Google has gotten smarter about JavaScript and can execute some JavaScript. I wouldn't say that we execute all JavaScript, so there are some conditions in which we don't execute JavaScript. Certainly there are some common, well-known JavaScript things like Google Analytics, which you wouldn't even want to execute because you wouldn't want to try to generate phantom visits from Googlebot into your Google Analytics". 

 

Matt Cutts: We do have the ability to execute a large fraction of JavaScript when we need or want to. One thing to bear in mind if you are advertising via JavaScript is that you can use NoFollow on JavaScript links" 

It sounds to me like Google has the ability to read embedded code from Pastie, Github, and other places if they want to. Bing probably can too, but it may need to be proxied through Google first.

But I want proof. So, I've thrown together a pretty lame little block of code to see if I can't get some Google juice flowing. I'll let you know the results as soon as I find out.

Update Feb 5, 2011: I need to retry this using something other than Posterous. Posterous actually retrieves the code, and embeds the actual contents in the post.

Filed under  //   code   gist   google   seo  

Ubuntu 10.10 and the Asus Eee Keyboard

I got this wonderful keyboard and mouse combo from my wife from Christmas. I was very happy to get it because it's very quiet, has the chicklet style keys, and it doesn't have that annoying number pad. But then it - more precisely, the right side of the keyboard - stopped working.

I was planning on sending it back to Asus, but then I ran across a solution while looking for something completely different. You see, I have an Asus laptop, but the number pad didn't seem to work. After a quick Google, I ran across this thread on the ubuntu forums: http://ubuntu-ky.ubuntuforums.org/showthread.php?p=9938431

Following the advice on response #3 (quoted below) my number pad started working. Just for giggles, I plugged in the Eee keyboard and lo and behold, it was working too. 

System -> Preferences -> Assistive technologies
click "keyboard accessibility"
go to the tab "mouse keys"
uncheck "pointer can be controlled using keypad"

Here's the screenshot of the control panel. Y'know, just in case:
Keyboard_issues
 

Hope this helps someone and saves you so pain and suffering on customer support.

Filed under  //   asus   eee   keyboard   linux   ubuntu  

The Pick Smoke 'n Grill

Just ate at a new restaurant here in Western Shawnee, "The Pick Smoke 'n Grill". The best way to describe it is as a sports bar meets a barbecue joint. I can't say it's strictly a barbecue place because barbecue was only part of the menu. The rest of the menu was very much like what you would find in a sports bar. It was still good, mind you, I'm just trying to let you know what the menu is going to look like.

I was pretty hungry - shocking, I know - but I really didn't know what to order. The owner suggested the "Porker Burger". It's a burger with pulled pork and bacon on top. "Just what the [cardiologist] ordered."

2010-12-13_11

The pork and bacon were great, but the burger itself was a formerly frozen patty. Could have done with a few more fries, but still, for $7 it was happiness on a plate.

It seems really dead at lunchtime, so I'm going back tomorrow to try something else.

Map: http://maps.google.com/maps/place?cid=10755287883475674896

 

Filed under  //   barbecue   restaurants   reviews  

Riddle me this

Three people check into a hotel. They pay $30 to the manager and go to their room. The manager finds out that the room rate is $25 and gives $5 to the bellboy to return. On the way to the room the bellboy reasons that $5 would be difficult to share among three people so he pockets $2 and gives $1 to each person.

Now each person paid $10 and got back $1. So they paid $9 each, totalling $27. The bellboy has $2, totalling $29.

Where is the remaining dollar?

Mahaffe Stage Coach Stop

(download)

The SQ3R Method and Reading Code

Recently, John Nunemaker, authored a post about reading code, titled, "Stop Googling." His argument in the post - and one could hardly disagree with him - is that too often, we as programmers turn first to Google to answer our programming questions rather than turning to the code itself. By relying only on Google rather than doing the legwork ourselves we weaken our programming skill. You just can't become and better programmer unless you are actively and deliberately flexing your coding muscles. Reading code is one of the best ways to do this.

Nunemaker linked to Alan Skorkin's excellent post on reading code, titled "Why I Love Reading Other People's Code and You Should Too." It's a worthwhile read. In it, Skorkin offers up a little bit of the "Why" and the "How" with regard to reading other people's code. Both of these posts got me thinking about how to go about systematically reading other people's code. That's when I remembered SQ3R. SQ3R is a study method for reading and stands for "Survey. Question. Read. Recite. Review."

Before I go further, let me state the obvious: reading other people's code isn't always easy. You will have to think; you will have to meditate; you will have to research; you will have to dig. It gets easier, but it will never be easy; few things worth doing are.

Here then is my adaptation of the SQ3R technique for reading code: Survey. Question. Research. Respond. wRite.

Survey
The first thing you will want to do is get an overview of the body of code you are studying. The idea is to get a general feel for the layout and purpose of the code you are looking at. Here are some suggestions for how to survey code:
  • Read all the comments
  • Read all the code (it doesn't matter if you don't understand it)
  • Write down functions and methods which are called, libraries, and anything else you are unfamiliar with
  • Diagram the structure of a library, or in the case of an application the flow of information. 
  • Write down any and all questions which pop into your head during this stage.
Question
In the second stage, you will diving back into the code, this time to assault it with all manner of questions (see Rudyard Kipling's Six Honest Working Men). The questions you should be asking and writing down at this point are those which are trying to pull information out, (e.g. what is this function doing?) not putting information in, (e.g. how would I do this better?). Here are some questions to get you started:
  • What problems is the code trying to solve (as a whole, as methods, as classes, etc.)
  • What is this code doing?
  • Why is the author doing x like that?
  • Why might the author have chosen to do things this way?
  • Where is the author's thought process leading?
Research
At this point, it's time to interact more with the code. Remember all those questions you've been asking and writing down? This is where you start answering them. As you answer your questions, continue to ask more and answer them. Track down libraries and methods you aren't familiar with. Read up on them, and if they look interesting, make a note of them in order to study the code later.

By the end of this stage, you should really have a good idea of how the code flows, works, and what it's for. If you don't have a grasp on the code, keep researching - start over at "Survey" if you need to.

Respond
The purpose of reading code is not to reach some level of technology enlightenment. Reading code isn't just an intellectual pursuit. If you're not applying what you're learning, you're wasting your time and you're depriving the community of another resource. The purpose of studying code, as with all studies, is to apply what you've learned.

Here's some ways you can respond to what you've learned in your research:
  • Refactor - find ways of improving the code and give it back to the author(s).
  • Get involved - Don't stop at just fixing one bug or refactoring one method, start contributing regularly to the project.
  • Answer questions - Mailing lists get a lot of questions and there are a lot of beginners who could use a hand (remember, you were there once too). Free up the core contributors' time by fielding a few of those questions.
  • Fix bugs
  • Document - You know the code, document what you've learned.
wRite
You've now become very knowledgeable about the code you've been studying, it's time to share your experience. One way is to blog about what you've learned. But isn't that just enabling people who are using Google as a crutch? Yep, but it also helps those people who are using Google responsibly (that's you, right?)

But don't just write words, write some code. You've learned something new, you've grown as a programmer, it's time to write something new. Scratch your itch and inspire someone else. 

If I may offer one last piece of advice: take your time. You don't have to sequester yourself away for weeks on end to read code. Just start by spending thirty minutes a day researching. You'll be surprised at how quickly you start picking up new techniques and new insights. And don't worry about reaching some sort of deadline, just focus on the doing. Pretty soon, it'll be a habit and you'll be a better programmer.

Filed under  //   methodologies   reading code