Breaking Through a Plateau

Wow. That was an awesome workout! For the first time in months I actually had ton's of energy from beginning to end. I pushed through every exercise and challenged myself with heavier than normal weights. I'm not sure if it's the Zinc and Magnesium I started taking last week or the 5mg of creatine I started taking earlier this week -- maybe a combination of both. Either way, I finally feel like I'm getting somewhere. I finally broke through that plateau!

Doomed to a life indoors?

Is this generation of the technically savvy doomed to a life indoors? Is there not any synergy... any balance that can be found? With the way most of us live our lives, you'd think we were inhabitants of Mars.

Case Sensitivity in Mac OS X

Case sensitivity in Mac OS X does not exist.

The OS X command line is probably the most commonly used feature of my MacBook Pro. I love the fact that almost all the Linux commands I'm used to using on a Linux box work the same way in OS X. So, as you can imagine, I was shocked when I couldn't rename a simple directory:

eris:~ raam$ mv Downloads/ downloads/
mv: cannot move `Downloads' to a subdirectory of itself, `downloads/Downloads'

That command should allow me to rename 'Downloads' to 'downloads', but apparently OS X thinks 'Downloads' and 'downloads' are the same thing! That's absurd! In the Unix world, case matters!

So how did I eventually rename it?

eris:~ raam$ mv Downloads/ downloads2/
eris:~ raam$ mv downloads2/ downloads/

That's just ridiculous.

I installed the Fluxbox window manager on my MacBook Pro a while back and decided to start it up to make sure I had access to a "real" command line. Sure enough, the command worked as expected within Fluxbox. Maybe I'll start using Fluxbox a lot more often.

Check out this snippet from an article on InformIT:

Mac OS X, like the classic Mac OS before it, is not case sensitive; it doesn't care whether you said File1.txt or file1.txt. Only one of them can exist in a folder at the same time, and there's no ambiguity for either computers or humans in telling which file you meant. Even Unix commands like ls will work if you give them filenames to operate on that don't match the capitalization of the actual files (try it: ls /library).

That's really quite disappointing. I have suddenly lost so much respect for the OS X command line. Being derived from BSD in the Unix world, you would think Apple would keep something as fundamental as case sensitivity in OS X.

Manu Delago – Hang Drums

The sound of Hang Drums is absolutely amazing. Today was the first time I heard them and I'm already hooked. Manu Delago's site has an audio player (top right corner of the site) and I've been listening to his music all day.

I recognized the way Manu's fingers hit the Hang Drums. After reading his background I discovered he's had experience with the Indian Tabla; a percussion instrument that I took a few classes for when I was young.

Dabbling in Java Web Programming

A bunch of new projects at work are requiring that I become familiar with Java programming, web programming and GWT in particular. My co-worker gave me this tutorial to try out, as the principles are similar to what we're using in the new projects.

