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: http://xregexp.com/

  • 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">
                   SyntaxHighlighter.all();
                 </script>
               

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);
		}
		
		SyntaxHighlighter.autoloader(
			[ 'applescript', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'actionscript3', 'as3', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'bash', 'shell', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'coldfusion', 'cf', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'cpp', 'c', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'c#', 'c-sharp', 'csharp', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'css', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'diff', 'patch', 'pas', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'erl', 'erlang', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'groovy', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'java', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'jfx', 'javafx', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'js', 'javascript', 'jscript', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'perl', 'pl', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'php', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'text', 'plain', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'py', 'python', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'ruby', 'rails', 'ror', 'rb', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'sass', 'scss', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'scala', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'sql', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'vb', 'vbnet', getSyntaxHighlighterScriptPath([email protected]') ],
			[ 'xml', 'xslt', 'html', 'htm', getSyntaxHighlighterScriptPath([email protected]') ]
		);
		
		SyntaxHighlighter.all();
	</script> 

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/...play-x.y.z/framework/play-x.y.z.jar
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.

Téléchargement:

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