Bytes for lunch

Visions of a web developer about software creations

Simple jQuery Dropdown button (open source code available)

leave a comment »

A couple days ago I faced a common user interface problem to solve. The design approach involved using a drop down button in a web form.
The idea was pretty simple, but I didn’t find any jquery plugin to accomplish my needs.

So… I decided to build my own. Simple and useful.

Here’s a picture of my drop down button in action:

jQuery Dropdown button in action

Source code available under the MIT license at Github, download here.

Written by bytesforlunch

June 13, 2013 at 6:37 pm

Open Data: my doubts on today’s most used ways for sharing data

leave a comment »

While Open Data is promising, I have doubts on how data is shared

Open Data is one of the best opportunity for people to really know facts about their lifes and how our world works. Open Data is a natural result from what Open Source means for software.

Let me shortly give you the idea at the heart of Open Data:

Open data is the idea that certain data should be freely available to everyone to use and republish as they wish, without restrictions from copyrightpatents or other mechanisms of control.

source: Auer, S. R.; Bizer, C.; Kobilarov, G.; Lehmann, J.; Cyganiak, R.; Ives, Z. (2007). “DBpedia: A Nucleus for a Web of Open Data”. The Semantic Web. Lecture Notes in Computer Science 4825. p. 722.doi:10.1007/978-3-540-76298-0_52ISBN 978-3-540-76297-3, Wikipedia

A lot of great guys in Open Data are facing issues about organizations, licensing and laws. This is a really important effort.
But, on the other hand, I don’t see an organic effort on the technical side. I admit my vision could be limited to what my eyes can see, but it seems there’s a lack of technology in how open data should be deployed.

Maybe not really a “lack of technology”, but it looks like the political arm runs faster than the technology one.
A practical example of what I mean? Yes: it’s unbelievable that a huge part of open data repositories are made of Excel files. It should be strictly avoided. Excel is a closed tool, at least use Open Office. Preferably, use CSV. JSON is even better.

I would like to start a discussion with people in Open Data focusing on which technologies are suitable for open data, offering my skills as a developer to find out pros and cons of each technology.

And you, what do you think about it? Am I missing something?

Written by bytesforlunch

May 21, 2013 at 11:47 pm

Posted in Open Data

JSAutoCaption: a simple JQuery plugin to automatically show alt and title image attributes

leave a comment »

Some days ago, I’ve been talking to a friend of mine when he gave me a nice idea. He was looking for a jQuery plugin to automatically extract alt and title attributes from an IMG tag and display them under the image.

Wow, such a funny task!

So I did it. It’s simple, and it plays right!

Here’s a couple of screenshots


The text under the image has been automatically extracted from alt and title attributes of your image.


HTML code

Like it? You can get it!

I’m so happy when I give even a little contribute to the open source community.

I release this plugin under the terms of the MIT License. So have fun.

Source code and live example available here, at the great JSFiddle.

Written by bytesforlunch

February 21, 2013 at 6:29 pm

Finest Tools: introducing AppleScript

leave a comment »

I bought my first Apple computer ten months ago, and a day doesn’t pass without discovering new exciting features of my Macintosh.

A few weeks ago I wrote a post about HyperCard, a great piece of software born from Bill Atkinson, Dan Winkler and Apple.
A few days after, I happily discovered that something similar already existed in my Mac, under a different name: AppleScript. In this post I’m gonna show you how to accomplish basic tasks with it.

Introducing AppleScript

ApplesScript is used to automate actions of the Macintosh operating system. You can script commands to run applications, open documents, browse the web, copy files, store informations, etc. Furthermore, AppleScript is perfectly suitable for database applications, searching and organizing data. One of the coolest things in AppleScript is it can be programmed in plain english, and best of all, it’s a built-in software that comes with your Macintosh.

How it works

A set of instructions is called “Script”. An interpreter executes the commands to interact with the applications and the system. These commands are written in AppleScript, an english-like computer language that contains verbs, nouns, adjectives, articles and other English elements we use everyday.

A script is created in AppleScript Editor, a free tool included wih the platform. It’s extremely simple to use, with a clear toolbar.

An important point to remember is that AppleScript considers everything an object, with properties that can be changed to model the behavior of your script.

Make your computer talk

Let’s try to create our first script. First, launch the AppleScript editor. A window like that one shown in figure will appear.

Now, write this command

SAY “Hello”

and press Run. Nice! Your computer talks.

Now let’s do something useful. Write this:

tell application “Finder” to open home

and press Run.

A window displaying your Home folder content will appear.

Now let’s see how to play with Google Chrome. We’re gonna open it and load a website.

tell application “Google Chrome”
    set theUrl to “”
end tell

Pushing a tool to the max

Even if we just scratched  the surface of AppleScript, I hope to stimulate users to be serious about pushing their expensive computer to the max.

