Dual Boot Magic

I dual boot on two out of three computers but I really only spend less than 1% of the time in Windows. Occasionally I do find the occasion to bring the red headed stepchild out of the basement. As if this weren’t annoying enough I would often reboot, lack the patience to babysit the reboot, and come back just in time to see that I missed the grub menu and now I have to reboot again. Well some time ago I found a solution to this mess. Enter grub-set-default <num>—this nifty command sets the grub entry to load by default for the next boot only. So I count my grub entries and put the proper number in a nifty reboot script. Alas, by the next time I use this script various Ubuntu updates have changed my grub menu such that now I get some old kernel instead of Windows like I wanted. This clearly wouldn’t do, so I fixed it. Now you can do the same.

Save the following to a script, such as ~/bin/windows.

#! /bin/bash
TARGET=windows
MENU=/boot/grub/menu.lst
ENTRY=$[`grep ^title $MENU | grep -n -i $TARGET | cut -d: -f1` - 1]
sudo umount /media/surfer
sudo grub-set-default $ENTRY
sudo reboot

The umount /media/surfer line just unmounts my network media, speeding up the reboot process working around an annoying Ubuntu bug where the shutdown hangs waiting for network drives even as the network is already down, hence no response from the share and a long timeout.

The ENTRY= line is the interesting part. First grep ^title grabs all the grub entries from which we will count the indexes. Next, grep -n $TARGET prints the line number of the entry we are interested in (Windows) along with the line. cut -d: -f1 splits the line on ‘:’ and returns the first field, the number we want to boot. Finally, grep counts from 1, but grub counts from 0, so $[<stuff> - 1] does bash math, wich is like normal math mostly, and hence we have the proper argument to give grub-set-default, et voila.

You can even put an icon in your panel or desktop that will run this script, giving you Windows in one easy click.

24 Dec 02:48 :: 0 comments :: Comment
Tags: linux, computers, annoyances, cool

Mysterious strftime segfault

Say you're working on a big project. Then at some point you call strftime or maybe ctime and what do you get but a nasty and mysterious SEGFAULT?? What's more you are absolutely sure you have no memory leaks, nothing is wrong with the arguments to the call. Then gdb tells you only that the segfault is happening somewhere deep inside the library call. Furthermore, it works on some platforms but not others, indicating again that memory leak you are sure you don't have. So what do you do but spend three hours tracking down your much doubted memory leak? Well hopefully you find this very post and save those three hours. You see, if time.h is included in another source file, you may have forgotten to include it where you use it. The compiler won't blink an eye. The linker doesn't even complain. Yet somehow it all works dandy until you try it on the TA's computer. So long story short, check your includes.

19 Sep 09:49 :: 0 comments :: Comment
Tags: programming, c, troubleshooting, annoyances, computers, linux

CSApprox

Probably the coolest VIm plugin since netrw, welcome CSApprox! Just put this in your .vim/plugin and away you go with completely transparent and automatic 256 color themes for your terminal vim that look amazingly not unlike the GUI versions of those themes. Just make sure your terminal properly reports 256 colors, and that your vim binary is compiled with gui support (debian flavors do this, but apparently not red hat flavors). If either of these are missing it will give you a little message and delay opening vim, if this is a problem you might want to suppress that output.

I also highly recommend enabling 256 colors via Xresources rather than setting TERM=xterm-256color, this will save headache when sshing in from a less fine terminal or when logging in at the console. A quick google turns up plenty of info on how o set your Xresources with one caveat; if you use uxterm like any sane person would, you need s/Xterm/UXterm/. I’ve also found cases where I need xterm as well, so I simply put all three in there to be safe.


Xterm*termName: xterm-256color
UXterm*termName: xterm-256color
xterm*termName: xterm-256color

25 Nov 09:22 :: 2 comments :: Comment
Tags: linux, programming, computers, cool, vim, colors, terminal, xterm, uxterm, gvim, 256

Mutt Color Theme

Some time ago, being the no good visual designer I am, I decided to put together a mutt color theme. This was no ordinary theme, I’m talking 256 colors! No, don’t worry, the theme doesn’t use all 256 colors.

