Skip to content

Archive

Category: General Posts
Zero padding in BASH shell:
There are a couple of ways to pad integers with leading zeros in BASH. One way is to add a larger number and truncate the leading digit:
foo=100000
smallNumber=25
largeNumber=$(( $foo + $smallNumber ))
zeroPaddedNumber=${largeNumber:1}
echo $zeroPaddedNumber

This displays: “00025″ the ${largeNumber:1} chops off the first character from 100025.

Another way is to use printf, but this creates another process and is more expensive in larger loops.
zeroPaddedNumber=`printf "%05d" $smallNumber`

Same results, but in larger loops will have slight performance penalty

Enforcing decimal for integers with leading zeros
Doing calculations with zero padded integers may provide inaccurate results. Specifically “00025″ is counted as octal in bash. To force bash to recognize it as a decimal number:

smallNumber='00025'
decimalNumber="10#"$smallNumber
hexNumber="0x"$smallNumber
echo $(( $smallNumber + 1))
echo $(( $decimalNumber + 1))
echo $(( $hexNumber + 1))

The above prints “22″, “26″, and “38″. The “$(( ))” construct does arithmetic calculation and returns the value in base 10.

String substitution or substring search in bash variables
Sometimes you assign the output of a command to a variable, expecting it to hold some information. If the command failed or did return the expected values, you must check the values returned.

