Skip navigation

Category Archives: GNU/Linux

I was using gnome-do as my application launcher through out last year with my ubuntu 9.04 installation. I installed it right after installing 10.04 recently too. But I kinda needed a change. I realized I wasn’t using the launcher THAT MUCH so it better be lightweight. So I found dmenu. A nifty tool coming with ‘dwm’ window manager. I also found yeganesh, a wrapper around dmenu which lists most used app first. Yeganesh is written in haskell. Not that I don’t like haskell but let’s go with python yeganesh clone called pydmenu since ubuntu has python installed by default.

First install dmenu which is in dwm-tools on Ubuntu repositories.

$sudo aptitude install dwm-tools

Then download pydmenu, extract it and copy it in to /usr/local/bin


$ wget http://www.codercpf.be/stuff/pydmenu.tar.bz2
$ tar xjfv pydmenu.tar.bz2
$ sudo cp pydmenu.py /usr/local/bin/

create a file named dmenu-bind.sh inside /usr/bin/local and put following code in it.


#!/bin/bash
exe=`pydmenu.py` && eval "exec $exe"'

Or just run following command and it’ll automatically do it for you.

$ echo -e '#!/bin/bash\nexe=`pydmenu.py` && eval "exec $exe"' | sudo tee /usr/local/bin/new.sh

You should change persmission of the file too


$ sudo chmod 755 /usr/local/bin/dmenu-bind.sh

OK enough playing in goofy command line. Let’s go on the surface and set up a shortcut key combination for our new launcher.

Go to System > Preferences > keyboard Shortcuts and press Add button to add a new shortcut. A dialog box called Custom Shortcut will show up. type in dmenu as the name and dmenu-bind.sh as the command and press Apply. Now you’ll see your new shortcut entry under Custom Shortcuts. We need to set the key combination now. For that click on Disabled (in ‘shortcut’ column) in the new entry. It’ll change to New Shortcut… Now press the key combination you prefer. (ex: press ctrl + space) Make sure the combination will not clash with others. I chose Super key (Some people call it windows key.)  and Space (Super Key + Space) which is the default for Gnome-Do. Close the keyboard shortcut window.

Now you can press the key combination you chose and see how it goes typing in few characters of your fave app’s name. Use arrow keys to move between suggested applications and Enter to run. You can dismiss dmenu with Esc.

PS: You can change the looks and orientation of dmenu editing dmenu command in pydmenu.py file (/usr/local/bin/pydmenu.py) with help of man dmenu.

And it obviosly is not sexy :D

dmenu in action. Click to enlarge.

Usual Chanux crap

I always used SCIM input method with sayura sinhala input scheme. But it had weird bug that screws up almost all the text input areas (My friend @gaveen pointed out it’s SCIM related). So the people who new about iBus told me to try it but as always I didn’t have time to try it on my previous ubuntu 9.04 installation. iBus came default on ubuntu since Karmic Koala (9.10) and since I switched to Lucid Lynx (10.04) it was the right time to check iBus-sayura out.

As lazy as I’ve become I chose seemingly easier way of installing ibus-sayura. I used the ibus-sayura unstable PPA on launchpad to install. And it worked, සෙටිපිකට් ඇත්ත. So you too can take the easier route.

The actual How-to

Step 1 – install
First, to add the PPA repository your system run the following command in a terminal (Applications > Accessories > Terminal)

</p>
<p>$sudo add-apt-repository ppa:skhome/ibus-sayura-debianised-alfa</p>
<p>

Then update package list with

</p>
<p>$sudo aptitude update</p>
<p>

Then comes the installing step.

</p>
<p>$sudo aptitude install ibus-sayura</p>
<p>

(Yeah, you are right. You can use apt-get instead of aptitude)
Step 2 – Launch and use

Now you are ready to use sayura. Go to System > Preferences > Ibus Preferences*.  Select the input method tab. Find Sinhala,Sinhalese in “Select an input method” drop down list and select sayura there. And now press add button. Close the preferences window if you want to :P.