Aaron’s post prompted me to put up my theme for consumption, enjoyment, and comment. If you want details on how to make the colors work, follow the link above, he did a good job of that already.

Now, the theme and screenshots.

14 Nov 11:45 :: 4 comments :: Comment
Tags: linux, computers, mutt, cool, color, email, 256

Bye Bye smbfs

Please, Von, please, next time you set up a samba mount, just use cifs and not smbfs. Save yourself a lot of headache.

14 Apr 23:42 :: 0 comments :: Comment
Tags: computers, linux, annoyances, troubleshooting, reference

Walls and Blocks and Beasts! Oh My!

Some people were poking around for the beast game on #utah today. So I dug up ye olde code and got it to compile without so much as installing some libs and adding a #include. That’s promising, I haven’t touched that code in 4+ years. Anyway it compiles but when you run it the screen is all garbage. #utah says it probably has to do with sfms. I don’t have a hint of time to do anything with it right now, but here I post it anyway in a darcs repo for the whole world to enjoy.

Some history on the project, you can stop reading now if you hate history. This was the first major thing I ever worked on. Before this it was writing a few graphics routines in BASIC for my friends game “Target”. It was then I drew the best ever 8×8 pixel rendition of an angry green blob. Wish I still had that… Prodding the time machine along… My brother Jacob and I set out to clone our good friend beast around 1997-8 in C++. He did all the work at first, with me watching intently and asking such questions as “what does that do?” and “why do it like that?”. Before the end I was writing as much code as he (or at least so I remember it). We had a good ol’ time playing it. When I returned from my mission in 2003 I did a rewrite to port it to linux using ncurses. At some point I also added some fancy self-preservation AI to the beasts. I’m really not sure if the AI stuff is in this version of the code I dug up; I hope it is.

05 Oct 19:42 :: 1 comment :: Comment
Tags: programming, darcs, linux, C++, cool, beast

Network Manager

As I just said, I attended fozzmoo’s presentation at the UTOSC. I spent some time trying to get Network Manager installed and working on my laptop before hand, and about half way through the talk. Both fozzmoo and others in the room were very helpful in getting it up and running. Now it is and I must say, it’s pretty slick.

That said, I will tell you that Network Manager isn’t the end-all be-all of your networking experience. It is for a very specific niche, which is for ‘on the go networking’. If you don’t try to shoehorn it outside of this, you’ll have a great time with it.

I mention this because in the presentation several people asked about static ip’s and such. NM doesn’t do these well, nor do I think it really should. I admit though it irked me at first. My next tidbit of helpful information is what actually brought me around to this understanding of what NM is.

At the presentation there was some discussion about ubuntu and network manager. By myself, as you can imagine, as well as others. I poked around on my laptop, and figured out that an interface would only be managed in network manager if it was not in /etc/network/interfaces as well as finding that the normal ubuntu network configuration tool made changes to this file. This concerned me and I made it known to others, saying if you want NM you should go in and disable the interface in ubuntu’s config. That seemed kludgy to me.

Well, when I got home I fiddled with it some more. There I found that you don’t actually have to disable the interface, ubuntu’s config tool actually has an option in the interface properties to put an interface in ‘roaming’ mode. “Cool,” I thought. But more than cool, this is what made me realize the true nature of NM. So I configured some profiles in the network config as such:

  • Home: wireless in roaming, wired static on my home network (my laptop serves as gateway through the wireless)
  • Caradhras: wireless configured to caradhras (my router) if I’m ever again lucky enough to have my router serve as gateway.
  • Other: like it sounds, anywhere I don’t have a specific configuration. This one puts both interfaces in roaming mode.

It’s pretty sweet how they work together once you figure out the respective roles.

10 Sep 13:18 :: 0 comments :: Comment
Tags: utosc, troubleshooting, linux, ubuntu, network, debian

iDissent

