I was sitting at the Lone Star Ruby Conference and during one of the workshops the speaker mentioned we could find a pair programming partner for the next segment of the workshop. Being a little shy and the only person I knew there was with his co-worker, I thought it would sure be nice to easily find a pair programming partner! During the break I had this idea and bought rubypair.com … I had hoped that during the conference I would find someone that also would share my vision and keep me on task to finish it. I had heard Evan Light during his talk when he mentioned has has open “office hours” where you can make an appointment to pair with him. So I found him and told him of my idea. He liked it and we agreed to pair on rubypair on the last day of the conference. We were trying to get it done so we could demo at the lightning talks but we kept wanting to try new and shinies (rails 3.1, sass, compass, mongodb etc) that we didn’t make it in time! But we made some progress and said we’d pair remotely to work on it.

The next weekend we set up time to pair on it and we worked through somethings. I was pretty rubied out though having spent the weekend prior to Lone Star Ruby Conference at an all night-hack fest in Austin. Evan took the bull by the horns (yes I live in texas now!) and worked out more kinks, David Browning did the logo and site design and Evan implemented it with SASS and Compass. Others helped out almost immediately and we had pull requests! We deployed RubyPair.com on Sept 3! See the Contributors list for the growing list of contributors.

Give it look and never code alone!

Repo: https://github.com/rubypair/rubypair
Tasks: https://github.com/rubypair/rubypair/issues

Recently I worked on a project where I needed certain config variables for staging, production, test etc and I wanted to store all these in a yaml file. I could set them in the different environments files but I prefer them all in one file.

Create a file in the config/initializers .. I called it 00_load_app_config.rb so I can be sure it gets loaded first. In it I have only a single line

RUBY:
  1. APP_CONFIG = YAML.load_file("#{Rails.root}/config/app_config.yml")[Rails.env]

Then I create a yaml config file at config/app_config.yml

RUBY:
  1. base: &common
  2.     company_name: 'The Awesomest Company Evar!'
  3.     api_username: 'api_user'
  4.     api_password: 'bob123'
  5.  
  6. development:
  7.     <<: *common
  8.     api_hostname: 'http://api-development.myawesomesite.com'
  9.     twitter_app_key: 'fff'
  10.     twitter_app_secret: 'fff'
  11.  
  12. staging:
  13.     <<: *common
  14.     api_hostname: 'http://staging-api.myawesomesite.com'
  15.     twitter_app_key: 'sss'
  16.     twitter_app_secret: 'sss'
  17.  
  18. test:
  19.     <<: *common
  20.     api_hostname:  'http://test-api.myawesomesite.com'
  21.     twitter_app_key: 'eee'
  22.     twitter_app_secret: 'eee'
  23.  
  24. production:
  25.     <<: *common
  26.     api_username: 'api_user_prod'
  27.     api_password: 'bobprod123'
  28.     api_hostname: 'http://production-api.myawesomesite.com'
  29.     twitter_app_key: 'yyy'
  30.     twitter_app_secret: 'yyy'

The variables in the common section are applied to every environment and overridden like in the case of production, which overrides the api_username and api_password. In each environment they pull the company_name from the common block.

To use a value in your rails app, use the APP_CONFIG array, like
APP_CONFIG['website_name'] or APP_CONFIG['twitter_app_key'] and it will always return the value for the environment currently in Rails.env

Thanks to my friend Rath who showed me this, I changed the name from config to app_config because I liked it to be more specific, but use whatever name you like!

I recently went on a small vacation and finally had some time to catch up on some railscasts! I like to setup a project and "play along" with Ryan Bates and pause/play and work through the examples. With all my experimentation/playing I keep a git repo at http://github.com/rubygeek/rubygeek where I keep code for reference later. Sometimes when trying to remember if i did something, I grep a keyword or two on the root directory and see if I have done something with it before. I can put notes in the readme file for each project, so I can remember what resources I used.

#264 Guard - Setups up monitoring for files to run something like tests, compile coffee script or sass. The cast shows how to use it to run your rspec tests. It shows liverefresh, with that and a plugin it will automatically refresh your browser!

#262 Ancestory - I spent a good deal of time using acts_as_commentable_with_threading and although its pretty good, I think now I will change to using this, it seems like it will be more efficent on queries and has more scopes defined.

#254 Kaminari - Wow, this is totally awesome! I did have to do some digging to figure out will_paginate for rails3, and this is way better as it is a rails engine, so its soooper easer to customize. The labels for the next/previous are stored in the language file (ie. en.yml) so if you support multiple languages, this is awesome. If you need to customize beyond css, you can run the rake command to generate the views.

