Posterous theme by Cory Watilo

Starting up with Node on Heroku

Was curious about all this fuss about Node being the new hype, so I decided to try it out, as I had to do a very simple website, for which I also intended to use mobile first and responsive design.

Also as Heroku now supports Node on the Cedar stack, the mission was easier.

Heroku has some documentation on getting started: http://devcenter.heroku.com/articles/node-js

But first, you have to install Node on your machine, which for me is Mac (Lion), so I went with Homebrew. Heroku (and Express, the Web framework, as well) need the version of Node to be quite old, 0.4.7. After a little of digging, I came up with this:

brew install https://raw.github.com/mxcl/homebrew/cb6a4b4765ca4439eb03cd137cc6cbae143a8c62...

That installs Node using the formula when it was set for 0.4.7, ahhh so easy. Installing NPM, the package manager, is a joke:

curl http://npmjs.org/install.sh | sh

Follow Heroku's instructions and set up the Hello World example and Heroku login. NPM install display is quite cool. Last thing to setup is the Procfile and then start Foreman. Running!

The rest of the steps are easy and your app will be on Heroku fast enough.

(to be continued)

Steve Jobs inheritance

T_hero

(picture from apple.com homepage: they named the file t_hero.png)

Yesterday, I just had a late dinner and the voices of an opera event I attended in the night where still resonating in my head. Music from my latest holiday in Ibiza was running in the background. Then I read a tweet, it was saying: "Steve Jobs is dead". I thought: "what bad taste for a joke". It was a retweet from a source I had never seen.

Then I read another one, seconds after and this was a trusted source. It took me some other seconds to realise. Steve didn't present and wasn't even seen in the latest Apple's keynote. He stepped back from his CEO position. He should have been resting and enjoying more time with his family. No. Way.

It was around half midnight and the Twitter stream was suddenly flooded by tweets with the words "Steve" "Jobs" and "dead". Music still running. A big void. Nothing. Absolutely nothing. But I didn't want to stop the music and go to bed. For some reason. I just wanted to think about him. About what he did. About why me and thousands other people felt so obliged to pay him respect.

Today I imposed myself a ban on tweeting and posting on Facebook, apart from answers to people, activities on which normally I'm very prolific. My shirt/tie/belt/trousers/shoes was adjusted to a black/black/black/black/black. To honour him.

That's not to say we should mourn and complain about the present, life and whatever. That's just to say I respected him. And I respect him. He had enemies as every man and woman that has a backbone should. If you have a strong vision of life and will to fight to make the difference, you will not be liked but some. But you will be loved by others. That's the way it is.

He was the best CEO in the history in my opinion, and according to a lot others, and one of the best entrepreneurs I've ever seen or dreamt to be. He was one of those youngsters starting out a successful company in a garage and he managed a company of 50,000 employees as only a master could. This year Apple had more cash in the bank than the United States of America. They sold more than ever. Every device has been a success. Yes. Those are facts. Which Apple could reach thanks to him.

If I believed there was a Hell, I'd be sure he would be presenting the next great device, iNfernal, to Satan right now. All pictured in his head. With those eyes that could see what we don't see. I still remember complaining about the iPad when it first came out: "it's a useless device" I thought. Couldn't be more wrong: only another lesson from Steve.

He was visionary. A visionary is rare. He changed our lives. Do you know what fonts are? The pretty little styles you can use for your text when you write a document. You would be writing using only one style, without him. The nice graphical interface? You would be typing green words on a black screen instead of clicking nice buttons, without him. Do you remember the touchscreen devices before iPhone? No? Of course not. Because they sucked. Every single one of them sucked, before iPhone. But then he had this idea about a touch phone. We could go on and on.

Today Twitter was going at a rate of 30K tweets/h about Steve. That shows how much he was an idol for people of every kind. Young and old. Geek and ordinary. Successful and unsuccessful. Did you ever see a business person becoming an idol for common people? I saw a reaction from pretty everyone. Even cynical reactions, but if there is light, there has to be shadow.