mylongstring="This is a really long string I want to check"
searchstring="I want"
if [[ ${mylongstring#*$searchstring*} != $mylongstring ]]; then
echo "'$searchstring' was found in '$mylongstring'"
fi
searchstring="I have"
if [[ ${mylongstring#*$searchstring*} == $mylongstring ]]; then
echo "'$searchstring' was not found in '$mylongstring'"
fi

I was able to convince my wife to allow me to purchase a Mac Mini yesterday. Her argument was that we have too many computers at home already and don’t need another one. That’s very true, we have way too many laptops and old PCs. Plus 2 IBM servers (or jet engines if they are on.) That is too much for a household of 4. My argument that we needed an always on machine able to handle backups for our numerous machines and serve up family photos won out in the end. We headed to the Apple store in Valley Fair and was able to go home with one immediately.

At home, I had a little bit of a hard time setting it up. The main problem was I had an old bluetooth keyboard (thanks Albert) and a bluetooth magic mouse. The Mini booted up fine but would not detect either device. I ended up having to pair and unpair the devices with one of my laptops, then leave the devices directly on top of the Mac Mini before they were able to be detected.

The mouse was detected first and I had a bit of trouble with the keyboard too, but ultimately it paired successfully and I was able to boot.

As far as getting it setup for remote access and Time machine backups, I will update detailed info when I finish that tonight.

The weather this entire summar and fall has been rather odd. We had really cold temperatures during June and July and caught a big stretch of warm weather in late August. Mother Nature even psyched out a pear tree I had planted this spring into thinking that it had already wintered. I got white pear blossoms on my grafted asian pear tree.

After waiting most of October and the first week of November thinking, “There’s no way Heavenly will open the slopes by Nov. 19th.” The first cold front of the 2010 winter has arrived. Clear blue skies have been replaced with a serious winter storm as shown by the picture below: .

That’s fine by me though. I have spent the last 5 years getting out of shape, and it’s high time for me to hit the slopes with a vengeance this season.

For anyone who still doesn’t have a season pass yet, Heavenly bought Northstar-at-tahoe and the $379 Heavenly pass is good for all three resorts (Sierra-at-tahoe is included too). If you want to save $20 on your Heavenly Season Pass, use the link above and submit your first name and email for a referral.

Update: Here’s a quick look at the aftermath after the weekend’s storm. .

I had an interesting experience this weekend when a Kenmore 106.5 fridge my uncle owned stopped cooling. The funny thing was, the freezer was working fine. After doing some quick google searches, it seemed that some other people were having the same problem around the same 4 year mark. After messing around with the damper and finding that it works fine, I pulled off the plastic backing in the freezer and noticed that the air flow was extremely low. That made me suspect that flow of air is blocked. Taking off the light bulb and removing 6 1/4″ hex screws let me remove the metal sheeting which covers the heat exchanger. As soon as I lifted the bottom of the sheeting, the fan noise significantly lowered and I knew that I had found the source of the problem. The bottom of the coils were frosted over completely and thus was blocking the air flow. We turned off the fridge and went to work with a hair dryer. Making sure to cover the bottom with some towels because I didn’t want the pan to overflow and ruin the flooring, we quickly defrosted the coils and the unit is now working fine.

For a while now, when I opened up my Zend Studio editor, my PHP Explorer window started up in a sub-directory of one of my projects. I had since removed that project so it kept coming up with an empty (and un-navigable) PHP Explorer window. After doing some searching and head scratching, I figured out how to change this.

Open up the Navigator (since you can’t go anywhere) and find a folder that you want the PHP Explorer to start in. Right click on the folder and select “Open in a New Window”. Now, close the old window with the broken or incorrect start up folder. That’s it. When you close the remaining window, the next time you start up Zend Studio, the PHP Explorer will start in the folder you selected.

Our marketing department at Chegg.com will be posing a
challenge question at an event later this month. Since I know
pretty much none of my readers (all 2 of them) will be there to
participate, I wanted to put this question to the general public.
How many Campbell Biology textbooks (11.2″ x 9.3″ x 2″) can you fit
in a cardboard box (46′ x 22′ x 9′) ? Note: There is 1 answer, but
many approximations. I’m looking for your answer and the way you
solved for the answer. -Huey
$ n

Dear NYT,

I thank you for making your excellent articles available for free and I get a majority of my news from you. I don’t even mind paying a bit for archived articles. However, in your eagerness to boost pageviews and revenue, you created a bastard child called altClickSearch.js. This little bugger has caused me untold grief as I like to highlight as I read, double-clicking becomes an instinctual action. I can’t deal with the pop-ups that even Firefox 3 won’t block.

As I write this, I would like to put a little more room between us. I feel smothered with your constant attention to what I highlight. My other friend Greasemonkey has shown me a wonderful relationship modifier that is allowing me to proceed with my sanity intact, appropriately called “New York Times (NYT) Sanity”.

Thanks and please keep up the excellent articles.

It’s been more than 2 years since the number game sudoku started spreading internationally. During that time, it has popped up in many daily publications and numerous websites have created their own dedications to the game. A subset of latin squares (or magic squares), it is logic based and purports to help sharpen one’s mind. Nintendo has used it (very successfully) to market their DS game platform [B000EGELP0]. Palm also has multiple publishers of sudoku games. My question is “How long will people play Sudoku?”

When I first found the game, it was Websudoku.com that provided an easy and addictive introduction to the game. I spent numerous free hours trying to improve my solving skills. However, after writing a javascript sudoku solver in 2006, I’ve found that only very occasionally will I even think about it anymore. Is this common? How many of you are/were addicted to sudoku?

Seems like I can’t even goto the grocery store anymore without having sudoku puzzle books taking up valuable checkout line shelf space. Unlike crossword puzzles, sudoku does not expand your vocabulary. It also doesn’t help with making word associations and re-enforce current events. Is it just the biggest productivity sapper ever created?

Well, for me anyway, it’s helped me polish up some javascript coding. I recently finished revamping my solver to allow actual game play. Still needs some more TLC and some sticky features, but some features are fairly unique to the online sudoku games. For instance, my implementation allows you to take a snapshot of your work so you can go back if it gets hopelessly messy. I should allow you to save the progress and come back, but that’s for a future release. My best Sudoku puzzle game can be found at http://www.numbercrazy.com/.

This is a follow-up post to my last post Microsoft is desperate. After writing up a quick Anagram solver for Chicktionary, I’ve fixed up the script to handle some other games as well. Now the new GreaseMonkey script can help with Flexicon, Clink, CrossWire and Dingbats. To get the most out of them (for Club Live), you should
continue reading…

While reading the business news on NYTimes today I noticed an appealing ad for an anagram game at Microsoft’s new club.live.com offering. After clicking over and playing their little game, I realized that they are trying to artificially boost their search volume. Most of the games are somewhat intellectual and requires some searching to come up with answers, this is fine and all, but the game Chicktionary fires off a search for every word attempt. This and the fact that they are awarding ‘points’ for the play seems to point at a desperate grab by MS to increase their daily search volume. The implied value of their points is rather high, you can get a Xbox 360 game machine for 35,000 points. Seems to peg 100 points at over $1. Games award between 10 to 20 points from what I have seen so far.

They must have just launched this because I played 1 game of Clink and actually made their high score list! Seems like the existing scores are all random inserts.

I wonder how long before this hits the news? You can find more at Microsoft is Desperate