#271 Resque - I might need to do something like this soon for a project, so I was happy to see this. It was pretty easy to do and I like the admin interface to see what is going on. Even more cool, is it is written in sinatra and you can hang it of your rails app if you want and assign a route to it. Definitely a fun screencast to follow along with!

#269 Template Inheritance - Finally, this makes perfect sense. Available in Rails 3.1 you can have an Application directory in the views directory and there you can place things common to all views, like header, footer, sidebar etc ... then if you need it customized footer for say the Products page, you can put a footer partial there and that is used on product pages. Previously you had to make a directory like common, shared. etc etc and it always seemed hackish to me.

Recently Ryan has put before and after version of the code in his gitrepo, and though I usually try to do it all myself, I did grab his before code for the Template Inheritance.

Thats about all for now, give those a try and practice ruby!

I first learned about Koans from EdgeCase Ruby Koans project, it was great fun and great practice. Since then, whenever I mentored a DevChix or RailsMentors member I suggest to start doing Koans... even on a regular basis, once you finish them all .. then start over! I always have a ruby koan mid-way and work on it when I want to practice ruby. Sometimes I try to complete the whole file then run it. Since I've been learning Groovy this week, I looked to see if there was Groovy Koans, found those.. then i just started compiling all the languages I know of..

Ruby
http://www.rubykoans.com

Python:
https://github.com/gregmalcolm/python_koans

Groovy
https://github.com/cjudd/groovy_koans

Javascript
https://github.com/mrdavidlaing/javascript-koans

Scala
https://github.com/rubbish/scala-koans

Perl
Sadly...I was not able to find one for Perl ...

Functional Koans
FSharp, clojure, haskell, python, scala
Functional Koans

CoffeeScript
https://github.com/sleepyfox/coffeescript-koans

And while I was searching for other languages... I ran into this

http://rosettacode.org/wiki/Main_Page

Its has sample problems done in multiple languages. Kinda fun!! (I recognize some of them as interview questions)

Any koans that you know about that are not in my list?
Update 9/25/2011 - Added coffeescript

I don't know what else to call this post, I've been doing a little bit of everything in past few months. I've changed jobs and thats taken much of my freetime to ramp up and get going on new projects. SO, I will write up a little of what I've been doing.

Facebook -- Yes, I worked on some facebook projects. Some were fan pages and some were applications. It was pretty interesting, I hadn't done much with facebook other than get addicted to some stupid games (Yes, cafe world, i've quit again.. for now..). Developing on facebook can have some frustrating moments, as if you are using FBML, then facebook takes liberty to rewrite things at will and not give you much information on errors. Programming in FBML can be irritating but, when using iframe in an application canvas url... its pretty cool because then you can code in the familiar word of jquery. The new stuff coming out like the social plugins/widgets is pretty handy.

Python -- Yes, I like to gripe about python and the sometimes functional and sometimes OOP nature of it. But.. I worked on a project where they already had apps in python and they weren't interested in supporting a rails app, I am not interested in supporting a rails app (they didn't want to use heroku) so.. python it is. And postgresql ... I had more problems with postgresql then python. We had our moments but we are good now. I just needed a lightweight framework so I used web.py which is pretty similar to Sinatra for Ruby. So, that was pretty good. I didn't find it as irritating to program in python as I thought, it didn't bother me about the intenting/whitespace at all.. and only a few times I forgot the : at the end of a block statement.

PHP -- I tried Zend Framework.. I did PHP for 6 years of my life, never really gave the MVC framework from Zend a fair shot. So I set out to give it a whirl, I started working through the tutorial on zend .. when I got to the part where I had to do all this coding to setup the database.. I was like, ack, i can't take it. I am not going to knock it if you like it..but its not for me :)

