Showing posts with label software. Show all posts
Showing posts with label software. Show all posts

Wednesday, September 30, 2015

Let x = x + 1

Let x = x + 1

The first time I saw it, my brain revolted. The math in me screamed: NNNNOOOOOO!!!!

But I kept digging, and one day found I had gradually succumbed to my present affliction: earning a living, more than full time, writing software bits.

The math part of me had learned, before I first saw this, that x is x is x, wherever it may be strewn throughout the equation. Wherever it appeared, it represented the same exact value. If it changed over there, it changes here, too, simultaneously. x = x + 1 is a mathematical impossibility.

Yet it's the way things work nowadays.

I eventually came to understand, as programmers tend to do, that x is not always x. x on the left is different than x on the right, and things which are named the same as other things are not actually the same thing. Embrace the ambiguity. Breathe it in. Let it seep down in to the very cells of your body and emit its light of illumination from within.

Let x = x + 1. The x on the left means "put the result of the stuff on the right into the spot named x." The x on the right means "use the value in the spot named x and add 1 to it to produce the result." These two xes are NOT the same, and because they are not the same, x = x + 1 is actually not a mathematical impossibility.

It's merely a Maths geek finally accepting his inner English geek.

Let x = x +1.

Forever and ever. Amen.

Wednesday, May 04, 2011

Sgt Fitness: now available in the App Store

Help me give $1,000,000 to charity!

My latest creation for the iPhone, Sgt Fitness, the workout coach for the Twitter generation, is now available in the App Store.

It's an exercise reminder app that drills you daily with short workout sessions that you can do anywhere, anytime. Each one only takes a minute or two, but over the course of the day, these drills add up to way more activity than you normally get just sitting in front of your computer.

If you've been making excuses like "I don't have time for a workout" or "I can't afford a gym membership" or "there's no shower at work" or ... then Sgt Fitness is for you. Everybody's got time for a minute or two here and there, the app costs way less than a gym membership, and working out in micro-bursts of activity won't get you too sweaty for your officemates.

Sgt Fitness converts your iPhone into a pocket-sized dose of self-discipline to help you get and stay fit.

Watch out, though. Sgt Fitness has a voice! If the sound is on, sarge'll let you know it's time for a drill with a verbal "Drop and give me 20!" Or, if you're like me, and you hate it when your phone makes sounds in the middle of a conversation with somebody, you'll get the old "vvvmmmppp" vibration alert. Either way, it's time for some activity, private.

Got ADD? No worries: the sergeant tells you exactly what to do and when to do it. You don't even have to think about it. And by the time you get distracted while doing the drill, it's over anyway. On to the next shiny thing, and before you know it, another couple of hours and a few hundred web pages have gone by, and it's time for the next drill.

"David, this is fantastic!" you say. "I've been thinking I should get more fit, and Sgt Fitness will help me there. I get it. But how will this help you give a million dollars to charity?"

I'm glad you asked. But I'm not going to answer that question until the next blog post. For now, suffice it to say that I am seeking the first 4,000 users of Sgt Fitness, and that I hope to recruit them within a month. Friends and family, I implore you: help me sell Sgt Fitness to the whole wide world -- blog, tweet, linked-in and facebook it up for me.

Sgt Fitness is available exclusively for iPhone, iPad and iPod Touch devices. Buy a copy today, and then let all your friends know there's a new workout in town. No gym membership required.

Stay fit!

Follow @SgtFitnessApp on Twitter for news and updates about the app... And check out the Sgt Fitness web page.

Thursday, March 31, 2011

Bling, bling, it's silver...

Another geek badge:

Ohloh profile for David Cole

From their "about" page:
"Ohloh is a free public directory of open source software and people."

If my ranking is true, I'm in the top 1% of open source contributors in the world. Not sure I believe such a ranking...

Wednesday, March 09, 2011

Wednesday, March 31, 2010

"Fun" With Batch Files

Here's how to compute the root Program Files directory of the Visual Studio 2008 installation from the VS90COMNTOOLS environment variable... (for example...) Obviously: same technique may apply to other env vars and other programs.

The Line of Code
In a batch file:
for /f "usebackq delims=" %%d in (`echo "%VS90COMNTOOLS%\..\.."`) do set VS_ROOT_DIR=%%~fd

Directly in a command prompt:
for /f "usebackq delims=" %d in (`echo "%VS90COMNTOOLS%\..\.."`) do set VS_ROOT_DIR=%~fd

The only difference between the two is the doubling up of the "%%d" percents when referencing for loop variables. Don't ask why, just learn: that's the way it is. Actually, if you want to ask why and then go figure out the answer... that would be a good blog post for you to write.

The Dissection
On my machine, the command...
echo "%VS90COMNTOOLS%\..\.."

...produces:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\\..\.."

Nice. Accurate and all, but look at all the ugliness we've produced. Doubled up backslashes, enclosing double quotes, ..s, not to mention the length.

So. That fancy "for /f" line. Let's clean up that output to remove the ugliness.

