2010-06-23

Blogger Page Title Hack

If your Blogger blog posts come up in search engines as "My Wonderfully Great Blog: Name of my post that...", it's being cut off where it matters! It's better to have the post name first, and your blog site name after, so that search engine results don't chop off the most specific part describing your blog post.

To change that in Blogger, go to your Settings tab and click on Edit HTML. Then replace:

<title><data:blog.pageTitle/></title>

with:

<b:if cond="data:blog.pageType != "item"">
    <title><data:blog.pageTitle/></title>
<b:else>
    <title><data:blog.pageName/> - <data:blog.title/></title></b:else></b:if> 
 

Then your blog post page title will now be: "Name of my post that doesn't get cut off - My Wonderfully Great Blog."

2010-06-08

Building Clojure projects with Leiningen

When I first started learning Clojure, I had no idea the ecosystem it was situated in. C and C++ is situated in an ecosystem where there's make for managing the building of an application, and GCC for compiling the code. You can use a plain text editor to actually write the program if you like, there's a debugger GDB, and version control can be with CVS, Git, or whatever else. emacs is a plain text editor that also has the option of pulling together all these separate parts together to work as one integrated development environment.

Of course, nowadays people seem to like the whole IDE concept so much it's probably the most popular way to program (Apple Xcode, Eclipse, NetBeans, etc). For Clojure, you can use some of those IDEs too, eg, using NetBeans with the Enclojure plug-in.

If you like the "bag of separate tools" way (the "unix way") of programming, as I do and as I described for C at the beginning, then you'll like Leiningen - I think of it as a much better make, but for Clojure. It's documentation is sparse right now, so the following may help you.

2010-06-07

Namespaces in Clojure: How to use the multitude of ns options

Namespaces in Clojure allow you to use various options, like :require, :use, etc. The syntax of those isn't as well documented as I'd like though in the API documentation.

Stack Overflow again comes to the rescue with some good answers, distinguishing between using :use versus :require.

The syntax is easily understood by an example, like so:


(ns example-namespace.core
  (:gen-class)
  (:require [incanter
            [core :as i.c :only [col-names sel $ dim]]
             [io   :as i.io :only read-dataset]]
            [mmemail.core :as mail]
            [clojure.contrib
             [seq          :as c.c.seq :only positions]
             [except       :as c.c.except :only throwf]
             [json         :as c.c.json :only read-json]
             [command-line :as c.c.cmd :only with-command-line]]))

:use and :require has the same syntax, except the :as short-namespace-name is useless for :use since :use allows you access to the functions in that namespace without qualifying which namespace it's from.

The :only function-name and :only [fun1 fun2] parts says only the specified functions are being used in this namespace from the specified namespace.

The [package.name class1 class2] or alternatively [package.name [class1 :only fun1] [class2 :only fun2]] tells us which "classes" or specific namespaces are being used from the specified package of namespaces.

You need :gen-class if you want to one day compile and package your program for distribution as a Java jar.

There's a subtlety with having namespaces or packages with a dash in it as in example-namespace. See my previous post on namespaces for details.

2010-06-06

Building a Clojure app that handles command-line arguments

Clojure-contrib has a great package (clojure.contrib.command-line) that'll process command-line arguments for you so you don't have keep writing custom code to parse it yourself.

Only problem is the documentation is sparse, to say the least.

Look to Stack Overflow instead, where there's a great answer that's essentially the API's documentation.

2010-06-05

Leiningen 1.1.0 bugs

There's a pesky bug in Leiningen 1.1.0 right now. Actually two.

One attacks modules with dashes in their name (you should get a java.lang.NoClassDefFoundError error when you try to java -jar your-app.jar).

The second attacks when your Clojure program depends on a Java signed jar (you should get a Exception in thread "main" java.lang.SecurityException: no manifiestsection for signature file entry some/package/some.class).

Here's the workaround.

Let's say you have a project pesky-bug, and you build it into a standalone application using lein uberjar, which outputs a pesky-bug-standalone.jar.

Jar's are just zipped containers, so open it up as a zipped file. I use the Archive Manager in Ubuntu, which is great for this purpose.

Look for directory META-INF. Inside, there should be a file called MANIFEST.MF.  Both bugs will require you to fix this MANIFEST.MF file.

Mitigating new Adobe Flash, PDF 0day attack on Ubuntu Lucid

By now you'll have heard of the new 0day security vulnerability. So how to mitigate it? Two things, update to Flash Player 10.1 RC (I've wrote instructions on how last night), and disable Adobe Reader's access to Flash. Here's how to disable Reader's access to Flash on Ubuntu Lucid.

For Ubuntu Lucid, delete or rename these files (I had acroread installed via Synaptic Package Manager):

  1. /opt/Adobe/Reader9/Reader/intellinux/lib/libauthplay.so
  2. /opt/Adobe/Reader9/Reader/intellinux/lib/libauthplay.so.0.0.0
  3. /opt/Adobe/Reader9/Reader/intellinux/lib/librt3d.so

Note that Adobe Reader may crash when it tries to access Flash or 3D content, but that's the price of securing against Adobe's security bugs. Let's see how long it takes for them to fix it.

2010-06-04

Installing Flash 10.1 on Ubuntu Lucid for Firefox and Chrome

Adobe Flash Player 10.1 is still in beta, but it's the way to avoid the all new 0day security vulnerability in Flash Player 10.0.45.2. Here's how to install it on Ubuntu Lucid so that it works for both Firefox and Chrome.  Yes, Chrome recently started to bundle Flash Player within itself, but only for 32bit versions, so if you have 64bit Chrome for Linux you'll need the following too.
  1. Grab the Linux version of Flash 10.1 beta. After unzip and untar, you should have a libflashplayer.so
  2. Go to Synaptic Package Manager and install flashplugin-nonfree, which will set up all the directories for you
  3. Do the following to backup the old 10.0.45.2 version:
    • cd /usr/lib/flashplugin-installer/
    • sudo mv libflashplayer.so libflashplayer.so.old
    • sudo mv path/to/new/libflashplayer.so /usr/lib/flashplugin-installer/ (replacing "path/to/new/" obviously)
  4. You might want to sudo chown root:root libflashplayer.so as well
  5. To verify, just re-open your web browser and go to the Flash Player about page.  Look in the small "Version Information" box about center on that page to check
And that's it!  Now Chrome and Firefox will both get access to the newest Flash Player that's free of the pesky 0day security bug (or so Adobe says...their security track record is...disturbing).