tonyto.es - Blogging... http://blog.tonyto.es Connecting dots to make sense of my journey to enlightment posterous.com Tue, 10 Apr 2012 14:51:00 -0700 Corey Haines - fast rails tests [video] http://blog.tonyto.es/corey-haines-fast-rails-tests-video http://blog.tonyto.es/corey-haines-fast-rails-tests-video Corey haines talking about writing faster tests in rails. Requiring
spec helper into your tests will spin up an instance of rails before
running your tests, this is slow and boring. Corey runs through a few
techniques of how he isolates code by leveraging on Ruby itself rather
than Rails.

http://arrrrcamp.be/videos/2011/corey-haines---fast-rails-tests/

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Mon, 09 Apr 2012 06:46:46 -0700 Good things come to those who wait. Or... http://blog.tonyto.es/good-things-come-to-those-who-wait-or http://blog.tonyto.es/good-things-come-to-those-who-wait-or
Media_http28mediatumb_hkeio

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Tue, 27 Mar 2012 14:38:42 -0700 Avoid "just another side project" http://blog.tonyto.es/avoid-just-another-side-project http://blog.tonyto.es/avoid-just-another-side-project
Ok, so say an idea pops into your head, and you have that light bulb moment!  You carry on about your day, and somehow you start thinking about the idea again, but this time with a bit more flesh, and you start asking questions to yourself.  This happens several times throughout your day.  Maybe you jot it down in your pad or a piece of paper for later.

After more deliberating, you sit down and say, ok, I'm going to start a project.
What do you do?

I under stand the practice of MVP, proving assumptions, failing fast.  But that leads you to just jump into code and start prototyping before you've fully fleshed out the idea.

So, before you type,
rails new my_new_project

Write a read me, just a few paragraphs, to describe the idea, whom will use it, how will they use it.  Use personas and write a scenario extract.  Identify the problem!
By doing this, it will make you think about the problem at a deeper level.  You will begin to ask yourself more questions.

I did just this, with my most recent idea.  When I was done with the read me, I sat back and asked myself, is this exciting/interesting enough for me to see through.
The answer was no!

What do you do when you come across this situation? How do you avoid starting another project before finishing the last?  I'd love to hear your thoughts, comments and experiences.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Sat, 17 Mar 2012 06:37:22 -0700 Untangling Ruby modules http://blog.tonyto.es/untangling-ruby-modules http://blog.tonyto.es/untangling-ruby-modules I came across a bug recently where an object mixed in 2 separate modules, but they both had a method name that was identical.  The method was invoked but it's was invoking the wrong method.

module Practical
    def test
        "I'm taking my Practical test"
    end
end

module Theory
    def take_test
        test()
    end 
 
    def test
        "I'm taking my Theory test"
    end
end

class FirstDrivingLesson
    include Practical
    include Theory
end

class SecondDrivingLesson
    include Theory
    include Practical
end

The two driving lesson objects, include the modules in different orders.  From the results below, we can tell this affects what module gets called first.

FirstDrivingLesson.new.take_test 
=> "I'm taking my Theory test"
SecondDrivingLesson.new.take_test 
=> "I'm taking my Practical test"

If we inspect the corresponding object's ancestors, it reveals the order modules get pushed into the ancestor stack.

FirstDrivingLesson.ancestors 
=> [FirstDrivingLesson, Theory, Practical, Object, Kernel, BasicObject] 
SecondDrivingLesson.ancestors 
=> [SecondDrivingLesson, Practical, Theory, Object, Kernel, BasicObject]

So when a method is invoked on an object, it searches self to see if it exists, if not, it will start going up the ancestor stack and invoke the method the first time it's found.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Tue, 13 Mar 2012 15:43:28 -0700 Ruby: Symbol#to_proc http://blog.tonyto.es/ruby-symboltoproc http://blog.tonyto.es/ruby-symboltoproc
The to_proc method on the symbol, simply converts the symbol into a Proc object and invoking itself 
class Symbol
  def to_proc
    Proc.new { | x | x.send(self) }
  end
end

The Proc object (short for procedure), is just a block of code, bound to a variable.

So instead of declaring a block, to invoke a single method 
['james', 'jessie', 'emma'].map { | name | name.upcase }

 You can use Symbol#to_proc
['james', 'jessie', 'emma'].map(&:upcase.to_proc)

