Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts
March 20, 2009
The command line tutor returns
I had stopped work on this long back, but found people still downloading it and discussing it once in a while. So here we go - a rewritten version can be got from its new home at google code. Any suggestions are welcome.
January 21, 2009
'Scroll animating' an image
![]() |
![]() |
Needing to create an animated image of an ECG scrolling, I wrote a bash script to create sequential frames from the image and then combine them into an animated gif, all using imagemagick.
#!/usr/bin/env bash # Convert a rectangular image into an animated gif with # sections from the image scrolling through # Raja S # Jan 2009 # GPL nargs=$# if [ $nargs -eq 0 ] then echo "Error - No arguments provided !" echo "" echo "animate converts rectangular image to a scrolling animated gif" echo "Usage : " echo " animate filename [width] [overlap] [delay] [loop]" echo " width is width of final gif (pixels), default same as image height" echo " overlap is overlap between successive 'frames', default is tenth of width" echo " delay in time in hundredths of a second between frames, default is 20" echo " loop is number of times to loop, default is 0 (loop infinitely" exit fi # command line arguments - filename, width of gif (opt) and overlap (opt) imagefile=$1 basefilename=${imagefile%.*} # find image size using identify imagesize=$(identify $imagefile | awk '{print $3}') imagewidth=$(echo $imagesize | awk -Fx '{print $1}') imageheight=$(echo $imagesize | awk -Fx '{print $2}') # width of gif - default is image height if [ $nargs -gt 1 ] then width=$2 else width=$imageheight fi if [ $width -gt $imagewidth ] then echo "Error - Width of gif cannot be larger than width of input image !" exit fi # overlap - default is tenth of width if [ $nargs -gt 2 ] then overlap=$3 else overlap=$(($width/10)) fi # delay if [ $nargs -gt 3 ] then delay=$4 else delay=20 fi # loop if [ $nargs -gt 4 ] then loop=$5 else loop=0 fi # make the image frames filecount=0 for i in $(seq 0 $overlap $(($imagewidth-$width))) do printf -v suffix '%06d' $((filecount++)) convertstring="$width""x""$imageheight""+""$i""+0" filename="$basefilename""part""$suffix"".jpg" convert -crop "$convertstring" "$imagefile" "$filename" done # combine into gif convert -delay "$delay" -loop "$loop" "$basefilename""part*.jpg" "$basefilename""animation.gif" |
If you want to try it out, you can download it here.
Example usage:
raja: ls /data/tmp/sample/ train.jpg raja: ./animate.sh /data/tmp/sample/train.jpg raja: rm /data/tmp/sample/trainpart* raja: ls /data/tmp/sample/ trainanimation.gif train.jpg |
Disclaimer: This is provided with all good intentions, but I cannot guarantee that it will cause not harm. Note that I do not delete the files to avoid inadvertent deletion of any important files. However, it is best to place the target image in a separate folder and then run the script.
April 6, 2007
An interactive Linux command line tutorial
Edit: A new version of cmd-tutor is now available. See here.
There has been a gradually increasing influx into the linux community in recent years. The release of Vista has encouraged a lot of people to take the plunge and switch to linux. And while it is not any more essential to use the command line to manage your linux desktop today, many newcomers are interested in knowing what it is all about.
A lot of excellent tutorials are available, like this for example, but there were some requests for an interactive tutorial. Those who have tried the online ruby tutorial will know what I am talking about.
So, I wrote this tutorial in python. Keeping in line with Unix philosophy, the mechanism for presenting the lessons is kept separate from the lessons itself. Therefore it is easy to extend it by adding more lessons later. Currently there are 5 lessons that I have written. These would serve as a gentle introduction to a newcomer.
You have to be running linux to use this. You can download cmd_tutor here. The instructions to install are in the package. Briefly, you have to extract the package somewhere, navigate to the src directory from the terminal and then type 'python install.py install' with superuser privileges. Once installed, you can type 'cmd_tutor' in the terminal to start the tutor.
Any comments and suggestions will be welcome.
There has been a gradually increasing influx into the linux community in recent years. The release of Vista has encouraged a lot of people to take the plunge and switch to linux. And while it is not any more essential to use the command line to manage your linux desktop today, many newcomers are interested in knowing what it is all about.
A lot of excellent tutorials are available, like this for example, but there were some requests for an interactive tutorial. Those who have tried the online ruby tutorial will know what I am talking about.
So, I wrote this tutorial in python. Keeping in line with Unix philosophy, the mechanism for presenting the lessons is kept separate from the lessons itself. Therefore it is easy to extend it by adding more lessons later. Currently there are 5 lessons that I have written. These would serve as a gentle introduction to a newcomer.
You have to be running linux to use this. You can download cmd_tutor here. The instructions to install are in the package. Briefly, you have to extract the package somewhere, navigate to the src directory from the terminal and then type 'python install.py install' with superuser privileges. Once installed, you can type 'cmd_tutor' in the terminal to start the tutor.
Any comments and suggestions will be welcome.
March 4, 2007
The User Interface of the future ?
Arguing whether the Command Line Interface (CLI) is superior to the Graphical User Interface (GUI) or vice versa strikes me as a futile exercise. It quickly becomes clear to anyone who has used both that the best way to interact with the computer is to use both methods. A CLI + GUI interface is vastly more powerful than a plain GUI interface. As you use both, you find more and more uses for the former, where it clearly surpasses the GUI. Why, you even start ordering your pizzas from the command line.
However, the difficulty many face in approaching the CLI initially is what Eric Raymond calls the 'mnemonic load'. Don Norman writes how the next major UI breakthrough should be in CLI. He anticipates the development of a more flexible command line language, with more resemblance to natural language and not requiring a strict adherence to an idiosyncratic syntax.
An alternative to an entire new language for the command line is to use a user-friendly intermediate layer which translates the user input into the syntax that the command line understands. This is analogous to the frequently used concept in Unix when a user friendly GUI actually uses command line tools, but provides a user friendly front end.
What you see below is a working prototype of such a program written in python. In its main loop, it collects user input and outputs a command to the terminal. When the input is a valid command line input, it is passed unchanged. But when it is not, it is 'translated' into a valid one. I call it the Genie. Here are a few examples of the genie in action.

