Archive for the 'howto' Category

Windows: Change Your Default Telnet Handler

Wednesday, November 21st, 2007

At this point I see basically two legitimate uses for telnet: mud’s and nethack. While both forms of entertainment are still popular, they are far from mainstream even in the geekier circles. They have mostly niche audiences, and general public has little or no use for telnet these days. You really do want to use ssh for any kind of remote shell stuff. This is evidenced by Microsoft disabling the telnet client by default in Vista. So the only remaining use for the tool is simply poking around by connecting to random ports. These days I mostly use telnet to see if I can access an email server from a remote location by telnetting to port 110 or 25. But then again, I could also use netcat for that with pretty much the same results.

As you may or may not know, I set up my own little public nethack server that can be found by telneting to luke.kicks-ass.org. And since for some reason he output is a bit garbled in the default windows client, I sought out replacement. PuTTY is probably on of the better free, open telnet clients for windows out there. There is simply not much competition on that market anyway, because the basic windows client is not that bad. Still, I find PuTTY superior.

The problem is, by default handling telnet links such as telnet://luke.kicks-ass.og is by default hard wired to the windows client. Therefore if I wanted to use PuTTY I had to manually open it, and type in the server address instead of just clicking on the link. I decided to change this behavior, and set PuTTY to be my default telnet handler from now on.

How to do it? You can use the little registry hack below:

Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\telnet\shell\open\command]
@="\"C:\\Program Files\\PuTTY\\putty.exe\" %1

Copy the code snippet, paste it into your favorite text editor and save it as a .reg file. Then double click it to run it. From now on, telnet links should open in putty, as long as you have it installed in C:\Program Files\PuTTY. If you want to change it back to the windows client, here is a snippet to reverse it:

Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\telnet\shell\open\command]
@="rundll32.exe url.dll,TelnetProtocolHandler %l

Enjoy!

Btw, can you think about other legitimate uses of telnet, that would not be appropriate for ssh or other tools? Let me know in the comments.

Logitech VX Revolution in Dapper

Thursday, November 1st, 2007

I just inherited a Logitech VX Revolution mouse - one of those high end mice that I could not bring myself to buy. And by inherited I mean someone who was leaving dropped off their company laptop with all the peripherals and I was lucky enough to call dibs on the mouse. Now I have it sitting on my desk, replacing a much less expensive wired Logitech mouse. It seems barely used, and the wirelessness is a really nice feature for my cluttered desk. I no longer have that mouse cord getting in the way. )

Logitech VX Revolution

The mouse is nice, but not all that special. It seems a bit more accurate, and it is comfortable but I’m not entirely sure if I would buy one. It’s a notebook mouse so it’s slightly smaller than my old mouse, but I guess thats not a bad thing, considering that my new humongous keyboard takes like half my desk. The middle mouse button is a bit stiff and takes considerably more force to push down than on most regular mice. The zoom bar is located in a really weird, out of the way place that kinda makes it a bit useless. Still, it’s a very nice mouse so I’m not going to complain. I just need to remember to switch it off when I leave for home to conserve the battery.

Now the task at hand was to get the damn thing working under Dapper. By default my Kubuntu completely ignored the zoom bar, site tilts of the scroll-wheel and the little button above it. The side buttons were detected as right and middle mouse buttons. So the mouse was functional, but not fully.

I found this lovely thread on Ubuntu forums with a solution. There is an app out there called btnx designed with the Logitech Revolution and MX high end mice in mind. It let’s you configure all the nifty additional buttons. The newest version has a very nice GTK GUI that let’s you detect and configure all the buttons using an easy to use wizard. Unfortunately I couldn’t use that version because it requires GTK 2.10.x and I’m on Dapper. The most recent version in the dapper repos is 2.8.x. I didn’t feel like compiling GTK from source just to get a damn configuration wizard working.

Since the VX Revolution is one of the mice fully supported by btnx out of the box, I opted to install the old 0.2.14 version with a text based config and no GUI. The process was very simple:

wget http://www.ollisalonen.com/btnx-0.2.14.tar.gz
tar -xzvf btnx-0.2.14.tar.gz
cr btnx-0.2.14
make
make install

At this point I got a weird error message. Here is the output of the last command:

root@inuyasha:~/btnx-0.3.2/btnx-0.2.14 # make install
chmod a+rx ./scripts/install.sh
./scripts/install.sh
Installing...........
btnx successfully installed. Starting btnx.
/etc/init.d/btnx: line 34: /lib/init/vars.sh: No such file or directory
make: *** [install] Error 1

People in the Ubuntu forums say this is a non-issue. So I went into /etc/init.d/btnx and commented the line that refers to vars.sh (line 34 I think). Then I did:

/etc/init.d/btnx stop
/etc/init.d/btnx start

This restarted the daemon and plopped btnx_config file in my /etc/btnx. This is where all the keys are configured. The side buttons are mapped to key combo that changes tabs in most applications. It works in Firefox as well as Komodo Edit so I’m relatively happy with it. The little button above the scroll wheel refreshes the page in FF which is also a nice touch. I think I’ll keep that. The zoom bar was configured to do Ctrl+Alt+Left and Ctrl+Alt+Right which switches virtual desktops in Gnome. I reconfigured it to Ctrl+Tab and Ctrl+Shift+Tab for equivalent action in KDE but the key repeats very fast making it a bit difficult to control. To switch desktops one at a time you kinda have to quickly tug at the button instead of holding it. I may change this to something else.

Finally tilting scroll wheel invokes back and forward browser commands by default. I don’t particularly like this option because it seems like it can cause trouble. I can see myself tilting by accident and backing out of a half, written blog post. So I will probably change that also. Then again this haven’t happened yet so go figure.

I might actually swap the functionality between the side buttons and scroll wheel tilting. Use scroll wheel to control tabs, and side buttons to go back and forward. This way there is less risk of accidentally leaving the page while scrolling inside a text box.

My only issue is that one of the side buttons is still sometimes detected as RMB. It’s like a little lottery - I never know what it will do. There might be a way to override it. If I find it, I’ll post it here.

Create and Stream Video With Flash On The Buntu

Tuesday, October 16th, 2007

The other day I was handed a quicktime mov file and told to put it on the company website. The catch was that the file was obscenely large, and we didn’t want the clients to have to download Quicktime or an equivalent to view it. It pretty much boiled down to “can you make it work like Youtube without actually uploading it there?”

Sure I can! I can do it faster than Lex Luthor can fucking steal the cakes. All 40 of them. I mean, this will be done in 4 easy steps - observe, and be amazed:

Step 1

First we need to get something that will convert the MOV format to the FLV format. There are several encoders out there that can do it, but the one that is both fast and free is FFMPEG. So let’s get it, shall we?

sudo aptitude install ffmpeg

Step 2

Let’s actually do the conversion. If you want to keep it simple (and I do) you don’t really have to do much beyond:

ffmpeg -i movie.mov movie.flv

Now just sit back, and enjoy the blinkenlights till it finishes.

Step 3

Now we need something to play the movie. Sticking the FLV on the server just doesn’t cut it. We want Youtube like experience where people can pause the movie, skip ahead or rewind it back at will. Enter JW FLV Player.

Go to that website, download the zip, stick it in some web accessible directory along with the movie file, edit the HTML to take out all the useless examples, then point it to the correct FLV and you are done!

Step 4

This is the point at which you try to watch the movie and realize it has no fucking sound. Why? Because you are using Ubuntu - that’s why. Let me explain - ffmpeg usually needs to be compiled and linked with stuff like mp3 and AAC encoders. Unfortunately on Ubuntu (and debian for that matter) mp3lame and faac end up in different repositories based on their licensing terms. So the default Ubuntu ffmpeg package does not have these things included. This makes the package virtually useless for our purpose.