or the more cutdown version
['james', 'jessie', 'emma'].map(&:upcase) 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Tue, 13 Mar 2012 15:16:36 -0700 Ruby: debugging 'train wrecks' with tap() http://blog.tonyto.es/ruby-debugging-train-wrecks-with-tap http://blog.tonyto.es/ruby-debugging-train-wrecks-with-tap I've just uncovered the tap().  It can be used to simply debug chained methods.

Given the following statement:
[1,2,4,[3,8,[5,2,5,7]],4].flatten.sort.join('t')

To uncover what the result of sort, you don't have to break the chain and reconstruct it
temp = [1,2,4,[3,8,[5,2,5,7]],4].flatten.sort
puts temp
temp.join("t") 

Just add tap to the chain with a block,
1,2,4,[3,8,[5,2,5,7]],4].flatten.sort.tap {|i| puts i}.join('t')

I'm not a fan of 'train wrecks' but it seems to be a Ruby idiom, and rubist love their DSL's

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Mon, 12 Mar 2012 14:01:13 -0700 Ruby private method != inaccessible http://blog.tonyto.es/ruby-private-method-inaccessible http://blog.tonyto.es/ruby-private-method-inaccessible So after playing about with Object#send I discovered that I could access private methods from outside the object.  This doesn't seem right to me, but I'm sure there's a thread debating this on the mailing list.

So given an object

class MyObject
  private
  def hide_me
    puts "shh... I'm hiding"
  end
end

In irb, I create a new instance of the object
foo = MyObject.new
 => #<MyObject:0x000001009e78d8> 

Try to access the private method from the instance, but get a NoMethodError, rightly so!
foo.hide_me
NoMethodError: private method `hide_me' called for #<MyObject:0x000001009e78d8>
from (irb):8
from /Users/tonyto/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `<main>'

But passing the private method as an argument to send, makes my private method no to private!
foo.send(:hide_me)
shh... I'm hiding
 => nil 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Mon, 12 Mar 2012 13:24:48 -0700 surround.vim http://blog.tonyto.es/surroundvim http://blog.tonyto.es/surroundvim
Surround.vim is all about "surroundings": parentheses, brackets, quotes, XML tags, and more.

csw"        =>      To surround a word with quotes
cswtP>    =>      To surround a word with a tag

cs"(         =>      To change the surrounding quote to brackets

