Archive for the 'technology' Category

Page 2 of 6

Posting multipart form data using PHP

@shvi asked me for this code over Twitter, I though it would a good idea to share it here.

The following code is used to post two different fields, a simple text data named “somedata” and a file named “somefile”.
Hope it helps :)

$destination = "http://yourdomain.com/yoururl";
 
$eol = "\r\n";
$data = '';
 
$mime_boundary=md5(time());
 
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="somedata"' . $eol . $eol;
$data .= "Some Data" . $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="somefile"; filename="filename.ext"' . $eol;
$data .= 'Content-Type: text/plain' . $eol;
$data .= 'Content-Transfer-Encoding: base64' . $eol . $eol;
$data .= chunk_split(base64_encode("Some file content")) . $eol;
$data .= "--" . $mime_boundary . "--" . $eol . $eol; // finish with two eol's!!
 
$params = array('http' => array(
                  'method' => 'POST',
                  'header' => 'Content-Type: multipart/form-data; boundary=' . $mime_boundary . $eol,
                  'content' => $data
               ));
 
$ctx = stream_context_create($params);
$response = @file_get_contents($destination, FILE_TEXT, $ctx);

I Can Haz Java?

They announced it yesterday at the Google Campfire ’09 (here and here) and it is today on the Google App Engine blog: Java is now supported on Google App Engine!

It comes with a set of Eclipse plugins to test and deploy Java servlets, using JDO or JPA to support database access. Of course, the database behind this is BigTable, which means that a lot of relational features are not available, but it scales!

Go there to get you started, or, if you want to know if your preferred framework will play well with GAE, go to the “Will it play in App Engine” page.

That’s good news! Especially because we may start having more and more Java applications outside of the corporate walls.

Yes Google, YES!

vedovini.net is on Facebook

As you might have noticed already, Facebook as been on vedovini.net since last December. To this purpose I have been using the Sociable! fbConnect plugin for WordPress that enables visitors to login using their Facebook credentials and later comment using their Facebook identity and feature those comments on their Facebook stream.

However, I wanted a deeper integration between this blog and my Facebook profile. Here is what I have done.

In the process of installing the fbConnect plugin you have to create a Facebook application and, among other things, Facebook applications feature a canvas page and an application tab. The canvas page is the main application page, the tab can be added to any user’s or page’s profiles.

To setup the canvas page you specify an URL that will either serve FBML (Facebook markup) or pure HTML. In the latter case the page is displayed in an IFRAME.

Initially, I used the IFRAME version to display the home page but I found awkward to have my blog design mixed with the Facebook design. Additionally this technique cannot be used for tabs, that only support FBML.

Finally, I crafted special pages on this blog that serves only FBML with a special Facebook styling extracted from Foxinni’s Facebook WordPress Theme. The resulting canvas page can bee seen here and the corresponding profile tab is now featured on my own Facebook profile, here (you may not be able to see this one because of Facebook privacy control so I inserted a screenshot below).

If this is getting enough interest I might package it as a WordPress plugin. Leave a comment if you are interested or if you have additional ideas.

UPDATE (2010-03-13): This is now a WordPress plugin, see my plugins page.

What BOINC are you?

SET@HomeI have been participating in the SETI@Home project since January the 6th, 2000 (at this time I was a huge fan of The X-Files and I though it may help Fox Mulder find his lost sister…). Since then I have been installing the SETI@Home client on every desktop or laptop computer I have been using.

For those who do not know what the SETI@Home project is, the goal is to sort out radio signals from the Arecibo radio telescope using grid computing in order to find extraterrestrial signals.

As far as I know this was the very first large scale implementation of a grid based computer and today, with 556,888 machines and 1,393.74 TeraFLOPS per day, I think this can be considered the most powerful super-computer in the world.

We still did not find any track of Samantha Mulder, but what this project has actually proven is that it is possible to use desktop computers idle time to do useful scientific researches.

In 2005, the SETI@Home software became BOINC (Berkeley Open Infrastructure for Network Computing) and mutated into a platform which is now not only supporting the SETI@Home project but many other scientific projects.

When I am not using them, my laptop and my desktop are running the following projects:

What are you doing with your computers’ idle time? If you have BOINC installed, list the projects you are supporting in the comments, if not then install it and become part of the most powerful super-computer in the Solar System ;)

Shooting in the dark

One think I hate about software is when you must integrate with a poorly documented system.

To be able to code and unit test you part you have to make assumptions about the workings of this system, deploy in a real environment (which can be quite time consuming) and pray.

This is like trying to shoot a bear in the dark, if you miss it the first time it will run after you like a delivery deadline. The only thing you can do is try again until you hit or it passes you by…

If you feel any relief in sharing your dreadiest experiences feel free to comment :)