I never could get myself excited about the iPhone, and I began to wonder if I was becoming less of a techie. I would look at the sites, and sure enough it was darn cool. I would read about the interface, the multitouch, the accelerometers. It was all very cool, but did I want one? The answer was consistently no. Sure, if you dropped one in my lap with paid-for service, heck, I’ll take that, and be quite glad. I’ve come to realize that the reasons for my dissent were generally Apple (I guess my anti-apple blood runs thicker than I thought) and more specifically openness, or lack thereof.

I came to this realization after stumbling, nay, tripping over this, and on Yahoo! of all places. The Neo 1973 got me excited like the iPhone couldn’t dream of. I actually want to go out and spend $300 on a phone now (as I’m sure many Apple fans actually want to go out and spend whatever it is for an iPhone), even though it’s a little behind (no multitouch). Still, it has GPS, accelerometers, standard usb hookup (don’t think the iPhone has this), and the whole thing is made to be hackable. It runs on a Linux kernel with X! Oh the joy.

I predict this and other such products will dominate the mobile market the same way intel and it’s many clones did the not-so-mobile market. It will be interesting to see how prices will plummet, cool apps will be in abundance, and there will be a whole slew of Free phones. That reminds me, I love the slogan, “Free your phone.”

So if you want to get me a present (Christmas and my birthday are both coming up) now you know what I want.

25 Jul 20:24 :: 1 comment :: Comment
Tags: linux, open source, cool

MP3 Woes

IMMS was complaining to me that sox couldn’t read mp3 files to alalyze them. I wasn’t about to let this go on too long, I want IMMS to work to it’s full potential. I tried installing liblame0 and liblame-dev, I even tried libmad but all to no avail. Finally I did apt-cache policy sox. The installed version was some studio version from DeMuDi. I thought if any of the available packages would support mp3 it would be the one from demudi, alas this was not the case. I installed the version from ftp.easynet.fr (PLF) and now I have (readonly) support for mp3. Good enough for me.

15 Jul 12:35 :: 2 comments :: Comment
Tags: copyright, linux, debian, annoyances, troubleshooting, music, computers, entertainment

Inline DOC

“Wouldn’t it be nice if I could see an inline text version of .doc attachments?” I thought. That wish quickly became reality in this well-ended story.

Finding a sufficiently constrained search term proved difficult, so I resorted to #utah. I soon received an answer from spr (thanks man!) citing wv. I installed it with apt-get install wv. Then I constructed this line for ~/.mailcap:

application/msword; /usr/bin/wvText '%s' /dev/stdout; copiousoutput; desciption=DOC Text; nametemplate=%s.doc

Now fire up mutt and read that darned email-with-a-doc-attachment with nary a care.

15 Jun 18:52 :: 0 comments :: Comment
Tags: debian, computers, mutt, linux, annoyances

More Pango Goodness

I noticed yesterday that firefox now uses the newest pango and it displays cambodian properly. This makes me happy. I would type a few things in cambodian except my laptop is gone and I don’t have the keyboard layout set up on this computer. There is another post
however that has cambodian in it. And if you need a font, get it here.

02 May 15:51 :: 0 comments :: Comment
Tags: khmer, linux, language, ខ្មែ

Quodlibet idiosyncrasies

I’ve been using quodlibet for a couple weeks now. I actually was introduced to it by my brother Hans some time ago, but it lacked an imms interface so I clung to xmms. Subsequently, xmms managed, in it’s awesome ability to annoy, to drive me away once and for all.

Using quodlibet I now have a couple fun projects ahead of me. First is writing an imms plugin for it. Next is fixing some quirky behaviour involving the play queue. Queue is probably the most awesome media player feature since random/shuffle. It allows you to add specific songs to come next without muddling around with the playlist itself—the playlist can happily remain in random mode or any other mode you can fathom.

Now I describe those queue quirks. If someone wants to tackle them before I get to it, go ahead. Just let me know so I don’t duplicate a work in progress. ;) Both issues seem to arise from the fact that a song in queue is a seperate instance that != the same song in list. This causes problem 1) the playlist doesn’t show the current song as playing or jump to it. Problem 2) likewise, when quiting quodlibet, the queue state, the playlist state, and the current playing song are all saved. However, upon resuming the current song, if derived from queue, fails to register as anything and doesn’t play. I assume this is because song_from_queue != anything_in_list.