The prompt includes a battery status monitor - I find it useful and it shows that the prompt is easily customizable. 'Normal' shell commands are interpreted directly - like 'ls -l | grep 2007-03' in the example. Navigation to usual places is easy just - 'go home' or 'go desk'. 'space' functions like an alias mapping to 'df -h / /home'. Note the genie says line which lets you know the command that is passed to the shell. So that a newcomer also learns shell syntax along the way.

When you want to install an application just 'install'. If the app is found in the apt-cache, installation is started. Otherwise you are allowed to choose from the matches in the apt-cache.

Any calculations are automatically recognized and passed on to bc. Finally, a listing of directory names is stored and searchable. So if you want to navigate to the python site-packages folder and didn't remember where it was, genie can help you.
Obviously, the possibilities are almost endless. The genie can be taught to understand new commands as you desire. It may be necessary to be able to carry genie around so that you have your custom genie on any computer you have to use. But finally, will the added ease of use facilitate introduction of the command line to new users or will the use of a simple interface like this preclude users from learning shell commands and thereby never being able to make full use of it ? Comments are welcome.
However, the difficulty many face in approaching the CLI initially is what Eric Raymond calls the 'mnemonic load'. Don Norman writes how the next major UI breakthrough should be in CLI. He anticipates the development of a more flexible command line language, with more resemblance to natural language and not requiring a strict adherence to an idiosyncratic syntax.
An alternative to an entire new language for the command line is to use a user-friendly intermediate layer which translates the user input into the syntax that the command line understands. This is analogous to the frequently used concept in Unix when a user friendly GUI actually uses command line tools, but provides a user friendly front end.
What you see below is a working prototype of such a program written in python. In its main loop, it collects user input and outputs a command to the terminal. When the input is a valid command line input, it is passed unchanged. But when it is not, it is 'translated' into a valid one. I call it the Genie. Here are a few examples of the genie in action.