Using "for /f" with the "usebackq" option allows you to put a command inside backticks, as in `echo something`, and capture the output of that command in the for loop variable. In this dead simple example, the for loop would iterate exactly once, and the value "something" would be in the loop variable.

Using the "delims=" option allows you to split the output by delimiter characters. When you say "delims=" with the equal sign right up against the closing double quote, that means: no delimiter characters, give me the full output all at once. Much different result than "delims= " with a space in between... that one loops over the output separating by space characters, giving multiple for loop iterations based on how many spaces are in the output. You could also say "delims=\" to split at the path separator character, or "delims= \/:" to split at common date time separators.

Now that usebackq and delims are well understood, or at least explained, how does that help us get rid of the ugliness? Well... it's mostly the magical "%~fd" at the very end of our friendly line of code that makes the universe beautiful again. The usebackq/delims pain we went through was really just a way to get the string we want into a for loop variable so we can take advantage of for loop variable expansion modifiers.

for /f "usebackq delims=" %d in (`echo "%VS90COMNTOOLS%\..\.."`) do set VS_ROOT_DIR=%~fd

The "%~fd" says this: give me the value of the loop variable %d, and while you're at it, remove any enclosing double quotes (~), and resolve it to a full path, assuming the variable represents a file or directory name (f).

The net effect of all this is that our line of code...
for /f "usebackq delims=" %d in (`echo "%VS90COMNTOOLS%\..\.."`) do set VS_ROOT_DIR=%~fd

Finally, in the end, simply evaluates to the line of code we wanted to write in the first place, but without hard coding a machine specific path name in a batch file:
set VS_ROOT_DIR=C:\Program Files (x86)\Microsoft Visual Studio 9.0

Type "help for" in a Windows command prompt for more of the gory, sickening details regarding loop variable expansion.

And help keep the universe beautiful. Even if you still have to write batch files once in a while.

Monday, March 01, 2010

Must Have Windows Software

Whenever I get a new computer running Windows, like I am today at work, the first thing I download and install on it is Firefox. Then, using Firefox, I have to download and install the following shet of shtuff to make it programmer friendly. This is my way of avoiding being ripped to shreds by the open source sharks for actually having paid money for a computer running Windows... Actually, to avoid that completely, I'd have to install emacs or gvim, too. But I won't do that until somebody else has to use the computer and looks like he's floundering without it.

Must haves:
  • Process Explorer
  • notepad++
  • PuTTY
  • VNC
  • CMake
  • TortoiseCVS, including CVSNT command line client
  • TortoiseSVN
  • SVN command line client, usually the CollabNet one
  • Git, the msys one
And then, the hard core development tool:
  • Microsoft Visual Studio, whatever version(s) necessary to do my job...
And then, as necessary, but only as necessary:
  • xampp, for a localhost web server
  • NSIS, the installer builder
  • doxygen
  • graphviz
  • ActiveState Python
  • ActiveState Perl
  • ActiveState Tcl
  • MagicDisc, or similar ISO image mounting utility
Details:

notepad++ -- like notepad, but seriously OD'd on steroids: all kinds of built-in language syntax highlighting

VNC -- if I'm lucky, one that includes a free server so I can access the Windows box from other computers... if not, then at least RealVNC client so I can access other machines

Anybody out there have any other "must haves" that belong on a Windows box?

Saturday, February 27, 2010

Sick of these C# warnings? Here's how to eliminate them...

8>warning CS1668: Invalid search path 'c:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\lib\i386' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '

8>warning CS1668: Invalid search path 'C:\Program Files\Microsoft Visual Studio 9.0\lib' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '

The Visual Studio installer does a mysterious thing here.

The entries found at "Tools > Options > Projects and Solutions > VC++ Directories" point to some non-existing directories. But the entries are used to populate the LIB environment variable when building projects inside the IDE. So... if you build a C# project in the IDE, you get this warning about invalid search paths in the LIB environment variable.

Now, I'll give them the benefit of the doubt: maybe some installations of Visual Studio *do* produce these directories. However, this warning has been occurring all through the VS 2005 and 2008 series and I have always encountered it on every machine I've ever built a C# project on. Of course, there's one thing unusual about the way I typically build C# code that I forgot to mention: I usually build C# code with custom commands that drive the C# compiler directly from the build context of a C++ project. So I understand if Microsoft doesn't have a test that tries this scenario out. "Why would anybody do that, anyway?" :-)

The fact remains: those settings cause these warnings, and the installer has never installed those directories for me. I'm calling it a bug.

The way to get rid of this warning is to edit the entries to remove the ones that point to non-existent directories. The trick is figuring out which ones they are.

This one: "c:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\lib\i386" comes from the entry for "Win32" / "Library files":

$(VCInstallDir)atlmfc\lib\i386

VCInstallDir evaluates to "c:\Program Files\Microsoft Visual Studio 9.0\VC\"

This one: "C:\Program Files\Microsoft Visual Studio 9.0\lib" comes from the entry for "Win32" / "Library files":

$(VSInstallDir)lib

VSInstallDir evaluates to "C:\Program Files\Microsoft Visual Studio 9.0\"

Click on each of those in the Tools > Options dialog and delete them.

Voila. Warning gone.