WordPress 2.5

I’ve just upgraded this blog to WordPress 2.5 and so far I love it. The only glitch was an easy-to-fix UTF-8 problem but that’s it. Everything’s working.

By the way, I love its new media browser! It makes it easy to find old items I’ve published ages ago, like the image below :)

Update, 2008-03-31: There is a problem with comment moderation

Update, 2008-03-31: I found the error with the comment moderation! Somehow the updater failed to create an index in the comment_date_gmt column of the wp_comments table! If you fail to manage your comments properly, go to your preferred MySQL interface (command line, or like in my case, phpMyAdmin) and add an index to that column, reload your comment management page, and you’re done!

WWDC 2008: I’ll be there!

I’ve just bought my e-ticket for Apple’s Worldwide Developer Conference 2008! This one will be the first one featuring iPhone developer tracks, and that’s one of the main reasons for me to go. Another good one is that neither Claudia nor me know San Francisco, so it’ll be a great time to hang out and visit the city.

Will you be there? Feel free to leave me a comment and we’ll meet at San Francisco, from June 9th to 13th!

Playing with HTTP libraries

It’s fun to find out how to tackle the same task in different programming languages; in this case, it’s all about doing HTTP requests over a network: fortunately, there are networking libraries in virtually all major programming languages. In my current project, I’m generating wrappers easing the access to the core of the project itself, a RESTful API. This way, developers interested in using the API can just take a wrapper, include it in their projects, and start coding right away. No need to know this (relatively low-level) stuff; just use the API. The wrappers themselves are auto-generated from the API definition itself, but that’s another story ;)

Below there is a sample of the different ways I’ve found to do a network access to a remote server, using HTTP Basic Authentication and a couple of headers, in PHP, Ruby, Python, JavaScript, and even Objective-C! I’m even generating ActionScript 3.0 code, but I’m not a Flash coder :) So I’ll post the wrappers that work best at the moment, and in the future I’ll include other examples, particularly for .NET, C++ and Java.

In all the cases below, there is a “request” function or method that takes an HTTP verb (GET, POST, PUT, DELETE, etc), a URL (without the slash “/” at the beginning) and some parameter data, in the form of a dictionary. The function wraps the underlying libraries of each programming language, offering a simpler interface, and allowing for HTTP Basic Authentication (for HTTP Digest Authentication it would be much, much more complex!). There are synchronous (useful for server or command-line applications) and asynchronous versions (for GUI systems). Off to the code! Continue reading

Screen Savers for the Mac using Flash

This is an evening project that turned out to be really cool. Let’s say that you’re a Macromedia Flash designer, and your clients ask you to bundle your nice Flash movie as a screen saver. What to do? For Windows there are free utilities to convert a SWF into a screen saver, but not for the Mac – and the first commercial one costs around USD 200!

I propose here a simple solution for this problem:

  1. Using Xcode, you can create screen savers (basically, Cocoa apps).
  2. Cocoa applications can host a WebKit component (basically, Safari).
  3. Safari can show local HTML pages (basically, “file:///” stuff).
  4. And HTML pages can show Flash movies (basically, <OBJECT> and <EMBED>)

The idea, then, is to bundle your own page, with your own movie, inside the screen saver bundle, and show the Flash movie this way. Easy said, easy done.

It all goes nice until… you try this solution :) The problem is, Flash movies loaded from “file:///” URLs are blocked by the built-in security mechanisms of Adobe… and you have to find a workaround for that. Mine was to follow the instructions on how to bypass the Flash security mechanism, and then create an installer package that will do what’s needed for you to enjoy the screen saver.

You can get both the project and the installer package in my projects section. I’ve tested the installer in three different machines, and it worked, so I hope it’ll work for you too :) Enjoy! As always, try this at your own risk. Murphy says that things can go wrong, so watch out.

Templates

Did you knew this is possible in C++? I didn’t.

[source:c] void Fun() { class Local { //… member variables … //… member functions … };

// ... code using Local ...

} [/source]

This feature is called “local classes” and is part of the standard; the limitations are that these local classes cannot have static member variables and cannot access nonstatic local variables. But, as Alexandrescu points out (page 28), you can use them in template functions:

[source:c] class Interface { public: virtual void Fun() = 0; // … };

template Interface* makeAdapter(const T& obj, const P& arg) { class Local : public Interface { public: Local(const T& obj, const P& arg) : obj_(obj), arg_(arg) {}

    virtual void Fun()
    {
        obj_.Call(arg_);
    }
private:
    T obj_;
    P arg_;
};
return new Local(obj, arg);

} [/source]

Not only that, but partial template specialization and template-based compile-time verifications just blew me away. The second chapter of the book was realizing I just haven’t had the slightest clue about all the cool things you could do with C++!

Blow your mind

Take a careful look at this:

[source:c]

include

class Gadget { public: void sayHello() const { std::cout << “Gadget!” << std::endl; } };

class Widget { public: void sayHello() const { std::cout << “Widget!” << std::endl; } };

template class OpNewCreator { public: T* create() { std::cout << “Using ‘new’: “; return new T; } };

template class MallocCreator { public: T* create() { std::cout << “Using ‘malloc’: “; void* buf = std::malloc(sizeof(T)); if (!buf) return 0; return new(buf) T; } };

template