As a practical example, I use AppleScript to automate the process of starting tools for coding. It’s a great accomplishment to automate the tedious process of opening your IDE, your browser with some preferred urls, a couple of Finder windows and a MAMP server.

Here my very simple script for starting coding tools:

tell application “TextMate”


   open “/Applications/MAMP/htdocs”

end tell

tell application “Cyberduck”


end tell

tell application “MAMP”


end tell

tell application “Google Chrome”

   make new window

   set URL of active tab of window 1 tohttp://localhost:8888/pixcone/”

   set myTab to make new tab at end of tabs of window 1

   set URL of myTab to”

   set musTab to make new tab at end of tabs of window 1

   set URL of musTab to”

end tell

say “Happy coding”

Enjoy Applescript!

Written by bytesforlunch

December 5, 2012 at 12:07 am

Posted in AppleScript

Parsing JSON string in javascript

leave a comment »

All we know how JSON is good at describing objects. It is compact and clear, and brings a lot of benefits when used as a transport vehicle for informations between applications. When I say JSON my mind immediately think about REST. Yes, such a great DUO: REST+JSON.

That being said, using JSON requires for an application to parse JSON strings.
In this post I’m gonna talk about parsing strings to JSON objects.

Option 1: Eval() (is not always the evil)

When parsing json strings, a common choice is using the javascript function Eval().

A lot of programmers consider using the  function eval a bad practice. All around the Internet, it seems there’s a psychosis about it.
I argue that this is not always the truth. Actually, it depends on the context. As everything in software, you must know it before use it.

Eval is a javascript function that evaluates an expression. It can be used to run a piece of code, or to evaluate an expression.
Calling Eval to parse a json string invokes the compiler, and the result is a native javascript object that is naturally understood by javascript.
Yes, Eval has some points to be taken in consideration.

First, there’s a security issue. Invoking Eval on a piece of code means to execute it. So be sure that code is trusted. Consider where that json is coming from, and do the math.

var myObject = eval('(' + myJSONtext + ')');

I think  eval() is a good choice to parse json string, especially when you trust the origin of the string.

Option 2: JSON.parse

This is the most suggested way to parse json strings.
Please note that JSON.parse uses the eval() at its core, but it does some control on the input, so it’s considered better.
JSON.parse is supported by the majority of today’s browser, but if you need to provide a backward compatibility, you can download the famous Douglas Crockfors’s library.

Option 3: JQuery

JQuery has a solution for almost everything in the javascript world. Check this:


Do you wonder if JQuery uses eval() internally?

Well, we just need to see the JQuery code.

