This really shouldn’t have taken me as long as it did to figure this out, but it was a big enough of an annoyance that I decided to share it.

How to convert a relative path to an absolute path in linux/unix/bash script:

#!/bin/bash
# Assume parameter passed in is an absolute path to a directory.
# For brevity, we won't do argument type or length checking.
echo "Absolute path: `cd $1; pwd`"


For those unaware, you don’t have to ‘cd -’ because the backticks perform command substitution and don’t modify the working directory of the script.

I like to think of snippets like this as an ingredient when cooking with technology. Individual ingredients may be good, but combining them with a recipe yields something far better :)

I use the StumbleUpon firefox plugin to try and find those ‘gold nugget’ webpages in things I am interested in. One of those things happens to be (surprise!) technology. Now, probably two out of every 5 sites is some ’search engine optimization’ or ‘how to improve your blog’ blog post that offers zero-science techniques for improving your pagerank and increasing traffic.

As far as I can tell, the only people these posts appeal to are other bloggers. So the traffic these sites are attracting are bloggers, who implement the changes, who then attract the bloggers they got the idea from. All I see here is a bunch of reciprocal traffic. Kudos, blogger. Your site is a raging success among other bloggers doing the exact same thing you are.

And as far as techniques used, who invented the ‘insert advertisement in the middle of an article’ technique? And furthermore, who was the idiot that decided to call it a ‘jump’? It is not a jump, it is an advertisement in the middle of your content. I strongly believe the concept was the result of a blogger angry that the blink tag they were so fond of is no longer supported in most browsers. “Hey, I can’t annoy people with blinking text. Time to come up with something new.” Viola, the ‘jump’ is born.  Bloggers: if I think your content is good, I’ll probably keep reading despite the annoyance (yay adblock). But if your content isn’t fantastic and I see the word ‘jump’ in your post, I’m leaving your site and am likely to never return.

Stop being silly.

All of you. I mean it. You are ruining my StumbleUpon experience.

Windows Server 2003

May 8, 2007

Reinstalling Windows Server 2003 isn’t necessarily difficult. However, when you introduce 3rd party disk controllers and no floppy drive, things get tricky.

The question here is simple: Why Microsoft, WHY!? Requiring a floppy drive is ridiculous, especially on newer servers! Please allow, at the very least, a usb flash drive to be used instead. Thank you.

Build Hell

May 7, 2007

At my place of work, we have a project that compiles for multiple platforms. Unfortunately, multiple platforms means g++ for linux, and a crazy perl script that generates a Visual Studio project out of the files instead of using g++ running under cygwin to generate executables directly. (So you have to run a bat file which runs a perl script which generates MSVS .sln and .vcproj files which you then open in MSVS and then build within the IDE.) To make this mess even further convoluted, the perl script depends on an in-house method of including dependent libraries for the generated files. Some of them use environment variables to set the path to these libs, while others assume that all portions of the project (in-house and third party) were put in the same root directory. Glorious amounts of relative path traversal occur in the form of repeated instances of “../”. This is hard to read and debug, and since dependency providing includes are at multiple levels of the filesystem hierarchy, it takes a lot of searching to find where things are defined initially.

Ideally, this system wouldn’t be so complicated and shitty.

First of all, there is no reason to be going through MSVS. It can be assumed the build system already has cygwin on it because that is how our perl script runs, so using g++ isn’t an issue. Heck, even Microsoft has a command line compiler if they wanted to use it over g++ – bottom line, there is no reason to use the GUI IDE, especially since it is only used to build the binaries.

Second, the paths in the dependency files are ridiculous. If the current system is to be kept, then the root makefile should contain the paths to each of the libs that will be used, and those variables will be passed down to the other project specific makefiles. No relative paths should be used except for when branching from that main lib environment variable.

Third, things should all be done from makefiles. In our case, it is safe to assume the build machine has cygwin on it. There is little reason to intermingle bat files and make scripts for ‘platform independence’ when we already use cygwin for perl.

I can’t believe what professional software engineers get away with.

Windows Path

April 26, 2007

The Windows PATH environment variable, as most of you probably know, is delimited with colons. We ran into a problem at work where some systems weren’t running properly because it couldn’t find some libraries. The problem? A space was inserted after the colon and before the next path element. Seeing as there is –never– a space as the beginning of a path in Windows, why isn’t it just parsed out? It would increase readability and eliminate problems like this.

