Hacker News: Mark All Read Source Code Released

TL;DR: I just released under an MIT license the source code of the Hacker News: Mark All Read Chrome extension. You can find the code on github.

Background: I often thought about open sourcing many of the little projects I create from time to time, but until now I never went on with it. The reason: I’ve got pretty strong perfectionist tendencies against which I’m always struggling, and releasing unpolished code that I’ve quickly hacked up to solve some practical little problem doesn’t bode well with those tendencies.

But with this one I got many feature requests that I already know I won’t have time to implement. So I decided to publish the code anyway and see what happens. Just consider it what it is: A quick hack I created in one afternoon, and polished just a little bit the day after. Have fun with it!

PS: I thought about it and decided not to release the “artwork”, because having more extensions on the Chrome market with the same look would be confusing. The extension works anyway as it is, but if you add a button icon in an “images” folder it will look better.

To discuss on HN: link

Save Time On Hacker News: Mark All Read

Hacker News is and incredibly useful resource for hackers and startuppers. In true hacker style, its usability is pretty basic though.

In the myriad of widgets and extensions that hackers created to improve that usability, I’ve never find the one I wanted most: An optimal way to know which titles I already scanned and didn’t find interesting enough to open. So that, when I reload the home page, I don’t have to scan them again.

This is why I created Hacker News: Mark All Read. It is a (free) Chrome extension that solves exactly that problem, in a very simple way: After you scanned all the titles, you can click the “mark all read” button, and all news items will appear as if you visited the link.

This way, when you reload the page, you can immediately see what is new. It works across different pages (home, new submissions, second page etc.). And you can hide the news you marked as read, for super-fast scanning of the new news.

You can install the extension from the Chrome web store. If you have any comment… please do comment :)

Update: I also released the source code.

OpenVZ howto addendum: Migrating your virtual machines to a new server

As I wrote some time ago, creating your own OpenVZ infrastructure is very easy, and it can save you a lot of money compared to the usual VPS providers. But it also has other advantages.

Hashtagify uses redis to store all its data in memory, which is great for performance, but… it requires a lot of RAM. So it happened that I almost finished my 24GB, right when I learned about a new great offer for a 32GB server which costs 33% less than my 24GB one. Moving to it means that I’m going to get back my 150€ of activation costs in just 5 months, while at the same time having 8GB more. Great!

This is why I bought a new server and decided to move all my virtual machines to it from the old one. It turned out to be quite easy, but I had to find the instructions in different places, so I’ll post here how I did it for both my future reference and for anybody else having the same problem.

First of all, you have to install OpenVZ: I did it just following my previous howto.

Then, you can migrate your machines. I thought I would need to back them up and then restore them in the new server, but I found out there is a more direct and much faster way to do it: The vzmigrate command.

To use it, you first need to enable password-less ssh login from the old server to the new one (this is because vzmigrate uses the ssh protocol to move the files). First, generate your public and private keys if you didn’t already:

ssh-keygen -t rsa

It is important that you create it with no passphrase. Then, move the public key to your new server, like this:

scp /root/.ssh/id_rsa.pub root@XX.XX.XX.XX:./id_rsa.pub

Now log into the new server and do

cd .ssh/
touch authorized_keys2
chmod 600 authorized_keys2
cat ../id_rsa.pub >> authorized_keys2
rm ../id_rsa.pub

After this, in the old server check that everything is ok with:

ssh -2 -v root@XX.XX.XX.XX

If everything is ok, you whould be logged in without being asked for a password. You can log out


and start migrating your machines. For each machine, for example the one with id 101, you do:

vzmigrate -r no XX.XX.XX.XX 101

This will take a pretty long time, depending on how big the virtual machine and how fast the net between the two servers are. There is no progress indicator, but you can get an idea how it is proceeding by checking the original size of the machine and the size of the copied one, by using the command

du -hs /vz/private/101

on the old and the new server respectively (this of course only if you mapped the openvz data directory to /vz as shown in the original howto.

When the command finishes, the new machine is ready… but only if you could move the VM IP from the old to the new server. In my case that wasn’t possible, so I had to ask for new IPs on the new server. You can assign the new IP, and remove the old one, like this:

vzctl set 101 –ipadd NEW.NEW.NEW.NEW –save
vzctl set 101 –ipdel OLD.OLD.OLD.OLD –save

So, now you’re really good to go:

vzctl start 101

And that’s it!


Update CSS rules with 5 lines of CoffeeScript

I recently (ie, today) had to find a way to update a CSS rule dynamically in javascript. jQuery, my library of choice, doesn’t offer this functionality – and I really wonder why – so I looked around a little and found how to do it with plain javascript.

As I’m actually using CoffeeScript, I decided to rewrite it in that language and make it a generic function; it could be useful to others, so, there you go:

@updateCSS = (selector, styles) ->
  for sheet in document.styleSheets
      for rule in sheet.cssRules || sheet.rules || []
        if rule.selectorText == selector
          for style, value of styles
            rule.style[style] = value

You can also find an usage example (and play with it yourself) on jsfiddle. Enjoy :)