For me he was a role model for his restless will of creating something that would change the world, for being a true leader, for his values, for being the only geek I don't hate, for his eccentricity, for his being pickier than anyone, for the respect he gained even from his competitors, for his willingness to inspire and give advice, for his ability to surprise, for his humanity (would you imagine the CEO of Goldman Sachs directly answering an email of a client?) and for his infinite strength.

He presented a mere 4 months ago. I have seen close people die by cancer. It beats the crap out of you. It shreds the will of even the strongest people. Yet he was there, black turtle neck, jeans and rounded glasses as always, talking about his new baby.

As a witness of all this I can't help but dedicate myself to rip the best fruits of life, following the advice he gave to Stanford students in his infamous talk. Sad in my heart, but stronger in the deep of it.

Thank you Steve, for everything you have shared with us and to have made us dream. Now it is our time to continue your journey and create a new future, isn't it?

"Steve Jobs was born out of wedlock, put up for adoption at birth, dropped out of college, then changed the world. What's your excuse?"

Rails 3.1 tips and gotchas

I wanted to share rapid firebolts about working with latest Rails 3.1 (rc4).

Some words about Coffeescript, that I already described in my other post:

the language is nice and permits you to use abbreviations like this for jQuery.ready(function(){}):

$->

Apart from the language itself, I didn't like a lot how it works with Sprockets in Rails. There is no clear use of different *.coffee files. What I mean is that I would have expected the code for i.e. pages.js.coffee to influence only the behaviour of PagesController views. Instead it's simply injected into application.js and that's it. If you want some javascript code to work only for a page, you have two solutions:

  • include javascript/coffeescript in page;
  • include manually a different file, taking care it is not included itself into application.js with the require_tree . directive.

Same stuff for stylesheets. If you have two completely different styles that are overlapping (let's say main.scss and admin.scss have styled the same container) you will have to manually change the file inclusion, taking care of substituting require_tree . with require_directory in application.css. Also if you are precompiling you have to tell Rails you have more than one manifest:

config.assets.precompile = ['application.js', 'application.css', 'pages.js', 'pages.css']

See all the conversation on github here: https://github.com/rails/rails/issues/1981.

Now you can enjoy automatic SASS compilation (hail to you, SASS author) without having to install Compass. If you want to use absolute paths for your images, you will have to use /assets in place of just / for the root (due to Sprockets).

The deprecated syntax for helpers that generate code in their output (form_for, content_tag_for etc.):

<% %>

now doesn't render anything: so beware of those perky Textmate snippets for form_for.

Capistrano spits some warnings about not finding the usual structure under /public, but works (even if not with shared resources). See https://github.com/capistrano/capistrano/pull/35 for updates.

jQuery is provided by jquery-rails: "jQuery is no longer vendored, it is provided from now on by the jquery-rails gem. [fxn]" from the RC4 changelog written by Ryan Bates. jQuery-UI from the jquery-rails gem has to be included manually if you want to use it, but it's without theme, so you have to manually download it.

Rails 3.1 doesn't work with Heroku addon New Relic at the moment: http://support.newrelic.com/help/kb/ruby/new-relic-for-ruby#known.

I tried PJAX plugin that provides you with the redirect_to_pjax helper and I can say it's nice, but you have to be careful to use the normal redirect when you are for example logging out the user, as you will want to refresh the menu that hopefully you were not loading every time with pjax.

First dip into lean

I am writing about my first experience with idea validation and customer development.

After being taught once again by great speakers at the Startup Lessons Learned conference of the importance of customers, I knew I couldn't code any more without finding first if there was interest in my idea of a product. The problem is, I always want to do things perfectly, polishing details and also I never directly sold anything in my life, so I don't know how to approach people to pitch them my idea.

I have this kind of hate for current analytics solutions, neither of them does what I want. So I was slowly building one, every now and then in the patches of my limited free time.

Then yesterday, while I was preparing to go out for a relaxing shopping session, I read a post written by Joel. He is a young UK entrepreneur that with his product sent more than 100K tweets. He wrote this post about the Startup Genome project and how a tool type startup (same as his) is the one that has the higher probability of success.

OK, I thought. My idea is of the same type. Let's see how this bloke started. On his company blog the first post was exactly what I was searching for. I was stunned when I learnt that he started with only two pages with basically only text.

I couldn't go out any more. At least not until I had my two pages online. I spent two hours, most of them solving issues between Rails 3.1 and Heroku (I'm an adventurer, I admit it, but the project was already converted when I started this), and I wrote the two most minimalistic pages I ever put online. Only text, the only fancy thing the rounded borders for CSS buttons.

