Archive for June, 2011

SyntaxHighlighter brush autoloading

Wednesday, June 15th, 2011

SyntaxHighlighter is a very cool syntax highlighting JavaScript library created by Alex Gorbatchev (if you don’t know about it yet, check out the demo page). As you’ll notice, I actually use it on this very blog.

Using it is pretty straightforward:

  • load the XRegexP library required by SyntaxHighlighter:

  • load the main script:

    <script src="js/shCore.js" type="text/javascript"></script>
  • load one or more of the available brushes (syntax highlighting scripts):

    <script src="css/shBrushJScript.js" type="text/javascript"></script>
  • include at least one of the available theme stylesheets:

    <link href="css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="css/shThemeDefault.css" rel="stylesheet" type="text/css"/> 
  • wrap the code to highlight in a <pre> block and specify the brush that should be used:

                 <pre class="brush: js">function foo(){ ... }</pre>
  • finally, execute the highlighter using the following:

                 <script type="text/javascript">

The main issue with this way of configuring SyntaxHighlighter is that you’ll either have to load exactly those brushes you need or load them all even if they’re not needed. This problem remained until version 3 introduced the Autoloader script.

You can find all the details about its usage on that page, but basically you have to load the autoloader script and tell it about all the brushes aliases that it should recognize along with the path to the corresponding scripts. Much better, yay!

One problem I’ve had with the autoloader script is that it doesn’t seem to appreciate URIs for the location of the brush scripts when using the default syntax:

Array: [ 'alias1 alias2 /full/path/to/brush.js', ... ]

Although, it works perfectly fine when using the alternate syntax (which is alas a little bit more verbose):

Array: [ [ 'alias1', 'alias2', '/full/path/to/brush.js' ], ... ]

Finally, I’ve come up with the following script, largely inspired by the example on that page but using the alternate syntax:

	<script type="text/javascript"> 
		var baseSyntaxHighlighterScriptsPath = "http://base-path-to-scripts-folder/";
		function getSyntaxHighlighterScriptPath(name){
			return name.replace('@', baseSyntaxHighlighterScriptsPath);
			[ 'applescript', getSyntaxHighlighterScriptPath('@shBrushAppleScript.js') ],
			[ 'actionscript3', 'as3', getSyntaxHighlighterScriptPath('@shBrushAS3.js') ],
			[ 'bash', 'shell', getSyntaxHighlighterScriptPath('@shBrushBash.js') ],
			[ 'coldfusion', 'cf', getSyntaxHighlighterScriptPath('@shBrushColdFusion.js') ],
			[ 'cpp', 'c', getSyntaxHighlighterScriptPath('@shBrushCpp.js') ],
			[ 'c#', 'c-sharp', 'csharp', getSyntaxHighlighterScriptPath('@shBrushCSharp.js') ],
			[ 'css', getSyntaxHighlighterScriptPath('@shBrushCss.js') ],
			[ 'diff', 'patch', 'pas', getSyntaxHighlighterScriptPath('@shBrushDiff.js') ],
			[ 'erl', 'erlang', getSyntaxHighlighterScriptPath('@shBrushErlang.js') ],
			[ 'groovy', getSyntaxHighlighterScriptPath('@shBrushGroovy.js') ],
			[ 'java', getSyntaxHighlighterScriptPath('@shBrushJava.js') ],
			[ 'jfx', 'javafx', getSyntaxHighlighterScriptPath('@shBrushJavaFX.js') ],
			[ 'js', 'javascript', 'jscript', getSyntaxHighlighterScriptPath('@shBrushJScript.js') ],
			[ 'perl', 'pl', getSyntaxHighlighterScriptPath('@shBrushPerl.js') ],
			[ 'php', getSyntaxHighlighterScriptPath('@shBrushPhp.js') ],
			[ 'text', 'plain', getSyntaxHighlighterScriptPath('@shBrushPlain.js') ],
			[ 'py', 'python', getSyntaxHighlighterScriptPath('@shBrushPython.js') ],
			[ 'ruby', 'rails', 'ror', 'rb', getSyntaxHighlighterScriptPath('@shBrushRuby.js') ],
			[ 'sass', 'scss', getSyntaxHighlighterScriptPath('@shBrushSass.js') ],
			[ 'scala', getSyntaxHighlighterScriptPath('@shBrushScala.js') ],
			[ 'sql', getSyntaxHighlighterScriptPath('@shBrushSql.js') ],
			[ 'vb', 'vbnet', getSyntaxHighlighterScriptPath('@shBrushVb.js') ],
			[ 'xml', 'xslt', 'html', 'htm', getSyntaxHighlighterScriptPath('@shBrushXml.js') ]

Play Framework and Cygwin

Wednesday, June 15th, 2011

Tip of the day:

Last week-end, I wanted to learn a bit more about the Play! framework, thus I downloaded it, installed it and created my first application. Then I encountered a frustrating problem: Play currently doesn’t seem to be friends with Cygwin.

The following command, supposed to start the application doesn’t really work as expected when executed from a Cygwin bash shell:

    $ play run

Instead of starting the app as expected, it just fails and whines:

Error opening zip file or JAR manifest missing : /cygdrive/
Error occurred during initialization of VM
agent library failed to init: instrument

Fortunately, it seems that using play.bat instead works as expected:

    $ play.bat run

That problem is in fact being worked on, I just saw that there’s a pull request for a (partial ?) fix: .

Mémoire: Systèmes P2P et de réputation

Saturday, June 11th, 2011

Pour les gens désireux de découvrir le monde des systèmes distribués, peer-to-peer, les différentes architectures possibles et surtout les systèmes de réputation, voilà ma thèse de master. Je la distribue sous license Creative Commons, vous pouvez donc en faire ce que bon vous semble.


Remarque: un remède idéal pour les insomniaques!