gatopeich's simple unix tools & hacks
|
These tools I crafted to cover certain needs in my everyday computing activity. I offer them here in an attempt to contribute something back to the community. Among my heterogeneous software creations, I am selecting those that stand the best chance to become useful for others, hopefully for you!
Use and share as you like. Feel free to reproduce any useful idea or piece of my work. Copying, that's what we do most of the time. Then sometimes, improving! :-). Suggestions are most welcome.
Kind regards,
gatopeich.-

|
Contents:
|
A BASH prompt that displays running command on Xterm title
In order to have a quite explanatory bash prompt showing current directory and time, and an Xterm title that shows the currently running command or the current directory when idle, use this:
PS1='\e]0;\W\007\n\[\e[0;35m\]\u@\h: \[\e[1;36m\]\w/\n\[\e[1;33m\]\t $ \[\e[0m\]'
trap 'echo -ne "\e]0;$BASH_COMMAND\007"' DEBUG
set +o functrace # Do not inherit traps, to prevent messing with completion
... As learned at http://www.davidpashley.com/articles/xterm-titles-with-bash.html
Compcache: Easy installation
Being a happy user of compcache (on a Xubuntu system), I have prepared a very simple patch to have it easily installed on my system, and reinstalled whenever kernel changes or I just want to try a new version. The patch adds an "install" target to compcache's main Makefile, in order to install an LSB-compliant init script, so compcache is loaded and unloaded at the proper system levels.
This is, roughly, the make code:
PWD := $(shell pwd)
KD := /lib/modules/$(shell uname -r)/build
install:
make -C $(KD) M=$(PWD) INSTALL_MOD_STRIP=1 modules_install
depmod
install init-compcache /etc/init.d/compcache
update-rc.d compcache defaults
Here is the init script:
init-compcache.
And here is the full patch that you can apply with "patch < compcache_installation.diff " on a fresh compcache-0.5.1 source tree:
compcache_installation.diff. After that, build it with "make" and install it with "sudo make install".
USB D2XX driver for Wine
I have a very nice logic analyzer that didn't come with any software for Linux. However, it uses some FTDI chip through its standard driver library 'ftd2xx.dll', which happens to have a Linux version whose API is pretty much the same, called "libftd2xx.so".
So I took the effort to wrap-up a Wine DLL 'ftd2xx.dll.so' which offers the native Linux driver to any Windows application running under Wine. It was a tedious task, but quite straightforward thanks to 'winedump'.
If you want to use your favourite FTDI-based USB devices under Wine too, just install ftd2xx.dll.so on your Wine lib installation, usually /usr/lib/wine/. Source code and detailed instructions are available here. Just don't forget to install FTDI's D2XX drivers for Linux from their site.
My particular device (Ant18e) demonstered some funny behaviour under Linux, somehow it didn't report a correct USB serial number. The strange thing was that it worked flawlessly under windows... I had to reprogram its EEPROM to get a good serial number with MPROG, a standard utility provided by FTDI, and a 'EEPROM template' provided by my device's vendor.
I also built a 'libd2xx_table.so' (source) that you may want to install right beside your libftd2xx.so (typically at /usr/local/lib/) in order to get all your FTDI-based devices (VendorID=0403) recognised by the driver. Otherwise only a few ProductIDs will be working. More details on D2XX Linux driver package, under "lib_table".
Use this stuff at your own risk! I already risked my brand new logic analyzer in this development :-).
Update for 64-bit systems: I have not been able to compile this on a 64-bit architecture, however the 32 bit binaries work fine when placing ftd2xx.dll.so at /usr/lib32/wine, and libd2xx_table.so (together with 32-bit D2XX drivers) at /usr/lib32/.
gatopeich's OpenGL wrapper or how to run most 3D games on my old Savage3D chipset
A library wrapper that downsamples textures as they are dealt to OpenGL system, enabling my old 3D card to bear with some modern Linux games that are unusable otherwise.
Some history: After years of patient waiting, my Savage 3D chipset (an MX/IX that comes with most Thinkpads T2x) is supported in Linux (X11/Xorg/etc.) with direct rendering! (DRI). Just in time, as everything seems to come in 3-D now. Only my card has grown a little bit old (by consumerist standards) -- most software (read "games" here!) come with 'big' textures that just won't fit, while few will even check for errors. So I spent some time studying OpenGL (horrible learning curve!) and found that a simple workaround around "glTexImage2D" could solve the issue. Then coded a wrapper library for that call with 'the ole handy LD_PRELOAD trick'.
Checks if a texture passed to OpenGL core is greater than "max_texture_size". If so, downsamples it.
you just preload it setting LD_PRELOAD=glWrap.so before running your favourite 3D games.
Here: glWrap.c. Build & run instructions are embedded in the first lines of comments. You may want to comment out the printouts, change "max_texture_size" parameter or whatever. It is just 88 lines of straight-forward code, don't be scared!
- What if I am too lazy to build it?
Let's see what I can do for you... Have glWrap.so, and run your games with the following command line:
$ LD_PRELOAD=/path_to_wrapper/glWrap.so OpenGL application here
Enjoy!
gatopeich's page on Graphic Algorithms
The page where I am publishing some computer graphic algorithms that developed some years ago: gatopeich's Graphic Algorithms.
'gatotray', monitor CPU graphically from your system's tray
Notice to gatotray users!!!
The official gatotray home page is now at http://code.google.com/p/gatotray
There you will be able to browse the code, download the latest version and request improvements.
'gatotray' is a colorful tray icon to watch over CPU status including usage, frequency and temperature.
- Pseudo-logaritmic time scale: right-most columns reflect last seconds while lefter columns accumulate older measures, providing an idea of cpu usage evolution for up to 30 minutes in a glimpse. It makes a beautiful smoothing effect too.
- Colors of the usage bars vary with frequency, from green to red.
- Tooltip shows current usage percentage, frequency and temperature numerically.
- Instant temperature is shown graphically, in the form of a nice thermometer :-). Thermometer blinks on high temperature (>=85 C).
- Pops-up a 'top' window with detailed system usage (on click).
- Preferences dialog allows customization of colors and options.
- Transparent background (optional).
Screenshot:

Requeriments:
- Linux.
- GTK+ v2.10 or later.
- Any freedesktop.org compliant system tray like that of XFCE, KDE, GNOME, etc.
Download:
Build & install instructions:
$ make
$ sudo make install
(This will install in /usr/local/bin).
Python prototyping: During an early design stage, gatotray was coded in Python. This allowed me to code & debug interactively, specially useful while coding GTK+ events. Then converting from Python to C was pretty straightforward and the resulting application is very lightweight in resources and dependencies.
'unsort', the missing UNIX filter
The UNIX filter that should have been there since the beginning!
Unsort is the natural opposite to standard 'sort', it takes lines and shuffles them. I wonder how it is not part of every standard UNIX system. How the hell did they test 'sort'?
Sample run:
$ echo -e "1\n2\n3\n4\n5\n6" | unsort
stderr: Using seed: 542941369
6
4
1
5
2
3
stderr: Jumps: 4 left, 4 right, balance: 1.000000
This 'unsort' implementation works as follows:
- reads lines from standard input
- assigns them random, unique indexes
- sorts lines by their random index
- when input finishes, lines are dumped as sorted.
The only limitation is on file size, since the whole file is kept in memory during the process.
Download 'unsort' here: unsort-1.0.1.c. Simple build & install instructions are within the file, along with shell script for testing the statistical distribution, like this one:
Statistical test #2 "Permutations of 3 elements"
$ i=9999;while [ $((i--)) -ge 0 ];do echo -e "a\nb\nc"|unsort -q|xargs echo;done|sort|uniq -c
1644 a b c
1681 a c b
1680 b a c
1633 b c a
1709 c a b
1653 c b a
total visits. Recent visitors:
Comments (0)
You don't have permission to comment on this page.