The European Tech Scene in Blogging

I’ve been too focused on my work on hashtagify pro lately – the first beta isn’t far, by the way – to notice it when it came out, but this article about the European tech blogging scene is very interesting.

The long and the short of it is that we in Europe should blog more in English, to make it easier to create a European tech community and a more interesting scene to report on. Incidentally, that’s why I started blogging in English for hashtagify, so I just have to agree. I’m also seeing more conversations in English between Europeans, eg on Google+, so I hope we’re headed in the right direction.

Writing in English isn’t as easy as I’d like it to be, but the good signals – both those cited in the article, and those which I can see for myself – make me even more resolute. Let’s all keep our efforts up.

Is the open source/internet singularity coming?

Many have heard about the idea, popularized by Ray Kurzweil, that a technological singularity is coming. In a nutshell, the idea is that as the power of computers is growing exponentially, at some point it will bring about an artificial intelligence that will overtake human intelligence, reinforce itself and change everything beyond any (human) imagination.

I personally don’t believe that the creation of an AI able to compete (let alone surpass) with human intelligence is near at all. But while working on my latest web project, I noticed just how easier it has become to create incredibly powerful and attractive new software than just a few years ago. And all this thanks to Open Source and the internet.

Increasingly, we see amazing new software libraries, frameworks, programming environments being released as (Free) Open Source on the internet. This makes it progressively easier for other people, even solo developers working from home in their free time, to create great software, and often give something back to the Open Source community.

Not just that; the internet is making it easier and easier to find the best new pieces of software, to get answers to the most difficult programming questions, to circulate ideas and to publish the end results of it all. And to bring this all to even the most isolated programmers, in the remotest parts of the world.

Isn’t this all it’s needed to create an exponential growth of software innovation? I guess it is. And I don’t know what this will bring about, but it is a fact that information technology is disrupting lots of industries, with consequences that are harder and harder to predict – as unfortunately the current economic crisis is showing.

I don’t know if this could be the real technological singularity, even without artificial intelligence in the mix, but it could come damn close.

Javascript async testing tutorial: Jasmine + Rails 3.1 + Coffeescript

I recently wanted to create automated testing for coffeescript code in Rails 3.1, including some async (ajax) code. I had to dig around quite a lot, so I’m writing here what I ended up doing for future reference for myself and others who might need it.

There are many test frameworks for javascript, and the one I chose is Jasmine. Reason why: It is one of the two most used frameworks, and the other one is dependent on jQuery. I’m using jQuery in this project, but I’ll be able to use Jasmine for future projects without jQuery too, so I chose it – I also like its syntax.

You can integrate Jasmin in Rails 3.1 yourself just using the Jasmine gem, but to simplify things with Coffeescript I decided to use a specific gem for the latest version of Rails and its assets pipeline. I couldn’t really choose between test_track and jasminerice, which are both very young, so I went with the first one just based on intuition. Using the other one shouldn’t be very different.

So, I added to my gemfile:

gem "jasmine"

gem "test_track"

and installed the new gems with “bundle”

I then created a spec/javascripts and spec/javascripts/helpers folder in the project tree. As I wanted to be able to easily test jQuery, I downloaded jasmine-jquery.js from github and copied it into spec/javascripts/helpers.

At this point I created the following jasmine.js file om spec/javascripts:

// SUITE :: Jasmine
// SUITE MANIFEST :: spec/javascripts/jasmine.js
// TEST SRC DIR :: spec/javascripts
//= require helpers/jasmine-jquery
//= require JsonDataSpec

JsonDataSpec is the coffeescript spec file that I was going to create and that will be executed in the test. See the following example


describe "JsonData", ->
  it 'should should have the correct format', ->
    answer = null
      (data) ->
        answer = data

    waitsFor ->

    runs ->
      expect(typeof answer.string).toEqual('string')
      expect(typeof answer.number).toEqual('number')

The secret here is waitsFor -> answer, which will wait until the answer variable gets a non null value – that is, when the ajax call is complete. Only after that the actual test is run.

Last thing, I configured the test_track engine adding this code to routes.rb:

mount TestTrack::Engine => "test"