Grails -- Yes, I've always thought that other frameworks that try to mimic rails FAIL. I haven't gotten too much into grails, but.. so far I haven't run screaming. Hehe. One thing I noticed.. the first time you run the app, it will go ahead and install all the plugins. No need to run something like bundler or rake gems:install ... it has meta-programming aspect because of Groovy, so I think that it might be successful where other frameworks zend, cakephp, etc don't quite cut it for me (I've always held fast to the reason that rails is so successful is because its made with Ruby).

Groovy -- This is the scripting language that Grails uses... it compiles to the JVM and i haven't quite got it all figured out .. but i found this Koans to learn the language (I love ruby koans and go back every now and then and work through them)...I know that if I knew about groovy when I was doing java a few years ago I would have been alot happier. Java just requires so much typing, ack. Groovy (although i think it could use a better name) might make java programming fun again...

Javascript -- Been doing more javascript/jquery. I'm always on the lookout for for screencasts/tutorials and I subscribed to ThinkVitamin. They have great tutorials on css/html5/javascript and a growing section of frameworks. Its 25 a month but I think its well worth it. They have a series now about making an HTML5 game .. exciting!! I've been looking at javascript game frameworks. Keeping a collection of options in mind for when I figure out what kind of game I want to make.

Misc -- I finally got the Seven Languages in Seven Weeks by Pragmatic Programmers. When I first saw it, I squealed with delight but held off buying it till I had some time to dig in. I got it, did most of the ruby which I knew most of but it was good. Now I am working on the Scala section. I was listening to the Java Posse podcast and heard the excitement and joy in Dicks voice, so I was intrigued to find what is scala? Once I tried it, I understood his excitement. Scala has clear syntax (like ruby) and one thing I like for learning an interactive console...the completest (or maybe its compulsive crazy person) in me is not wanting to try the others until I finished the Scala section.

My <3 still belongs to Ruby, but I like to try out other things from time to time...I basically strive to use the best tool for the job and sometimes that means using whatever is going to be supported (as in the case of using python for one project) or one that is already in use (the grails site I am working on) and I don't want to begrudge anyone on their choice of languages.

And Happy New Year!

Go forth and program!

In past few months, I worked on a project developed entirely on linux. Previously, I mostly did rails development on mac with textmate. I had a brief period of rails and perl where I did vim and screen...oh maybe 4 years ago. Anyways, so I didn't forget much vim over the years, but I had forgotten how to use screen. I looked some documentation to refresh my memory and this post is mainly notes for me :)

Most commands start with CTRL-a
I refer to each spawning of a new screen in the current session as a window.

Detach
One things i really like about screen is I can detach it on one computer... then log in somewhere else and reattach. Also handy when you are on a wifi card on the train and you get disconnected. (doh!)

ctrl-a d to detach
then start with -r to reattach: screen -r

Create window
This creates a new terminal window

ctrl-a c

Name that window
Name your window, so its easier to keep organized
ctrl-a A (Yep, ctrl-a then SHIFT-a)

List the windows
See a list of your sessions and their number (this is why you name them) and you can use arrows to select)
ctrl-a "

Navigating Windows
You can flip through the windows in order or specify the number:
ctrl-a p previous window
ctrl-a n, ctrl-a [spacebar] next window
ctrl-a # the number you want to go to (starts at 0).

multiple regions in one
ctrl-a S create a split, creates a new region
ctrl-a TAB switch to next region
ctrl-a c create a terminal session in region
ctrl-a X close the region
ctrl-a C clear, this is like typing clear at the prompt to clear the screen

Closing
To exit a window, simply type exit. To exit and kill all windows do
ctrl-a ctrl-\

Scrolling
Using terminal on mac or linux won't capture the scroll back.... so you must do it through screen
ctrl-a [ use the arrow key to navigate up

Refresh
ctrl-a l refresh the current display

HELP!!
To see the two (!!) pages of screen commands type:
ctrl-a ?

Command mode
Do you like typing?
ctrl-a : to get to command mode, then you can type commands instead of the ctrl foo jibberish

Need the time?
ctrl-a t ....displays the current system time

Named Screen Sessions
Maybe you are working on two separate projects at once, give each one its own screen session
screen -S ProjectOne
screen -S ProjectTwo
screen -list

then later you can do
screen -r ProjectOne

to reattach it and continue

One thing you can do it make it easier is to add this to your .screenrc

hardstatus alwayslastline "%?%{yk}%-Lw%?%{wb}%n*%f %t%?(%u)%?%?%{yk}%+Lw%?"

It will show the names of the windows you have and highlight the current one. You can see the numbers too so you can do ctrl-a # quickly to jump around.

Anyways, hope this was useful to someone. Let me know any suggestions or anything I can do better!

Sources:

I never really used a debugger until I did Java. Before that I did what was called "PHP Debugging" which is littering your code with print statements until you figure out what you need to know, then going back and making sure you deleted them! I sometimes would put a unique string like

print "QWE" . $myawesomevar

Or something like that, then going back and searching your code for QWE (just picked something that was easy to type!). But all that gets rather annoying. They might have nice debuggers for PHP now, I haven't really done php in 4-5 years. I really didn't understand the power of breakpoints until I did java and I thought that was pretty cool. Now that I do all ruby, I sort of miss eclipse (I didn't actually think I'd ever say that...) since all I use right now is textmate and vi which don't have the built debugger support that eclipse does. Some of the newer ruby editors might, I haven't spent any research on them.

I found ruby-debug and it works great! You can set a breakpoint and then climb inside your application and peek around and see what is going on. I've done this in controllers and even in test mode.

If you use passenger, you can still use it but its a little tricky to setup. This blog post from duckpunching.com has some neat tips and a rake task to make it easier. Be sure to start the rdebug -c from the console after you have set a breakpoint and reloaded your page.

If you are using passenger, you can't use the irb command inside of the ruby-debug console, but I found that most of the time just being able to poke around the variable space inside my app has been enough for me to understand what is going on.

There are quite a few commands available in the debug console, but these are the ones I've used:

help - view the list of commands
l list - this shows context around the current line the debugger is on
n next - moves to the next line
p print - print a variable
irb jump to console - I dont use this very often and it doesn't work if you are using passenger
c cont - continue to end of breakpoint or end of page load, after I have seen what I want to see I do this to get out of the console

Resources

Anyways, hope some of you find it useful and happy debugging :)

