Category: Programming
Hoje em dia cada vez temos mais Javascript nos sites que produzimos. Existem “milhentas” bibliotecas giras que usamos para produzir experiências teoricamente mais ricas para os visitantes dos web sites. Vê-se de tudo, desde bibliotecas para efeitos visuais, até frameworks de AJAX incluindo também os nosso próprios ficheiros de script.
O download destes ficheiros corresponde a um overhead considerável, e por isso mesmo enquanto estava, recentemente, a trabalhar num site recorrendo à framework Adobe Spry, pesquisei sobre formas de minimar este peso extra no download. Encontrei uma entrada de um blog bastante interessante. Compara algumas abordagens.
A redução do tamanho de um ficheiro de código Javascript pode ser realizada removendo todos os caracteres dispensáveis: comentários, quebras de linha, espaços, etc. O código continua a ser válido, e correctamente interpretado, perdendo apenas a legibilidade. Encontra-se “na moda” haver versões de debug e release para bibliotecas Javascript por esta razão.
Pode-se ainda aproveitar a capacidade de compressão no protocolo HTTP e reduzir ainda mais o tamanho dos ficheiros, tendo sempre em consideração que vai implicar processamento extra no lado do cliente, pois o que foi comprimido tem de ser descomprimido, de forma a poder ser interpretado.
Deixo a comparação entre 2 métodos distintos de redução de tamanho de ficheiros javascript, que dá bem a ideia do compromisso que está em causa.