You’ll see a little keyboard icon on upper panel. Click on it and select sayura and enjoy typing sinhala.

*If this is your first I bus run it will ask whether to start ibus daemon. You should say yes. Then it might present another scary message with following  commands.

<br />
export GTK_IM_MODULE=ibus<br />
export XMODIFIERS=@im=ibus<br />
export QT_IM_MODULE=ibus<br />

If IBus doesn’t work, you’ll have to run these commands in a terminal like we did in the beginning and log out and log in again. Don’t forget to keep your fingers crossed, literally. Now you may want to try the step 2 again.

I like Command Line Interface. Maybe I’ve been saying this earlier on my twitter if not on this blog. Since I started with GNU/Linux I was so fascinated with the CLI. The first reason was it’s something not everyone preferred. The next it’s the preferred way of all the hackers I read about in text files.

With time I learned why people called it’s easy and powerful. I was familiar with it to the point that I felt home in a text terminal with green text on black background. Then came the time I was looking for CLI tools for most of my day to day stuff. Ever since I found Amarok not doing well for me I didn’t use a GUI music player. Right now I’m using MoC and never had second thoughts.

And I recently had this moment I found GUI to be very confusing. And when I was thinking about it later it was very confusing for me to understand too. GUI are made to be easy to use right?.

It was the last semester and we were doing Prolog. There was a practical session in labs to get us familiar with the visual Prolog (I’m not certain though) interface. But as always I had a good reason to not go there which I can’t remember now. But there’s a limit even a student can push things off. And so came the day I do Prolog.

As you can imagine it was the last possible moment start with Prolog and I was in a hurry. I checked out the the IDE on a friends machine and I thought it’s the end.

What Visual Prolog presented me (thx @varunarl)

What I saw. cc public.resurce.org

If I found the software for GNU/Linux I would use it, somehow. But luckily I didn’t and found swi-prolog instead. I just wanted to write some code and see how it works. swi-prolog got me going in no time. I wanted to learn how to use consult and it was pretty much all about it. I learned how to do it in visual Prolog in order to help a friend. But it was still way too complicated.

Swi-prolog basic usage

I know that the fact I’m trying to convey is not really rational. But the point is, in the GUI environments all controls are visible and for a beginner that can be too much. But in the CLI I only chose what I want. I learned both swi-prolog and visual Prolog with guides found on internet but I’m sure I took more time to filter out the necessary details in visual Prolog guide.

I didn’t do any serious programming in Prolog so I can’t say how each tool would serve you in such a scenario. But in my situation the CLI tool saved me a lot of frustration and time which helped me achieve required knowledge level for the exam. And on a not so related side note, *surprise surprise* I have passed that module :D.

My tweet you just read says the long story short. In case you didn’t come across, Google made DNS a buzzing topic again with Google Public DNS. So I felt like trying a dns cache again. The logic is “If a better DNS server makes things better, DNS cache makes it even better.”

This is more of a note to self than a HOWTO. If your use case atches with mine, feel free to use this.

My use case: I use an HSDPA, mobile broadband connection on Ubuntu 9.04 Jaunty Jackalope.

Install pdnsd with,

$sudo apt-get install pdnsd

Now launch the text editor you hate and add following to /etc/pdnsd.conf

(By default all the parts are commented so just adding this was fine enough for me)


server {
ip=208.67.222.222 , 8.8.8.8;
timeout=5;
interval=30;
uptest=ping;
ping_timeout=50;
purge_cache=off;
}

global {
 perm_cache=5120;
 cache_dir="/var/cache/pdnsd";
 min_ttl=15m;       // Retain cached entries at least 15 minutes.
 max_ttl=1w;        // One week.
 timeout=10;        // Global timeout option (10 seconds).
}

I copied this piece from here and edited ;). Added the global field because defaults were not cool enough for me. And in ip field I’ve put respectively OpenDNS and Google DNS addresses. You can just add one address there. ‘man pdnsd.conf’ will teach you more about the content in the file.