ds(          =>      To remove the surround bracket

yss$         =>     Wraps the whole line with a $
ySS"        =>     Wraps the whole line in quotes and puts it onto a new line indented

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Mon, 05 Mar 2012 01:58:48 -0800 Backbone koans http://blog.tonyto.es/backbone-koans http://blog.tonyto.es/backbone-koans https://github.com/larrymyers/backbone-koans

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Fri, 17 Feb 2012 07:33:00 -0800 Cooking mono with Vagrant and Chef http://blog.tonyto.es/cooking-mono-with-vagrant-and-chef http://blog.tonyto.es/cooking-mono-with-vagrant-and-chef
Vagrant is a tool for building and distributing virtualized development environments, and that's exactly what I'm planning on using it for.
I wanted to build a VM ready for mono development and distribute it within my team.
Vagrant is packaged as a RubyGem, so if Ruby's installed, it's pretty easy to get started (check out their site).
Veewee lets you build a custom base box from a wide range of OS. It's a RubyGem too, so install it along with vagrant then,
vagrant basebox templates
should list all the base boxes veewee supports.
The github readme explains how to create your own base box.  I wouldn't recommend building a windows server basebox, it's time consuming and I didn't see the light at the end of the tunnel.
Once you've created your basebox, run the following to get up and running,
vagrant box add base PATH_TO_YOUR_BASE.box 
 vagrant init
vagrant up
By default, the VM runs headless, so you can ssh into the VM,
vagrant ssh
Chef or Puppet can be provisioned with vagrant, just edit the VagrantFile and tell it where the cookbooks or manifests are.
1
2
3
4
5
6
7
config.vm.provision :chef_solo do |chef|
  chef.cookbooks_path = "cookbooks"
  chef.add_recipe "vim"
  chef.add_recipe "tree"
  chef.add_recipe "mono"
  chef.add_recipe "git"
end

Reload the VM, and it should spin up again with the configurations in place.
Mono
I haven't quite figured out chef, and my innovation time was closing to an end, so to test the concept, I've hacked up a bash script to configure and install the bare bones of mono and added it as a recipe in the chef cookbook.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash

# this ran fine on Debian-6.0.3-i386-netboot.
# Not tested it on anything else so enlighten me..

clear

echo "======== installing required packages"
echo
sudo apt-get install g++
sudo apt-get install bison
sudo apt-get install gettext
sudo apt-get install make
sudo apt-get install pkg-config
sudo apt-get install libglib2.0-dev

echo "======== Getting mono from source"
echo
wget 'http://ftp.novell.com/pub/mono/sources/mono/mono-2.10.2.tar.bz2'

tar -xvjf 'mono-2.10.2.tar.bz2'

cd mono-2.10.2

echo "======== Configuring and install mono"
echo
./configure

make

sudo make install

echo "******** We are done! ********"
echo
Grab a project, run xbuild at the solution level and you should be cooking on gas.
I've barely touched the surfaces of chef, so to follow up, I'd like to learn more about chef and test it's limits and potential.

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Wed, 18 Jan 2012 10:21:00 -0800 "Saff Squeeze" http://blog.tonyto.es/saff-squeeze http://blog.tonyto.es/saff-squeeze
To effectively isolate a defect, start with a system-level test and progressively inline and prune until you have the smallest possible test that demonstrates the defect.

After banging our heads and tangling up with the debugger, Paul enlightened us about the "Saff Squeeze" technique.  Isolating the problem through writing narrow tests where we think the problem/bug might be occurring.

To save me from going into more detail, Paul was one step ahead. "Tests aren't just for testing: Stop using the debugger"

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Tue, 03 Jan 2012 02:44:05 -0800 Vagrant base boxes http://blog.tonyto.es/vagrant-base-boxes http://blog.tonyto.es/vagrant-base-boxes Resource for Vagrant base boxes.

Or package your own using the veewee gem.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Sun, 16 Oct 2011 12:12:03 -0700 Gourmet lovers club - spanish inspired brunch http://blog.tonyto.es/gourmet-lovers-club http://blog.tonyto.es/gourmet-lovers-club

Thank you Bex and Nick (the gourmet lovers) for a fabulous spanish themed 6 course brunch. Pictures say a thousand words but does no justice to those flavoursome dishes.

(pictures are in order of courses)

Gazpacho
A spicy bloody mary gazpacho. Cold, refreshing with bits.

Cerveche de Salmon y Aquacante
Salmon cooked in citrus with avocado on toast. Overheard someone saying the toast would have been the hardest part but it was done just right, for me anyway.

Champinones Frito con Queso Cabra
Deep fried oyster mushrooms and goats cheese.

Huevos al Nido
Eggs in a nest of bread with chorizo & sweet peppers. The yolk was sitting on top, ready to be popped. Runny, just how I like it.

Panqueque de Higo y Nuez
Fig and walnut pancakes with greek yoghurt and honey. Anything with figs deserve a high 5! I'm loving them atm.

Heldo de Aquacante
Avocado ice cream with bittersweet chocolate. Finishing on a high note, the crystallised mint brought out the freshness in the creamy ice cream.

All washed down with lots of Horchata, refreshingly sweet and creamy beverage with a nice cinnamon zing.  My and I could drink this all day long...

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Thu, 06 Oct 2011 10:40:00 -0700 Future Of Web Apps - highlights and brain bump http://blog.tonyto.es/future-of-web-apps-highlights http://blog.tonyto.es/future-of-web-apps-highlights

Firstly I'd like to thank all the organisers, speakers, sponsors and venue for making FOWA 2011 an awesome conference. Wifi was flawless and the bean bags were a nice touch.

So I guess to sum up the conference, conversations were formed around launching web apps, html5, javascript rich applications with a distinct focus on mobile devices. 
Tools, browsers and web standards are enabling this. The only thing that is holding back native functionality on web apps is hardware restrictions. Wouldn't it be awesome if you're web app could access your camera or get your geo-location? But what are the security implications? Still some kinks to iron out.

Rich client-side apps
Alex MacCaw spoke about Spine.js, and Chad Pytel gave pointers to Backbone.js.  Both are client-side MVC frameworks, built with the aim of making it easier to develop rich event-based client-side applications. What framework you choose, is up to you, but you are strongly urged to use one. Alex also launched Spine Mobile for building mobile web apps.

Sam Stephenson was bigging up coffee-script. Some of the good parts Sam pointed out are:
  • variables and functions are private by default
  • use of var is redundant, it scopes it for you at compile time
  • strict comparisons is enforced by default
  • the compiles JS that is JSLint compliant
It's got me very excited about it.  The syntax draws influences from Ruby, so it looks clean and you can achieve more with minimal code.

Pitching and starting up
Pete Koomen, from Optimizley, gave some pointers of their startup journey. 
  • They got a paying customer on day 1.  That's a huge validation of the idea.  
  • Engage and talk to your customers, ring them up, meet them in person, get them to use your product infront of you. 
  • If they want to leave, find out why and see if it's in your power to resolve their problem and retain their loyalty. 
To sum up Pete's talk, "Get to know your customer, understand why they buy, focus and fix pain points. Deliver value! Feel like a bad ass."

Dave Mclure set the tone of the conference with the line, "pitch the problem not the solution".  Using that problem to grab their attention, so you can share an emotional context. 
When you're pitching and you are asked a question, stop and address the question. Forget about your script, you've got their attention, engage in a conversation and close the deal.

Scott Chacon got the biggest round of applause for talking about the apps, principles and culture that are engrained into github. They have no office hours, no meetings, no vacations, no assignments, no bosses and 100% innovation time.
"Alcohol is a great way to connect with people. Organise meetups and get to know your customers, get them drunk "

That's my brain dump of my 2 days at FOWA. It probably doesn't all make sense but meh. I met some great people and had some interesting conversations. 
I've got a lot of energy for mobile web apps now, watch this space for some hacks. 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Tue, 04 Oct 2011 15:16:00 -0700 Student advice http://blog.tonyto.es/student-advice http://blog.tonyto.es/student-advice

After chatting to some grads at FOWA, the advice @raoulmillais and I would give to any buddying undergraduate/graduate developer is "find a space you're interested in and contribute to opensource projects".

Be it bug fixing, writing documentation, questioning why things are done the way they are...etc.  Open-source communities like ruby, node, python and probably others, are active, vibrante and receptive to contributors. I just wish I knew this when I started my software development career.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Sat, 01 Oct 2011 04:05:42 -0700 Stop living someone else's to-do list. http://blog.tonyto.es/stop-living-someone-elses-to-do-list http://blog.tonyto.es/stop-living-someone-elses-to-do-list

I came across this very interesting video by Scott Belsky. He talks about an obstacle he calls "reactionary workflow"--that constant influx of messages, to-do items, and interruptions that are part of every day.

We get overflowed with messages,through facebook, twitter, email, sms, and many others. "Rather than being proactive with what means most to us, we are being reactive with what comes into us."

source: [http://www.fastcompany.com/1783440/work-smart-scott-belsky-reactive-workflow]

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Mon, 26 Sep 2011 12:44:00 -0700 Command to uninstall all Ruby gems http://blog.tonyto.es/command-to-uninstall-all-ruby-gems http://blog.tonyto.es/command-to-uninstall-all-ruby-gems

Could come in handy again one day...

gem list | cut -d" " -f1 | xargs gem uninstall -aIx

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Fri, 23 Sep 2011 06:04:43 -0700 LostType http://blog.tonyto.es/losttype http://blog.tonyto.es/losttype

Just stumbled over LostType, a Pay-What-You-Want type foundry.

"Users have the opportunity to pay whatever they like for a font, you can even type in '$0' for a free download.

 100% of funds from these sales go directly to the designers of the fonts, respectively.

Lost Type takes no cut of sales, and holds no funds."

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Sun, 11 Sep 2011 12:56:00 -0700 Stop supporting crappy browsers http://blog.tonyto.es/stop-supporting-crappy-browsers http://blog.tonyto.es/stop-supporting-crappy-browsers

Screen_shot_2011-09-11_at_20
[NodeConf 2011 - Henrik Joreteg]

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To
Tue, 02 Aug 2011 12:30:00 -0700 Execute a child process in Node http://blog.tonyto.es/execute-a-child-process-in-node http://blog.tonyto.es/execute-a-child-process-in-node

A little node snippet that will execute a child process...

 

var exec = require('child_process').exec;

function output(error, stdout, stderr) { 
        console.log(stdout) 
};

exec("ls -la", output);

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914744/tonyto85.JPG http://posterous.com/users/YC2llnWTkgF Tony To Tonyto85 Tony To