Joshtronic

Bash script to flatten a directory

Tuesday, 25 November 2008
I just came across an old CD of Fonts that I had purchased before I knew better. Well I didn't want to throw the disc out without copying all the fonts to my system. All the fonts were broken up into directories that corresponded to the first letter of the name. It seems like there is some Windows software interface to handle installing the fonts that would make those directories transparent. Since I didn't want to have those fonts split up by first letter, I wrote a little bash script to flatten the directories. All it does is loop through all the directories in the passed source directory, and copies every non-directory file to the passed target directory (or . if the argument is omitted).

flatten-dir:
#!/bin/bash

# Copies files inside nested directories to a single directory
# @author Josh Sherman

if [ -z "$1" ]
then
    echo "Usage: flatten-dir /path/to/nested/directories [ /path/to/target/directory ]
    exit
else
    NESTED_PATH="$1"
fi

if [ -z "$2" ]
then
    TARGET_PATH="."
else
    TARGET_PATH="$2"
fi

for i in `find $NESTED_PATH`; do
    if [ -f "$i" ]
    then
        cp $i $TARGET_PATH
    fi
done

Why I still use GNOME instead of KDE

Sunday, 23 November 2008
When I first started using Linux a decade or so ago I had no real preference in desktop environment. I used KDE, I used GNOME, I even ran command line only depending on the distribution. Once settling on Slackware as my distro of choice, I found myself using GNOME on a full time basis. From time to time I would switch to KDE for a short stint and then switch back and acted like the whole thing never even happened. I even dabbled with XFCE, Enlightenment, and Blackbox and it's derivatives on a few occasions, still going back to GNOME. Just to get it out of the way, Enlightenment was too sluggish for me back in the day, and XFCE and Blackbox are fine, but I really haven't been able to get into the minimalistic menus and stuff. And then there was KDE. KDE is something I keep giving every major release and a lot of times on the minor releases a try, but none have ever swayed me. First and foremost, early on KDE was sluggish to me compared to GNOME and it reminded me too much of Microsoft Windows, which is what I was trying to get away from. In modern times, the sluggishness isn't too much of an issue for me. What does drag me down is the software and the GTK versus QT display issues. GTK apps look like shit in KDE without a lot of massaging and hackery. I don't have the time in my day to sit around trying to make those applications look pretty. Now that being said, I am aware there are alternatives to the GTK software I use in KDE. I don't want to use those applications, I want to use the applications that I'm used to and have fallen in love with. Specifically, Firefox is the web browser of Linux. I know WebKit is all the rage these days, but I've never liked Konqueror, and all of it's superior abilities when it comes to passing the Acid test. The other app that I can't stand in KDE is Kopete. I'm not sure what the hell that name is supposed to mean or what, but the application in general has given me more problems than it's worth. Pidgin (formerly GAIM) has been my choice for instant messaging for many years and will remain as such for many more years. Those two applications aside, I really dislike the Konsole and for whatever reason (perhaps I'm dumb) I have a hell of a time finding anything on the KDE menu, the new one (KDE 4.x) especially. So call me a creature of habit, but that's why I don't use KDE. I am infinitely more productive in GNOME, it still seems to be the de facto standard for a lot of distributions and quite frankly, I don't care that Linus Torvalds says I should use KDE over GNOME. The beauty of Linux is that we can pick and choose what we want to use, and I choose GNOME.

Upgrading from Ubuntu 8.04 LTS to Ubuntu 8.10

Saturday, 1 November 2008
Well after a few days of not being able to run any upgrades on my installed copy of Ubuntu 8.04 LTS, last night things started moving. The upgrade process from Ubuntu 8.04 LTS to Ubuntu 8.10 took all of last night (I started it around 9PM) and on through this morning due to some interactive dialogs. The upgrade went surprisingly well compared to my previous Ubuntu upgrades (most of which ended up with me doing a clean install). This upgrade was not without it's complications though.

First and foremost, the UbuntuStudio menu refused to upgrade at all. I know it's not a package maintained by Canonical, but it was a flat out failure when trying to upgrade it. I proceeded with the rest of the upgrade, and then went on to remove all of the UbuntuStudio packages I had installed previously, and then reinstall them. No issues with the UbuntuStudio menu on reinstall.

Next came Compiz Fusion / Emerald Theme Manager. Compiz was running prior to the upgrade, and after the upgrade as well but Emerald Theme Manager was not running. After some Googling I found a nice forum post that outlined the uninstall and reinstall steps. Still no dice until after I started Emerald Theme Manage with the --replace flag. In hindsight, I should have just tried that first, I ran `emerald` from the command line, but didn't include the --replace flag, so that would have saved a bit of time. Long story short, Compiz Fusion with Emerald Theme Manager is back and I installed the Compiz Fusion Icon to help troubleshooting in the future.

At this point, my desktop is looking good and my window decorations are solid, "I wonder if my local development environment is hosed," I thought. Sure as shit, it was, and kind of baffling to boot. Apache2 was up and running but all of my virtual hosts were pulling up the default document root. This was a surprisingly easy fix once I started digging into the Apache error log. Seems the way I had my virtual hosts set up, as was not accurate compared to the NameVirtualHost directives in apache2.conf. I went ahead and added NameVirtualHost * to the end of apache2.conf and restarted. Now all my sites are up and running.

On top of doing the upgrade, I made the decision to (yet again) remove KDE entirely from my system. I wasn't entirely sure of the entire list of packages to remove, so I used Synaptic's section list and removed everything from all three KDE Desktop Environment sections. There are a small list of packages still installed when I search for "KDE" but it's not enough to force me to put any more efforts into it. I'll elaborate more on why I continue to go back to GNOME after numerous attempts with KDE on another day.

