...making Linux just a little more fun!

next -->

2-cent Tips

2-Cent Tips

2-cent tip: HTML conversion
2-cent tip: More HTML fun
2cent-tip: Disabling Javascript in Firefox with a blacklist
2-cent Tip: Randomizing a playlist
2 Cent Tip: vnc2swf - a cross-platform screen recording tool developed by Yusuke Shinyama
2 Cent Tip: Excel files

2-cent tip: HTML conversion

Benjamin A. Okopnik (ben at linuxgazette.net)
Tue Jul 11 08:05:03 PDT 2006

If you need to convert a plain-text file to HTML - particularly code with nice highlighting thrown in for free - try the 'TOhtml' feature in Vim.

All you have to do is open the file that you'd like to 'HTMLize' - if it's code, make sure that 'syntax' is set to the correct language and is turned on (e.g., ':set syntax=perl' and ':syntax on') - and enter ':TO' in command mode. That's it. Vim will add the correct headers, footers, and color tags to make it all look just the way you see it when editing it in Vim.

There's much more to it - you can do this as XML, or with CSS instead of physical formatting, etc. The documentation for this plugin can be seen by entering ':help TO' from command mode.

2-cent tip: More HTML fun

Benjamin A. Okopnik (ben at linuxgazette.net)
Tue Jul 11 08:35:53 PDT 2006

Followed up by: Ben, Thomas

One of the annoyances of converting plain text to HTML is in having to wrap every paragraph in a pair of '<p></p>' tags. This task can be mostly eliminated by using the substitution operator in Vim; just enter


in command mode.