Update: I wrote this in preparation for a short talk at AustinOnRails while giving the talk, the group had some suggestions:

put in a ~/.rdebugrc

set autoeval
set autolist

autolist - will run list command when you enter
autoeval - will eval each line, so instead of "eval @profile" to get it to print, it will automatically eval

doing m [object] can show methods in a nice table format. Thats cool, i have often gone to irb and did String.methods.sort but that is kinda hard to read.

Anyways, good stuff!

Yesterday I went to the Texas Javascript conference! Its was held in Austin, TX. I had bought the ticket probably about 3 months ago. In part, I wanted to learn more javascript and I wanted to check out Austin. Now, through a series of events, I have moved to Austin from Chicago recently. I really like the smaller local conferences, I've really liked attending Windy City Rails in Chicago and the YAPC (Perl) when we had it in Chicago.

There were 2 tracks of speakers and one track of impromptu talks/discussions in a third room. It was sometimes hard to choose, but here's what I attended:

Douglas Crockford: Really, JavaScript?
I really liked this talk, he spoke very frank about the language and highlighted the good parts and bad parts. ECMAScript5 was passed and he said most people working on the language have never used it. He went over parts of the language explaining what is new. He said "Mashups are the most interesting thing in decades, taking components and wiring them together for the benefit of the user" ..which he followed with "A Mashup is a self inflicting XSS attack." XSS attacks were first invented in 1995 and we have made no progress in 14 yrs to solve it. He talked about HTML5, stating that its a big step in the wrong direction. Its not correcting the problem. He recommends scrapping it and starting over, its terrible for security. It increased the attack surface and gives attackers new modes of attack, such as access to local database and inter-process communication. His final slide was "IE6 MUST DIE" in huge letters. Several people including myself snapped a photo. He said IE6 won't die because we keep supporting it and coding around its flaws. He doesn't think its unreasonable to ask people to update their software once a decade! So this talk was very informative and had some funny parts.

John Resig: JavaScript on the Mobile Web
I expected this to be more of how to make your javascript run on mobile phones, but it was an overview of all the platforms that are used and which ones have what browsers. He graded all the phones and their browsers with A, B or C scale. Some have very good emulators but some things are hard to test in an emulator, like interactions with the touch screen. That was pretty interesting...and now I know I need to spend about 5k to have all the phones I need to test on :)

Joe McCann: Rapid Prototyping with JavaScript
I watched this for about 25 mins, wasn't sure its usefulness to me. So I went to Dan Webs talk.

Dan Webb: Building @anywhere: A Client-side Interface to Twitter
I walked in as he was talking about how twitter does communication when you give a site access to your login. It was pretty interesting. I wish I had seen all of this talk.

Paul Irish: 10 Things I Learned from the jQuery Source
I debated between going to "Eugene Lazutkin: Dojo for Programmers" because I think I know more about jQuery than Dojo, but since I don't plan on doing Dojo at work, I decided to check out Paul Irish. I really like him on the yayQuery Podcast and his blogs. He gave a great presentation and it was my favorite of the day! He basically talked about javascript and looked up things in the jQuery source and explained what the javascript was doing. He was pretty funny and I really enjoyed it. I tried taking notes, but it was pretty fascinating to watch him code.

Alex Sexton: Breaking The Cross Domain Barrier
Another person from the yayQuery Podcast. He talked about different ways to get around the cross domain barrier. It was interesting, many things are new since I last did alot of javascript where I needed to load from another domain. He was pretty funny too.