Grumble.

Back To School: Terminal Tips

September 30, 2006

Over the past week I’ve been doing a lot of tweaking to my shell environment, and helping others do the same. I’ve come across a few fixes and common things that people might find useful, so here we go!

The first is a script snippet to change your shell to bash on login. It only works in some environments, but for those of you who are desparate, throw this in your .cshrc:

if ($?prompt != 0 ) then
     setenv SHELL_NAME /bin/bash
     if ($SHELL != $SHELL_NAME ) then
          set shell = $SHELL_NAME
          setenv SHELL $SHELL_NAME
          exec $SHELL
     endif
endif

One of the more frequent questions I answer is how to get around having to type ‘./’ to run programs in your current directory. The answer is in editing your PATH variable. Throw the following in your shell’s rc file:

export PATH=.:${PATH}

In order to make use of colors in your terminal, you first need to be using a terminal that supports them, and then tell the tty so. To do this, you need to change your SHELL variable to something that supports colors:

export TERM=xterm-color

To make full use of your color supporting terminal, we can make use of newer versions of grep and ls to make output use colors. While we are doing this, we might as well make things more human friendly, so let’s make du and df print out human friendly data. Aliasing automatically replaces words you’ve specified in your .bashrc with the strings they’ve been aliased to, and allows us to do all of these things at once. Here are some examples:

# Aliases for making the command line human friendly
alias df='df - h'
alias du='du -h'      # Make du and df always report human readable data
alias ls='ls --color'     # If your version of ls supports it, use colors
alias grep='grep --color'     # If your version of grep supports it, use colors

Finally, some misceallaneous tips. The first clears the *extremely* annoying issue of having a command line that doesn’t support backspaces or other common keys. Put this in your shell’s rc file:

stty sane

Some environments allow other users logged into the same machine as you to send messages to your terminal. This is annoying if your peers think it is funny to disrupt your debugging. To turn it off, just issue the following at the command line (to disable it for that session) or in your shell’s rc file as a permanent fix:

mesg n

And if you want to be one of those kids that interrupts someone else, don’t just write them stupid messages and giggle about it. It is much more entertaining to send an endless amount of gibberish to their screen. The following script will pipe data from /dev/random to another user’s terminal until you kill it:

#!/bin/bash
echo "Enter a username: "
read user
dd if =/dev/random | hd -c | write $user

Fixing Backspaces

September 21, 2006

One annoyance of working with Sun machines is that the backspace key never seems to map in such a way that vim can understand it. The usual way to fix the behavior of the backspace key, as told by :help fixdel, is to issue the following at the vim command line or put the following in your .vimrc:


:set backspace=2

Or:


:fixdel

However, this doesn’t work if the signal being passed from your keyboard to your terminal to vim is incorrect, as it was for me. So, the symptoms of “My terminal acts appropriately on the command line, but in vim backspace produces ^?, and :set backspace=2 and :fixdel don’t fix it” can be solved with a quick line issued at the command prompt:


stty erase ^?

It is important to note that ^? does not mean typing ^ and then ?, it means hitting ‘ctrl-v’ and then ‘?’. Try it: you’ll see the output matches mine. The reason for this is ctrl+v is telling the terminal to capture the signal recieved by the keypress instead of the actual keypress after it has been interpreted. The command above is actually forcing the terminal to interpret the ^? signal as the erase function, which is the effect you want bound to your backspace key.
Remember, if it works, put it in your rc files (such as ~/.bashrc for you bash users) so it will magically work every time you login.

On a new print server I am setting up for the Software Engineering Department at RIT, I did an apt-get upgrade and was met with the following messages for all following package operations:


perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_JP:en",
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

I really don’t like having my terminals filled with junk (read below for another example in Ruby), and I doubt anyone else does either. The messages can be cleared simply by issuing the following and choosing the correct locale:


dpkg-reconfigure locales

As far as I am aware, this fix will also work for Ubuntu users affected by the same issue.

In an application I’m developing at work, we are working with temporary directories that house non-sensitive information. When working with these files in these directories, ruby would kindly report:

warning: Insecure world writable dir ..., mode 04077

This is is annoying, because the messages are filling our terminals with unnecessary content. Turning it off requires only a line near the top of the source file:

# Turn off ruby warnings
$VERBOSE = nil

Enjoy seeing only the messages you want.