Category Archives: Tips & Tricks

Create a symmetric matrix in Mathematica

Here is a quick way to create a symmetric matrix in Mathematica. The code below creates a generic 6×6 matrix (line 1), then mirrors the above-diagonal elements to their below-diagonal counterparts (substitution in lines 3-5). am = Array[Subscript[a,##] &, {6,6}]; am = am /. Flatten[Table[ Subscript[a,i,j] -> Subscript[a,j,i], {i,2,6}, {j,1,i-1}]]
Also posted in Scientific Computing | Tagged | Leave a comment

ezproxy redirect bookmarklet

A while ago I wrote a Google Toolbar button for redirecting the current page to the same page accessed through an EZproxy server. As I was missing this functionality in browsers without Google Toolbar (it’s still not available in Google Chrome), I realized that it’s a very simple thing to do with a bookmarklet. Here [...]
Also posted in Papers, Web | Tagged , | Leave a comment

XML parsing with Perl using XPath

use strict; use XML::LibXML; # data source my $xml_filename = "xml/data.xml"; my $parser = XML::LibXML->new; my $doc = $parser->parse_file($xml_filename); my $xpath = "//word/entry[\@src=\"pr\"]/.."; my @words = $doc->findnodes($xpath); foreach my $word (@words) { print $word->findvalue("\@id"); print "\n"; }
Also posted in Data Processing, Programming | Tagged , , | Leave a comment

File modified timestamp with Perl

This is how to quickly get the timestamp of when the file was last modified in Perl: $lastmod = (stat($filename))[9];
Also posted in Programming | Tagged , | Leave a comment

XSLT transform with Perl

Here is a Perl snippet that transforms an XML file with XSLT: use strict; use XML::XSLT::Wrapper; my $xml_input_filename = "xml/data.xml"; my $xml_output_filename = "xml/out.xml"; my $xsl_filename = "xml/transform.xslt"; my $xslt = XML::XSLT::Wrapper->new( ProcessorList => [ 'libxslt', 'sablotron', 'xslt' ], ); my $result = $xslt->transform( OutFile => $xml_output_filename, xml => $xml_input_filename, xsl => $xsl_filename, ); $xslt->dispose();
Also posted in Data Processing, Programming | Tagged , , | Leave a comment

Sitemap generator configuration for Blogger

If you are using Google’s sitemap generator [code]]czoxNDpcInNpdGVtYXBfZ2VuLnB5XCI7e1smKiZdfQ==[[/code] to generate a sitemap of your Blogger blog , here are the configuration lines to add to the config.xml file:
Posted in Tips & Tricks | Tagged , | Leave a comment

Function call counting in Matlab

Here’s a neat way to keep track of the cost, i.e. number of function calls in Matlab: rather than using a counter variable and increment it each time a function is called, use the internal Matlab counters, accessible through the FunctionTable struct array. The loop below is necessary only to get the index of the [...]
Also posted in Scientific Computing | Tagged | Leave a comment

Images in LaTeX

Problem: you can’t get those images to appear in a typeset document. Cause: [code]]czo4OlwicGRmbGF0ZXhcIjt7WyYqJl19[[/code] and [code]]czo1OlwibGF0ZXhcIjt7WyYqJl19[[/code] have virtually no graphic drivers in common. For instance, [code]]czo4OlwicGRmbGF0ZXhcIjt7WyYqJl19[[/code] can't handle eps files. Solution: I converted my eps files to pdf using a thing called [code]]czo4OlwiZXBzdG9wZGZcIjt7WyYqJl19[[/code], which is included in latex distributions, and [code]]czo4OlwicGRmbGF0ZXhcIjt7WyYqJl19[[/code] handled those pdf graphs perfectly, so that the output [...]
Also posted in LaTeX | Leave a comment