parseJSON: function( data ) {
if ( !data || typeof data !== "string") {
return null;

// Make sure leading/trailing whitespace is removed (IE can’t handle it)
data = jQuery.trim( data );

// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
return window.JSON.parse( data );

// Make sure the incoming data is actual JSON
// Logic borrowed from
if ( rvalidchars.test( data.replace( rvalidescape, “@” )
.replace( rvalidtokens, “]” )
.replace( rvalidbraces, “”)) ) {

return ( new Function( “return ” + data ) )();

jQuery.error( “Invalid JSON: ” + data );

(taken from

Ok, as we can see, JQuery used JSON.parse except for old browsers, where it uses this construct:

return (new Function(‘return ‘ + data))();

Using new Function makes the code operating only on its local variables, giving it a more secure context.


JSON support is officially part of JavaScript since Decembre 2009, when ECMAScript Programming
Language Standard – Fifth Edition was adopted by the ECMA General Assembly.

Even if we would like our users to be using modern browser, sometimes we need to cope with backward compatibility. For most cases, json2.js is the best choice.

Written by bytesforlunch

November 15, 2012 at 9:12 pm

Posted in Javascript, JQuery

A taste of Semantic Web

with one comment

For sure, Semantic Web is one of the most heard word on the Internet.
But how many people can really use it? Due to its steep learning curve and its manifold nature, penetration of semantic techniques in web development is still poor.
In this post I’m gonna show you how to implement simple Semantic techniques in a web page.

Why the Semantic Web?

Everyday, the most of information we get from the web comes by algorithms that mainly look at text. This is because the majority of web pages are made up by human-readable words.

The base principle of the semantic web is to provide metadata for giving text a meaning. Several techniques are on the table, the one we’re gonna see is Microdata.

Microdata consists of annotating the DOM of a web page with  scoped key/value pairs, that give meta-informations about the thing they’re related to.

Let’s see an example.

Some days ago I’ve published a web application (PixCone) and I wanted to add information about myself using semantic definitions.

As a side note, please keep in account that on summer 2011 the big three (Google, Yahoo and Bing) launched an initiative to endorse Schemas and Microdata as key technologies for their search algorithms. You do the math…

A simple example: the author section

Before to dig into the example, we should spend a few words on defining the concept of Schema.

Annotating html tags with microdata means to add new attributes to describe the entity. Most of times these attributes already exist, and must be conformed to a particular Schema. A schema is a definition of an object. See here to read more.

In the next piece of code we’re going to add semantic data to the author section of a page. This is a relevant chunk of informations because tells the world who created what.

Let’s give a look at the code

<div itemscope itemtype=””&gt;
<span itemprop=”name”>Francesco Ricceri</span><br>
<span itemprop=”title”>Software Developer</span><br>
<span itemprop=”worksFor”>Pix Cone</span>

Job completed! We have defined a few properties of a “Person” schema.

The line n.2 declares the schema which the object belongs to. In this case we’re giving informations about the author, which is a Person.
Person is defined as a schema. More info here.

Lines 3-4-5 are pretty easy to understand.

With a few lines of code, we made this section to be understood by machines. Great! This is your first step in the world of semantic web.

Microdata in action

One of the Chrome plugins I find absolutely useful is Semantic Inspector. It allows to find semantic data in a web page.

Here’s what I see in the Pixcone homepage.


By clicking on the Semantic Inspector, we’ll see semantic informations sniffed by the plugin:



Now some links I consider a good starting point.


Written by bytesforlunch

November 6, 2012 at 11:46 pm

Posted in Semantic Web

When computer programmers were heroes – Bill Atkinson and Hypercard

with 5 comments


Bill Atkinson demonstrating Hypercard in an episode of Computer Chronicles

In this post I’m going to talk about the golden era of computer, when programmers where heroes.

They spent their days crafting great software, giving all their skills and attitudes to the computer science.
They simply loved what they were doing, just for the sake of building quality and innovative products.

Most of them, are still loving computer programming today and making great stuff.

Today, what are we doing as computer people? We have huge computational power, great machines, all the documentation we need, but we don’t use it at all.

Furthermore, it seems  the majority of software strategies are driven only by money and profit, despite of programmers creativity and software quality.

Go back to the 80′s: introducing HyperCard

Wow, such a lot of time has passed from  1985, when Bill Atkinson started the development of HyperCard. That time, HyperCard was a disruptive innovation. It was a software built for the Apple Macintosh and the Apple II GS.

The idea at the heart of HyperCard was simple and  clever: a stack of virtual cards. Each card contains clickable objects, hyperlink, text and images, buttons, table and charts. By clicking on an object, user could perform an action, such as execute a piece of code or go to another card. This was the principle behind the hypertext.

The result was a cool piece of software, where users could navigate from a card to another to extract information, find cards that provide calculations, or that show images and texts. Common applications of HyperCard were  database oriented systems with an high level of interaction.

Why the name HyperCard? The name came from the rolodex, a popular object where a stack of circular cards hold hand-written information.

One of the crucial features of HyperCard was the script section, where a user could write instructions to the software. Instructions were in english, making the task of query the system very natural and easy.

I saw a video presentation of HyperCard (link is provided below) where Bill Atkinson queries HyperCard by writing “find horse” and the system returns the first card with an horse on top of it.
I got impressed by the high level of User-Experience quality that emerges  by that video. For example, once you find a card, if the user clicks on the top of the card then the system presents the next card, and so on.

Simple, clever, amazing.

Since HyperCard was a programmable system, a huge community of developers emerged, bringing to light tons of fresh software for various fields: accounting, estimation, retail and sales package, even videogames.

The language at the core of HyperCard was HyperTalk, created by Dan Winkler, and it was object oriented and easily extensible. Hypertalk was thought for non professional, and its easy-to-use nature was the reason of its big success. Thousands of stacks where written, originating a class of software known as “Stackware”.

A little bit of history

The work started in 1985, with the first release in August 1987. Apple managed to time the release of HyperCard to coincide with the MacWorld Conference in Boston, Massachusetts, and it was a great success.

Between 1989 and 2000, a couple of new versions were made (HyperCard 2.0 and 3.0), then the project was stopped.
Apple ceased selling HyperCard on March 2004.

A lesson of quality and creativity for today programmers and entrepreneurs

The story of HyperCard is one of passion and heart, that brought more than a great software: a whole ecosystem of software, where other people could work on. It’s a story of success from a brand that made the excellence as its core flagship, despite of costs.

In the official biography of Steve Jobs, I read that one day he decided to rewrite the heart of their operating system. Programmers told him: “Hey Steve, this is simply unrealizable. It’s impossible, there’s high risk of errors, it’ll take too much time to get done.”

Then, Steve simply said the guys. “Ok, I understand. We must do it”.

And today we have Apple OS X.


To see the complete tv episode of Computer Chronicles, where HyperCard was presented (I really suggest you to see, it’s a piece of computer history!):

Computer Chronicles tv episode, HyperCard (on

Wikipedia article on HyperCard

Wikipedia article on HyperTalk

Who is Bill Atkinson?

Written by bytesforlunch

October 23, 2012 at 11:03 pm


Get every new post delivered to your Inbox.