Para utilizar ficheiros em Javascript “gzipped” basta utilizar uma ferramenta que comprima neste formato, compactar o ficheiro e colocar o ficheiro gzip no atributo src da tag script.
Exemplo: <script type=”text/javascritpt” src=”mylib.js.gz”/>
I’ve been working in college assignment which goal is to integrate several information systems. One of those is a website where we can see the flight schedules from/to Portuguese airports.
The website URL is http://www.innovata-llc.com/ana/default.asp. Me and a colleague of mine had to write a web service that was used by BizTalk as a wrapper of this web site’s form. It was supposed to send an HTTP request passing some request parameters using POST parameters, and to parse the HTML response in order to extract the flight list for a given destination city and departure date.
First of all lets see the code we used to get the response.
Uri address = new Uri(requestURL);
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.Method = “POST”;
request.ContentType = “application/x-www-form-urlencoded”;
StringBuilder data = new StringBuilder();
data.Append(“DPT_Date=” + “17-05-2008″);
data.Append(“&RET_Date=” + “20-05-2008″);
data.Append(“&dpt_station=” + “LIS”);
data.Append(“&arv_station=” + “LHR”);
data.Append(“&non_stops=” + “on”);
// Create a byte array of the data we want to send
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
// Set the content length in the request headers
request.ContentLength = byteData.Length;
// Write data
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
// Get response
String htmlResponse;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
// Get the response string
htmlResponse = reader.ReadToEnd();
}
After getting the response content is time to use a nice HTML parser helper library. It is called HTML Agility Pack and it is open-source. You can find it at Codeplex.com/htmlagilitypack.
Now it is time to create an HtmlDocument (a class which ships with HTML Agility Pack) and load the response into this new instance. //Load HTML as XHTML
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(htmlResponse);
After looking to the HTML source code, we got the right Xpath expressions to extract the flight list.
//Get flight lines
HtmlNodeCollection flights = htmlDoc.DocumentNode.SelectNodes(
“//body/div/table[3]/tr[position()>=4 and position()<last()-1]“);
foreach (HtmlNode flight in flights)
{
//Get attributes
string departureTime = flight.ChildNodes[1].FirstChild.InnerText;
string arrivalTime = flight.ChildNodes[3].FirstChild.InnerText;
//Do some stuff …
}
That’s almost it. The next step was adding the extracted information into some data structures, and returning that data. But these details are out of this post scope.
During this week I’ve been experiencing some problems with browser caching.
I’ve a dynamically generated XML file which contents change a lot (it is a photo gallery based on Slide.Show), and I want the people who see this gallery to see newly added photos immediately. Today someone asked me how to prevent the client-side caching (regarding Slide.Show too), so I did some searches and testing in order to enlight us both.
I’ve found reference to a few lines of code which should be used in ASP.NET web pages to prevent caching.
Response.CacheControl = “no-cache”;
Response.AddHeader(”Pragma”, “no-cache”);
Response.Expires = 0;
I tried the first one alone both in IE 7 and Firefox 2 and it seamed to be enough, nevertheless, being care is never enough,so I’ll probably use the 3 lines together!
Just try to be careful and don’t feel tempted to prevent caching in every single web page in your web site, it leads to poor perfomance in both your servers and in the client side. And every one likes to see the content of a previously visited page rendered quickly, right? 

Yesterday I had a nice surprise in my e-mail inbox! I passed in the certification exame I took in January. It is great news, since I just took this exam just as a first time experience with Microsoft Certification Exams.
I took part in the Beta Program of this exam, so I took it for free. And another great thing was the background that the preparation gave me in workflow engines, pretty useful now that I am learning about Microsoft BizTalk.
A great book that I read was Microsoft Windows Workflow Foundation Step by Step.
More details about the certification can be found in the Preparation Guide.
Today I’ve upgraded my blot to WordPress 2.5. I had a problem with this upgrade… The front page of my website showed the “Sorry, no posts matched your criteria.” message instead of my latest posts list.
After diving into the WordPress engine source code, I realised that it was trying to open my homepage as a single post (using the correspondent template). The is_home() function was returning false, and the is_single() was returning true…
I still don’t know the cause of this behavior, but I got it fixed by using my programmer hammer.
In the index.php file, I added the following line:
$_SERVER['REQUEST_URI']=’/page/1′;
This way, the engine renders the first page of posts instead of the single post page.
P.S.: I don’t like the new WordPress administration interface. 
Last weekend I had a great time at Madrid (Spain), sponsored by West Icon, the company which I work for. The goal of this trip was to learn more about Adobe Air in, as a follow up action of the Flex Camp seminar at ISCTE which had a great impact in the company perspective about the impact of Rich Internet Applications (RIA’s) on the web. During the last couple of weeks we’ve been starting to work with Adobe Flex and Adobe Air in a new product (still top secret
). onAIR tour event was great to get some tips about nice functionalities of Adobe Air. This was the first event of the European tour and it went pretty well.
We went to Madrid by car. A loooong trip. we arrived on Saturday, and headed to Parque Warner. It was great! I just love Superman, and because of that I just love the fountain bellow. The Superman roller coaster was pretty awesome. I really felt like flying.

The weather was great. And during this season, there isn’t a lot of people in the park. The longest wait we had was about 15 minutes, in Superman roller coaster. I can’t even imagine how crowded this place can be in Summer… We paid 25 € per person. This is the price when entering into the park after 4:00pm (it closes at 10:00pm). During this time of the year, it is plenty of time to visit the park. The place is beautiful, and makes you feel like you’re in a Warner film. You can to the Daily Planet, or visit Bat-cave!
I really liked the Wild West area too. A lot of emotions and excitement can be achieved in the several attractions like the roller coasters. I even saw Batman driving his Bat-car in front of Gotham City city hall! Children were delighted to take photos with him! Jerry was in the streets too. I wonder where was Tom… He wasn’t chasing him.

In the photo bellow you can see Atocha train station. It is pretty big, and really beautiful. It is the central point in public transportation in Madrid (unfortunately you may know it only because of the terrorist attacks at March 11th…).
Right next to Atocha station, there is a great art center, called Museo Nacional Reina Sofia. We were pretty lucky, because the entry was free, and there was a temporary exhibit of Picasso paintings (The collection of the National Museum Picasso of Paris). But those that I really loved were Salvador Dali’s paintings. Madrid is a pretty nice city, but I hate Spanish food, and I prefer Barcelona rather than Madrid. Nevertheless, it is worth to visit, and I really mean it.

onAIR event was pretty nice. Since this was the first event of the European tour, the sessions weren’t recorded yet. But because Portuguese people are awesome, riaPT (Rich Internet Applications Portuguese Community) guys recorded the sessions by their own, and they are available in their blog.
You can take a loot at the agenda in the official website. I only have one complaint: the event was supposed to be in English, but there were some sessions in Spanish… Luckily it was pretty easy to understand.

During the breaks I was able to try Guitar Hero for X-Box 360. It is nice, but I wouldn’t buy it. Maybe a friend of mine will, and then I can enjoy it. I also playing Wii Sports in the Wii that was available in the Gaming area.