Good news is: there is a solution. Bad news is that you will need to roll your own copy of ffmpeg. Fortunately Paul Battley wrote a very good step by step guide on how to do it. I will replicate some of these steps here for the lazy part of the readers.

Step 4a

First let’s prepare and download all the build dependencies and tools you will need:

sudo apt-get build-dep ffmpeg
sudo aptitude install liblame-dev libfaad2-dev libfaac-dev libxvidcore4-dev checkinstall fakeroot
apt-get source ffmpeg

Note that aptitude does not have build-dep or source parameters, so we use our good old apt. First line fetches build dependencies for ffmpeg (there may be quite a few of them). Second one installs the mp3 and aac libraries on your system, along side with checkinstall and fakeroot which we will use for building.

Step 4b

Now you will have a directory that starts with ffmpeg-0.cvs*. Cd into that directory. We will have to edit the debian rules file to include the mp3lame and faac in the build. Add the two following lines directly under all the other confflags entries:

confflags += --enable-mp3lame --enable-faad
confflags += --enable-faac --enable-xvid

Step 4c

Let’s fucking build this shit! But let’s do it the Ubuntu way. Screw Mrs. Configure and her two friends Mr. Make, and Mr. Make Install. We are using fakeroot!

fakeroot debian/rules binary
sudo checkinstall

Fakeroot may generate all kinds of funky warnings, but as long as you don’t run into any errors you should be just fine. You can safely just ignore the output and go grab some coffee.

When you do checkinstall change the version of your package to something bigger (ie increment the build number by 1 or something). Otherwise when you update your system, apt may want to replace your version with the current copy from the repository - and you don’t want that. Also change the name of the package to ffmpeg instead of whatever is there by default.

Once you are done, you should have a brand new ffmpeg on your system that will convert your MOV file to a FLV with sound.

So, go back to Step 2 and re-encode your video and re-embed it as in Step 3.

That’s it. Not entirely in 4 easy steps (thanks Ubuntu!) but close enough. The build process is really not that bad. And you only have to go through it once. Once you do it, you should be all set. Best part is that your newly built ffmpeg is a deb package. You can easily remove or upgrade it via apt or aptitude the way God intended.

Howto: Two Way Sync Between Kontact and GCal

Thursday, October 11th, 2007

Ever wondered how to sync up your Kontact Calendar with your Google Calendar? Me too! But I figured it out. Below you can find step by step instructions on how to set it up.

First, you need GCALDaemon. Yes, I know it’s Java but it’s not as bad. I’ve been running it in the background for few days now and I don’t really see any performance hit. So stop whining. Just download the linux bundle and unpack it into /opt. You can follow the default installation route, and put it in /usr/local/sbin but to me /opt is where it belongs. That’s where I have Firefox and Komodo Edit and all the other apps that like to have their own personal directory. Once you do that, follow the official instructions on how to edit the following files:

/opt/GCALDaemon/bin/password-encoder.sh
/opt/GCALDaemon/bin/standalone-start.sh
 /opt/GCALDaemon/bin/sync-now.sh

You will need to update all the paths and change them to the new /opt location.

Make sure you give yourself write permissions to /opt/GCALDaemon/log/ because the daemon it will desperately and obsessively want to write there. If you run it as a user without write permission to that folder you will see a nice stack of Java exceptions popping out. For some unexplainable reason, there is no way to configure this. Retarded, I know but what are you going to do… Fortunately there is a way to put “working” files, such as the local ical file in your home directory. Open the /opt/GCALDaemon/conf/gcal-daemon.cfg and add the following line somewhere close to the top:

work.dir=/home/yourusername/.GCALDaemon/

Make sure you use your change the path to your home directory there. Now just create .GCALDaemon in ~ and you are ready to do the next step.

