Nerd stuff that I thought up or noticed. It could be interesting or useful.
I decided that in the end, even though I’ve neglected my little blog here for so long, I shouldn’t be ashamed if the first post a put in a while is a technical one. So here goes:
If you want to kill one or many processes that all involve the same command or similar command, you can do it with the handy unix command pkill. It will kill all processes containing the string you give it as an argument. Use the -u option to restrict it to a particular user. For instance:
pkill -u joeuser java
to kill all processes with ‘java’ in their name started by user ‘joeuser’.
Another related handy command is pgrep which only lists the process id’s of matching processes and doesn’t actually kill them.
pgrep -u joeuser java
Recently I’ve become aware of Panorama Tools, which are a collection of programs for putting multiple overlapping photos together into one large composite picture. It’s excellent software, giving great results--it’s difficult or impossible in many instances to tell that a resulting photo used to be multiple ones. The problem with it is that it’s not very user-friendly, and very technical. The learning curve is steep. And to me at least, it’s unclear whether the software is still supported, and where the definitive version is.
Because of this, there have sprung up a few graphical-front-ends to this panorama code to make it easier to use. At first, I was only aware of the shareware offerings: PTGUI (€65 to register), and PTAssembler ($39 to register). I’ve tried PTGUI, and it works, but after 30days I wasn’t willing to shell out the $70, so I uninstalled it.
Well, help is here, there is a program called Hugin which is a totally free frontend to the Panorama tools. It’s at version 0.5, meaning presumably things still need to be cleaned up, but I can vouch for the fact that it is already very nicely usable. And of course, it creates great results.
Here are some examples of my first attempts:
This picture was made from two separate photos that I didn’t take with the intention of stitching them together.
A more impressive example is the inside of Santa Maria del Mar, in Barcelona. I couldn’t physically get this much field of view with my camera, because the lens isn’t wide enough, and I couldn’t back up anymore because I was inside. However, by pivoting the camera and taking a bunch of pictures, I could stitch them together with Hugin and get this great shot. This picture is a composite of 9 separate overlapping pictures. Also, the final composite picture is nearly 10Mpixels, while my camera is only 7Mpixels. I assume if I ever want to make a poster, this would be the way to cheat and get more pixels than my camera can take.
Finally, there’s this beautiful composite of the Monastery on Montserrat, also near Barcelona. It was originally 4 separate photos. It’s not perfect, as you can see that because the original pictures had different exposures, the sky has a funny gradient on the right side. Also, if you’re very observant, you can see that the lower-left corner is completely made-up. I love the “Stamp” tool in photoshop. The original panorama had no photo for the area that is now in the lower left part of the composite, so I copied some mountainside to it in photoshop. Also, there didn’t used to be any sky in the upper right, which was a bit easier just to copy outright.
Here’s what it used to look like. Hugin actually produces a copy of each of the component pictures accurately warped and with alpha channels on each photo to allow you to put them together yourself, if you want. If I had spent the time, I could’ve fixed where the seam was between two photos to correct for the strange way the sky changes on the right side of the picture. But it’s pretty cool the way it is, and I was getting lazy…
I love almost everything about Picasa, but there are some drawbacks:
A very cool thing that I discovered is that Picasa supports uploading to a number of different online photo services from Picasa itself. That is, you don’t have to download a bunch of different lame programs from each online photo place, Picasa will upload your Picasa photos with its own interface to their site. This seems to work well for Kodak EasyShare at least. When you have pictures in your Picture Tray, just select “Order Prints” and you can upload stuff to the online photo site of your choice. It’s nice.
I have a linux box at home which I like because it can act as a file server, a web server, and many other things. Having a desktop unix machine means I can also remotely logon from the outside world via SSH, which is cool. I have normal cheap DSL at home, and my IP addres changes every once in a while. I use DynDNS, a free service, to associate an unchanging name to my ever-changing IP address. A program on my computer notices if my IP address changes, and notifies dyndns to update my name to the new IP address. This means that as long as I use my dyndns name, I can always reach my computer from the outside world.
Editor’s note: for the rest of this description, I’ll use “Windows computer” for the computer you’re sitting at, and “Linux computer” for your unix server you’re trying to connect to.
SSH is only a text window, which is great for most things, but sometimes I want access to graphical programs running on my Linux computer. Originally, I tried to accomplish this with a free X-server on my laptop: Cygwin/X. It really is free, and it really works, and you can really run X-windows programs from your ssh shell and have them show up on your Windows computer. There are some quirks. For one thing, the last part of the install using Cygwin’s “setup.exe” (a distinctive name if I ever heard one) hangs for me on my Windows computer at the end of the install, if I’m using setup.exe version 2.510.2.2, which at the time I’m writing this is the “stable” version. They offer a lot of ways to try and make things work in their troubleshooting, and I tried them all with no success. What did work, however, was to use one of their “unstable” newer versions which worked beautifully (I used version 2.523). Since Cygwin has ported basically almost all standard unix programs to work on a Windows computer, you can also install a lot of other free software if you want. Part of the default install is bash, a much better command prompt than Windows’ standard command prompt cmd.exe. I also installed tcsh because I’m used to it, and the open version of ssh, which is up-to-date, powerful, and free. In addition I installed of course the X-Windows support.
The best way to connect to a Linux computer to start running X programs on your local Windows computer is to first ssh, forwarding the X connections through your secure ssh “tunnel”. To do this, you first start the Cygwin X-server on your Windows computer. It is a “server” because it serves your computer’s resources (display, keyboard, mouse) to programs that want to show up on your computer. Then, with an open cygwin shell (one usually starts up when you start up the Cygwin X-server) ssh to your Linux computer, and be sure to use the “-X” option to make sure you are tunnelling X connections through ssh. Like so:
ssh -X linuxbox.mynetwork.com
Where linuxbox.mynetwork.com is your Linux computer. Then, any X program you start in that ssh session, like for instance xeyes, will show up on your Windows computer, and be running on your Linux computer. This works fairly well for two computers on the same local network.
If you’re much farther away from your Linux computer, for instance somewhere on the internet, this can quickly become way too slow. Also, you have to start everything from scratch every time you reconnnect, because all of your programs will die when you disconnect.
Enter VNC. VNC is more like viewing your desktop on your main Linux computer from afar and being able to control it from afar. The main difference is that the desktop still exists on your Linux/Unix computer and all the programs are still running even if your remote connection disconnects. So you can start up some graphical program, have it do something that will take a long time, disconnect from your Linux computer, and reconnect later to see what happened while you were gone. It also means you don’t have to restart all of your programs everytime you reconnect. It’s really what you usually want.
VNC is also usually much faster than X if you’re far away from your desktop computer. I’ve been connecting to my computer in California from Minnesota, and it’s almost real-time. Almost. X would be much much slower.
To start a vnc session between your Linux and Windows computers, first you need to ssh to your Linux box. You need access to a particular port in a range that starts with 5900, on your Linux box. To do this, we will “tunnel” the ports securely using ssh. VNC uses different display numbers to identify different sessions. We’ll use display 2, because usually that’s free (display 0 is usually the screen you see when you’re logged in on the console of your Linux/Unix machine.) The port you need to access for VNC is number 5900+display, or in our case for display 2, 5902. So we securely forward that port to our Linux machine by using ssh as follows:
ssh -L 5902:linuxbox.mynetwork.com:5902 linuxbox.mynetwork.com
This opens up an ssh session to linuxbox.mynetwork.com, and connects local (Windows) port 5902 (the first number after the “-L”) to port 5902 on linuxbox. This works as long as you can ssh to your Linux computer. You don’t have to do anything else, like open ports in a firewall surrounding your Linux box. ssh does everything. You can also do this with Windows graphical ssh programs. You need to specify an “Outgoing” port forwarding, and 5902 on the linux box, and 5902 on your computer.
Once you get this ssh session open, all you need to do is type
vncserver :2
and you should have started up a new session on display 2. If this is the first time you run vncserver, it will ask you for a password. Use something reasonably secure, like maybe your account password.
To connect to this vnc session, you need a VNC Viewer on the Windows computer. A good free one is TightVNC. Remember, for what I’m describing, you only need the viewer. Usually it’s one self-contained program.
Now, since we’ve tunnelled our port 5902 to the Linux box’s port 5902, to any programs on our Windows computer, our local port 5902 is what we want to access. So when the viewer starts and asks for the computer to connect to, we’ll connect to:
localhost:2
Which is shorthand for saying, “Connect to port 5902 of this very computer”. ssh will then take everything it sees on port 5902 of this Windows computer and make it show up on port 5902 of the Linux box. Like magic. Hopefully, it will ask you for your password, and Voila! A window will open that shows your desktop of your Linux computer.
That’s the main functionality. Now for the finer points. You probably don’t want full 24-bit or 32-bit color being forwarded across the internet, because that’s just slow. So use the following vncserver command instead:
vncserver -depth 16 :2
That will use 16-bit color instead, which if fine for most uses. You can even go really primitive and use a 256-color palette for even faster performance:
vncserver -depth 8 :2
But this kind of sucks.
Another thing: Most likely the VNC session will use a custom Desktop, i.e. a plain vanilla X-session with twm, an old but reliable window manager. If you want to see a normal session, with something like KDE or Gnome, you’ll have to doctor some files. Personally I like KDE, so what I did was to doctor my xstartup file inside the directory ~/.vnc to be like so:
#!/bin/sh xrdb $HOME/.Xresources xsetroot -solid grey xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & # twm & startkde
As you can see, I commented out the line with twm and added startkde. Now when I start a new VNC session, I get a new kde session.
KDE is also cool, because it allows you to take an existing console logon and make it available for remote viewing using VNC. To do this, to the the KDE Control Center, Internet and Network, Desktop Sharing. Check “Allow uninvited connections” and “Allow uninvited connections to control the desktop”. Uncheck “Announce service on the network” and “Confirm uninvited connections before accepting”. You may also want to check the box for “Always disable background image” in the Session tab to speed things up. Also, you might want to choose your port in the Network tab instead of having it assigned automatically, so you always know which port to connect to from the outside world using your ssh tunnel.
The final tweak is probably beyond the scope of this document (or would be even longer than I’m willing to write.) Just be aware that there are a lot of compression options for VNC, especially if you’re using a TightVNC server on your linux box and TightVNC viewer on your remote computer. TightVNC can use JPEG compression for things, which speeds up everything a lot, but can make your desktop look like you’re viewing it through a smudgy window. Both normal compression and JPEG compression can be adjusted by a number from 1 to 9, so you can fine tune how much compression you use to balance speed with prettiness.
Some more tidbits: TightVNC and other programs make available VNC servers for Windows computers too, so you can see and control Windows computers’ desktops remotely. I’ve never tried this and don’t know the security/usability implications. I’m sure there’s also some implementations for MacOSX, because that’s basically Unix underneath too.
ADDENDUM: Apparently, if you have an alias for your network address, (in a ‘hosts’ file perhaps) there will be problems with ssh tunnelling. You may receive an error on your Linux console saying “open failed: administratively prohibited” if you use an alias for your computer in your hosts file.
For instance, when I’m in my house, my Linux computer has a different, local ip address because it’s inside my firewall. I have this called ‘mylinuxbox’ in my hosts file, so I can have a name for what would otherwise just be a local ip address (i.e. 192.168.x.x). If you try to say “ssh -L 5902:mylinuxbox:5902 mylinuxbox” you will get the cryptic “administratively prohibited” error on your Linux console. The correct way to do it is to use the full non-aliased form inside the -L argument:
ssh -L 5902:192.168.x.x:5902 mylinuxbox
where you would replace “192.168.x.x” with whatever your local ip address is.
For those of you who know me, you know that one of the longest-running of the Scattered Random Projects has been the bookcase that I’ve been building. It’s probably been over 2 years since I started it in grad school. I’m not overly concerned with this lack of progress, because really it’s just nice to have it there to putter around with every once in a while when I need to take my mind off of other things in life. Sort of a “It’s the journey, man, not the destination,” kind of thing.
Well the other day I was looking around my new apartment, and realized that I still have a lot of crap sitting around in piles. “Wouldn’t it be nice if I had a more efficient way of storing all of this crap, especially the books,” I thought to myself. Later, while noticing that one of the things taking up space in my apartment was unfinished bookshelves, I had what many authors call a “Eureka Moment”.
The task of finishing these bookshelves has gotten more complicated, now that I live in an apartment, and not a nice rowhouse with a full basement/workshop area. Really, the only task left for finishing the bookshelves is the literal “finishing”, or applying varnish to the outside. The sort of horribly messy task best accomplished in a garage, with unfinished concrete floors and separate ventilation from human-inhabited spaces. Since I don’t have a garage, I had to improvise an isolation chamber for my bookshelves. With suggestions from my co-worker Nader, I created the Bookcase Fortress of Solitude. Basically, this consists of a plastic-enclosed 6ft. x 6ft. area with an open window.
I must say it worked out rather well. After arduously hand-sanding the whole thing with 220grit sandpaper, I just finished one coat of polyurethane over the whole structure (or “carcass” in the woodworking lingo) and it looks pretty good. It only took two and a half hours for the sanding and varnishing. Probably the sanding took a lot longer because I had to remove all of the greasy hand-prints of the movers.
We’ll see how long it takes before I can finish the second coat! Now to leave my apartment for a few hours so I don’t gas myself…
Recently the picture on my television was “bouncing” or jittering up and down. Whacking it on the side or stamping your foot on the floor would make the picture stable again. I began to think that possibly my 9-year-old Panasonic CT-20G21U 20-inch television had come to the end of its useful life. Or at least the effort needed to fix it would be far more than what it was worth. At any rate, with all the foot stamping, I was starting to be reminded of a carnival act in which the horse was supposed to solve math problems.
It had other problems too, like color “blobs” or regions which looked like they were more purple than other regions. I was pretty sure that just meant the tube needed degaussing, but my TV doesn’t have a degauss button, so I wasn’t sure how to do that. Some webpages suggest that you can get TVs to degauss by turning them off or on, or possibly by unplugging them, but that never seemed to work for me. So another problem.
Then I came across the Panasonic TV Service Modes page. On it, the author tells how to get into the super-secret maintenance mode of certain Panasonic TVs, and make adjustments to all sorts of crazy things affecting super-low-level functioning of your television. My model wasn’t listed, but as it turns out, it worked anyway. So I got into “Serviceman Mode”. I quickly discovered that there weren’t any adjustments that I was comfortable messing with. So I exited the Serviceman Mode. On exit, the TV did what looked like a full reset.
Voila! Unexpectedly, the purple blobs and vertical picture bounce went away! My only guess is that the full system reset may have degaussed the set. It’s possible that my set was so magnetized that even the vertical hold was suffering.
So if you have weird problems with your TV set, maybe they can be fixed by degaussing. And if you can’t figure out how to degauss your set, try googling for a way to get into its service mode. (Or its sexist “Serviceman” mode.)
Sci.Electronics TV Repair FAQ by Samuel Goldwasser
If you run a Windows computer and are more ambitious about fixing problems then throwing your hands up in the air and sobbing softly, you should know about http://www.sysinternals.com/ . It’s an excellent collection of freeware windows diagnostic programs. They give you excellent access into the inner workings of your Windows computer.
The utility on the Sysinternals website I found recently is called PageDefrag. Hopefully you’re on top of things enough to know that every drive in a windows system needs to be defragmented once in a while. Defragmentation is the process where some program gathers all the pieces of each file on your hard drive that may be scattered around your hard drive, and puts the pieces in one place, speeding up future accesses of your files. If you’ve defragmented before, you may know that any files that are “in use” are not defragmented by the standard windows defragmenter program. Some files that are always in use are the most important ones to the proper and speedy functioning of your system. These include, most notably, the page file (swap) and the Registry. Enter PageDefrag. It’s a very simple program. You run it, and it tells you if some of these important files are fragmented. If they are, you can schedule PageDefrag to defragment these files on the next boot of your computer, before they start being used by the operating system. Since these files are accessed all the time, it’s a great efficiency boost to your system if they are defragmented.
Other programs on Sysinternals that I love:
Sometimes I generate a pdf or PostScript receipt of an online purchase which I then save somewhere on my computer. It’s nice to have around a record of my purchase, just like a real paper receipt, especially if I need to return something, etc. Other times I have actual important things like electronic tax returns, etc. that I need to keep around.
The problem then becomes: What if someone steals my computer, or breaks into it? Then they get to see all these files and potentially use the sensitive information for mischief.
Thankfully there’s ccrypt. It’s a simple program that runs on Windows, Linux, and MacOSX. All it does is ask you for a password to encrypt your files. It then encrypts them and adds a suffix “.cpt” to their filenames. Done. To decrypt your files you just supply the same password. (Make sure you remember it!) It isn’t nearly as complicated as PGP or GPG. But it still uses real encryption, so the security of your files is limited only by your choice of password, not the encryption method. The normal program is command-line, but there are some additional packages that allow you to integrate it into the GUI desktop of some notable operating systems.
Note that encrypted files look like random information, and thus are not very compressible. If you want to compress your files, you should do this before you encrypt them.
This is as much for my reference as for everybody else!
Recently my tivo hung on the boot screen. (“Your recorder is starting. Please wait a moment.”) Luckily, since I am a big nerd, I had upgraded my tivo to a larger hard drive, and in the process had created a backup image of my tivo’s hard drive. So I could restore the backup image and fix my tivo! Here’s what I did:
MFSTools v2.0: http://mfstools.sourceforge.net/
Full backup and restore directions (The Gory Details): http://www.newreleasesvideo.com/hinsdale-how-to/index9.html
If you want a batch file to spawn another program and then go on with its life (or end, if there’s no other commands) you need to specially ask it to. Normally, if a batch file spawns another program, the batch file will wait at that point until you close that program.
What you need is the batch file command called start. Like so:
start "A Pretty Title for your Program" myprogram.exe
The first argument is always a title, and the second is the name of your program if you don’t specify any switches inbetween.
As an example, here’s a batch file I made called acroread.bat which is useful for starting Adobe Acrobat from the command line without changing your path, or typing in the full path to the executable.
rem @echo off start "Acrobat" "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe" %* exit
Normally, if you were to double-click on that batch file, it would leave a cmd shell up until you closed Acrobat Reader. start prevents that. Note that if you’re actually running this from the command line you should omit the exit command. I included it because this batch file is being spawned by another program, LyX, in order to view PDFs, and I never wanted to see a shell prompt. LyX for Windows 1.33 currently doesn’t like spaces, so I couldn’t specify a location for Acrobat Reader with spaces. I made the acroread.bat file to fix that, and put it in a directory in the path that has no spaces.
Orig. reference: http://www.americatoday.com/hanar/dosb.htm