Tom Hughes-Croucher: JavaScript Everywhere! Creating a 100% JavaScript web stack
I meant to go to this talk, but was in the hall talking to a guy from Facebook, swapping stories of working for Facebook vs Google and how I use facebook. I also talked to Jason Huggins a bit, creator of Selenium. I knew him from Chicago and we chatted about what was going on in Chicago and caught up a bit... and talked about testing. We share some of the same opinions and it was great to catch up.

Jason Huggins: JavaScript Frameworks & Functional Testing
This Jason leading a discussion with the creators of jQuery, Dojo and extJS talking about how we can standardize a way to test. It was pretty interesting, but they ran out of time.

JavaScript Tim Caswell: Writing a real-time game with NodeJS
I have looked at nodejs few times but never tried it. Now, I am going to have to try it. The speaker was very good and it was interesting.

Kyle Simpson: Web Performance & UI Architecture
I didn't find this too interesting nor the other talk, so I basically talked to a few people in the lobby and headed home. Long day but I learned some cool stuff. :)

So, a great conference and made some new friends and saw some old ones! :)

For this years Finding Ada post, I would like to highlight several members of DevChix and their contributions and inspirations to the group.

Desi McAdam - One of the co-founders of DevChix. She is always there to put some perspective on things and teach me about diplomacy. Sometimes I get frustrated and speak without thinking things though :)

Susan Potter - Very technical and has very good reasons for why and how she does things. Whenever I see her post on DevChix mailing list, I will pay close attention to what she says.

Jen Stander - Another of the co-founders of DevChix, always a good friend to listen to me and helps me plan DevChix activities in Chicago.

Ginny Hendry- Member of Chicago Ruby group, she has been instrumental in planning Hack Nights for the group and enthusiastic about learning!

Sarah Allen - Inspired me to learn more about mobile development and I am amazed at the variety of things she is doing!

Sarah Mei - Along with Sarah Allen, they both have inspired me to do something for women in Chicago. A one-day workshop or something, the Chicago DevChix have a meeting in a few weeks to plan this!

And I would like to thank all of DevChix, veterans and newcomers alike! We are nearing 400 members and really I don't know how to explain how supportive and inspiring they are!

/tear You Ladies Rock!!!

A few weeks ago I set out to compare Blueprint and YUI Grid. I built a page with blueprint. Then built it with YUI2 Grid and then thought about it awhile.

At first I was sold on blueprints CSS. Thats cool, thats tight! It just seemed to be so clever. But when i read the following blog I realized, hey blueprint's syntax "span-4, span-20" was putting the implementation into the markup and why is that much different than doing

which we all run in horror when someone uses a table to layout a page.

I quote from:
http://foohack.com/2007/08/blueprint-css-framework-vs-yui-grids/

If it is important enough to define your grid layout in the markup, then you should be using a table. The whole point of CSS layouts is to separate the layout information from the structural semantic markup

.. yuck!! I much prefer YUI2 grid and they have a nifty generator layout generator. I like that, I want to be able to define my basic layout and get on with life! I don't want to figure out how many "columns" this is and that. The class names for YUI are kind of non-intuitive (ie: yui-t7 and yui-g), but thats ok. They do use "hd" for head, "bd" for body, and "ft" for footer. So that is good enough for me!

You can easily assign accessibility tag of "role" to your layout too in the generator, by clicking on the regions drop downs and selecting things like banner, navigation, main, etc.

The following is a 75/25 two column layout

HTML:
  1. <div id="doc" class="yui-t7">
  2.    <div id="hd" role="banner">
  3.      <h1>Header</h1>
  4.    </div>
  5.    <div id="bd" role="navigation">
  6.      <div class="yui-ge">
  7.        <div role="main" class="yui-u first">
  8.       <!-- YOUR DATA GOES HERE -->
  9.       </div>
  10.       <div role="complementary" class="yui-u">
  11.      <!-- YOUR DATA GOES HERE -->
  12.       </div>
  13.     </div>
  14.    </div>
  15.    <div id="ft" role="contentinfo">
  16.      <p>Footer</p>
  17.    </div>
  18. </div>
  19. </body>

And the same converted to haml:

HTML:
  1. #doc.yui-t7
  2.     #hd{ :role => "banner" }
  3.       %h1
  4.         Header
  5.     #bd{ :role => "navigation" }
  6.       .yui-ge
  7.         .yui-u.first{ :role => "main" }
  8.           <!– YOUR DATA GOES HERE –>
  9.         .yui-u{ :role => "complementary" }
  10.           <!– YOUR DATA GOES HERE –>
  11.     #ft{ :role => "contentinfo" }
  12.       %p
  13.         Footer

Pretty slick, huh?

Next Page »