Follow the file-based setup instructions on the GCALDaemon page. Make sure you pay close attention to step 4D. When you are pasting in your gcal address make sure that:

  1. You are pasting in the Private URL (not the public one)
  2. You delete http://www.google.com from the URL. The address in the config file should be starting with /calendar

I got both of these things wrong on the first try because I didn’t read the instructions carefully. Also, make sure you change the file.ical.path property to something like:

file.ical.path=/home/yourusername/google.ics

Steps 6 and upward are Rainlendar specific (Rainlendar is some shitty desktop widget calendar for windows btw) so you can safely ignore them. Once you start the daemon, it should put the google.ics file into ~/.GCALDaemon.

Now open Kontact, and pull up Calendar. On the left hand side you should see a box labeled Calendar. It probably has Default KOrganizer Resource entry in it:

Add New Calendar

Hit the Add button in the lower left corner. When prompted what kind of calendar you want to create, choose Calendar in Local File:

Calendar in Local File

Finally, name your calendar and point it to the google.ics file in your home directory:

Set it up with google.ics

If everything went right, you should see your GCal entries pop up in Kontact calendar. If they are not, it means you did something wrong. Go back and check your settings. Make sure you copied and pasted the whole encrypted password, and check both paths. I can verify that this setup works.

This is a two way sync meaning that you can add events on either side (KOrganizer and GCal interface) and they will transfer to the other medium. Sometimes you might run into issues when you edit the same entry on both sides in a really short amount of time. You never know which edit will stick - but then again, that’s to be expected.

Now all you have to do is to make the GCALDaemon run on startup. You can start it in several way. The best one would probably be an rc script. But since I use it on my laptop, which always runs KDE I decided to make it a KDE startup entry. I simply created a gcaldaemon.desktop file in my ~/.kde/Autostart directory with the following contents:

[Desktop Entry]
Exec=/opt/GCALDaemon/bin/standalone-start.sh
Name=GCALDaemon
Type=Application
X-KDE-StartupNotify=false
X-KDE-autostart-phase=2

It’s probably not the best or most robust method, but it works.

So that’s it - this is all you need to do to convince your Kontact Calendar and GCalc to start talking with each other. Enjoy!

How To Kill Stuff On Linux

Friday, October 5th, 2007

You are happily working on your linux box when all of a sudden something freezes and becomes unresponsive. What do you do? Let’s talk about killing today!

Killing Stuff On Linux
img © Rossy ℗∑ñℊ⊍ïñ found @ evilpenguins.tribe.net

Everything really depends on situation. If it’s just a single application that decided to stop responding you can simply kill it. Now, you may think that killing is a bit harsh punishment for not talking to you - and it is. Best practice is to wait a little bit, and the app may un-freeze itself eventually. Chances are that some blocking process seized up the focus, and rendered GUI unusable for a little while. Then again, applications sometimes just freeze or get themselves into a runaway loop. And then there is not much you can do but send them SIGTERM or SIGKILL signal using kill or killall. The former takes the PID of the process as an argument, while the latter takes a name of the binnary and additionally tries to kill the whole process tree which is usually (but not always) a good idea. Note that both commands send SIGTERM by default which is essentially equivalent to nicey asking them to drop dead. If you use -9 you no longer ask - you shiv them in the heart with a rusty spork and watch them bleed to death on your new carpet. And by that I mean data loss, and other unexpected side effects so use it carefully. RTFM for all the other fun signals you can send to your processes.

But how do I kill something if I don’t even know whats it’s pid or the name of the binary?

Good question, voice in my head. You always bring up these interesting things. There are three ways to deal with this problem. First one is to STFU, stop being such a luser and use ps, and top to figure out which application is acting up and then -9 it like a man. But if you can’t handle that, there are two other remaining alternatives for the whussies: pkill, and xkill.

I mentioned pkill before, so I’m not going to repeat myself. All you need to know is that pkill is a smart fellow. He went to ninja school and is sneaky enough to figure out that when you tell it to kill firefox, you really mean firefox-bin. By that logic Kill and killall are kinda like mob hitmen - effective, but dumb as bricks. You have to tell them exactly who to hit, and how.