Screen_shot_2011-05-30_at_15

Screen_shot_2011-05-30_at_15

I started writing in first person, as if I was talking about my problems to someone. If there is a thing I learnt in between the swears of Dave McClure is: problem first, solution afterwards (if people care about the problem). Then I converted to the second person. I left out any image on purpose, it would have taken too much time, and I wanted to be online in the shortest time possible. I finally managed to put the content online, with a new domain, naming it OnSightApp.

Then I posted it on Hacker News. I had already proved the power of that community, receiving more than 1K visits in 3 hours on my post about CoffeeScript. And in fact I received hundreds of visits. I was happy for two reasons: I was validating my idea (no prices yet, but it's a start) and receiving feedback on the presentation of it.

I was especially curious to know if my words were clear and understandable. What I got is:

  • I wrote too much text;
  • I need images to explain concepts;
  • I need to point out explicitly my differentiator, otherwise people won't be interested in "yet another" analytics solution.

Not only I learnt this, but also I discovered that there are people working on pretty much my same idea. A classic. But in my opinion execution is what in the most part gives you success. So a competition starts.

The figures I got, with two hours of work:

  • 533 unique visits;
  • 242 clicks on 'see prices and register';
  • 17 people sent me their email.

That makes:

  • 45% more curious;
  • 3% conversions.

If you're wondering where I got these numbers: I already have a very basic working version of the product, that I made to check visits on my personal website. In the end it all started from a problem I had, so I'm trying to find if there are other people with the same problem and if they're willing to pay to have it solved.

And now in a cafe, back to coding. But I will kindly request feedback from my early users very soon.

 

Another way to donate: expertise

I wonder how a team of random people can work so well and deliver so much in the first two days they meet — especially after seeing how many consolidated teams can do nothing for months.

Maybe it was the passion for the cause. You go to Good for Nothing* because you want to help someone with their cause, because you believe in their idea and share their vision. 

Maybe it’s because of the community sense that you get, after only 10 minutes there, sitting down on the floor talking as a group about what has to be done. No formalities. Just do what you are able to do to help. Share your ideas.

Maybe it’s because there wasn’t a predominance of males. Actually it was the opposite. If you work in IT as I do, you know what is like: men every day, everywhere. Women have a different touch on the way of getting things done, also have a different vision and let’s be honest: a feminine smile will make you work faster!

Maybe it was for the format of the event: no hierarchies or managers, just a flat “organisation” where everybody can stand up and have his say. Like the ancient Athens was. Everybody self-managed. As in 37signals.

Or maybe it was luck. More than 60 people came by their will and they chose in which of the three groups they wanted to go, after the initial pitch by the founders of the three causes. Our group, the foodcyclers**, had developers, digital artists, designers, marketers, strategists and writers. Working in synergy.

I just know that I never coded like that. It felt like a startup: everybody getting the shit done, no matter what and doing great work. I was amazed at the quality of every single person in what they did and you could see they really loved what they did. Everyone with her passion.

In a way, there were some elements reminding me of lean: the organisers initially talked about delivering and the deadlines by which we had to show what we had done. Half of the team the first day went to the Cambridge FoodCycle hub to get an idea of the “product” and the “customers”, coming back with content that then went into strategy and marketing. 5 Whys and Customer Development anyone?

I have a passion of coding: Rails programmer, I evangelize Ruby every time I can. Unfortunately FoodCycle’s website was using another language, PHP. No frameworks, no database. I allowed me an hour to try to at least import it into a framework using SQLite for the database, the time constraints were tight.

No luck: CakePHP was the more Rails-like, but the support to SQLite was crap. Yii and Symfony were so ugly I couldn’t look at them. Kohana and CodeIgniter were nice but the time was up. So I coded the administration backend and the new main page in plain PHP. For non-techies: it's like to build your bike from zero instead of inflating the tyres, before starting the race. I didn't have time to find another bike that I could use***.

Meanwhile, other people were producing great stuff on other aspects of spreading the message of FoodCycle: the new tagline, the strategy for developing and growing the reality, a stop frame animation and a story video. In two days!!!

Contributing was so great. The satisfaction of getting shit done for good is awesome. The guys from FoodCycle were so happy. And, as a hardcore learner, I was thrilled by the skills of people present in the room, so much things I didn’t ever think about, that now I have to research.

But the best part, was the human side of the event: imagine meeting dozens of people, practically living in an open space together for two days, eating, talking, joking, with music in the background. Doesn’t it remind you of a high school trip?

To summarise, I think the guys from Good for Nothing had a great idea: donating expertise. What do you usually do if you want to help a cause? You donate money. But money is only a raw resource. It’s like handing a box of Spaghetti to a homeless. Yes, it’s food, but you have to cook it.

When you donate your expertise, it’s different: you give the final product they need and that is usually hard to find, even with money. Anyone paid a developer or a designer and didn’t get what requested or got it after ages? Ten-fold value is added by people working in teams, with founders next to them.

So next time you donate, try thinking if you could use that brain and hands of yours instead, to change the world by yourself, maybe even only for a weekend.

If you got thrilled by this story, come to the next event. If you didn’t, come as well, as you may understand once you are there. There is only one word for it: awesomeness.

A big thank you to every person that was there****.

 

* Good for Nothing is a community project that fosters creative collaboration to do some good for nothing.

** FoodCycle combines volunteers, surplus food and a free kitchen space to create nutritious meals and positive social change in the community. It's a place where people that suffer denutrition or are usually alone go to find good food and share a laugh together. Its reality is all about slow food and creating connections between people.

*** The new pages will be live on the website in about two weeks.

**** You can read the conversations by searching for the tag #goodfornothing on Twitter.

 

El Coq: a new restaurant that makes you dream

He has worked at a Michelin starred restaurant right after coming out from high school, at one of the best restaurants of London, at one of the best restaurants of Australia, he has cooked for the delight of Ferran Adria in San Sebastian and eaten with him himself at El Bulli when it was closed to the public, he has worked at the restaurant that now is renowned as the best-in-the-world, surpassing even El Bulli, in Denmark... if you are in Northern Italy and you don't go to the newly opened restaurant of Lorenzo Cogo you will miss surely the next thing. The owner of a 3-Michelin-star restaurant has been seen there taking photos at the dishes.

219778_101824883240773_100002397847498_13897_4176144_o

Do I need to say anything more?

Site: http://www.elcoq.com

Map: http://bit.ly/ll7DFs

Twitter: http://twitter.com/#!/ELCOQRISTORANTE

How to use CoffeeScript in Rails 3.1 with Haml

I'll explain briefly how CoffeeScript is used in Rails 3.1. First create the gemset with RVM (you are using it right??!) in a test directory:

rvm --create --rvmrc default@example_app

Install Rails 3.1:

gem install rails -v=3.1.0.beta1 --no-ri --no-rdoc

Generate a new app including jQuery (shipped by default in 3.1):

rails new example_app -j

Add coffee-script and haml gems to Gemfile and run Bundler:

gem 'coffee-script'
gem 'haml'

If you see the layout file, Erb or Haml if you already converted it, the include for javascripts refers only to 'application'. And you don't need anything other in Rails 3.1. Sprockets will automagically include in application.js (with the aid of the gem jquery-rails) the concatenation of:

  • jQuery;
  • rails.js;
  • any javascript file present in app/assets/javascripts;
  • any compiled javascript from the coffeescripts living in app/assets/javascripts.

Now try to generate a scaffold:

rails g scaffold post title:string body:text

You can see that aside from the usual stuff, some assets were generated, with the new integrated CoffeeScript format (no need for the barista gem):

invoke assets
  app/assets/javascripts/posts.js.coffee
  app/assets/stylesheets/posts.css.scss

OK, now example of CoffeeScript, that you can try to run by writing it in posts.js.coffee and then firing up /posts in your browser:

If you then look at the source code of the page and open application.js you see Sprockets puts jQuery and concatenates all the javascripts!

For in page CoffeeScript with Haml, like when you use the command javascript_tag: use coffee-filter. Add coffee-filter to Gemfile:

gem 'coffee-filter'

Then use CoffeeScript interpolation to get Ruby variables inside CoffeeScript blocks, i.e.:

What if I want to release my Javascript without views... well, there isn't a way in Rails, just use a Rake task. My example, using closure-compiler gem to compress the code, no need for barista:

Then from the Rails root:

rake release:js

Well... great job Rails team!

First time with CoffeeScript

For my new website I'm using Rails 3 and after the flamewar for the fact that Rails 3.1 will be including CoffeeScript support at default, I was curious to try it. Just added the gems barista and therubyracer to my Rails project, restarted thin, created the folder app/coffeescripts and written my first .coffee file.

I needed a facility to write/read cookies with Javascript, I looked for jQuery plugins but I only found crap. So I used low level code from http://www.quirksmode.org/js/cookies.html and translated it into CoffeeScript.

 

Original Javascript

function createCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function eraseCookie(name) {
        createCookie(name,"",-1);
}

The original javascript isn't exactly the best code I've run in, but does its job.

 

CoffeeScript

createCookie = (name,value,days) ->
        if days
                date = new Date()
                date.setTime(date.getTime() + (days * 24 * 60 * 60 * 365))
                expires = "; expires=" + date.toGMTString()
        else
                expires = ""
        document.cookie = name + "=" + value + expires + "; path=/";

readCookie = (name) ->
        nameEQ = name + "="
        cookie_array = document.cookie.split(';')
        for value in cookie_array
                value = value.substring(1, value.length) while (value.charAt(0) == ' ')
                return value.substring(nameEQ.length, value.length) if value.indexOf(nameEQ) == 0

eraseCookie = (name) ->
        createCookie(name,"",-1)

The syntax of CoffeeScript reminds a lot Ruby, in fact you can see it's very compact and clear. Uses also indentation as Haml/Sass. I'm quite satisfied.

 

Generated Javascript

(function() {
  var createCookie, eraseCookie, readCookie;
  createCookie = function(name, value, days) {
    var date, expires;
    if (days) {
      date = new Date();
      date.setTime(date.getTime() + (days * 24 * 60 * 60 * 365));
      expires = "; expires=" + date.toGMTString();
    } else {
      expires = "";
    }
    return document.cookie = name + "=" + value + expires + "; path=/";
  };
  readCookie = function(name) {
    var cookie_array, nameEQ, value, _i, _len;
    nameEQ = name + "=";
    cookie_array = document.cookie.split(';');
    for (_i = 0, _len = cookie_array.length; _i < _len; _i++) {
      value = cookie_array[_i];
      while (value.charAt(0) === ' ') {
        value = value.substring(1, value.length);
      }
      if (value.indexOf(nameEQ) === 0) {
        return value.substring(nameEQ.length, value.length);
      }
    }
  };
  eraseCookie = function(name) {
    return createCookie(name, "", -1);
  };
}).call(this);

The generated Javascript was absolutely what I was expecting after reading CoffeeScript's documentation. Good job. Code could be a little more compact though, as you see there are braces that could be removed around i.e. an if clause in the readCookie function.

In the end I'd say this is a nice improvement over plain javascript, as you can use all native Javascript functionalities or jQuery with this cool syntax.

EDIT: it'd be also nice to have alert print automatically the content of objects, translating in something like this. Or better:

alert JSON.stringify visitor

Why Twitter should add the Vote Up feature

Let-me-think-what-is-best
The other day I was reading through all my tweets with Nambu and noticed I only stopped on about 3 out of 10, while skipping the others. So I thought: «I'd wish to have a system that could tell me which are the most interesting tweets!» A day after that, Google shipped his social feature +1. It's one of the moments you think «Crap! See I was right, they implemented my idea.» Not that whining about it does anything positive, I know that if I don't put an idea to work, it just remains a cristallized entity with no value.

So my beloved Twitter, I'm calling you out. It would be fairly simple to take existent ideas and apply them to your case. The algorithm (spam proof) could be as simple as:

  1. every tweet starts at 0 points;
  2. every time I click "vote up" on a tweet, the author significance for my stream grows by 1;
  3. every time one of the people I follow votes up the tweet importance for my stream increases by 1.
  • I can vote up a tweet only once (undo functionality useful);
  • I cannot vote up my own tweets;
  • points could include retweets.

An example: @TechCrunch importance for me (47) + importance for the tweet from the people I follow (12) + retweets from people I follow (3) = tweet importance for me (62)

I think this could improve the process of reading a personal tweet stream, especially for people that are busy and/or are following a lot of tweeple. The web app could build on this information to highlight the tweets over an arbitrary threshold or hide the ones below that threshold. The thing is, signal/noise ratio isn't very high nowadays, so a little filtering could help and people originated filters are way better than Bayesian et similia. Moreover, referring to the post So a bar walks into an app..., when Twitter points out that «there are still significant benefits to increasing awareness of what’s happening outside the home timeline», 3rd level (followed by whom you follow) people votes could help in that, by avoiding to just shove random tweets in the user's stream.

Now... who is going to vote me up? :-)

