Thursday, July 16, 2009

Syntax Highlighting on Blogger

I put some code in my first post and it took a little effort to make it look pretty, so here is exactly what I did to make your life easier.

While customizing your blog, go to the "Layout" tab, then click "Edit HTML" at the top. Add the following lines inside the <head> element:
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css">
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" id="shTheme" rel="stylesheet" type="text/css">
Also, paste the following at the very bottom, right before the closing of </html>:
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDelphi.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushGroovy.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAS3.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJavaFX.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPowerShell.js' type='text/javascript'/>
<script type='text/javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>
Now, if you want to post a block of code, edit the HTML of your blog and simply add it as a preformatted block, and specify one of the available languages being used as part of the class. Here is an example:
<pre class="brush:java">
System.out.println("Hello world!");
</pre>
The only thing left to worry about is that you cannot embed < and > symbols. Instead, use &lt; and &gt; respectively.

That's it! No need to host any files; just copy and paste! I should also mention that the following websites did most of the work for me:

Getting the Palm Mojo SDK to work on 64-bit linux

This is my first post, and I hope you will find it helpful.

Today, Palm released the Mojo SDK to the public. Awesome! I've been meaning to try developing for a mobile platform and have been put off by the iPhone's price and the fact that it only runs on a Mac. Palm's SDK claims to be cross-platform, but the .deb package it has available for linux is built for i386 only. I have Ubuntu 9.04 (Jaunty) on my machine in x86-64 mode so I was really bummed when I wasnt allowed to install the package.

Determined to get it working I dug around in the package (any .deb can be opened as a .tar.gz) and found that most tools are just scripts, which shouldnt care about the platform they run under. Now how do I fool the installer to use the package they gave me? It turns out there is a file in each .deb that specifies which architecture the package is for. If you look inside the .deb you will find a file called control.tar.gz, and in that archive you will find a file called "control" which is just a list of properties, one of which is "Architecture". Change it from "i386" to "all" and you're all set!

Since the file is kind of deep in the .deb, its not trivial to edit the "control" file, so here is a script that will do it for you:

#!/bin/bash
packageName=$1
tempDir=`mktemp -d`
architecture="all"

# extract the files from the original package
mkdir $tempDir/DEBIAN
ar p $packageName control.tar.gz | tar -xz --directory $tempDir/DEBIAN
ar p $packageName data.tar.gz | tar -xz --directory $tempDir

# replace stuff
if [ -n "$controlFile" ]; then
cp $controlFile $tempDir/DEBIAN/control
fi
if [ -n "$architecture" ]; then
sed "s/Architecture:.*/Architecture: $architecture/g" < $tempDir/DEBIAN/control > $tempDir/DEBIAN/control2
mv $tempDir/DEBIAN/control2 $tempDir/DEBIAN/control
fi

# rebuild the package
dpkg --build $tempDir $packageName

# get rid of temporary working files
rm -rf $tempDir
To use it, save as debAllArch.sh and run it from the terminal:
./debAllArch.sh mojo.deb