Marcello Barnaba Homepage (A Blog)

Section: development

Facebook Developer Garage 2009, Milan (Italy)

This is my recap of the first italian facebook developer garage, held in milan on April 23, 2009, and hosted by mikamai. The morning has been dedicated to developer sessions, the afternoon to marketing & communication ones. Some videos of the event are available here.

Morning: developer session

The first talk was held by James Leszczenski, facebook engineer, who presented the connect platform vision, mission, and values. interesting, besides the talk, for user participation: the audience was deeply interested about which information they get from facebook, how should they handle it, and which means connect does provide to match identities and find friends on an enabled web site.

Later I had the occasion to ask James about whether FB was inclined or not to adopt OpenID as an authentication method: [ ... ]

continue reading >>>

Posted at 23PM on 04/26/09 | 1 comment | Filed Under: development politics

Implementing an image gallery using facebox and will_paginate

On VisitaCSA we’re using defunkt’s facebox to show places images at large. Facebox is a great general-purpose lightbox, because it is fast, stable, is based on jQuery and has got a really clean API.

But we needed more than a simple display lightbox, because we wanted our users to navigate easily between all images, possibly without modifying facebox at all. The solution turned out to be pretty simple, thanks also to the will_paginate plugin we were already using. It all burns out to have:

  • A Photo model, instrumented with the has_attachment method
  • Resource routes for photos (map.resources :photos, :only => :show in config/routes.rb)
  • A show controller method in the PhotosController that calls .paginate with a :per_page argument of 1
  • An HTML view for the photo resource, that has pagination controls using the will_paginate helper
  • Some jQuery code hooks onto the pagination links and make the browser load via AJAX the next photo directly into the facebox.

continue reading >>>

Posted at 00AM on 02/22/09 | 1 comment | Filed Under: development

The obfuscated blinking border

This is the obfuscated piece of Javascript code that implements the red border and loads Google Analytics on the Segmentation Fault site :


     77   <script type="text/javascript">// <![CDATA[
     78   var theLoadSequenceToRunAfterTheDocumentHasBeenLoaded = function() {
     79
     80     // The blinking border
     81     //
     82     (function(t){// (C) 2009 vjt <segmentation-fault@core-dumped.info>
     83       var $=function(_){return(document.getElementById(_));};var ee =[
     84       $('n'),$('s'),$('w'),$('e')],e,_=true;setInterval(function(){for
     85       (var i=ee.length;i&&(e=ee[--i]) ;_) {e.className=e.className?'':
     86       'b';}},t*08); /* .oOo.oOo.oOo. ^^^^^ -*** * *** *** *******- **/
     87     })((4 + 8 + 15 + 16 + 23 + 42) * Math.PI / Math.E + 42/*166.81*/);
     88
     89     // Google analytics
     90     //
     91     try{var pt=_gat._getTracker("UA-1123581-3"); pt._trackPageview();}
     92     catch($aMarvellousErrorThatWontBeDisplayedOnTheUserBrowserAtAll){}
     93
     94   }// end of theLoadSequenceToRunAfterTheDocumentHasBeenLoaded routine
     95   //]]></script>

To me, it looks like a contrived melody, or complicated poetry. It’s evil engineering, I know. But when I was writing it, I felt exactly the same I did while writing verses with rhymes. _why’s words are absolutely pertinent here: “until programmers stop acting like obfuscation is morally hazardous, they’re not artists, just kids who don’t want their food to touch.”.

You can view the code with syntax hilighting on github, or with the “View source” function of your browser while you’re on the segfault site. :)

Posted at 04AM on 02/20/09 | 0 comments | Filed Under: development

How to mirror a static copy of the opensource.org website

I currently maintain the italian mirror of the Open Source Initiative web site, and today I realized that the script I wrote some months ago wasn’t doing its job well.. because the CSS files weren’t downloaded at all, causing a rather unpleasant rendering of the site.

To mirror opensource org I’m currently using the plain’ol GNU Wget -r—mirror and so on. While the good’ol wget downloads each page prerequisite defined in the HTML source, it doesn’t support @import CSS rules, and doesn’t download images referenced in CSS with url() rules.

BTW, nothing that can’t be resolved with some regex-fu: that’s why I’m sharing the script I’m currently using to mirror the opensource.org web site, hoping it will generate either a new mirror or some insights on how to do this job better :).

The script: update_opensource_mirror.sh

Enjoy! :)

Posted at 18PM on 02/10/09 | 0 comments | Filed Under: development

Continuous evolution


releases$ du -sch *
7.6M    20081209132347
7.0M    20081209133350
7.6M    20081209144343
7.1M    20081209145133
7.1M    20081209151843
7.1M    20081209163013
7.1M    20081209175506
7.1M    20081209183553
7.1M    20081211122939
8.6M    20081212190026
8.3M    20081212201852
8.3M    20081212203943
8.3M    20081212205430
8.3M    20081213014847
8.3M    20081213020357
8.4M    20081213163428
8.4M    20081213173633

continue reading >>>

Posted at 14PM on 02/03/09 | 0 comments | Filed Under: development number 42

A permalink_fu improvement: allow modification of permalinks and send HTTP redirects on-the-fly