And that’s it! To use my tests, I just run the server using rails s and access the tests opening http://localhost:3000/test/jasmine in the browser. Smooth and easy.

Happy testing!

Bootstrapping hashtagify pro: How I doubled my workweek productivity

Creating a startup while working a full time job has its pros and cons. Among the pros, you don’t have to use a lot of your time minding your investors (or looking for them), and you can devote your energies to just make the best possible product. Among the cons, progress is slower and it is very difficult to be productive on workdays, when you already spend 8 hours or more on your day job.

But a week ago I read a comment on HN (edit: thanks to raju in the comments for pointing me to the exact link) that inspired me to rethink how I’m organizing myself , and with one simple change I doubled my productivity on workdays. How? Instead of working on hashtagify at nights, after getting home from my day job, I’m starting my day two hours earlier, and doing 2 hours of programming in the morning, before going to work.

I’m usually a night person, and have always been very productive at nights, since when I was just a student. But after eight hours of work, it is difficult to have that kind of focus that you need to program, and the two (or two and a half) hours in the morning have been much more productive than the equivalent time in the evening.

After coming home I still do some lighter work, and don’t go to bed without having scheduled a task to do the next morning; this way when I wake up I don’t have to think what to do and I can be immediately productive.

So, the bottom line is that work on hashtagify pro is proceeding very well: now I’m making as much progress during the workweek as I usually make during weekends, while before I only made major progress outside workdays. This means that soon enough I’ll be able to release the first beta. Stay tuned!

Got half an hour to kill? Make it useful to the community!

TranslatewikiRecently I was looking for an open source engine to create a stackoverflow-like website in Italian about mortgages. The best alternative I found is Shapado, which is also rails-based, always a plus for me.

Anyway, on their website I found out that they’re going to release a new version soon, and that it still missed an Italian translation. After a little investigation, I also found out that everybody can contribute to that translation on translatewiki.net

I had never heard of that website, which is part of MediaWiki. I decided to give it a try, and after subscribing and waiting a little for approvation, I started translating the latest version of Shapado into Italian.

I would never have believed it, but it was kind of fun! The web translation interface is really very well-thought, the google and bing suggestions are quite helpful (and sometimes funny), and it only took me a couple of hours to translate all the parts that weren’t already translated from the previous release.

The best part is that this is something that you can do whenever you have some free time and a web connection; you are immediately productive, and seeing the list of missing translations becoming shorter by the minute really gives you a good feeling of accomplishment.

So, if you know one language different from English and have a little time to spare, what are waiting for? There are already 20 open source projects on translatewiki waiting for your help. Give them a hand!

Saved by the magical powers of GIT

Yesterday evening I was very happy: My first mobile app, after a little more than a week, was practically finished. It just needed some little finishing touches.

At that point I decided to take a look at it on my phone, after a few days during which I had only tested it on the Android emulator, which allows much faster debugging cycles. So I connected my phone, started deploying the app, waited, started the app… and… crash! It didn’t even open the first screen.

At 12:10 AM and with a long day at my day job waiting for me the next day, I tried to redeploy the app; then, to restart the development environment and redeploy the app; and, last try, to restart the phone and my pc and then redoploy the app. To no avail: It worked perfectly well on the emulator, but on my phone it just wouldn’t start.

So today, after coming home from work, I prepared myself for a LONG debugging session. My plan was to find the latest version on GIT that worked on the phone, and understand what went wrong after that – hoping that there was only one thing that went wrong.

First, I started going just a couple of commits back – I commit very often – to check that the problem was there. It was. Then I tried to remember when I last tried the app on my phone – it had always worked – and checked a version from around that time. I was a little apprehensive by now… but it worked!

I then started the methodical search for the time when the problem came out, so I tried the commit at the middle of the road between the working version and the not-working one. It worked. Then, I again found the middle of the road, and tested. OK. And again: OK. And again: OK! This was just two commits before the not-working one.

At this point, I went up one commit only. It worked. Another one, the last one before my first test (which failed). It worked. Was it possible that, just by chance, I had tested first exactly the commit where the problem arose? Well, I tested it again, to be sure and… surprise, surprise… it worked!! I’m pretty sure that, however much Dijkstra might have liked them, I didn’t use any non-deterministic programming techniques, so I was a little flabbergasted.

Next try, I checked out the master; deployed it; and it worked!

How can I explain it? I’m sorry, but I just can’t. And, as tomorrow I’m going to leave for a short vacation, I don’t even have the time to find out now. I suppose (and hope) that it was just some weird problem in the Titanium compilator, and not in Android itself. If it isn’t either of the, well, I guess I’ll have to suggest adding “Magic” to the list of GIT features.