The first expression looks for more than two newlines (possibly followed by white space) in a row - which is how paragraphs are usually defined - and replaces them with a newline, a paragraph closure (</p>, since it's the end of the previous paragraph), the content that was matched in the expression (i.e., the newlines themselves), and a start-of-paragraph marker (<p>) followed by another newline. The second expression just takes care of the first and the last paragraph markers, since they're not included in the first algorithm.

This can also be scripted as a Vim macro in your '~/.vimrc' file, e.g.

" Mark the file with HTML paragraphs
map \H :%s#\(\s*\n\)\{2,\}#\r</p>&<p>\r#g<CR>:%s#\(.*\n\)*#<p>\r&\r</p>#g<CR>

After adding the above, simply typing '\H' in command mode will do all the paragraphing for you. Note that the second expression can be easily modified to add an HTML header and footer to provide a browser-ready HTML file - all in one pass!

[Thomas] - In Vim7, and with using omni-completion, it gets easier than that. Just press:


For a tag, and it will complete it. There's lots of cool tricks like that in Vim, but it for Vim7, which is certainly not de facto.

[[Ben]] - The last time I tried to figure out ^X mode, I got a headache. Too many 'if's. If I want tag completion, I'll just source my little 'html.vim' file, which includes, in part:

" Make HTML tag:
"	Insert mode		Command mode
"	tag^K			<tag>\n</tag>
"	tag^L			<tag>
"	<tag>...^E		<tag>line</tag> <tag>...</tag>
imap <C-k> <Esc>yiwi<<Esc>ea><CR></<C-r>"><Up><End>
imap <C-l>	<Esc>yiwi<<Esc>ea>
imap <C-e>	<Esc>T<yiwA</<C-r>">
map <C-e>	m`T<yiw``i</<C-r>">

2cent-tip: Disabling Javascript in Firefox with a blacklist

Jason Creighton (jcreigh at gmail.com)
Wed Jul 12 19:22:28 PDT 2006


I wanted to disable Javascript for one particular site, but the de facto Javascript blocking extension, NoScript, works by whitelisting instead of blacklisting. Undoubtedly better security practice, but I'm too lazy to do that. It took me a bit of time to find the answer, so I thought I'd post it here for posterity.

All you need to do is place the following incantation in your user.js:

user_pref("capability.policy.policynames", "nojs");
user_pref("capability.policy.nojs.sites", "http://site1.com http://site2.com");
user_pref("capability.policy.nojs.javascript.enabled", "noAccess");

...with "http://site1.com" and "http://site2.com" replaced with the actual sites for which you want to disable Javascript, of course. This example was taken from http://www.mozilla.org/projects/security/components/ConfigPolicy.html, which has many other examples and information regarding setting security policies in Firefox.

2-cent Tip: Randomizing a playlist

Benjamin A. Okopnik (ben at linuxgazette.net)
Fri Jul 14 05:32:29 PDT 2006

Well, this isn't just for playlists - but that's what I'm playing around with this morning, and I can't think of too many other reasons to randomize a file (unless it's to scramble a political campaign speech; it's very amusing to see them make just as much sense as they did originally...)

In any case, this is one of those places where Perl comes in very useful indeed:

perl -we 'print sort { int( rand 2 ) * 2 - 1 } <>' list.m3u > random.m3u

Conversely, for more features in your randomness, you could install Adam Rosi-Kessel's 'randomplay':


(If you use Debian, it's already available as a package.)

2 Cent Tip: vnc2swf - a cross-platform screen recording tool developed by Yusuke Shinyama

Peter Knaggs (peter.knaggs at gmail.com)
Thu Jul 20 20:20:16 PDT 2006


vnc2swf is a cross-platform screen recording tool developed by Yusuke Shinyama. It's a way to record your VNC session as an Adobe/Macromedia Shockwave Flash animation format file (swf), so that you can later play it back in Firefox, or using a standalone flash player e.g. gnash or swfdec or gplflash. For Debian stable, to build vnc2swf proceed something like this:

  sudo apt-get install libxmu-dev
  sudo apt-get install libxaw7-dev
  wget http://www.unixuser.org/~euske/vnc2swf/vnc2swf-0.5.0.tar.gz
  tar zxvf vnc2swf-0.5.0.tar.gz
  cd vnc2swf-0.5.0
  ./vnc2swf -startrecording outfile.swf your_vnc_server:1 > outfile.html

This will bring up a VNC client which is recording everything from your VNC server into the outfile.swf and once you quit by pressing F8 Q it will also build outfile.html which you can open in Firefox to review your captured animation, or should I say your next blockbuster.

Update: The Python version of vnc2swf includes a nifty sliding search bar at the bottom of your masterpiece, so that you can seek (and your audience can skip over any less-than stellar segments of your creation). For Debian stable, we can get it installed something like this:

  sudo apt-get install python2.3-tk
  sudo apt-get install python-pygame
  wget http://www.unixuser.org/~euske/vnc2swf/pyvnc2swf-0.8.2.tar.gz
  tar zxvf pyvnc2swf-0.8.2.tar.gz
  cd pyvnc2swf-0.8.2

This brings up a nice friendly dialog box, with a "Start" button, which initiates the recording of the VNC server session, so you just control the VNC session you're recording using your regular VNC viewer.

2 Cent Tip: Excel files

Kapil Hari Paranjape (kapil at imsc.res.in)
Thu Jul 27 04:25:46 PDT 2006


If (like me) you have people who send you worthwhile information as ".xls" (MS Excel) files and you want to handle everything in "text mode", then read on.

1. Debian package "catdoc" contains the utility "xls2csv". xls2csv file.xls > file.csv converts the file into "comma separated values" format. This is still not much use since people who use Excel assume that you understand "spread sheets".
2. Debian package "sc" contains the utilities "psc" and "sc". psc -L -k -d',' < file.csv > file.sc converts this file into the "sc" input format. The "sc" text-mode spreadsheet can be used to edit it ("man sc" is your friend here). You can even save it to a LaTeX table.

Seems like too much work? I really have to get used to OpenOffice one of these days!

Talkback: Discuss this article with The Answer Gang

Copyright © 2006, . Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 129 of Linux Gazette, August 2006

next -->