The prompt includes a battery status monitor - I find it useful and it shows that the prompt is easily customizable. 'Normal' shell commands are interpreted directly - like 'ls -l | grep 2007-03' in the example. Navigation to usual places is easy just - 'go home' or 'go desk'. 'space' functions like an alias mapping to 'df -h / /home'. Note the genie says line which lets you know the command that is passed to the shell. So that a newcomer also learns shell syntax along the way.

When you want to install an application just 'install

Obviously, the possibilities are almost endless. The genie can be taught to understand new commands as you desire. It may be necessary to be able to carry genie around so that you have your custom genie on any computer you have to use. But finally, will the added ease of use facilitate introduction of the command line to new users or will the use of a simple interface like this preclude users from learning shell commands and thereby never being able to make full use of it ? Comments are welcome.
February 24, 2007
Hide and show panels with a keyboard shortcut in Ubuntu
I usually keep the default top and bottom panels in gnome, but especially on my laptop, place great value on the screen estate that I can get by hiding them. The usual way I do this is by using autohide and then setting the hidden size to 0 or 1. Mostly I dont need the panels because I can launch applications with Alt-F2 or with shortcuts. But when I need to access something from the panel, I have to mouse over the hidden panel to bring it up. The other minor irritation is that the panel may spring out when you dont really want it if your mouse wanders close to it.
In a recent post in the Ubuntu forums, it was suggested that it would be nice to set up a keyboard shortcut to show the panels when needed. Since it is easy to access the gconf-editor from the command line, it was easy to write a script to toggle the hide status of the panel. Here is a short how-to if someone is interested.
Copy this script and save it as "toggle.sh". A good location to keep it would be /home/<username>/.toggle.sh. Make the file executable :
chmod +x ~/.toggle.sh
#!/bin/bash
#find the current state of the panels
state=`gconftool-2 --get "/apps/panel/toplevels/top_panel_screen0/auto_hide"`
#if autohide on, turn it off
if [ $state = "true" ]; then
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "false"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"
fi
#if autohide off, turn it on
if [ $state = "false" ]; then
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "true"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"
fi
Open gconf-editor now, and in /apps/metacity/keybinding_commands, change the value of command_1 (or any other command which is unused) to /home/<username>/.toggle.sh.
Then go to /apps/metacity/global_keybindings and change the value of run_command_1 (if you mapped the script to command_1) to <Control>F12 or any other key combination you choose. Close gconf-editor and try it out ! I tested this with both metacity and beryl and it works perfectly.
In a recent post in the Ubuntu forums, it was suggested that it would be nice to set up a keyboard shortcut to show the panels when needed. Since it is easy to access the gconf-editor from the command line, it was easy to write a script to toggle the hide status of the panel. Here is a short how-to if someone is interested.
Copy this script and save it as "toggle.sh". A good location to keep it would be /home/<username>/.toggle.sh. Make the file executable :
chmod +x ~/.toggle.sh
#!/bin/bash
#find the current state of the panels
state=`gconftool-2 --get "/apps/panel/toplevels/top_panel_screen0/auto_hide"`
#if autohide on, turn it off
if [ $state = "true" ]; then
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "false"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"
fi
#if autohide off, turn it on
if [ $state = "false" ]; then
gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "true"
gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"
fi
Open gconf-editor now, and in /apps/metacity/keybinding_commands, change the value of command_1 (or any other command which is unused) to /home/<username>/.toggle.sh.
Then go to /apps/metacity/global_keybindings and change the value of run_command_1 (if you mapped the script to command_1) to <Control>F12 or any other key combination you choose. Close gconf-editor and try it out ! I tested this with both metacity and beryl and it works perfectly.
Labels:
command line,
google reader,
linux,
medicine,
presentation,
pubmed,
python,
research,
RSS
Subscribe to:
Posts (Atom)


