Tuesday, December 23, 2008

Stop blinking WiFi LED on Latitude D630 and Ubuntu

Forum post

Run the following using sudo:

For Ubuntu Intrepid Ibex:

#!/bin/sh
echo none > /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/leds/iwl-phy0:assoc/trigger
echo none > /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/leds/iwl-phy0:radio/trigger
echo none > /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/leds/iwl-phy0:RX/trigger
echo none > /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/leds/iwl-phy0:TX/trigger

echo none > /sys/class/leds/iwl-phy0:RX/trigger
echo none > /sys/class/leds/iwl-phy0:TX/trigger
echo none > /sys/class/leds/iwl-phy0:radio/trigger
echo none > /sys/class/leds/iwl-phy0:assoc/trigger


For Ubuntu Karma Koala you need to add extra colons (thanks to James Becwar!):

#!/bin/sh
echo none > /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/leds/iwl-phy0::assoc/trigger
echo none > /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/leds/iwl-phy0::radio/trigger
echo none > /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/leds/iwl-phy0::RX/trigger
echo none > /sys/bus/pci/drivers/iwl3945/0000:0c:00.0/leds/iwl-phy0::TX/trigger

echo none > /sys/class/leds/iwl-phy0::RX/trigger
echo none > /sys/class/leds/iwl-phy0::TX/trigger
echo none > /sys/class/leds/iwl-phy0::radio/trigger
echo none > /sys/class/leds/iwl-phy0::assoc/trigger

Friday, November 7, 2008

bash arguments and spaces

The showargs command is quite helpful for this. There's an interesting post on the issue here, I'm quoting Brian Dessent:

> I want to pass data arguments to curl using a bash variable instead of supplying
> them explicitly. So I defined a variable, like this:
>
> DOCDATA='-F "title=Hello World!" -F "body=Content goes here."'
>
> however, when I now invoke curl with that variable as an argument, like this:
> curl (url) $DOCDATA
>
> then I will get curl errors:
>
> Connection #0 to host localhost left intact
> * gethostbyname(2) failed for World!"
> * Couldn't resolve host 'World!"'
> * Closing connection #1

This has everything to do with how shell quoting works and nothing to do
with curl. Here's a simplified example that uses a C program "showargs"
that does nothing but print out its argv[]. (I find this program very
useful to keep around because if you have a problematic command you can
simply copy/paste or uparrow and insert 'showargs' at the beginning of
it.)

$ x='a b "c d"'

$ echo $x
a b "c d"

$ showargs $x
argv[0] = 'showargs'
argv[1] = 'a'
argv[2] = 'b'
argv[3] = '"c'
argv[4] = 'd"'

As you can see when the shell expands $x it does not see a string
containing three words, it sees four -- there are simply four things
separated by spaces (or more precisely, IFS.) The shell doesn't
consider quotes as meaningful in this context, so the fact that there
are double quotes inside x doesn't matter.

If you want to force the shell to evaluate x as an expression instead of
simply expanding it into words, then you have to use eval:

$ eval showargs $x
argv[0] = 'showargs'
argv[1] = 'a'
argv[2] = 'b'
argv[3] = 'c d'