So after setting up my environment (that's another post), I followed the tutorial and then began modifying the example code to see how I could change it. (The first thing that surprised me was that Java doesn't automatically sort stuff -- you need to do that separately (that's where SortedMap came in handy)):

package com.sonatype.maven.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.SortedMap;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SimpleServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException, NoSuchElementException {

		PrintWriter out = response.getWriter();
		out.println("SimpleServlet Executed");
		out.println("Character Encoding is " + response.getCharacterEncoding());
		out.println("ContentType is " + response.getContentType());

		out.println("nHere is a list of all query string vars:n");

		Enumeration e = request.getParameterNames();
		SortedMap sm = new TreeMap();

		while (e.hasMoreElements()) {
			String name = (String) e.nextElement();
			String value = request.getParameter(name);
			sm.put(name, value);
		}

		for (Iterator i = sm.entrySet().iterator(); i.hasNext();) {
			out.println(i.next());
		}

		out.println("nHere are the vars combined into a sentence:n");

		for (Iterator i = sm.values().iterator(); i.hasNext();) {
			out.print(i.next() + " ");
		}
		out.flush();
		out.close();
	}
}

So basically, after starting the Jetty Servlet container I was able to visit a URL like this:

http://localhost:8080/simple-webapp/simple?var1=Hello&var2=world&var3=of&var4=java!

And got an output like this:

SimpleServlet Executed
Character Encoding is ISO-8859-1
ContentType is null

Here is a list of all query string vars:
var1=Hello
var2=world
var3=of
var4=java!

Here are the vars combined into a sentence:

Hello world of java!

Java is cool stuff and I'm going to be diving into it a lot over the next few months. I'm reading an O'Reilly book called Head First Java which uses an innovative new method of teaching:

The latest research in cognitive science, neurobiology, and educational psychology shows that learning at the deeper levels takes a lot more than text on a page. Actively combining words and pictures not only helps in understanding the subject, but in remembering it. According to some studies, an engaging, entertaining, image-rich, conversational approach actually teaches the subject better. Head First Java puts these theories into practice with a vengeance. Chock full of mind stretching exercises, memorable analogies, and stories, humor and attitude that aren't just pasted-on distractions but that are used to drive home key points and make ideas come alive, the Head First approach is as effective as it is unique.

The method is definitely new to me, but it makes a lot of sense. I've started committing an hour each day to reading the book and doing examples/puzzles.

FeedBurner Login is Down

I just tried logging into my FeedBurner account and instead of a login form I got this:

[ServletException in:/body/narrow_login.jsp] /body/narrow_login.jsp(24,25) Unable to load tag handler class "org.apache.struts.taglib.html.CheckboxTag" for tag "html:checkbox"'

One more day of fence work

Spent most of the day helping my brother-in-law and sister put up their fence. We also dismantled (read: destroyed) a handicap ramp (it was attached to their house when they bought it). One more day of fence work (tomorrow) and their one acre yard will finally be fenced in (one acre is approximately the size of a football field).

Zinc and Magnesium

I started taking supplements of Zinc and Magnesium today (100mg and 400mg respectively) after reading that vegans (especially body-building vegans) generally have Zinc and Magnesium deficiencies. It's easy for me to notice the effect of slight changes to my diet (since I control my diet so well) and I'm really curious how the extra Zinc and Magnesium will affect my overall health.

Poison Ivy Infested Forest

I spent the day installing fence in a poison ivy infested forest. Hopefully the washing machine gets the urushiol out of my clothes! I am exhausted. My arms and hands started to cramp up towards the end of the day -- something that rarely happens. I'm ready for a good night's sleep -- my body needs to recuperate for the phase II week 6 workout tomorrow night.

Apple's home page not viewable in 1024×768

Apple's Site Requires 1280x1024

I do all my browsing with my web browser resized to 1024x768, mainly because I don't need the window to take up the whole screen, but also because I like to see how compatible sites are with lower resolutions. As you can see from the screenshot above, Apple's home page is not fully viewable in 1024x768.

According to Google Analytics, 30% of all the visitors to my blog are browsing with a screen resolution of 1024x768. I'm not alone: According to W3Schools 48% of their visitors are browsing their site with 1024x768.

Come on Apple, don't lose sight of usability!

Amazon S3 HMAC Signatures without PEAR or PHP5

The Amazon S3 proposal for uploading via POST describes how to assemble a policy document that can be used to create a time-sensitive signature. The obvious advantage to this method is that you don't have to worry about someone stealing your secret AWS key or uploading random files without your permission.

Here is the example policy document from the proposal:

{ "expiration": "2007-12-01T12:00:00.000Z",
  "conditions": [
    {"acl": "public-read" },
    {"bucket": "johnsmith" },
    ["starts-with", "$key", "user/eric/"],
    ["content-length-range", 2048, 20971520]
  ]
}

This Policy document is Base64 encoded and the Signature is the HMAC of the Base64 encoding.

The application I am developing at work requires this signed policy method of uploading files to S3, however I needed to do it with PHP4 and preferably without any extra PEAR packages. This posed somewhat of a challenge, as all the tutorials I found on the web explained how to sign the policy using the PEAR Crypt_HMAC package or some feature of PHP5.

I eventually figured it out, and I'm here to show you how. The two functions used were found on the web (I don't remember exactly where) and worked perfectly for my situation.

(Note: I had a lot of trouble saving the contents of the following code in WordPress due to some Apache mod_security settings configured on my server.)

/*
 * Calculate HMAC-SHA1 according to RFC2104
 * See http://www.faqs.org/rfcs/rfc2104.html
 */
function hmacsha1($key,$data) {
    $blocksize=64;
    $hashfunc='sha1';
    if (strlen($key)>$blocksize)
        $key=pack('H*', $hashfunc($key));
    $key=str_pad($key,$blocksize,chr(0x00));
    $ipad=str_repeat(chr(0x36),$blocksize);
    $opad=str_repeat(chr(0x5c),$blocksize);
    $hmac = pack(
                'H*',$hashfunc(
                    ($key^$opad).pack(
                        'H*',$hashfunc(
                            ($key^$ipad).$data
                        )
                    )
                )
            );
    return bin2hex($hmac);
}

/*
 * Used to encode a field for Amazon Auth
 * (taken from the Amazon S3 PHP example library)
 */
function hex2b64($str)
{
    $raw = '';
    for ($i=0; $i < strlen($str); $i+=2)
    {
        $raw .= chr(hexdec(substr($str, $i, 2)));
    }
    return base64_encode($raw);
}

/* Create the Amazon S3 Policy that needs to be signed */
$policy = '{ "expiration": "2007-12-01T12:00:00.000Z",
  "conditions": [
    {"acl": "public-read" },
    {"bucket": "johnsmith" },
    ["starts-with", "$key", "user/eric/"],
    ["content-length-range", 2048, 20971520]
  ]';

/*
 * Base64 encode the Policy Document and then
 * create HMAC SHA-1 signature of the base64 encoded policy
 * using the secret key. Finally, encode it for Amazon Authentication.
 */
$base64_policy = base64_encode($policy);
$signature = hex2b64(hmacsha1($secretkey, $base64_policy));

That's it! This method doesn't require PHP5 and doesn't require any additional PEAR packages.