Thursday, December 30, 2010

Ideone -- an online pastebin and compiler in one

What is ideone?
Ideone is something more than a pastebin; it's an online compiler and debugging tool which allows
to compile and run code online in more than 40 programming languages.

Sounds cool, I wonder if I will find a cool use for it sometime soon?

Thursday, December 9, 2010

Perl -- add the script's directory to @INC

Lets say you write a Perl script that includes some local packages, but you want to run the script from a symlink or from in your path. How can you get it to include those packages in your libraries (@INC)?

Near the top of your script place the lines:

use Cwd 'abs_path';
use File::Basename;
use lib dirname( abs_path $0 );

Should work in all cases and on all OSes. (source:

Friday, October 29, 2010

Simple LaTeX build and preview or "How I learned to stop worrying and love latexmk"

I have always loved LaTeX and liked latexmk to manage the compiling. latexmk checks to be sure that the proper compilers are run an appropriate number of times.

I also knew that it could be used with the -pvc option that leaves it in "continuous preview mode" which means it monitors the file and everytime you save it it recompiles automatically. This is a cool feature but it involved initializing a previewer that would check to refresh itself and I never gave it enough time to get it working.

Just tonight though I learned that latexmk can also have a configuration file in your home folder (i.e. ~ or /home/yourname) which can have all the necessary information for this setup all ready to go.

In your home folder create a file called ".latexmkrc" (no quotes). In it, put exactly this:

$pdf_mode = 1;
$preview_continuous_mode = 1;
$pdf_previewer = "start xpdf -remote %R %O %S";
$pdf_update_method = 4;
$pdf_update_command = "xpdf -remote %R -reload";

Of course you need to be sure that you have a LaTeX environment installed as well as the latexmk script and xpdf. I recommend using the latexmk that is available from CTAN rather than the one in your package manager (in fact I always manage my own LaTeX implementation, its not hard using the tools available from CTAN and using the tlmgr script included with TeXlive).

Anyway when you run latexmk yourfile.tex (yep you don't even need to use -pdf), it will compile and open xpdf to preview. Then the next time you save your document in your editor, the previewer will automatically reflect the saved (and compiled!) changes.

Cool eh?

NB: This might finally be the thing that finally breaks me of my old editor TeXlipse (still awesome, but might not play well with other things that change the workspace).

Wednesday, October 6, 2010

ruby script "cheat" for cheat sheets

If you find yourself looking for cheat sheets for all your programming needs try the little gem "cheat". Note that for Ubuntu (this blog features mostly Ubuntu specific instructions) you need to symlink cheat into /usr/bin/. Install ruby and gems if not already installed first.

$ sudo apt-get install ruby1.8 rubygems1.8
$ sudo gem install cheat
$ sudo ln -s /var/lib/gems/1.8/bin/cheat /usr/bin/

Then lets say you just can't remember that Perl special variable so you can just do:

$ cheat perl

and see what you get!

Tuesday, October 5, 2010

Ubuntu Maverick TERM variable

So on going up to Maverick Meerkat, I discovered that Tilda (my perferred terminal emulator) was suddenly throwing wierd errors, i.e. on running "clear" rather than a blank terminal window, I get "TERM environment variable not set."

The problem seems to affect many terminal emulators but the solution is simple, as I posted on a bug tracker:

On Ubuntu I think the easiest way to fix this problem, both workaround and packaged as a solution, is to make a simple script in /etc/profile.d/ . I called mine (must end in .sh). The file need only have in it

export TERM=xterm

and then either run "source /etc/profile" or reboot. This will set the $TERM variable for all users on each boot without hardcoding the variable as some of the other programs I listed above have done. In one command, for those who need it run:

echo "export TERM=xterm" | sudo tee /etc/profile.d/ && source /etc/profile

Monday, September 27, 2010

Zenity for popups to user

After ssh-ing in then export DISPLAY=:X where X is the user display, then zenity is a program that can display GTK popups to the user in question. Fun for the whole family.

Friday, September 10, 2010

Inkscape's PDF+LaTeX

Holy crap this is excellent. I have been looking for a way to use SVG in LaTeX and this is better than I could have hoped for, I don't get to \includegraphics{myfile.svg} but when I include the PDF that Inkscape generates it can have LaTeX source for text!

I found this from an ubuntuforums post. It has in it this link to a PDF on Inkscape's site which gives the usage and some extras. The Inkscape wiki page is here.

I would still like to directly use SVG images but oh well. Eventually when I can get a good TikZ exporter from an SVG editor this may all be moot, but for now this is excellent.