Another spin-off from the www.visitacsa.it website: a permalink_fu improvement that allows dynamic permalinks. I know it is an oximoron, because permalinks should be .. well .. permanent! And because search engines index them, they should never change. But what happens when you publish something, your permalink is generated with permalink_fu using the title of your post, and after a couple of days you want to change the title, and the permalink under which the post is accessible as well?

Following the specification, your app should send out a 301 moved permanently HTTP status when accessing the old permalink and redirect the client to the new Uniform Resource Locator. That’s quite the same thing what my modification to permalink_fu does: whenever your post attributes are changed, the former and new permalinks are saved to the database, and you can enable your controller to generate 302 moved temporarily redirects when needed. In other words, it checks whether the requested URL is an old permalink, and automagically redirects the client to the new one.

continue reading >>>

Posted at 19PM on 01/29/09 | 2 comments | Filed Under: development

The jQuery ajax-upload-fu plugin

I recently wrote jQuery plug-in, that allows AJAX file uploads without using a fixed file input button. It achieves its goals by installing an OnMouseMove handler over the selected elements, and moving the input button under the mouse cursor.

The quote that inspired this code is: “If Muhammad won’t go to the the mountain, the mountain will come to Muhammad”,the opposite of the more known proverb :).

It has been spinned off from the Visita CSA application JavaScript codebase, see the gist for more information, and have a look onto the live app code for an example of its usage.

Here is the source code:

continue reading >>>

Posted at 09AM on 01/29/09 | 0 comments | Filed Under: development

Pushing git commit messages to lighthouse in a batch

If you use github-provided lighthouse integration, from the “Admin” pages of your git repository, you may have stumbled upon on a glitch: every changeset on lighthouse appears as done by the lighthouse user that configured the integration on github.

This happens because lighthouse uses the API token to link changeset authors to LH users, and that’s not good when you’re not alone committing :-).

A simple solution is to use a post-commit hook, as described here, but that’s not satisfactory because it means that every time you issue git commit on your console, the commit message will go public, and if you --amend or reset --soft the index you’ll have to browse to lighthouse and delete the changeset.

A much smarter solution is to push all changed revs when pushing them to github: I modified the original post-commit hook and installed it alongside the git command in $(dirname `which git`)/<b>git-lh</b>.

continue reading >>>

Posted at 15PM on 10/22/08 | 1 comment | Filed Under: development

myousica.com was born today

Today we released the output of 9 months of hard work: myousica.com, a social networking site for musicians. Have a look at the promo video and check out the site. Have fun! :)

http://myousica.com

UPDATE 2009/02/23: The site is now paused.

Posted at 22PM on 09/11/08 | 1 comment | Filed Under: development

Remove a lightwindow trigger link after an AJAX call

Well, this is the result of 2 days of head-banging with lightwindow:

Index: public/javascripts/lightwindow.js, line 444
  _removeLink : function(removed) {
    // remove it from the links array
    //
    this.links = this.links.reject(function(link) {
      if (link == removed.href)
     return true;
    });
    // remove it from the gallery links array
    //
    if (gallery = this._getGalleryInfo(removed.rel)) {
      klass = gallery[0];
      name = gallery[1];
      if (this.galleries[klass] && this.galleries[klass][name]) {
        this.galleries[klass][name] = 
          this.galleries[klass][name].reject(function(link) {
            if (link == removed.href)
              return true;
          });
      }
    }
  },

call this function from your .rjs template, something like this:

page << "myLightWindow._removeLink($('element').down('a.lightwindow'));" 

More details to follow, when this work will be complete ;).

Posted at 17PM on 05/21/08 | 0 comments | Filed Under: development

Python2.4's urllib2 broken by default on Solaris Express 5.11

While happily installing prerequisites to build an app on Solaris 11, i enjoyed having Mercurial already installed in the base syste”.. except for a BIG issue: digest authentication was broken. I tcpdump’ed the traffic exchanged between the mercurial client and the CGI server and I saw that no Authorization header was sent, and obivously the server refused to serve the hg repository.

Before reinstalling python, maybe from source and replacing the default installation or having side by side two different versions, with consequent nuisances and dirt around the system, I tried a very very small patch to urllib2.py that… amusingly enough, fixed my problem:

continue reading >>>

Posted at 03AM on 01/25/08 | 0 comments | Filed Under: development

Active Gibberish

UPDATE: you don’t need this code, because starting from the 2.2 version of Rails, localization support is built-in.

Localization for Active Record error messages

Today i had to answer to one of the questions every non-english Rails developer stumbles upon now or after.. how to localize AR error messages for pleasant appearance to a non-english customer ;).

First off, thanks to “defunkt’s”: http://errtheblog.com excellent gibberish plugin and to the way AR validation errors are exposed, the task was accomplished in an easy and clean manner, without messing too much with AR’s internals.

continue reading >>>

Posted at 21PM on 01/22/08 | 0 comments | Filed Under: development

About

This is sindro.me, a weblog by Marcello Barnaba (@vjt) about technology, ruby, development, software, the internet, entertainment, politics, sociology, and the answer to Life, Universe, and Everything (42).

Links