Random Wisdom

Tag: tools

ThinkPad E530 battery charge threshold on Linux

by on Mar.04, 2013, under Hardware, Linux

Leaving a battery charged at 100% for extended periods of time can significantly reduce its service life. Unfortunately, this is quite often the case with laptops that spend a lot of time tethered to an AC power socket. On Windows systems, the Lenovo ThinkVantage power management tools offer a solution that can be used to stop charging before the battery charge level reaches 100%, and re-start charging after it drops below another predefined level. E.g., with the charge thresholds set at 40% and 80%, a laptop connected to the AC adapter will:

  • Start charging when the battery is below 40%
  • Stop charging when the level reaches 80%
  • Do nothing while it is above 40% — even though the AC adapter is connected

According to ThinkWiki, similar functionality can be had on Linux using tp_smapi but unfortunately support for E-series laptops is currently missing.

Searching further finally led me to tpacpi-bat. It is a very young project (about 3 months old at the time of writing) but I am happy to say that it successfully sets both start and stop thresholds on my E530 ThinkPad. The tpacpi-bat Perl script did require one small change to get it working:

diff --git a/tpacpi-bat b/tpacpi-bat
index d9ecf99..2dcdd9d 100755
--- a/tpacpi-bat
+++ b/tpacpi-bat
@@ -39,7 +39,8 @@ use warnings;
 use File::Basename;

 my $acpiCallDev = '/proc/acpi/call';
-my $aslBase = '\_SB.PCI0.LPC.EC.HKEY';
+my $aslBase = '\_SB.PCI0.LPCB.EC0.HKEY';

 sub readPeakShiftState($);
 sub readInhibitCharge($);

… but I’ll chalk it up to the rather immature state of the project. The most important thing is that it works as expected. The $aslBase setting for other ThinkPad models can be found by following these steps taken from the project’s issue tracker:

$ sudo acpidump -b -t DSDT -o /tmp/dsdt.aml
$ iasl -d /tmp/dsdt.aml
$ cat /tmp/dsdt.dsl | grep \\\\_SB\.PCI.*HKEY -o | uniq

If the tpacpi.service file is utilised to automatically set the thresholds at system start, it should also be modified as appropriate (particularly ExecStart=).

Leave a Comment :, , , , more...

Create links with absolute paths in Linux

by on Jan.16, 2010, under How To ..., Linux, Software

The default behaviour of the linking command (ln) is a little strange under certain circumstances. Since it creates the links using the literal value of the target, symbolic links created using relative path structures can often fail. Consider the following:

$ ln -s targetfile ../src/targetfile_link

Without a doubt, ‘targetfile_link’ will be a broken symlink since it links to a target that it assumes is in the same directory:

$ cd ../src && ls -l targetfile_link
lrwxrwxrwx 1 mafgani mafgani 5 2010-01-16 18:19 targetfile_link -> targetfile

This is quite unfortunate since it clearly clashes with the way that the linking mechanism should work intuitively.

The solution is to force ln into automatically appending the absolute path to the target files. This can be achieved by using a simple shell script that acts as a wrapper for the real linking command:


# Step through the supplied arguments and append the absolute
# path to targets that exist
for ARG in $@
  if [ -e $ARG ]; then
    LNARGS="${LNARGS} ${PWD}/${ARG}";
    LNARGS="${LNARGS} ${ARG}";

# Execute the actual link command with the modified args
exec /bin/ln ${LNARGS};

There are two known caveats:

  • The link is ‘sub-optimal’ if created from within the destination directory (the absolute path contains ‘../’s). It will still work however.
  • The links will always be absolute. If that is undesirable, save the script as ‘absln’ or something other than ‘ln’.

Using ‘absln’ instead of ‘ln’ in the previously described scenario now produces a working symlink:

$ absln -s targetfile ../src/targetfile_link
$ cd ../src/ && ls -l targetfile_link
lrwxrwxrwx 1 mafgani mafgani 16 2010-01-16 19:13 targetfile_link -> /tmp/files/targetfile
1 Comment :, , , , , more...

Graphics format conversion

by on Dec.09, 2009, under LaTeX, Linux, Software

