Coffee-Shit

I had it. I’m sick and tired of this nonsense. People, Devs in the specific, should pull their head out of their ass right now and act like adults. What am I on about? I’m about re-factored, recompiled languages. Stuff like CoffeShit (yeah, Coffee-SHIT - so what?). Who the fuck cares? Come on people, are we really saying that the grammar of a language makes you a better/smarter/faster developer? This is BULLSHIT! Grammar has nothing to do with the quality of your code or with your development speed. NOTHING! ...

June 2, 2011 Â· 5 min Â· 1049 words

Thinking out aloud: a JavaScript based console?

In the last month or two I started contributing to PhantomJS: PhantomJS logo PhantomJS is a headless WebKit with JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG. PhantomJS is an optimal solution for headless testing of web-based applications, site scraping, pages capture, SVG renderer, PDF converter and many other use cases. The project is really interesting and we are seeing a steady growth in terms of: ...

May 5, 2011 Â· 4 min Â· 679 words

From Wordpress to Bloggart

This post has been in my “TODO list” long enough. It’s time to put it in words. Let’s go! As you probably know, I decided to give up Wordpress.org in favour of Bloggart on App Engine. A great choice so far I must say. Migration, a proper one What I wanted to achieve My aim was to migrate more than 6 years of content (posts and comments) from my previous blog at detronizator.org into a bloggart installation. Why bloggart? Nick Johnson, the original author of Bloggart on Appengine, wrote a series of article on how to build a nice, little, smart blogging app on App Engine. At the same time, work on txty.mobi started to get more and more engaging, making me a lover (and advocate) of Google App Engine. Plus, I was interested in “starting from scratch”: Wordpress.org is a great project, but I just didn’t feel it “mine enough”. My blog must feel really mine: it’s about me after all. ...

October 11, 2010 Â· 8 min Â· 1498 words

gredirector - 'HTTP 301' through App Engine

When I decided to migrate to this new blog I was confronted by a very important issue: how do I make sure that the (already modest) traffic going to http://www.detronizator.org/* would be redirected to this new URL? 301 Redirection I started searching and I found this article by Danny Tuppeny on how to use a Google App Engine application to do the trick. So, what I did was to take his code and started putting it in place for me at http://redirector.ivandemarino.me. But because I’m a Software Developer that likes to make elegant stuff, I noticed that quite few things were missing: ...

September 29, 2010 Â· 5 min Â· 966 words

3 o'clock javascript

I was writing some code to react at a textarea.onKeyUp. I take the size of the current textarea.val().length, update an element and do some other stuff. yawn The first version of the code looked like: 1 2 3 4 $('#message').keyup(function(e){ $('#chars_num').html( new_len ); $('#sms_num').html( Math.floor($('#message').val().length / 161) +1) ); }); Working good, but was clearly slow: every keystroke was “giving back the cursor” too slowly for a fast typer like me. I went to take a look at twitter, and their text box was WAY FASTER. ...

March 28, 2010 Â· 1 min Â· 201 words

Binary Tree Rebuilder

Imagine you have a Binary Tree, with those characteristics: * Nodes do not respect any order relation - In other words: it's <strong>not</strong> a [Binary Search Tree](http://en.wikipedia.org/wiki/Binary_search_tree) of any kind * Every node appears <em>once and only once</em> within the tree A nice Binary Tree Then, your little brother passes by your desk and, to upset you, deletes the tree from your computer memory/HD (yeah, I know, I’m pathetic at inventing hypothetical situations :-P ). Fortunately though, you previously did a Pre-Order and an In-Order visit of your tree, and stored the result in an 2 nice array. Can you rebuild the original tree structure out of this 2 array? How are you going to rebuild it? Yes, you can! (Sorry, I couldn't resist). And it's quite easy as well. What you have to do, is the following: Take the first element of the PreOrder Array and use it as root of a new tree Find the position of this New Node in the InOrder Array, scanning it from 0 to n-1 (n is the number of Nodes) IF next element in the PreOrder Array is on the left of the New Node in the InOrder array: call RECURSIVELY this procedure, this time taking into account the portion of InOrder array that goes from 0 to the position of the New Node in the InOrder Array -1. IF next element in the PreOrder Array is on the right of the New Node in the InOrder array: call RECURSIVELY this procedure, this time taking into account the portion of InOrder array that goes from the position of the New Node in the InOrder Array +1 to n-1. Return the New Node By the way, this doesn’t work. To fix it we should be more generic, specifying things a little bit better. Things like: * Every recursive calls takes into account a portion of the InOrder array; in the case of the first call it's the entire array * There is going to be as much recursive calls as the number of elements in the PreOrder array Of course, is a tree what we are talking about here: recursion is a MUST. ...

February 5, 2010 Â· 5 min Â· 862 words

Prime Numbers Generator

I believe I don’t have to describe what primes are, what are their properties and what not. This post is more a tribute to geek-ness of 2 friends-and-colleagues (@lucabox) that have fun thinking of algorithms to solve stupid (or less stupid), and always useless problems ;-) . Optimus Prime :-P - yeah yeah, a stupid joke Briefing This code is based on the assumption that we want to generate very very large primes, so it uses unsigned long long to store the values, instead of classical unsigned int. Live with that. ...

January 23, 2010 Â· 4 min Â· 760 words

"Bidirectionally multiplied" array

Another small problem before I go to sleep tonight: There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1] will be multiplication of A[0] and from A[2] to A[N-1]. Solve it without division operator and in O(n). ...

January 22, 2010 Â· 2 min Â· 281 words

Use Backtracking to print all Subsets

I’m “studying” this algorithmic technique: Backtracking. This is an algorithmic approach to problem solution that I trust every good Computer Scientist already uses; but taking a good theo-practical look at it is something better. A Backtracking Tree I believe you can find enough informations about it online (the 2 links I provided are more than enough), so I’ll go straight to the problem. Problem definition Given an integer n, and the set S = { 1 … n }, calculate (print) all the possible subsets of S. For example, for n = 1, all the possible subsets are { 1 } and { } (empty set). For n = 2, all the possible subsets are: { 1 2 } { 1 } { 2 } { }. In general, for the set made of the first n Integers, the number of possible subsets is 2n. ...

January 22, 2010 Â· 4 min Â· 833 words

Money change problem: Greedy vs. Dyn.Pro.

This is a classical problem of Computer Science: it’s used to study both Greedy and Dynamic Programming algorithmic techniques. I hate having my pocket full of copper!!! -_- Definition Given: A set of n Denominations D[0…n-1] in ascending order, representing a Monetary Coin System An money amount A, as input calculate a solution: * <strong><code>S[0...n-1]</code></strong>, with <code>0 &lt;= S[i] &lt;= (A/S[i])</code> and <code>0 &lt; i &lt; n-1</code> where: * <strong><code>A = Sum<sub>[i=0 -> n-1]</sub> { D[i] * S[i] }</code></strong> * <strong><code>Min{ Sum<sub>[i=0 -> n-1]</sub> { S[i] } }</code></strong> In other words Find the smallest amount of coins to make the given amount. ...

January 17, 2010 Â· 4 min Â· 778 words