But this is a dangerous solution to rely on, because if your "Hello
world" was actually "I have $4 in my pocket", it would be mangled
because now you're telling the shell to not just split words but to
evaluate the string (as if you'd typed it), and it would see $4 as a
variable and try to expand it -- most likely into nothing. So you'd
have to make sure that all of the metacharacters in the text of your
variables are quoted!

This can get very ugly, because essentially what you're doing is
combining multiple words into one word, only to turn right around and
parse them back out into multiple words -- and all the quoting has to be
just right to make that roundtrip correct. It's much simpler just to
use one variable where you intend one word. For example I would have
written:

title='Hello World!'
body="Content goes here."
url="http://foo/bar"
...
curl "$url" -F title="$title" -F body="$body"

Note that when you use a variable that might contain spaces and you
*don't* want it to be split into words, you need to quote it as "$foo".
This allows foo to have spaces in it but still only represent one word,
which is what you want:

$ showargs curl "$url" -F title="$title" -F body="$body"
argv[0] = 'showargs'
argv[1] = 'curl'
argv[2] = 'http://foo/bar'
argv[3] = '-F'
argv[4] = 'title=Hello World!'
argv[5] = '-F'
argv[6] = 'body=Content goes here.'

Sunday, November 2, 2008

Logitech mouse (e.g. MX 500) and Ubuntu

See this forum post.

Most notably, change the protocol in /etc/X11/xorg.conf to "evdev" and run lomoco -8 to increase the resolution to 800 cpi.

Tuesday, October 28, 2008

Removing bash arguments

Use shift to remove the first ($1) argument from $@, as explained here in example 9-6.

Saturday, October 25, 2008

use flac tags to rename files

#!/bin/bash

for a in *.flac; do
ARTIST=`metaflac "$a" --show-tag=ARTIST | sed s/.*=//g`
TITLE=`metaflac "$a" --show-tag=TITLE | sed s/.*=//g`
TRACKNUMBER=`metaflac "$a" --show-tag=TRACKNUMBER | sed s/.*=//g`
mv "$a" "`printf %02g $TRACKNUMBER` - $ARTIST - $TITLE.flac"
done


(Also see the post on converting flac to mp3s)

Sunday, October 19, 2008

GPU fan runs endlessly after upgrade to Ubuntu Intrepid Ibex

After upgrading to Ubuntu Intrepid Ibex with a Dell Latitude D630 (nVidia Quadro NVS 135M GPU) and using the nVidia driver 177, my GPU fan started to run for two seconds, pause for one, repeat that a few times, and finally run on full speed endlessly. Others had similar problems, e.g. with a Dell XPS M1330 with GeForce 8400M GS, as can be read in this bug report.

One workaround is to switch back to the nVidia 173 driver (which however is not marked as recommended). Another option is to upgrade to the newest Dell BIOS (in my case A13, but A12 also appears to work).

Monday, October 13, 2008

skype and Logitech webcam in Ubuntu Intrepid Ibex 64-bit

There's a bug report on why many webcams stopped to work in Ubuntu Intrepid Ibex.

Here's a workaround using LD_PRELOAD:

sudo apt-get install lib32v4l-0 libv4l-0

(to have both the 32-bit and 64-bit versions.)

For camorama, which is a 64-bit application:

LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so camorama


For skype, which is a 32-bit application:

LD_PRELOAD=/usr/lib32/libv4l/v4l1compat.so skype


(skype can be found in the medibuntu repositories.)

Sunday, October 12, 2008

export firefox 3 cookies to cookies.txt file

Firefox 3 stores cookies in a SQL database. Having the cookies in a simple cookies.txt file can be helpful for using wget --load-cookies.

A python script to convert the SQL database cookies to the simple text file format can be found here. The corresponding original blog post (German only) is here.

The comments for the blog post above also mention a more advanced version with option parsing.

Modmap settings to combine US layout and German umlauts

The following .Xmodmap file should work to modify an US layout to give German umlauts when the corresponding keys are pressed together with the right Alt key:

! Xorg 8.10 has different keycode for Right-Alt
! keycode 113 = Mode_switch
keycode 108 = Mode_switch
keycode 20 = minus underscore ssharp
keycode 34 = bracketleft braceleft udiaeresis Udiaeresis
keycode 47 = semicolon colon odiaeresis Odiaeresis
keycode 48 = apostrophe quotedbl adiaeresis Adiaeresis
keycode 26 = e E EuroSign

This should work for Xorg 8.10 (e.g Ubuntu Intrepid Ibex, previously the keycode for the right Alt key was 113). This came as a bit of a surprise, as my left arrow key and the umlauts didn't work anymore after upgrading to Ubuntu Intrepid Ibex.

The keycodes for keys can easily be found using xev.

Tuesday, July 29, 2008

play all mp3s below a certain directory

(requires mpg123)

In bash, define the function myplay:

function myplay() { tmp=`mktemp`; find "`pwd`/$1" -name "*.mp3" | sort > $tmp; mpg123 -C -@ $tmp; rm $tmp ;}

Then simply use myplay dir/to/music. (This only works with relative paths.)

Wednesday, July 23, 2008

Download embedded google videos

The Flash SWF player doesn't work so well with Linux, so find the URL in the source code of the HTML page, e.g.
http://video.google.com/googleplayer.swf?docId=1234501631358404955
Replace the front part like this:
http://video.google.com/videoplay?docid=1234501631358404955,
There you can download the video.

Friday, July 4, 2008

vim pdflatex mapping

:map <C-p> :w<CR>:!pdflatex %<CR>

Thursday, June 19, 2008

Alice DSL and Linksys AG241-DE Router

Falls die Einwahl nicht funktioniert:
Im Feld "Dienstname" nichts eintragen!

Wednesday, April 30, 2008

vim word movement with underscore delimiter

see VIM FAQ, 12.35.
:set iskeyword-=_

Also see the camelcasemotion plug-in, described in one of the comments below by leoc.me.

VIM Quick Reference Card

Link

SCons error with Ubuntu Hardy: "scons: *** object of type 'int' has no len()"

delete .sconsign.dblite, since the function convert_old_entry in /usr/lib/scons/SCons/Node/FS.py that should handle old formats of .sconsign.dblite is buggy.

Monday, April 21, 2008

grep alias with arguments and filter

alias mygrep 'grep -i -R \!^ * | grep -v \.svn'

(!^ passes the first argument)

(works only in cshell, for bash use something like this.)

Sunday, March 30, 2008

skype on ubuntu gutsy amd64

install using AMD64 section of this HowTo.
(extract .deb packages using "-x", use LD_LIBRARY_PATH when starting skype.)

install webcam driver as described here. it is important to remove the old driver from its location.

Saturday, March 22, 2008

encode png images to x264 avi

for i in `seq 1 3`; do mencoder mf://*.png -sws 10 -vf scale=800:592 -ovc x264 -x264encopts qp=40:subq=7:pass=$i -o output.avi; done

Monday, March 3, 2008

debug http web form url

Save the page to your local disk and change the method to a get instead of submit and you'll see the values in the addressbar.

even more useful: Live HTTP Headers Addon

Friday, February 15, 2008

apt-get changelog

Manually for each package:
aptitude changelog package-name

Automatically for each upgrade (and of course also manually):
sudo apt-get install apt-listchanges
sudo dpkg-reconfigure apt-listchanges

Tuesday, February 12, 2008

crop and rescale without blur

see examples here.

convert input.png -crop 128x128+571+569 +repage -scale 1024x1024 output.png

With geometry argument as described here.
(width x height +offset_x +offset_y)

The positions of the filenames are important!

Tuesday, February 5, 2008

rename mp3 files using track number

for id3v2 tags:

for i in *.mp3; do num=`id3v2 --list "$i" | grep TRCK | cut -f 2 -d:`; mv "$i" "`printf %02d $num` - $i"; done

Thursday, January 31, 2008

Sunday, January 27, 2008

PDF Viewer with Text Highlighting

Unfortunately xpdf, evince, acroread etc. cannot highlight text or add comments to PDFs. PDFedit cannot select text properly for many PDFs.

However, there is a nice and free alternative, but you need wine to run it: PDF-Xchange-Viewer. There's also a thread on this on the SuSE forum.

Update: Apparently with newer wine versions you don't need the script below anymore, since opening files out of the PDF-Xchange-Viewer works directly. Also see the comments below on this.

After installing the viewer, the following script handles file opening:

#!/bin/bash

# PDF-XChange-Viewer crashes wine when File->Open is used.
# Command line argument filenames work, though.
# However they may only point to files in the current working directory.

PDFXVIEWER="C:\Program Files\Tracker Software\PDF-XChange Viewer\pdf-viewer\PDFXCview.exe"

if (($# != 1)); then
echo "usage: $0 filename"
exit 1
fi

cd `dirname "$1"`
wine "$PDFXVIEWER" `basename "$1"`

Friday, January 18, 2008

create iso image

dd if=/dev/dvd of=image.iso

Tuesday, January 15, 2008

reset printer

cupsdisable hp1gray && cupsenable hp1gray

Monday, January 7, 2008

measure the width of a LaTeX savebox

\settowidth needs \usebox!

\newsavebox{\mybox}
\sbox{\mybox}{hello world!}
\newlength{\myboxlen}
\settowidth{\myboxlen}{\usebox{\mybox}}
\noindent
\rule{\myboxlen}{1pt}\\
\usebox{\mybox}
box size: \the\myboxlen.

advanced computations are possible using the calc package.

Sunday, January 6, 2008

vim C / C++ auto completion

Scripts (extract zip in ~/.vim)

Needs ctags:
sudo apt-get install exuberant-ctags

Use Ctrl-x Ctrl-o for C++ omni-completion.

My omnicppcomplete settings can be found here.

You need to add your tags file if it's not in the current working directory:
:set tags+=/path/to/my/tags

Thursday, January 3, 2008

rewrapping paragraphs in vim

taken from here:

If you ever edited text and still wanted to make your lines break at about 70 characters, you know it's sometimes needed to "rewrap" the lines to make them fill those 70 characters again.

VIM has the ideal solution for this. Select a block of text and press gq. Instant rewrap! This even "understands" basic things like dashed lists, indentation of a block of text, and even Usenet quotation marks like '>'.

To rewrap the current paragraph, press gq}. Since this is a bit tiresome, I remapped this to Ctrl-q in my ~/.vimrc:
map <C-q> {gq}