Up until now I have been using the ‘convert‘ tool that comes with ImageMagick to switch between image formats — mainly for creating EPS files from JPG/PNG (raster format) files for use with LaTeX. Then I came across sam2p.

It is a light-weight utility that does one thing only and it does it well: convert between image formats. I’ve been using it for a while now and find that it can greatly reduce files sizes with minimal drop in quality. I’ve even used it to process existing EPS files just to get the reduction in file size. Best of all, it is multi-platform — executables are available for both Windows and Linux on the project homepage.

Goodbye convert and hello sam2p!

2 Comments :, , , , , , , more...

Realtime collaborative text editing

by on Nov.21, 2008, under Linux, Software

A while ago, I came across Etherpad. It a web based platform that allows multiple users to simultaneously edit a single text file. Since it doesn’t seem to support any kind of mark-up at the moment, it would seem that it’s not terribly useful for word processing tasks. Perhaps it’s good for real-time collaborative coding and the creation of agenda type lists …

The software equivalent of Etherpad is Gobby. It’s a multi-platform tool that claims to run on Microsoft Windows, Mac OS X, Linux and other Unix-like platforms — making it almost as flexible as a web-based service. There are a number of other advantages:

  • Flexibility and security that comes from having absolute control over the sessions.
  • Syntax highlighting!
Leave a Comment :, , , more...

Re-encoding MP3 files using LAME

by on Jun.06, 2008, under How To ..., Linux, Software

I have some MP3 files encoded at a constant bitrate of 320kbps that my phone seems to have trouble playing smoothly. So, I looked into LAME.

The files I had were named using the following scheme:

01 - Title of track 01.mp3
02 - Title of track 02.mp3

I used the BASH for-loop construct to process the files:

$ for A in *.mp3;\              # Process one mp3 at a time
  do B=${A%.mp3};\              # Extract track number and title
     C=${B#?? -};\              # Extract the title
     D=${B%% - *};\             # Extract the track number
     lame --vbr-new -V0 -q0\    # Variable-bitrate, high-quality
          --mp3input\           # Inputs are MP3 files
          --tt "$C"\            # ID3v2 tags: title
          --ta 'Artist Name'\   # ID3v2 tags: artist
          --tl 'Album Title'\   # ID3v2 tags: album
          --ty 2007\            # ID3v2 tags: year
          --tn "$D"\            # ID3v2 tags: track no.
          --tg 'GENRE'\         # ID3v2 tags: genre
          "$A" processed/"$A";\ # Keep filename and save in ./processed/

Since no bit-rate bounds are explicitly provided, the re-encoded files can contain anything between 32kbps and 320kbps. The LAME man-page provides an extensive list of options and their meanings.

1 Comment :, , , , more...

SSH Blacklisting

by on Nov.29, 2007, under How To ..., Linux, Software

After getting around 1500 failed ssh login attempts a day for a while on a server I manage, I decided to look into tools that automatically blacklist offending IPs.

Sshblack fits the bill perfectly. A HOWTO (including an init-script) for REDHAT-like systems is available from the OSS Watch Wiki.

1 Comment :, , , more...

Linux and DVD Regions

by on Apr.12, 2007, under How To ..., Linux, Software

Typically, Linux DVD playback software are capable of decrypting (libdvdcss must be installed) and playing back DVDs from any region, irrespective of the region code of the drive. Therefore, there should be no need to change the region code of the drive to watch discs from a different region. Regardless, there exists a very handy program that allows the user to change the region code and view other relevant information such as the number of changes remaining. It is called “regionset” and is available for Fedora from the Extras repository. The project website is:


There is also a useful article on Linux.com about DVD playback:

DVD Playback HOWTO

Leave a Comment :, , more...

Proxy tools

by on Jan.25, 2006, under Software

There’s a very nice list of servers here:


This Firefox extension is handy for changing Proxies quickly: SwitchProxy

Leave a Comment :, , , more...


by on Sep.17, 2005, under Art, Software

I installed Inkscape a few days ago out of pure curiosity. Today I’m glad that I did .. I needed to touch up some diagrams with a few translucent windows here and there and GIMP didn’t seem to have any easy of doing it. So came the first field test of Inkscape ..

It works quite well – at least from the first impression. I can already see it giving MS Visio a run for its money …

Leave a Comment :, , , , more...