17 Apr 12:02 :: 0 comments :: Comment
Tags: programming, entertainment, troubleshooting, linux, computers, music

Pango made my day

All I can say is wow.

I installed a fresh new distro (DeMuDi) this week, then today my brother logged into jabber. In my client I had him aliased as ‘ច​ិន’ (chen) which was spelled wrong but looked right. Well, this time, it looked wrong, or rather, it looked the way you would expect given how I spelled it. I about fell out of my chair! I updated the alias, spelling it right this time (ចិន) and lo and behold, proper glyph placement, nearly causing another chair incedent.
I quickly tried some more:

  • ខ្មៃ (khmai, cambodian for khmer)
  • ជ្រើសរើស (crəəsrəəs, choose)

Subconsonants, prefix vowells, they all work! Alas, firefox does not appear to be using pango, as I see it’s not exactly working here in the browser.

19 Oct 14:43 :: 0 comments :: Comment
Tags: computers, linux, language, khmer, foo, ខ្មែ

Quirky Queues

So my cups queue, which lives on the appartment server, shared amongst three computers, went “off.” I googled around a bit, and apparently this happens when the queue is accessed whilst the printer connection is not available for whatever reason.

I then had to hunt down the way to restart the queue, restarting cups was not enough. I know how to do it with the web interface, but that wasn’t set up, and I wanted the versitility of knowing the command line magic words.

I searched and browsed to no avail, after which I chanced upon the command cupsenable (using a command line and TAB!).

Magic words: cupsenable <queue>

09 Oct 18:21 :: 0 comments :: Comment
Tags: computers, troubleshooting, linux, debian

udev and NVidia

So, I installed udev and nothing, bootup scripts tell me kernel version needs to be >= 2.6.8, and well, there’s a long story that basically says I use 2.6.6. At Hans’ nudge, I modified the startup script to not care about the kernel version and vióla, udev.

Now this is where NVidia enters the story. udev is working great, my /dev directory no longer has a gazillion+ entries but rather fits in one screen. However, upon a reboot, the nvidia device drivers are no longer there. For a few reboots, I simply ran the NVidia installer when X failed to load. This got old fast and I found an answer on google. For debian, at least, you put the following in /etc/udev/links.conf:


M nvidia0 c 195 0
M nvidia1 c 195 1
M nvidiactl c 195 255

The funny thing is that I found this on a Gentoo site, describing the fix as “for debian.”

24 Jun 00:54 :: 0 comments :: Comment
Tags: linux, debian, troubleshooting

BYU Wireless Authentication

The BYU Wireless networks require authentication through a website everytime you connect and then some. This can be pretty annoying and slightly less than trivial to automate. So I took a quiet evening and wrote this script to handle authentication without the point-and-click hassle.

byuwireless.rb reads in a yaml configuration file that contains two elements and looks something like this:


username: your username
password: your password

You can edit where it looks for this file in the script, but the default is byuwireless.passwd in the current directory.

The script is really only a shell of a ruby script. Most stuff is done through other tools like grep and wget invoked through backticks.

26 May 20:49 :: 0 comments :: Comment
Tags: byu, linux, programming

Turning to the Dark Side

I decided to give evilwm a try. It’s a decent little manager. There were some things that I just couldn’t live with and some I couldn’t live without. Fortunately, evliwm is so small it lent itself readily to my hacking out the worst offenses. These included:

  • Raising a window anytime you move or resize it—I love to be able to move windows underneath other windows.
  • Resizing behaviour—It would jump the cursor to the corner of the window when resizing.
  • Directional and restrained resizement—or lack thereof

The foremost was fixed just by wraping the offending function call in my own #ifdef RAISE_MOVE (two occurences). Whilst fixing the second, I took it a step further to fix the third, one I might not have thought feasable had I not been dipping in that code already. This direction resizing, for the curious, works by dividing the window into nine squares. Each square on the edge will resize in only that direction, including diagonal for corner boxes. My only remaining complaint is that it doesn’t tile windows. Update: I have come to appreciate the more organic feeling of windows placed unprecisely

