Pedro Assunção

Adventures at the Indian embassy (or how Portuguese services suck)

Disclaimer: I’m not complaining specifically against the way the Indian embassy works so, before calling a xenophobic or some crap like that, keep in mind that i’m just venting out something that could have happened in pretty much any other Portuguese public bureau.

Where should i start? Ah, yes, the motivation: In about a month i am supposed to go to India in a business trip and – as such – i will require a visa.

I went to the embassy on Wednesday morning only to find out that visa applications are not handled on Wednesdays. Just my luck! It was clearly my fault, since i did not properly check the opening times on their – extremely hard to find – website. Did i mention you spend one hour in traffic just to get there? Suffice to say i was pissed, though mostly at myself. I did try to call them, but the automated response only directed people to their website. Why they bother having a phone is beyond me.

The next day i went back again (1 more hour in traffic) and finally got a ticket. The system works like this: You wait in the streets until a security guard calls you. Then he checks to see if your papers are all in order, and finally gives you a numbered ticket and sends you into the actual waiting/service room where you… wait some more. I arrived at the gate at around 11 am. I got ticket number 35. The embassy opens at 9.30 and they only had served around 19 tickets. I did my math and promptly went back home, at the risk of spending the entire day waiting. Again – probably my fault – but one should take some time to see the number of people that uses our services and get the appropriate amount of workers to be able to deal with them in a timely fashion. Two workers for 50 people, when the average time per person is 20 minutes, will not work.

Third day: Decided that i should be one of the first people to get there and get a ticket. Left home around 8 am. Arrived at the embassy at 9:15. Got ticket number 4. Not bad. Funny fact about lines in portugal: they don’t exist. I arrived at the embassy gate and there were around 10 people there already (the embassy opens at 9.30, though they only started actually working at 10). I asked politely “is there a line?” and was greeted with the response “not really, you know how it is with us portuguese, we just remember who came first”. This is exactly the kind of crap that pisses me off: lack of order and organization. But then again, looking at my living room right now, i shouldn’t really complain :)

So, i got my number and went ahead into the waiting room. Now, the website states that – for business visas – one is required the following:

- Invitation letter from the Indian partner,

OR

- Invitation letter from the Portuguese company explaining the details of the visit.

Note the emphasized “OR”.

After waiting for roughly 30 minutes, the lady tells me that i’m missing a letter from my company (i only had the one from the Indian company). I tried to explain that the website said i only needed that one but there was nothing that could be done. She told me how long it would take, explained that it had to be analyzed by two different entities and told me how much it would cost. Since – up until then – i saw everyone paying in cash i decided it would be a good idea to ask if they accepted cards. No cards. Really? What century is this? And you could put out a sign explaining that so that i would know about it – oh call me crazy – before i waited in line or – i don’t know – you could put it IN YOUR WEBSITE?

So here’s my summary of improvements, if anyone closely related to the Indian embassy in Portugal reads this and cares enough to help people not waste their time and money getting a freaking visa:

  1. Update your website! Seriously, read that again: Update your website. It’s the 21st century and pretty much everyone uses the web to know information about this kind of things;
  2. Put up a sign that you do not take cards as a method of payment. I do understand why you make the entrance process so explicitly phased, but people need to know what to count on when they get in there. I don’t want to stand in line for 1 hour (a very typical case, trust me) only to find out i cannot pay with my card. Also, see point number 1!
  3. Get more people working there. Clearly the waiting times should tell you that you are understaffed.

There, ended up being constructive. I feel much better now :)

UPDATE: As a good friend of mine very well pointed out, i should help other people find their website :)


Review: TotalFinder – Finder on steroids

Today i want to tell you about the best thing since canned tuna: a fantastic application that extends Finder’s functionality to provide you with features like tabs, cut-and-paste, dual-mode, and more. You know, the things that all of us have missed in Finder, one time or another. It’s appropriately named TotalFinder (in honor, i’m guessing, of the TotalCommander application).

Here’s a rundown of the features that i love and the ones i kind of like, as well as a few suggestions on what could be added or improved:

What i kind of like, but would probably change

Tabs

Tabs

Tabs : It’s nice to have the possibility of endless tabs, but i have trouble imagining having more than 2-3 open in any given window. It’s not a bad thing, but i think TotalFinder could totally get away with the dual-mode (maybe throwing in a tri-mode into the mix).

