spike_and_rarity__s_heart_shaped_fire_ruby_by_edwardtenDid you know it’s possible to run (aka build) your Ruby code straight from inside of Sublime Text 2?

That’s easy, just make sure your code is saved as a .rb file and hit Command+B.  But wait, there’s more…

Did you also know it’s possible to run your Ruby code straight from inside of Sublime Text 2… using RVM’s default Ruby?

There might be a better way but here’s one a quick and dirty for an OSX environment.  If you are using Linux, it’s hopefully the same but with the file paths modified:

Step 1:
Cut a hole in a box.

Step 2:
Open `~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.sublime-build`
And replace it’s contents with the following (be sure to substitute your user name):

 

Step 3:

  • Launch Sublime Text 2
  • Open a ruby file
  • Hit Command+B
  • The Sublime Text console should pop up with your output. If you want it to go away, hit escape.

Want to prove it’s working?

Here’s a quick script that computes factorial and then prints out the result AND the ruby version using ruby’s constant “RUBY_VERSION”:

 

Drop that into your own factorial.rb, open it in Sublime Text, and hit Command+B.  It should look something like this:

sublime-text-doing-the-most

As you can see above, that’s 1.9.3… and as you can see below… that’s what my RVM is set to use as it’s default ruby.

 

EVIL MASTERMIND... muhahahah aha AppAcademy had us coding some games today! Specifically, Mastermind and Hangman.

When my pair Brittney and I started this we had both never heard of mastermind; so that was the first challenge. Turns out mastermind is pretty straight forward AND it’s actually a really cool game.

Let me explain the rules of mastermind first…

You basically have a board that allows for 10 turns. There’s a code-maker and a code-breaker. The board has 4 columns and a row for each of the 10 turns. Each row (or turn) also includes a “correctness area” (just baked that term up fresh) for the code-maker to indicate how many of the 4 were wrong, near or correct; I’ll explain those soon. For our purposes the computer was the code-maker.

The code-maker’s role is to make a secret “code” that consists of 4 colors selected from a list of 6 available options. Once the code-maker has selected a code he keeps it a secret and allows the code-breaker to guess it.

As I mentioned above, the code-breaker gets 10 attempts to crack the code. Each time he makes a guess he sets 4 colors from the 6 available on the row corresponding to his turn. At that point, the code-maker takes a look at the code-breaker’s choices and using the “correctness area” indicates if any of his/her choices were exact, near or wrong.

If a choice was exact, meaning the color and column selected were correct, a black marker is placed in the “correctness area”.
If a choice was near, meaning the code-breaker selected a correct color but didn’t place it in the correct spot, a grey dot is placed in the “correctness area”.
If a choice is flat in every sense, meaning it’s a color not used in the code, then we do nothing.

If the code-breaker guesses the code before the 10 turns are over, he wins! woot!

Our implementation basically had 3 classes a Computer (the code-maker), a Player (code breaker) and a Game class that actually “played” the game.

The full source is as follows:

 

pairon

Under construction still…

Today was Awesome.  In my past experiences I’ve found that pairs balance out as they work but with Kriti I think we balanced out as a whole.  To explain that a bit further… Kriti is incredibly strong with recursion problems … like straight up a bad ass (and I have a line of code to show for it) and I’m stronger with some of the more common Ruby idioms — test first and similar stuff in that vein.  Instad of balancing out on a per problem basis it felt like we kind of showed our strengths against problems we were better at and the result was a good balance across entire duration of working together.

redneck-recursion

 

We worked on a lot of recursive problems and while working on one in particular ended up making a pretty ridiculous mistake… We used #each instead of #map. After probably an hour of trying to figure out why our ___________ method wouldn’t work we realized that we had been using #each (probably out of habit since it’s so common) and our results were coming out totally unchanged.

We actually ended up writing the same method like 3 different ways trying to resolve the issue and FINALLY zeroed in the fact that nothing was changing -> #each iterates and doesn’t make changes -> #map iterates and DOES make changes -> OMFGWTF

In other news, here’s an awesome, awesome, method that Kriti came up with.

____________________f

giggityHere’s a fun snippet of code we wrote today at AppAcademy.

Basically the goal was to take a bunch of couples who were into swinging and swap all of their partners.  Yep, swinging.. as in:

Swinging or (rarely) partner swapping is a non-monogamous behavior, in which singles or partners in a committed relationship engage in sexual activities with others as a recreational or social activity.[1] Swinging can take place in a number of contexts, ranging from spontaneous sexual activity at informal gatherings of friends to planned regular social meetings to hooking up with like-minded people at a swingers’ club. It can also involve Internet-based swinger social networking services online.
Wikipedia

In order to properly swing, a couple is supposed to show up at a party and swap their partner for another partner.  For our purposes we were to assume couples were heterosexual males and females.

The code we came up with was this:

Basically we found that we could randomize all of the couples then shift their partners by one.  By doing it this way we could ensure things that both things were spicy AND that a man never ended up with the same woman he arrived with.

Ned Ruggeri - AppAcademy teacher

Today marks the first day of my sprint through San Francisco based AppAcademy. It’s a pretty interesting setup.  Basically, you’re paired with a random person everyday and work through a large suite of problems assigned for that particular day.

To say the least, you and your pair bust ass HARD until the end of the day.  The day ends with more work — you are now assigned another pair and must review their code.  After reviewing the other pair’s code and sending them some comments the final part of the day (now night) is doing the readings for the next day’s schedule.

It’s very intense but the amount of code we are producing is really fantastic.

The teachers and TAs are VERY approachable.  Ned Ruggeri (mug shot on the right) presents complex concepts in great detail and definitely seems to genuinely care if people are “getting” things or not.

It’s a great environment.