Using evilwm has necesitated using a slough of auxilliary programs to do what my old wm (icewm) used to do for me—shortcut keys being one—and I’ve come to think that auxilliary programs is really the way to go. xbindkeys has handled shortcut keys nicely and even works with funky layouts like Khmer!

Anyway, here is the diff to get windows that stay down and directional resizemennt with evilwm.

28 Apr 14:47 :: 0 comments :: Comment
Tags: programming, linux

XXkb: Per window layout switcher

I came accross this program, xxkb, that will switch keyboard layouts per-window. “Very cool,” I thought, and I proceeded to install it. Once installed I could run it and it would show a tiny English flag in the corner of each window, but beyond that I couldn’t get it to do anything.

Reading the docs in /usr/share/doc/xxkb/ (the man page just points you there) revealed that xxdbdid it’s switching according to xkb configuration. This is where I got lost. I searched for a program called xkb and found xkbsel, xkbevd and other such programs and I thought maybe xkbsel was the one I needed. I couldn’t find a way to configure xkbsel in a manner to affect xxkb, and trying to use xkbsel -s us or any other map just resulted in X locking up and the only thing I could use was the power button.

Back to google again. A search for xkb config and a few hits down got me properly oriented. It turns out xkb is not a program but rather an integral part of X. And likewise those other programs like xkbsel where clients to this bit of X configuration. And since I hadn’t configured it properly, xkbsel did nasty things and xxkb gracefully did nothing.

Well, on to configuring it. Xkb allows X to load up to four keyboard layouts into memory for quick switching between them. To choose these put the following into your appropriate Input Device (keyboard) section:


Option “XkbModel” “pc104” # or whatever keybaord model you have
Option “XkbLayout” “us,kh,dvorak” # just a comma seperated list
Option “XkbOptions” “grp:alt_shift_toggle” # for quick keyboard switching

The alt_shift_toggle is the shortcut key combo to switch between the two most recently used. There are other options but alt_shift_toggle is Alt + RightShift. I am using the layouts us, kh (for Khmer a.k.a. Cambodian) and dvorak. These match in the order they’re given to the numbered groups in the XXkb configuration. To configure XXkb look at the configuration in you X app-default directory (/etc/X11/app-defaults/ on debian) and put changed lines in ~/.xxkbrc. I downloaded some miniature flag images and turned them to xpm for my languages as xxkb only comes with a few european flags.

21 Apr 09:58 :: 0 comments :: Comment
Tags: linux, language, cool, window manager, metacity

Installing your own X fonts

Getting fonts into X can be a little unintuitive, and everytime I need to add one, I find myself doing a lot of review for a few commands. So here it is.

Make a directory to put all your fonts in. I use ~/.fonts. Put fonts in there (*.ttf and whatnot). Then:


$ mkfontdir
$ xset +fp .

from within your font directory.

When you change the contents of your font directory, you can simply run:


$ mkfontdir
$ xset fp rehash

to get things up to speed.

05 Apr 18:50 :: 0 comments :: Comment
Tags: linux

Java on Debian quick

  1. Download the “Linux Binary” j2se jdk from java.sun.org
  2. Run the binary
  3. mv the resulting jdk directory (e.g. jdk1.5.0) to /usr/local/lib (or /usr/lib if you prefer)
  4. `ln -s /usr/local/lib/jdk1.5.0 /usr/local/lib/jdk`
  5. Install java-virtual-machine-dummy and make /etc/java-vm look like this (3 lines): `/usr/local/lib/jdk/bin/java` `COMPLIANT`
  6. `update-alternatives —config java`
  7. `update-alternatives —install javac javac /usr/local/lib/bin/javac 1 —slave javac.1.gz javac.1.gz /usr/local/lib/jdk/man/man1/javac.1`
  8. `update-alternatives —config javac`
  9. You might need to `ln -s /etc/alternatives/javac /usr/bin/javac`
04 Oct 09:58 :: 0 comments :: Comment
Tags: linux, debian, programming