Kyle->GetThoughts();
The sun is backwards
29 November 2007 @ 10:11 AM MST
Current Music: The Ataris - So Long, Astoria
Current Mood: Waking up
So I was thinking yesterday about the sun. Have you ever thought about the directional cues we take and associate with the sun? If someone showed us a picture with the sun low on the left side, we'd think, "oh, it's morning" and if it were on the right side, "it's evening". But, it would be reversed if we grew up in the southern hemisphere. We associate left with morning because in seasons other than summer we need to look south to see the sun, which makes it rises "on the left" and sets "on the right". In the southern hemisphere you'd have to look north to see the sun, consequently flipping the associations of morning and evening. During the day you'd look north and see the sun move from the right to the left.

We also take directional cues from the sun. If it's winter and I see the sun, I know I'm facing southernly. If I were in the southern hemisphere I wonder if I would have a hard time with directions because I'd unconsciously be thinking south when facing the sun, when in fact it'd be a northerly direction. I also wonder if we'd feel uncomfortable in the southern hemisphere because our unconscious mind expects the sun to move "left to right" and not "right to left". I guess I'll just have to take my trip to Australia sometime and experience all of these theories.

[This Entry]
Time for a vacation
20 November 2007 @ 10:18 AM MST
Current Music: Pandora
Current Mood: Restless
Today is the last day of classes before Thanksgiving break. Campus is mostly empty already. I have one class to attend, at 3:00. This weekend I get to run network cable all over my house. I bought a box containing 1000 feet of cat5e cable. I also got a crimper/cutter/stripper, a tester, and a bag of terminals. Last night I bought a drill bit. I'll need to drill a hole through the wall in Josh/Mike's room, setup a switch in on their desk, run a cable into their crawlspace, drill a hole through the floor into the ceiling of Jon's room, then back track a cable through the first hole in Josh/Mike's wall into my crawlspace, over to the edge of the house and through the floor into the ceiling of the living room. It will be a fun project.

Last night at FHE we played Guitar Hero III as our activity. It's a bunch of fun. I enjoy it particularly because anyone can start playing on "easy" without ever having played before, and be able to do alright. I've played a couple of times in the past and play on medium difficulty. It doesn't matter what system you play on, since they all use the guitar shaped controller, it's just fun. The people that make Guitar Hero, "get it". They know how to let the game be fun without getting in its own way.

Mom and Dad flew into town on Wednesday. Evan is coming in from Laramie, so we'll have everyone except Mike here for Thanksgiving. We haven't had this many of us together for Thanksgiving since Erin left for school in 2000. If Mike had been able to make it, it would been the first time since 1997 that the whole family has had Thanksgiving together.

I'm feeling unmotivated at the moment, so I'm mostly just killing time until I can leave campus today. I just want a chance to relax for a few days.

[This Entry]
POSIX Compliant string quoting Python
8 November 2007 @ 01:51 PM MST
Current Music: Pandora
Current Mood: Doing fairly well
So, I was having an issue trying to properly escape a string for use in the shell (command line) when using python os.system(...).

I did a google search and found a site on ASPN which had incorrect information due to someone's incorrect reading of the POSIX Shell Command Language specification. The spec can be found at: http://www.unix.org/single_unix_specification/ under "Shell Command Language" . So I read the spec and wrote a correct python method to convert a string for safe use on POSIX compliant shells.

# This function will properly quote a string for use on a POSIX compliant shell
'''
From: http://www.unix.org/single_unix_specification/
Under "Shell Command Language"
2.2.3 Double-Quotes

Enclosing characters in double-quotes ( "" ) shall preserve the literal value of all characters within the double-quotes, with the exception of the characters dollar sign, backquote, and backslash, as follows:

$ The dollar sign shall retain its special meaning introducing parameter expansion (see Parameter Expansion), a form of command substitution (see Command Substitution), and arithmetic expansion (see Arithmetic Expansion).
The input characters within the quoted string that are also enclosed between "$(" and the matching ')' shall not be affected by the double-quotes, but rather shall define that command whose output replaces the "$(...)" when the word is expanded. The tokenizing rules in Token Recognition , not including the alias substitutions in Alias Substitution , shall be applied recursively to find the matching ')'.
Within the string of characters from an enclosed "${" to the matching '}', an even number of unescaped double-quotes or single-quotes, if any, shall occur. A preceding backslash character shall be used to escape a literal '{' or '}'. The rule in Parameter Expansion shall be used to determine the matching '}' .
The backquote shall retain its special meaning introducing the other form of command substitution (see Command Substitution). The portion of the quoted string from the initial backquote and the characters up to the next backquote that is not preceded by a backslash, having escape characters removed, defines that command whose output replaces "`...`" when the word is expanded. Either of the following cases produces undefined results:
- A single-quoted or double-quoted string that begins, but does not end, within the "`...`" sequence
- A "`...`" sequence that begins, but does not end, within the same double-quoted string
\ The backslash shall retain its special meaning as an escape character (see Escape Character (Backslash)) only when followed by one of the following characters when considered special:
$ ` " \

The application shall ensure that a double-quote is preceded by a backslash to be included within double-quotes. The parameter '@' has special meaning inside double-quotes and is described in Special Parameters.
'''
def quote_for_posix(string):
return '"' + string.replace('\\', '\\\\').replace('"', '\\"').replace('$', '\\$').replace('`', '\\`')+ '"'



Since the code in that runs off the side of the screen for some reason, here's a version that is easier to read:
def quote_for_posix(string):
ret_val = '"'
s = string.replace('\\', '\\\\')
s = s.replace('"', '\\"')
s = s.replace('$', '\\$')
s = s.replace('`', '\\`')
ret_val += s
ret_val += '"'
return ret_val


Note that you do not want to do this if you're already taking care of what appears on the shell. I'm using it because I'm reading in filenames and paths with no control over what they look like, so I need to make sure I can then write those filenames in the shell without things breaking. My issue was coming up when I had a file name containing spaces, a single-quote character ', and parentheses ( ). The shell was not happy with it.

[This Entry]
Yertle the Turtle
5 November 2007 @ 10:57 AM MST
Current Music: Pandora
Current Mood: Pretty well
http://www.chuckwagner.com/yertle.html

We got to read "Yertle the Turtle" by Dr. Seuss for my CS678 Advanced Neural Nets and Machine Learning. That's right, we read it for a 600 level Computer Science course. There was good reason of course, we needed to make the point that you can stack as many levels of meta-learners as you want, but in the end, it's just turtles all the way down, and you've only pushed your problem up a meta-level.

What's more interesting to me about this reading, though, was how much Yertle sounds like Bush:

"I'm [president], and you're only a [citizen] named Mack."

"I'm Yertle the Turtle! Oh, marvelous me!
For I am the ruler of all that I see!"


-----
We need only attack.
And I'll rule Iraq.
And I'll rule Iran.
I'll even rule Afghanistan.
I'm the President.
And you're simply a resident.

"It's for your own good", I tell them each day.
When bad things happen, someone must pay.
So let's rattle the saber and monger for war.
I must, I must, I must rule more.
-----

"You hush up your mouth!" howled the mighty King Yertle.
"You've no right to talk to the world's highest turtle.
I rule from the clouds! Over land! Over sea!
There's nothing, no, NOTHING, that's higher than me!"

[This Entry]