So that was my upgrade in a nutshell, most of it was just waiting, but the outcome was well worth it. I'm hoping that my next upgrade to Ubuntu 9.04 next year will be even easier as I really don't have the time in my life to spend 10 hours trying to troubleshoot something that should just work (my Gentoo and Slackware days are long over).

"My Computer" hangs when accessing it

Monday, 13 October 2008
This just started happening to my work PC (Windows XP SP3) about a week or so ago. It was very annoying, mainly because I rely heavily on the CTRL+E hotkey to access "My Computer" on the fly. Well today I had enough. First stop was Google. My searching resulted in many sites recommending to launch Explorer, go to Tools then Folder Options and click on the View tab. From there uncheck "Automatically search for network folders and printers" (the first option) and then click OK (or Apply then OK if you're that guy). Yeah, no dice, still slow. Next step was to start disabling software and running services, I was sure Trend Micro OfficeScan or Apple were behind the hang ups. Still nothing. Well after another 20 seconds of waiting for "My Computer" to load, I decided to start going through my mapped drives to see if perhaps one of those was bad. Four mapped drives, the first three were fine. Then came number four. I double-clicked it and sure as shit, it hung for a moment, and then displayed an Explorer window showing my C:\ drive. Not a good sign. Well I disconnected the drive and tried CTRL+E. Surprise, everything is loading up as it should. Funny enough, I would have expected the option I unchecked to have possibly resolved the issue. Guess not, but now I'm back in business.

Recursive grep (grepr) for Solaris

Thursday, 9 October 2008
So if you're a Linux user that's ever used Solaris, you know that a lot of the commands don't translate exactly the same. One such issue is the lack of a recursive flag (-R) on the grep command. Not a problem though, bash is a powerful thing. Here's my solution to the problem

grepr:
#!/bin/bash

# Simulates the Linux grep with the recursive flag -R
# @author Josh Sherman

if [ -z "$1" ]
then
    echo "Usage: grepr pattern path"
    exit
fi

if [ -z "$2" ]
then
    SEARCH_PATH="."
else
    SEARCH_PATH="$2"
fi

for i in `find $SEARCH_PATH`; do
    RESULTS=$(grep "$1" $i)

    if [ "$RESULTS" ]
    then
        echo
        echo "$i:"
        echo "$RESULTS"
    fi
done

Firefox 3.0.1 on Mac OS X weirdness

Friday, 3 October 2008
So I ran into an interesting problem today. A site I built (validates as XHTML 1.0 Strict and CSS level 2.1 and runs in Standards-mode instead of Quirks-mode in Internet Explorer 6.0) renders great in Firefox 3.0.3 (tested on both on Linux and Windows), Internet Explorer 6.x (tested in Wine and Windows) and Safari (tested in Mac OS X and Windows). Unfortunately, it wasn't rendering properly (a side bar was displaying way too wide and was breaking the layout) on the client's installation of Firefox (version 3.0.1). My resident Apple fanboy / guru (his term not mine) tried it and it seemed fine on his Mac running Firefox 3.0.3. Well I restarted my Firefox today for the first time in ages (yeah I'm that guy) and noticed that there was an update to Firefox to be installed, 3.0.3. Wait, the client had 3.0.1 didn't they? "Hey client, can you check if there's an update for Firefox on your computer, just for shits and giggles and all?" "Hey, there was one, weird because I have automatic updates on as well... oh and look at that, it's working now" "Are you shitting me?" "No, seriously it looks fine now, must have been a bug in that version." Must have been, probably will never know. Anyone else ran into any weirdness like that with Firefox 3.0.1?

Issue with SQLyog Job Agent on Ubuntu

Saturday, 27 September 2008
No error message, it just says that the sync had started. What sucks about this issue, is that I ran into it with a previous version of SQLyog Job Agent (sja) but was able to troubleshoot it faster because the program would dump an error message. I have been messing with the issue very sporadically over the last few weeks and had not come to a conclusion. Some luckly Googling this afternoon let me to the same answer I had before, sja is looking for the MySQL socket in a different place than where Ubuntu thinks it belongs. Long story short, sja is now working again, and ShowsTonight.com's database can be in sync more often. An honorable mention should go to Maatkit: a toolkit of utilities and tools for MySQL as I tried to indirectly fix my sja issue by migrating to using Maatkit. Unfortunately, I found the comparisons to take an awful long time, and didn't feel it would suit my needs compared to sja. Good thing I got it working I suppose. It's a pretty quick fix, one command:
sudo ln -s /var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock
For reference, I am working with Ubuntu 8.04 and SQLyog 7.02

Re-establishing my web presence

Friday, 26 September 2008
So it's been a while since I've had a dedicated web presence for myself (roughly August 2005 was the last time). That's not counting the short lived static content site I had up on Joshtronic.com prior to this site. Anyway, long story short is, I'm re-establishing my web presence under the Joshtronic moniker. Why Joshtronic? Well because it seems there are quite a few Josh Sherman's out there with different variations of the name (I personally own joshuasherman.net but plan on letting it lapse... dot com's are where it's at). Seems every time I have a blog on a site, I end up posting the infamous "sorry it's been a while" type posts every few months. This time around will hopefully be different. First and foremost, no apologies and no regrets. Second of all, I run into problems that need a solution, so I figure, why not post about some of that stuff, and potential solutions that I ended up trying and what ended up working? That would force me to post on the site and also keep it from being so "dear diary" type drivel. This would also give me a bit of documentation on the problems, because I usually don't write out the steps to resolve the problems I've solved. I usually end up six months down the road wondering WTF I did previously to get it working. So yeah, I am Joshtronic, this is my site. Also, I'm aware that the site looks a lot like Daring Fireball to quote Picasso (yes, Steve Jobs stole the line) "Good artists copy. Great artists steal."