MoSH - The Mobile Shell

Posted 14 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

The Mobile Shell takes a number of new approaches in providing shell connections for mobile and roaming clients. By Alex Blewitt

Mechanics of Programming

Posted 14 days back at Segment7

I sat down with Elise Worthy at RailsConf to pair with her on a Rails application that used the Wunderground API to retrieve the weather for multiple cities. If you don't know Elise, she's a Hungry Academy student formerly of Seattle. You can read about how she built her app on the Hungry Academy Blog. Since Elise is new to programming, pairing with her made me think about how I work on small tasks when implementing a larger feature.

When I first sat down, Elise had a class to retrieve the weather for Washington D.C., a controller and a view to display it. Our task was to add a search box so you could show the weather for any ZIP code in addition to Washington D.C.

By implementing weather for a fixed city first Elise had followed the most difficult lesson for me to learn, only implement one idea, or story, at a time. When I try to add too much I can't fit all the details in my head. By making the weather work for one fixed city she had a solid base of work she could revert to to try again if she got stuck.

I mostly helped her with the question of "what should I do next?" Elise knew which steps she needed to perform but didn't know what the best order was. I've found that working on the easiest task first is best. By picking the easiest task you have time to think about the hard tasks in the back of your mind. By the time you get around to them you may have made them easier or you may have come up with an easier way to implement them.

In the course of doing the easiest thing next we switched back and forth between the API wrapper, the controller and the view. Each change we made was very small. For example, first add the search form, next extract the ZIP code from params, then replace showing Washington D.C. with the user's choice.

Each step only changed a couple lines that we verified in the browser so we didn't get ahead of ourselves. By first changing from a fixed city to an arbitrary city we advanced towards our goal without confusing ourselves with extra details. While this broke one feature of the app, it was obvious that it would be easy to restore in the future when we were ready to address it.

I also find it useful to add TODO comments when I know I need to change or fix something but don't want to do it yet. The TODO item may be a distraction at this time or something difficult that a future step will make easier. I find it easy to forget some necessary cleanup without them. We added a few when Elise would think of something she needed to change but I didn't want to get us distracted.

There was one other tip I had for Elise, as she was adding support for both Washington D.C. and the user's ZIP her first idea was to use two instance variables to provide the data to the view, one for Washington D.C. and the other for the user's city. She also asked if I thought this was the best way.

I told her that it is easier for me to think of handling just one item or handling many items, but not just two items. By having only these two categories of items to display it makes it easier to maintain your code by preventing duplication.

The best thing that came out of pairing with Elise was that I got to think about how I program at the lowest level. While I got to show Elise some tips I've learned over the years, she showed me the details of my own internal process that I barely think about anymore.

Ruby 1.9.3-p194

Posted 14 days back at The Ruby Show

Peter and Jason talk about the new release of Ruby, the Rails API gem, mruby and MobiRuby, and more.

Zepto.js in the wild: Typotheque’s Greta Sans Type System Specimen

Posted 14 days back at mir.aculo.us - Home

81 fonts, 1 SVG, 696 lines of JavaScript (no semicolons!), 565 lines of CSS, 74 lines of HTML and Zepto.js in a single 634KB compressed web page. Amazing stuff. Read up on how it was done.

Come Correct with Inject and Collect

Posted 14 days back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

Here’s a refactoring example for a simple Ruby math problem using the inject method.

The goal is to generate an n by n multiplication matrix. Pretty straightforward. Let’s make a first pass:

def multiplication_table(n)
  results = []

  (1..n).each do |row_index|
    row = []
    (1..n).each { |column_index| row << row_index * column_index }
    results << row
  end

  results.each do |row|
    header = '%-3s ' * row.length
    puts header % row
  end
end

multiplication_table(7)
1   2   3   4   5   6   7
2   4   6   8   10  12  14
3   6   9   12  15  18  21
4   8   12  16  20  24  28
5   10  15  20  25  30  35
6   12  18  24  30  36  42
7   14  21  28  35  42  49

It does the job, but it’s nothing to look at. We can condense using in-line blocks and fancy curly braces, but first let’s try using inject.

Quick background: Inject iterates over a set using a block with a collector, which is a variable whose value is passed back each round, making it good for iterative uses. The block’s return value is passed into the collector (make sure you return something or you’ll get a nil). Also, the return value of the whole inject block is the final collector value.

Simple example from the docs:

(5..10).inject {|sum, n| sum + n }            #=> 45

The inject method takes a parameter, which initializes the collector value (default is to set to the first value). You can pass in an empty array and add values:

def multiplication_table(n)
  results = (1..n).map do |row_index|
    (1..n).inject([]) { |row, n| row + [row_index * n] }
  end

  results.each { |row| puts '%-3s ' * row.length % row }
end

