Posts Tagged ‘plugin’

20091117 Delicatessen v2

Let me introduce Delicatessen v2, the new version of my WordPress plug-in for finding out who’s bookmarked your posts in delicious.com

It has taken a bit too long to produce this version, but it at last behaves like a nice netizen, and won’t spam delicious.com with too many queries in a very little time, therefore you won’t get banned ;)

Delicatessen

More info and downloads in the Delicatessen page.

20091102 SyHi: my minimalistic syntax highlighting plug-in for WordPress

I had been using Code Snippet for a year, or a couple of years (I can’t really remember), and was more or less happy with it. Apart from the fact that it didn’t preserve some stuff properly, like double dashes and quotes. So then I tried adding another plug-in to the mix, Preserve Code Formatting. But both at the same time didn’t work out as I expected hoped.

The solution?

I made a new plug-in. It’s very minimalistic, starting with its name: SyHi.

How does it work?

The problem with other plug-ins is that they apply their formatting and then let WordPress continue modifying the posts’ text. That’s a totally bad idea, and that’s why quotes and dashes were systematically altered. On the other hand, this little clever plug-in takes the code blocks apart, sets them aside while leaving placeholder text where they were, and when WordPress has finished with all its filtering and texturizing, SyHi replaces the placeholder texts with the preserved, syntax highlighted beatiful pieces of code that the author entered.

The resulting code not only is nice to look at, but can be copied and pasted into a compiler and it will work with no modifications at all. No more please replace em dashes with double hyphens because WordPress modified the snippet’s output…: your blog readers can now simply copy and paste!

Alphatesters needed

So far I have tested SyHi with a test blog and this blog too. It looks fine, but I would be more than happy if somebody else wants to have a go at testing it. I would even add you to the Thanks section!

Unfortunately, the plug-in is not yet available in the wp-plugins directory; I’m waiting for them to approve my request so that you can install it from within the plugins admin page.

Plug-in page at WordPress directory: SyHi. You can also clone the SyHi github repository or download the latest version from there.

Samples

So you don’t believe me when I say this plug-in works great?

Using Python

noise_output = wave.open('noise.wav', 'w')
noise_output.setparams((2, 2, 44100, 0, 'NONE', 'not compressed'))

for i in range(0, SAMPLE_LEN):
        value = random.randint(-32767, 32767)
        packed_value = struct.pack('h', value)
        noise_output.writeframes(packed_value)
        noise_output.writeframes(packed_value)

noise_output.close()

What about php?

class SyHi
{
        protected $code_blocks;
        protected $geshi_instance = null;

        public function __construct()
        {
                // Execute pre and post process functions before and after each post content is processed
                add_filter('the_content', array(&$this, 'pre_process'), 2);
                add_filter('the_content', array(&$this, 'post_process'), 1000);

                // Same for each comment
                add_filter('comment_text', array(&$this, 'pre_process'), 2);
                add_filter('comment_text', array(&$this, 'post_process'), 1000);

                // Add the css stylesheet link to the <head>
                add_action('wp_head', array(&$this, 'add_css'), 1);
        }
}

OK and what about C/C++?

void luisita_reportErrors(lua_State *L, int st)
{
    if (st != 0)
    {
        std::cerr << "ERROR -- " << lua_tostring(L, -1) << std::endl;
        lua_pop(L, 1); // removes error message
    }
}

As you can see, double dashes are being respected, quotes are kept as they are, and code is nicely highlighted. And if you’re still feeling skeptical, keep browsing posts in this blog, since all code snippets go through SyHi.

Update: added the link to the plug-in’s repository :)

Update 2: let me clarify something: this plug-in can beautify snippets in pretty much every programming language you can think of, thanks to the huge language support provided by GeSHi. I have shown you only three examples as a simple demonstration, but you can even show Z80 assembler code!

The full list of supported languages is in the left column of the GeSHi website, under the Supported Languages header. Heck, it even has support for a language called BrainFuck!

20090818 “If you’re new here, you may want to subscribe to the RSS feed”

And I wonder… why? Why would I want to do that? I just arrived at your site from Google, looking for something which maybe is not exactly what I will find here. I am just looking for something sporadic and very specific. Do you really think your ridiculous message at the top, right where my eyes begin scanning for the information I am looking for, is going to make me –a complete stranger, alien to your words and your editorial line– feel compelled to subscribe to your RSS feed to read your semi-daily musings about God knows what?

I’ll give you the short answer: No!

Most of these messages are generated thanks to the What would Seth Godin Do plugin. While I appreciate the effort of the developer and also think that welcoming newcomers is always a great idea, I am not sure you can build any kind of loyalty by using the plugin and not even changing the default text that comes with it.

The only way of capturing people who get to your blog via a search engine is to offer interesting content. If I like what I find, and the site navigation is nice and easy, without an Adsense ad in between every piece of content, I will probably have a look by myself and maybe I may subscribe to your feed. If, on top of that, you want to add a short Hello, new visitor! message explaining what your site is about, great. But please change the default text or you risk being Yet another WordPress weblog.

20090420 Generate bitmap font: a little plug-in for The Gimp

I made this little plug-in for the Gimp because I needed to generate a fixed-width font bitmap (what I have called a Bitmap Font) to load and use in an application of mine. I then thought that maybe someone would like to learn how to make plug-ins for the Gimp with Python, as I did, so that’s why I’m posting it here.

It turns out to be very simple. Your plug-ins need to be placed in your user’s directory for the Gimp. In my case, that is ~/.gimp-2.6/plug-ins. When the program starts up, it will scan that folder, looking for any possible plug-ins there.

In my case, I decided I wanted to place the plug-in in the File menu, under Create:

File ... Create...

That is done with the register function at the end of the code, amongst other configuration settings for the window that shows up if you select my plug-in:

register(
        "sole_generate_bitmap_font",
        "Generate bitmap font",
        "Generate bitmap font",
        "Soledad Penades",
        "Soledad Penades",
        "2009",
        "<Image>/File/Create/_Generate Bitmap Font",
        "",
        [
                (PF_FONT, "Font", "Font", "04b03"),
                (PF_SPINNER, "Font_Size", "Size", 8, (0, 1000, 1)),
                (PF_RADIO, "orientation", "Orientation", "horizontal",
                        (("_horizontal", "horizontal"), ("_vertical", "vertical"))
                )
        ],
        [],
        sole_generate_bitmap_font)

Generate bitmap font

The plug-in, as it is, offers only few configuration options but if you want more, they can be added very easily. There’s a but: the only thing I couldn’t manage to do is to remove the “Input image” and “Input drawable” options (note they aren’t specified in my code either, it seems they are added automatically).

Once you press ‘OK’, it will create a new document with the selected font. This is an example:
Example bitmap font

Now, that isn’t a fixed width font. When this texture is used for writing texts, it produces text that can be read but feels weird, because that font has not been designed to be used with fixed widths. Anyway, you get the idea. I’m still looking for a fixed width font that I like and find easy to read, so that’s why I’m using this one for the example. It is the classic 04b_03 by 04.

You can take a look at the full source code here and download it here too, directly from the SVN repository. Enjoy it!

20060210 Downthemall: A SuperYouReallyNeedIt extension for firefox

This is way better than flashget, flashgot, download accelerator or anything else you have seen before. And it works under mac, or windows, so you must definitely have it. Get this funky extension DownThemAll right now!

It is specially useful when you are browsing netlabel’s pages which just offer an html view of their archives and you have to download each song one by one… eeek!