What i love

Cut and paste : Been missing this feature ever since i bought my first mac. I love Apple, but i think sometimes they just assume that people are dumb and fail to provide some tools that we consider basic needs. This is one of them and TotalFinder brings it back to us.

Dual mode

Dual mode

The dual mode : The ability to look at two different folders in the same window is something that you will never want to live without again. Sure, you can open two finder windows and put them side by side. But it’s a much slower process. In TotalFinder all you need to do is press Command + T (opens a new tab, so you have 2) and then Command + U. Presto! Dual mode goodness.

The visor : Combine the dual mode above with the Visor and you have the best Finder experience ever! The visor is something like the Quake terminal (remember? the one that slided into view so you could type all the cheats in? :) ); It sits out of sight until you press a global shortcut (typically ALT + `) and then slides from the bottom of the screen. It’s the best way to always have a Finder window around.

Folders on top : Call me old fashioned, but i do believe that folders should always be shown before files in any list. I can’t explain why, but it just makes sense to me. And if it also makes sense to you, then TotalFinder allows you to set this option :)

Hidden files/folders

Hidden files/folders

Show hidden/system files : Again, Apple is protecting us from ourselves. I understand the motivation but sometimes i really want to see the hidden files. Especially for developers and powerusers who, from times to times, need to edit those dotSomething files (i.e. .bash_profile) this is a must-have!

Suggestions

Dual mode button in the bar : It wasn’t immediately apparent to me how to activate the dual-mode. I think it would be much simpler if there was a button in the bar, next to the quick-look and view mode buttons. Maybe it’s not even possible to implement, due to the Finder’s restrictions, so i’m just throwing it out there :)

Quick find folder feature : One thing i keep coming back to, when using file explorers, is the lack of a nice way to find a certain folder. I know i can use Finder’s search field, but then i have to specify that i’m searching by filename, and in the entire drive, and bla bla bla. A “find folder by name” feature would be a great addition to Finder, in my opinion.

Conclusion

TotalFinder is a great addition to your file/folder handling arsenal. It will bring back features that you missed for a long long time and are surprised Apple does not provide out-of-the-box. It’s not free. But then again, it’s a one man operation building a great product that will definitely give you more than the $15 you’ll pay for it. You can also get a 3 pack for $30 and offer 2 licenses to your friends :)

Bottom line: totally worth it!


Learning to sit-fly

Free flying is hard work, i’ll tell you that. It’s always very easy to watch guys like the Skywalkers, Omar Alhegelan, Tim Porter, and other skydiving idols and think: “hey, i could do that”. But what we tend to forget is that, like most things in life that are worth doing, it takes time, dedication, and a lot of hard work to make them look easy.

Last weekend at the DZ me and my pal “totaly” tried a couple of exits in a sitting grip and the result, though undisputedly hilarious, was not what i was expecting. I feel i’m getting a lot better at sit flying, but when it comes to grips, man, do i need to practice.

Enjoy the video, we know we did love creating it, hehe!

Blue skies! ;)

Évora – 2010-12-19 from Pedro Assunção on Vimeo.


Spring and hibernate: Lazy loading collections in desktop (swing) applications

So here’s something you can’t find on the internets. Or at least i couldn’t, when i was trying to find a way to do this.

The problem:

Traditionally, spring and hibernate have been mostly used in web applications. In this case, you can easily define your domain objects to have lazy collections because spring/hibernate will keep an open session during the whole handling of each web request. This means that you can access lazy loading objects even in your views (provided you use the open session in view filter ;) ).

Now, in desktop applications you usually don’t go around having open sessions all the time which means that, unfortunately, when you try to get a lazy loading collection, hibernate will give you a big finger in the form of a LazyInitializationException due to the fact of no open sessions existing.

One solution:

My application’s structure is such that no UI classes are being managed by spring (and by this i mean your mileage may vary with this solution), only my services and data access objects (DAOs) are. The UI accesses the services by use of a ServiceLocator pattern (which can be more or less complex, depending on your needs) and the DAOs in the services are autowired. The rest is just spring plumbing.

The way i found more elegant to deal with the lazy loading problem is the following. Take this bean (for the sake of simplicity some annotations or methods might be missing, beware):

@Entity
public class MyBean {
  @Column(name = "NAME")
  private String name;

  @CollectionOfElements(fetch = FetchType.LAZY)
  private Set<AnotherBean> children;

  public Set<AnotherBean> getChildren() {
    return children;
  }
}

If you try to access getChildren() hibernate will complain so i changed the method to this:

public Set<AnotherBean> getChildren() {

  children = DBUtils.initializeIfNeeded(this, children);
  return children;
}

And here’s the definition of that static method:

public static <T> Set<T> initializeIfNeeded(Object obj, Set<T> collection) {

  if (!(collection instanceof PersistentCollection)) {

    return Sets.newHashSet();
  }

  if (!((PersistentCollection) collection).wasInitialized()) {

    ServiceLocator.get(CompanyDA.class).initializeLazyCollection(obj, collection);
  }

  return collection != null ? collection : Sets.<T>newHashSet();
}

What we are doing is checking whether this collection is a instance of hibernate’s PersistentCollection and, if not, getting out. If it is, and hasn’t been initialized, we call a special method in the super of all my DAO’s that is responsible for asking hibernate to initialize the collection. Take into account that this method has to be inside a spring managed bean (i.e. non static) otherwise it won’t be able to open a new session and you’re back to square one.

Here’s the definition of that method in the DAO:

public void initializeLazyCollection(Object obj, Collection<? extends Object> collection) {
  sessionFactory.getCurrentSession().lock(obj, LockMode.NONE);
  new HibernateTemplate(sessionFactory).initialize(collection);
}

Hope this helps anyone and if you know of a better way to do the same thing, please share :)

Peace out.


Lighter naval ships made of aluminum foam

I can’t believe this is so hard to find on Google. Someone sent me a documentary video (in Portuguese – unfortunately – but, if you understand German, the creators of this idea speak in their native language) and i can find hardly any references to this online.

It’s basically about using a special aluminum powder that, when heated, transforms into a foam that is – check it out – lighter than water. Yes, imagine ships 30% lighter, that can carry many many more tons of materials. Less trips = less pollution = win/win ;)

Here’s a link to a 1998 paper about this.

I wonder if this technology is already in use in today’s ships and, if not, why?


Is your Safari 5 slow? Here’s a probable problem and solution.

I could not figure out why the hell Safari 5 was running so slow in my personal mac, when compared with the one i use for work. Until i read some nice tips on the subject, namely this one article.

To make the story short: I had installed (a long long time ago) a couple of plugins (not to be confused with the new extensions) and completely forgot about them. One of them was the cause for Safari to completely block for 5-10 seconds at a time and show me the spinning color onion. I don’t care which one but, bottom line is, one probable cause for your problem is a misbehaved plugin.

The safest way to check is to go to Preferences -> Security and disable the plugins. Then restart the browser and check if the problem went away. If so, point Finder to ~/Library/Internet Plug-Ins and move the files to another folder. Enable the plugins again in the browser and restart. If it’s still fast, then that was your problem. Now the only thing left to do is to re-add them to the folder one by one, until you figure out which one is making Safari suck ;)

Happy hunting :)


Kinect-related injuries

Being able to play games without having a remote sounds awesome, but it’s not without its perils. To prove it, here’s a video of a Kinect session that went wrong. You can see this one and a few more on CrunchGear’s original article.

I’m pretty sure we are going to see a lot more of these popping up on youtube :)


Java Web Start (jnlp) simple example

Folder structure

One of my current projects requires me to deliver a Swing application via Java Web Start. This meant some research to figure out how that works. Since i’m a nice guy, here’s the result for everyone that needs it.

As you can see – in the folder structure image – there are some files that are required for the whole thing to work. Here’s a brief explanation about each of them (in my creation order ;) ):

  • src/org/Test.java : My source code. It’s just a simple main that creates a JFrame and displays it;
  • Manifest.txt : The manifest file used to create the jar file that gets served by Java Web Start;
  • faren.jar : My application’s jar. I’ll explain how to create it in a while;
  • faren.jnlp : The Java Web Start description file;
  • faren.html : The html file that contains the button to start the application.

The first thing we want to do is create the source file. In the case of my simple test, here are its contents (blank lines removed for brevity):

Test.java

package org;

import javax.swing.JFrame;
import java.awt.Dimension;

public class Test {
  public Test() {
    JFrame faren = new JFrame("Test");
    faren.setSize(new Dimension(300, 300));
    faren.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    faren.setVisible(true);
  }
  public static void main(String[] args) {
    new Test();
  }
}

Moving on to the jar manifest file, it basically just says what the main class will be:

Manifest.txt

Main-Class: org.Test

Creating the jar is as simple as running the following command:

jar cfm faren.jar Manifest.txt org

It creates the faren.jar file, using the manifest file and the sources contained within the org folder. If – like me – you use Maven, you will have this for free using the app-assembler plugin, but for the test’s purposes i didn’t want to create a full maven project :)

Now we need to define a description file for the Java Web Start mechanism:

faren.jnlp

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="file:///Users/pedroassuncao/Desktop/jnlp_example">
  <information>
    <title>Dynamic Tree Demo</title>
    <vendor>Dynamic Team</vendor>
  </information>
  <resources>
    <!-- Application Resources -->
    <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="faren.jar" main="true" />
  </resources>
  <application-desc
    name="Dynamic Tree Demo Application"
    main-class="org.Test"
    width="300"
    height="300">
  </application-desc>
  <update check="background"/>
</jnlp>

Just to explain a little bit of what is going on in here (the important parts), what you want to make sure is that the codebase property is set correctly to the absolute path where the html file will be served from (in the case of a final deployment this will be something like http://myserver/jnlp/myapp, but in this case i’m serving without a web server, hence the file:/// part). You will also want to define a minimum version for the virtual machine of the client (the 1.6+ part) and eventually extend this information with the <shortcut> tag, that allows you to ask web start to create a desktop icon for your application on the clients’ computers. A full description of the structure of this file can be found here.

Finally, we need an html file that will show the java web start button. The following will suffice for now:

faren.html

<html>
  <head></head>
  <body>
    <script src="http://www.java.com/js/deployJava.js"></script>
    <script>
      // using JavaScript to get location of JNLP file relative to HTML page
      var dir = location.href.substring(0, location.href.lastIndexOf('/')+1);
      var url = dir + "faren.jnlp";
      deployJava.createWebStartLaunchButton(url, '1.6.0');
    </script>
    <noscript>
      <a href="faren.jnlp">Launch</a>
    </noscript>
  </body>
</html>

If the client’s browser supports javascript, this will use a special script from the java website that will ask to install the virtual machine if the client does not have it (or upgrade an existing one). If he doesn’t support javascript it will just show a link that will try to launch the java web start (depending a lot on whether the user’s file associations are correct (i.e. .jnlp files being assigned to the java executable).

Finally, with all this in place, point your browser to the place where you have the faren.html file and click the button; the application should launch.

By the way, does anyone know why my desktop shortcut is not being added on OSX? :)


Summing up Apple’s keynote

Apple had an event yesterday. And i saw that it was goooood. Seriously now, i was pleasantly surprised by – well – the surprises that were shown by Steve and co. Here’s a brief sum of coolness:

iLife 11

This update to the iLife family of products is one of the best ever, in my opinion.

iPhoto got yet more social features into it, like the ability to display your Facebook photo albums, as well as comments from your friends on those photos, and the fact that you can zoom to a particular part of the world map and, with one click, see the pictures inside that area. Other interesting features include a full screen mode, that takes away everything that is peripherical when organizing your pictures. They also introduced new slideshow templates and the books feature is very, very enhanced, showing a bookcase with all the photo book projects you have created and giving you complete control on the generation of the book.

iMovie also was added a lot of nice new features. The most notable include the long waited ability to edit audio directly in the timeline, like adjusting the sound level (even for just parts of a clip) and do fade ins and fade outs. Another great feature is the trailers part. It can now help you take your favorite footage and create movie-trailer-like movies, effortlessly. I can see myself using almost all these features in my podcast :D

GarageBand got some love as well: Between the ability to match the groove, or beat, of a track to another one, hence turning out-of-sync tracks into fully synced ones (which looks like magic), and a feature that reminds me of Guitar Hero called “How did i play”, GarageBand gets an incredible boost in terms of helpful features for artists and aspiring musicians.

No word on the rest of the products, but i can imagine some updates as well, though probably minor.

FaceTime for Mac

Yep, it’s here and fully available. You can now make video calls between iPhones and Macs (or macs and macs as well). Pretty awesome, though i wonder what will happen to iChat, and why wasn’t that integrated…

Mac AppStore

Will be available in 90 days time (yes, also for Snow Leopard) and will rock. These guys are going to make a ton of money on this thing. And for the end user, well, it means no longer manually installing updates for your favorite apps or using the (somehow) disparate software update mechanism in OSX.

MacBook Air

In one word: “Freakinawesome:)
No more spinning drives (yes, that means no optical drive as well: goodbye DVDs), which pretty much makes them lighter and smaller. 2 versions are available, one 13 inch and one 11 inch. The prices go from $999 to $1599, depending on the version and options you want.

OSX 10.7 Lion

They showed off some new features, though the most notable ones are:

  • A new dashboard: Where you can see all your installed apps from the Mac AppStore, like you do one your iPhone (yes, sliding panels and everything), and group them as well;
  • Full screen apps. Meaning, real fullscreen goodness for your applications. They basically want to make Lion a bridge between traditional OSX and the iOS, where every app is basically fullscreen;
  • Something called mission control, where you can see an overview of every app that is running on your Mac, be it fullscreen or windowed. Think Exposé, but better arranged.

What about you? What are your thoughts on Apple’s new features?


How does one change his domain name without losing hits?

I recently decided to drop one of the domain names that points to my blog. After (finally) getting the proper domain (pedroassuncao.com), i figured there was no sense anymore in keeping the old one (diffract.me).

Now here’s the problem: A lot of google links that bring a huge percentage of my traffic are pointing to the old one. That explains why – from last week to this one – i got a 90% traffic decrease in visits and page views. I definitely should have done something to prevent or at least minimize this “problem”, but i didn’t.

So my question is: What could i have done? Anyone out there has had this problem before? If so, what did you do to mitigate it?

UPDATE: Thanks for all the comments, that was really helpful. One in particular (by Ryan) explains a nice solution really in detail.


Google releases URL shortener and introduces new image format

Google is on a rampage. After opening up it’s short URL service to the general public, it now introduced a new image format (WebP) which they claim to achieve “an average 39% reduction in file size”. I wonder how long it will take for applications like Adobe Photoshop to include support for it.

As a bonus, in Google’s goo.gl (that’s the name of the URL shortening service), if you append .qr in any link you get the QR code for that link. This is especially useful for mobile devices to rapidly open links from their cameras. Try it out, here’s a link to my blog’s QR code. If you have a mobile device that can read QR codes it will open my main page in a browser. Very smart of them to allow this, as it will definitely be an advantage over other URL “shorteners”. Until they copy the feature, that is :)


Did a Russian scientist just invent an anti-aging pill?

He seems to be a very respected scientist in his field, with a lot of publications and a job at a very prestigious university. Even Gunter Blobel, a biochemist and Nobel laureate seems to respect him quite a bit. Is it just a couple of years until we are able to remain young and healthy – potentially – forever? Who never dreamed of living forever? I sure do!

Taken from here


Schiphol-Amsterdam : Airport security at its best

There i was at gate D83 (or should i say 53?), waiting for my flight back to Portugal when something suddenly starts beeping. I turn to look and see a man washing the floor who had just stepped through an unused set of security gates that is laying around there (see picture).

If i’m not mistaken, these (probably older) gates used to have security checks done here, instead of at the main central place where this happens nowadays. I saw these a couple of times before, though i always assumed them to be deactivated. So when the cleaning man passed through it i couldn’t help but thinking the potential for experiments. I mean, anyone can potentially play around with it and “try out” which items go through undetected and which will be safely concealed. Call me paranoid, but i think it’s already bad that the general public is allowed to be near these things unsupervised, much less the damn things being turned on.


Google instant is pretty awesome

Google Instant results

In case you missed the Google event, they are rolling out a new feature called “Instant”. It basically shows you search results as you type the query in the search box.

Currently i could only have it working on Chrome at www.google.com (can’t be any other suffix, like co.uk, pt, etc.) but you definitely need to see it at work to appreciate it. It makes it much easier to find what you are looking for when you can change the results on the fly, if you are not happy with what you got :)