November, 2009


22
Nov 09

Download a Web Page with Windows PowerShell

This is an example of using Windows PowerShell to download a Web page and print it to the screen.
$url = "http://www.ke5prl.com"
$client = New-Object System.Net.WebClient
$contents = $client.DownloadString($url)
echo $contents

Now while that might be a neat use of technology it is not terribly useful. If we modify the code just a little we can get back callsign information from one of the common Web lookups. For our first modification let’s change the first line to
$url = "http://www.arrl.org/fcc/fcclook.php3?call=ke5prl" and you can substitute your callsign for mine.

Now let’s turn this into a function. By making it into a function we can easily pass different callsigns to the function without changing the code.
function callsign($call){
$url = "http://www.arrl.org/fcc/fcclook.php3?call=" + $call
$client = New-Object System.Net.WebClient
$contents = $client.DownloadString($url)
echo $contents
}
callsign("KE5PRL")


22
Nov 09

The 555 Chip

The 555 Integrated Circuit (IC) chip is one of the most common ICs and is used in electronics projects by manufacturers and hobbyists alike. If you have an electronic device that has a blinking LED then there is a good chance that a 555 is being used in astable mode. Links about the 555 IC:


22
Nov 09

Hello World in Perl

Writing a Hello World! program in Perl is straightforward. Open a text editor and enter the following lines:
#!/usr/bin/perl
print "Hello World!";

Save the file as hello.pl.
In Windows I can leave that first line (#!/usr/bin/perl) out and the program runs. In a Unix or Linux environment you will need to leave that line in the program. To execute this program in Windows you will need to get a command prompt window open and you can do that by clicking Start > Run and entering cmd. In Vista just type cmd in the Start Search box. After entering cmd, press enter and you should be presented with a command prompt window like the one shown below.
cmd
If you have just installed Perl then you need to make sure that your PC knows where Perl is located. Check that by using the path command at the command prompt. The very long string that is returned from this command should contain an entry similar to C:\Perl\perl\bin. If it does not then review this article on ComputerHope.com to see how to add Perl to your path.

So now let’s run that Perl program. Simply navigate to the directory where your hello.pl program is saved and type perl hello.pl to run the program.


21
Nov 09

Windows PowerShell – Hello World (2)

With Windows PowerShell it is easy to enter a command at the command prompt to return “Hello World!” Part 1 covered how to do that. The code from Part 1 could be saved in a file with a .ps1 extension and it could be executed by calling it from the command prompt. For example, if saved as hello.ps1, the command to call this script would be ./hello.ps1 if you are in the same directory as the file hello.ps1.

If you have installed Windows PowerShell and have not tried running a script then there may be one extra step that you will need to take. It is described in detail at this link at technet.microsoft.com. What this article details I will summarize – the command you will need to enter at the command prompt is:

set-executionpolicy remotesigned

and that will allow you to run your script. Use Notepad or some other simple text editor for actually entering the scripts otherwise you will introduce various control characters that cause PowerShell to digitally puke.

Now for a Hello World script with a little more sophistication. Paste this into a file named ‘hello2.ps1′ and remember to use Notepad.
[reflection.assembly]::loadwithpartialname('system.windows.forms')
[system.Windows.Forms.MessageBox]::show('Hello World!')

My reference for this is http://powerscripting.wordpress.com/2008/03/03/one-liner-pop-up-a-message-box/.

After saving that file you can execute it by entering ./hello2.ps1 at the Windows PowerShell prompt if you are in the same directory as hello2.ps1 – otherwise use the entire path to call hello2.ps1. Your pop-up box will resemble the one below.

Hello World Pop-Up Box



20
Nov 09

Windows PowerShell – Hello World (1)

Making a program output “Hello World!” is the first program that one typically learns when getting started with a new language. You can read about Hello World in a Wikipedia article entitled Hello world program.

At the Windows PowerShell command prompt enter the following:

echo "Hello World!"

and hit enter. That’s all there is to it. In Part 2 learn how to write a short PowerShell script to display “Hello World!”


20
Nov 09

How to Learn Programming

Learning how to program can seem like a daunting task. With a wide array of languages to choose from it is not so difficult to be overwhelmed before even starting. The good news is twofold: 1) as you learn one language it becomes easier to program in other languages and 2) you can get started learning by investing only a small amount of time and no money.

Often when students come to me or my colleagues for help with a programming problem they seem to think that they are one syntax error away from crashing the system. Well if you are learning to program you are going to make plenty of these errors. Back up your system (you should be doing that anyway) and then program away. While you probably understand this next point I still feel that I would be remiss if I did not say this: DO NOT learn to program on a production machine. What is a production machine? Any computer that is essential to your business.

What language should you start with? I would start with Windows PowerShell or Perl. Both are free and there is a ton of helpful pages about both of them on the Web.