Nothing and Everything

2010.11.26

Unstoppable

Filed under: TV/Movies — kevenker @ 12:24 pm

I saw Unstoppable last night. If ever there is a movie that will make trains exciting, this is it. Combine decent acting with decent music and lots of shots with the camera sitting on the tracks and the train going over them (really fast!!) and you have a very watchable movie.

I imagine this movie was hard to pitch. “It’s a movie about trains (yawn). Only this one doesn’t have anybody on it! (OK… so what?) Only *this* train has a load full of dangerous chemicals! (Hmm… getting warmer…) And all attempts to stop it fail! (I guess that’s the ‘Unstoppable’ part…) except for Denzel Washington (Ah! Now we’re talking!) and his young sidekick played by Chris Pine (who?) – you know, the guy who was Captain Kirk on the new Star Trek movie (hmm… not sure if trains and spaceships have the same demographic… Nice, but still sounds boring…) We’ll we’re gonna do lots of shots of trains rumbling over the camera, and we’ll have close calls with head-ons with… other trains! And of course, we’ll have the train smashing things- but nothing big enough or heavy enough for it to derail! (Ooh! Smashing things. That’s sounding much better! … What about car chases? Everybody likes a good car chase!) Oh… well um… we’ve got that too! We have a guy who is chasing the train in big pickup truck! With a police escort! (So he’s gonna jump on the train and stop it?) Err… not exactly. He’s a welder. (A welder?) Yeah, but he works in the train maintenance department, so he… well he wants to stop the train really bad! (Why? Is a relative on board?) No. (Are his kids trapped on a bus sitting on the train tracks?) No. He just likes a challenge. (Oh…) Did I mention it’s got Denzel Washington? (Oh yeah? Sold!)

I’m sure it went exactly like that. :)

It may sound like I didn’t like the movie, but I did enjoy it. It was fun, if inconsequential. They did a good job with making things feel tense and making 70 miles per hour seem like it was fast. Do you need to see it in the theater? Probably not. One thing I was slightly disappointed by was that they didn’t play up the massively deep and powerful sounding diesel engines these trains have. Probably because most sound systems can’t do the sound justice.

It’s one of those movies that is quite enjoyable, eminently watchable but parts of it don’t really hold up under deep scrutiny. It’s a bit formulaic and clichéd on hindsight, but hides its pedestrian nature well. I’d definitely say it is worth renting. Even if you dont’ like trains I think you’ll be entertained.

6/10

2010.11.18

Windows CMD parsing, preventing environment variable expansion inside quoted string

Filed under: Programming — kevenker @ 3:45 pm

I have a console-based app that talks to a database. I wanted to set a particular field value to be the environment variable, not the value of the envrionment variable. For example:

myapp -setdbvalue "User %USERNAME% is on %COMPUTERNAME%."

So the string I want stored in the database is “User %USERNAME% is on %COMPUTERNAME%.”.

However, if you call the above, you would end up with a string like: “User KEVENKER is on KILOTWO.” Definitely NOT the intended value. :)

After about an hour of searching, I never found the definitive answer! However, I learned enough from reading http://stackoverflow.com posts and http://ss64.com/nt/ that I managed to come up with this solution:

myapp -setdbvalue "User "%"USERNAME% is on "%"COMPUTERNAME%."

So what happens here is that the cmd processer sees the following strings:

"User " + "%" + "USERNAME% is on " + "%" + "COMPUTERNAME%."

and simply concatenates these all together into one string when passing this argument to my program.

So there you have it. I hope this helps some hapless person. Hopefully the title will be good enough for searching. I’m sure this has been solved before but finding the solution is the hard part. :)

2010.11.04

Timestamps for Windows batch scripts

Filed under: Programming — kevenker @ 7:09 am

Just a quick snippet of code for Windows batch scripts. I had to fool around for a while to get this working so I figured I’d post it here so I wouldn’t forget it. And maybe somebody else would find it useful as well.

I wanted to generate a timestamp for naming files of the form yyyymmddhhmmss. The problem is that batch scripts don’t really support string formatting. You can get %date%, e.g. Thu 11/04/2010, and you can get %time%, e.g.  7:55:31.23. So you have to tease out the pieces manually, by using batch script’s “substring” abilities.

The only real “gotcha” is that the time doesn’t print a zero at the front of single digit times. So if you do something like:

set timestamp==%date:~-4%%date:~4,2%%date:~7,2%=%time:~0,2%%time:~3,2%%time:~6,2%

you can end up with a string that looks like: “20101104 75531″, with that space in it, which is rather annoying. Not to mention that it breaks scripts unless you put quotes around everything.

Basically, you need to check to see if the first character in the time portion is a space and if it is, insert a 0 at the front and grab everything after the space. So the snippet I developed is:


set datepart=%date:~-4%%date:~4,2%%date:~7,2%
set timepart=%time:~0,2%%time:~3,2%%time:~6,2%

if "%timepart:~0,1%"==" " set timepart=0%timepart:~1%
set timestamp=%datepart%%timepart%

PS – Sorry about the jacked up formatting. It seems WordPress is going through one of its periodic episodes where the editor decides to to whatever it feels like. The HTML mode no longer appears to actually let you edit HTML either, making things extra fun!!

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.