So that’s inject with the iterative collect (Whoo-aaaa - got you all in check)

Note: For a more in-depth discussion of inject, read Mike Burns’ recent post.

Interview: Philip Wadler on Functional Programming

Posted 15 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

Philip Wadler talks about the role of functional programming and some of the reasons for its slow rise in the past and its influence today. Also: lambda calculus, monads, continuations and much more. By Philip Wadler

Railsberry: a look back

Posted 15 days back at No Strings Attached

Railsberry: a look back

I was about to write my thoughts about Railsberry in Kraków two weeks ago, but I changed my mind and decided to let their awesome photos speak to you instead.

Therefore, I present you few moments from the Railsberry conference—in pictures.

<figure> Balloons floating above grass <figcaption>Grass field outside the venue for resting</figcaption> </figure>
<figure> Rich table of food <figcaption>Magnificent catering for lunch</figcaption> </figure>
<figure> Vuvuzela <figcaption>Vuvuzelas would stop lighning talks that were too long</figcaption> </figure>
<figure> The Balloon Gig <figcaption>Mayhem after a game of Balloon Hero</figcaption> </figure>
<figure> Happy Friday Giant Railsberry Hug with Aaron Patterson <figcaption>Tenderlove's Friday hug—with backup</figcaption> </figure>
<figure> José Valim & Josh Kalderimis <figcaption>José Valim & Josh Kalderimis</figcaption> </figure>
<figure> Unicorn at afterparty <figcaption>Atmosphere at the afterparty</figcaption> </figure>
<figure> Jana, Corey, Mislav, Josh & Elliott <figcaption>Me (in red) and the awesome people I love</figcaption> </figure>
<footer>

All photos are from Railsberry's official photostream.

Back to Mislav's blog </footer>

Rails Girls: Ruby on Rails workshops for women

Posted 15 days back at No Strings Attached

Prior to Railsberry in Kraków, I participated in a Rails Girls workshop by helping coach 40+ girls that attended the event in Applicake’s offices.

Me at Rails Girls

It’s been a fun and rewarding experience for me, and I look forward to where empowering more women with knowledge & skill takes us.

Next workshops take place in different cities in Europe, one in Buenos Aires, and there’s rumors of Rails Girls in San Francisco. There’s even a guide how to organize a workshop in your city.

#346 Wizard Forms with Wicked

Posted 15 days back at Railscasts

Creating a wizard form can be tricky in Rails. Learn how Wicked can help by turning a controller into a series of multiple steps.

Presentation: Dynamo Is Not Just for Datastores

Posted 15 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

Susan Potter discusses Dynamo, Riak, distribution, consistency and fault tolerance, along with techniques and an example for building an application with riak_core. By Susan Potter

How to extract an intention-revealing name using Vim

Posted 15 days back at GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS - Home

This method has a magic number:

def wait_time
  @env[QUEUE_WAIT_HEADER].to_i / 1000
end

Let’s extract that to an intention-revealing name. We’ll type:

/1000<Enter>                   # Find the number we want to extract
cwmilliseconds_per_second<Esc> # Replace the number with a variable name
O<Ctrl+A> = <Esc>p             # Assign the replaced number to the variable

The result:

def wait_time
  milliseconds_per_second = 1000
  @env[QUEUE_WAIT_HEADER].to_i / milliseconds_per_second
end

Under the covers:

  • <Ctrl+A> inserts the last text you typed in insert mode, so the variable name is available after replacing the number
  • Replacing or deleting text in Vim will place that text in your default buffer, so the number is available to put at the end

Assuming your cursor is at the value you want to extract, this creates an intention revealing name in 10 keystrokes, plus the keystrokes it takes to type out the name.

Can you beat my Vim golf?

Presentation: Hybrid Mobile Applications using PhoneGap

Posted 15 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

Dave Johnson introduces PhoneGap: how to write apps with it, the existing community, an API overview, extending PhoneGap, tooling, libraries, and an argument on web vs. native apps. By Dave Johnson

Gregg Pollack Talks with the Florida Technology Journal about Code School

Posted 16 days back at Envy Labs

Gregg Pollack talks about our online learning platform, Code School. Check out the video interview here.

<iframe width="560" height="315" src="http://www.youtube.com/embed/rgnO4XeiOwU" frameborder="0" allowfullscreen=""></iframe>

Presentation: Architecting in the Gaps

Posted 16 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

Eoin Woods suggests creating the architecture of a system by discovering the interactions between the components and focusing on the boundaries, helping with defining the interfaces and interactions. By Eoin Woods

Presentation: Android App Assimilation

Posted 16 days back at InfoQ Personalized Feed for unregistered user - Register to upgrade!

Logan Johnson exposes the Android integration points, explaining how to create apps that consume data and services provided by other applications. By Logan Johnson