Search

Sharing a few thoughts

The official web site for Mike Goldweber

Author

halciber

I'm a software engineer by day, and a blogger by night. I enjoy Science Fiction, strategy gaming, reading, archery, ham radio, and making art. It's just too bad that there isn't more time in the day!

Count down to the Inauguration

Some one had made a twitter posting of the number of minutes to the Inauguration later this week. I didn’t want to depend on their posts to keep me updated, so I made this little PowerShell script to give me the time to the minute. It can run all day long, and will stop at noon this coming Friday.

Here’s the code in case you would like to run your own.

 

clear
do
{   
    [long] $Minutes = [long]$((New-TimeSpan $(Get-Date) $(Get-Date -Month 1 -Day 20 -Year 2017 -Hour 12 -Minute 0 -Second 0)).TotalMinutes)
    "$Minutes minutes to the inauguration"
    Start-Sleep -Seconds 60
    clear
}while($Minute -gt -1)

"Donald Trump is President of the United States!"

Here’s the output:

mintoinaug

It’s pretty exciting, so if you have a heart condition, please consult your doctor before running this script.

The Mystery of the NULL Characters

Recently my supervisor reported that an application was popping “NULL Characters” errors.  Meaning, that the application she was running was trying to read a file modified by a Powershell script I wrote.  I used a couple of different text editors (Notepad++, UltraEdit) to examine the files, specifically the feature that allows the use of seeing/viewing symbol characters.  However, even with these tools, I didn’t see any NULL characters.  I even went so far as to write NULL characters to text files using Powershell.  These characters did in fact appear in the text editors!!

The problem persisted, and I was told that files not modified in Powershell were working properly.  Clearly my Powershell script was causing a problem.  So, I did a little bit of digging, and learned that the correct tool to use was a Hex editor.  I did a bit more digging, and found a freeware called XVI32.exe.  XVI32.exe is a utility created by Christian Maar, and it is super helpful!  This tool showed me that in fact, I did have NULL characters!  Here’s what I saw:
blog_20161023_1
All of those “00”s are the NULL characters.  I realized that at point, my problem was the character encoding.  It turns out the default encoding is Unicode, which uses 2 8-bit spaces, not the single 8 bits used in ASCII.  My fix ended up being simple, all I had to do was change the Out-File by specifying the -Encoding value, as seen here:
blog_20161023_2
Rerunning the script gave me a different file.  Here’s what XVI32.exe now showed me:
blog_20161023_3
You can see a considerable difference between the first and third picture.  This time, I got all asterisks (“2A”), as I expected.  More importantly, my supervisor’s application worked properly.

Why bother?

So, why bother with a writing a blog? Simply put, I want to share things that I find interesting and useful. I’ve frequently have benefited from the writings of others, and I thought that it was time that I started returning the favor.  Simply put, I’m interested in everything, so don’t expect this blog to be limited to solely computer programming or technology subjects.

Website Powered by WordPress.com.

Up ↑