Once you are done editing the configuration file restart pdnsd with

$sudo /etc/init.d/pdnsd restart

Now you should tell the network manager to look for pdnsd for it’s DNS needs.

Right click network manager icon and then follow Edit Connections > Mobile Broadband and choose to edit your preferred network connection.

In Editing <Your Network Connection> dialog box,
[1] Choose IPv4 Settings tab
[2] Choose Automatic Addresses (ppp) Only in Methods Dropdown box.
[3] Set DNS Servers field to 127.0.0.1 (which refers to pdnsd in our case)

And obviously, Apply Changes :P .

If everything went fine, you are now ready to enjoy DNS cache goodness with pdnsd.

You can check how good is it with dig command.

ex:
$dig yahoo.com

run this command twice and compare Query time field.

Note: If you followed all the steps but still it doesn’t work, try restarting pdnsd. If you get following error refer this page

/etc/resolv.conf must be a symlink

Update: Added the global settings for config file.

Hacking is always fun. That’s why I always lose focus on everything once I find something to hack around. And that’s why I spent whole last night trying to figure out how to mimic Window focus event in a shell script. Though this is completely new to _me_, you maybe very much comfortable with implementing it :) . If so please let me know in comments.

Anyway here is my story.

I found this nice command line IM client called centerIM (Thanx @chathuraw for info). Once I got it set up I was just scanning on it’s documentation page & came across this interesting part “External actions & auto-responses“. I wrote a script right away for GUI notifications, inspired by notify.pl script for irssi. Here is the script if you are interested.

Since the load of IM messages was very high at a time & It was useless when the terminal window with centerIM was already focused (which means I’m chatting on centerIM) I was thinking of getting notifications only when centerIM window is not in focus. Few Google searches lead me to very limited resources & I chose xwininfo & xdpyinfo commands for my work.

Workaround: I’m using gnome for now & so gnome-terminal as my terminal emulator. I had to set Edit >Pprofile Preferences > Title & command option to keep initial title, in order to have “Terminal” as the terminal window name all the time.

And ran xininfo to get following output.

chanux@nim:~$ xwininfo -name Terminal

xwininfo: Window id: 0x3800003 "Terminal"

 Absolute upper-left X:&nbsp; 0
 Absolute upper-left Y:&nbsp; 52
 Relative upper-left X:&nbsp; 0
 Relative upper-left Y:&nbsp; 27
 Width: 1280
 Height: 691
 Depth: 24
 Visual Class: TrueColor
 Border width: 0
 Class: InputOutput
 Colormap: 0x20 (installed)
 Bit Gravity State: NorthWestGravity
 Window Gravity State: NorthWestGravity
 Backing Store State: NotUseful
 Save Under State: no
 Map State: IsViewable
 Override Redirect State: no
 Corners:&nbsp; +0+52&nbsp; -0+52&nbsp; -0-25&nbsp; +0-25
 -geometry 156x37+0+25

This can be used to get the window id of the window which runs the script.

Then I can find the focused window at the moment as following.

chanux@nim:~$ xdpyinfo |grep focus
focus:&nbsp; window 0x3800004, revert to Parent

I fetched the window IDs with a little bit more work.

Anyway the problem I had is that, I get 0x3800003 (at this example) or likewise for the Terminal window id & even when the Terminal id is focused I get 0x3800004 as the focused window id. Yes I know with some more work I can manage to handle that & come to a point that I can compare those window Ids to check for the focused window. But I really like to know why that difference come up. Anyone have an explanation? Or anyone like to mess with this?

Following is the way I fetched window ids from above outputs

chanux@nim:~$ xwininfo -name "Terminal" | grep xwininfo | cut -d " " -f 4
0x3800003
chanux@nim:~$ xdpyinfo | grep focus | cut -d " " -f 4 | sed s/,//
0x3800004