Xkill is kill’s graphically inclined cousin who specializes in killing windowed applications. When you call him, he appears as a stylish (or tacky, depending on your taste) black skull and bones cursor. Kinda like an inverse Jolly Roger. If pkill is a ninja, then xkill is a pirate of the bunch. Think Jack Sparrow - can be quite destructive if aimed well, but tends to blow shit up if you underestimate him (ie. click in the wrong place). Point him at your frozen window, hit LMB and he will do the rest. Note that if you change your mind you can cancel it by clicking anywhere with RMB.

What if my whole X seems to be locked up?

Easy - swith to a TTY using Ctrl+Alt+F1 (or any function key from F2 to F6 for that matter)! Then use top/htop or whatever strokes your fancy to figure out which app is hugging all the CPU and eating all the memory. Kill it and chances are that all the other software will be given a breath of fresh air and will resume normal function. You can switch back to X with Ctrl+Alt+F7.

If that doesn’t work, and you don’t mind loosing some data, you can give X the good old 3 finger salute. And no, it’s not that one. The old Ctrl+Alt+Del salute remains a fond memory of Win-DOS 95 users whose machines had those awesome reset buttons on the case, that helped them to recover from frequent BSOD’s. Reset buttons are a thing of the past, and so is the Ctrl+Alt+Del which acts as a key shortcut to bring up task management console, or logout dialog on most modern systems. Let’s face it - pressing this key combination no longer feels like saying “Fuck You OS, eat shit and DIEEE!”.

The 3 finger salute I’m talking about is Ctrl+Alt+Backspace - and it’s the key combination that will kill your current X session. And it will give you as much gratification, and therapeutic frustration relief as Ctrl+Alt+Del in the good old times but without actually hosing the filesystem or making the system unstable. Think of it as a forced logout combined with a restart of the X server. 98% of the time this will do the trick and let you resume work quickly and easily.

What if my system is frozen solid?

There is still a way to restart it gracefully using the magic SysRq key combo. Simply hit Alt+PrintScrn (which is how you get SysRq key) and then type in R E I S U B with… Your nose… Or other part of your anatomy. This will trigger a nice reboot that will not corrupt any of your data, destroy the file system or wreck any other crazy damage. In fact each of these keys issues a special SysRq command:

R - switch the keyboard mode
E - send all processes the SIGTERM singal
I - sends all processes the SIGKILL signal
S - Sync filesystem
U - Unmount all devices
B - Reboot immediately

Theoretically you could just do SysRq+B to do an old school, Win 95 style Alt+Ctrl+Del reboot, but it’s just as bad as hitting that power button. Your best bet is to run the whole sequence to ensure that the system shuts down in the way it would normally shut down when you issue a reboot command.

And it’s almost guaranteed to work even on a completely locked up system. That is, if it’s enabled on your system. If you are not sure, do a really quick test right now:

cat /proc/sys/kernel/sysrq

If you see a 1, you are in good shape. If you see a zero, you can enable the SysRq keys by doing:

sudo echo 1 > /proc/sys/kernel/sysrq

Better do it now before you somehow hose your system and need to use it. It’s kinda hard to issue commands when nothing responds to you.

How the hell do you expect me to remember this REISUB thing?

Mnemonics my friend. That’s how you do it. The popular one circulating out there is Rising Elephants Is So Utterly Boring. If you are more of a visual person, I have another one for you. Observe:

Rei AyanamiSubway Sub

Get it? It’s REI Ayanami from Neon Genesis Evangelion and a Subway SUB. It’s easier to remember if you are a fan of the show. Just think about Rei eating a sub and you are good to go. )

So there you go - plenty of ways to kill, maim and slaughter your applications in many ways. And best of all - most of these are relatively safe, and won’t break shit. At least for the most part. Remember kids - kill responsibly.