Start Cup Veneto '11

I received an invite from Start Cup Veneto to participate to the next competition. I'm not a great expert of entrepreneurship, but still I spotted several flaws in its process.

First and most important: they award the group with the best business plan. What the hell is that? When the advanced world is going to focus on business models, creating MVPs in a weekend and testing on the street, they still believe a business plan has a real value? Bloody useless. And how is the winner chosen, out of air? Choosing the best only by judging from a business plan, is like guessing when the next volcano eruption is. Where's the prototype? There is a saying that goes like «No business plan survives at the first contact with the customer». Do you know what that means?

Second: the mail I received is so anonymous it seems like they're a robot talking to another robot. First line reads "Dear Sir/Madam"... at the very least they could have personalized the title, because I know they have the contact database of all the universities of Veneto and it doesn't require a massive amount of time to code that. (if some of the organizers is reading) Yes, who you are talking to is still a person.

Third: there is no Twitter account to read the updates and have realtime feedback. Get to 2011.

Fourth: why the minimum number of people in a group should be 3? What if I want to be a solopreneur? Or have only a partner? There are several cases that demonstrate that 2 is just fine. The only requirement is that the group must have skills in selling, designing and implementing the product. Finding another person just to fill the third spot is harmful at its best.

Fifth: there is little emphasis on mentors, that is in my opinion one of the most important services provided by the Cup. I'd want to see the list of the Angels, names and what they achieved; if I see someone well-known for his experience, I'd be a lot more interested in participating. This of course is not valid only for myself.

Sixth: I tried to write in their forum to give feedback. Wanting to help is not ordinary, nearly no-one of your customers does, especially with constructive critics. So you have to facilitate the process. What did I find? I had to subscribe to leave a message (ever heard about OAuth or Disqus?). Not only that. When I opened the sign up form, I found 20+ mandatory fields to fill in! No way I'm doing that. It feels like I have to be punished to join a forum/website. Moreover, the website generally feels like a '90s portal.

Well now I remember why I left Italy.

Veneto, if only you wanted, you could be globally competitive. If only...

(I will send this to the email address they have in the contact section)