Let’s turn this Ajax, PHP example into Mobil App

Let’s look at this example http://www.w3schools.com/php/php_ajax_php.asp. Click Here. I modified and changed some of the names in that code but most of it is the same.

Create a file called get_teams.php:

// Fill up array with names

$a[]='ARI|Arizona Cardinals|NFC-West';
$a[]='ATL|Atlanta Falcons|NFC-South';
$a[]='BAL|Baltimore Ravens|AFC-North';
$a[]='BUF|Buffalo Bills|AFC-East';
$a[]='CAR|Carolina Panthers|NFC-South';
$a[]='CHI|Chicago Bears|NFC-North';
$a[]='CIN|Cincinnati Bengals|AFC-North';
$a[]='CLE|Cleveland Browns|AFC-North';
$a[]='DAL|Dallas Cowboys|NFC-East';
$a[]='DEN|Denver Broncos|AFC-West';
$a[]='DET|Detroit Lions|NFC-North';
$a[]='GB|Green Bay Packers|NFC-North';
$a[]='HOU|Houston Texans|AFC-South';
$a[]='IND|Indianapolis Colts|AFC-South';
$a[]='JAX|Jacksonville Jaguars|AFC-South';
$a[]='KC|Kansas City Chiefs|AFC-West';
$a[]='MIA|Miami Dolphins|AFC-East';
$a[]='MIN|Minnesota Vikings|NFC-North';
$a[]='NE|New England Patriots|AFC-East';
$a[]='NO|New Orleans Saints|NFC-South';
$a[]='NYG|New York Giants|NFC-East';
$a[]='NYJ|New York Jets|AFC-East';
$a[]='OAK|Oakland Raiders|AFC-West';
$a[]='PHI|Philadelphia Eagles|NFC-East';
$a[]='PIT|Pittsburgh Steelers|AFC-North';
$a[]='SD|San Diego Chargers|AFC-West';
$a[]='SEA|Seattle Seahawks|NFC-West';
$a[]='SF|San Francisco 49ers|NFC-West';
$a[]='STL|Saint Louis Rams|NFC-West';
$a[]='TB|Tampa Bay Buccaneers|AFC-South';
$a[]='TEN|Tennessee Titans|AFC-South';
$a[]='WAS|Washington Redskins|NFC-East';
//get the q parameter from URL

//lookup all hints from array if length of q>0
if (strlen($q) > 0)
for($i=0; $i<count($a); $i++)
if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
if ($hint=="")

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint == "")
$response="no suggestion";
$response="<br>" .$hint;

//output the response
echo $response;

Now create showteams.html:

<title> Football Names</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
function showTeams(str)
if (str.length==0)
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp.readyState==4 && xmlhttp.status==200)

<p><b>Start typing a name of a NFL team in the input field below:</b></p>
<input type="text" onkeyup="showTeams(this.value)">
<p>Suggestions: <span id="txtTeams"></span></p>


The key is pointing to JQuery Mobil. To test app start typing a NFL Team. It will display Team Abbeviations. Team Name and Division. Click Here


Make a Password Protected File

Making a password protected file is easy using WinZip. Let’s start by making a text file on your desktop. Right Click on desktop move mouse to New and click on Text Document.



Rename file to Pass.txt. Now Right Click on the file just created and move mouse to  Send and select Compressed (zipped) folder.



Double Click on the zipped folder called Pass.zip on your desktop that was just created. Once WinZip opens you should see the Pass.txt file. Click on file then press Encrypt.



You will get a warning just click OK.



This is important make sure you check 256-Bit AES under encryption method then enter a strong password at least 15 characters in length. Get a  password generator app for your cell. Don’t worry you be putting in this file.



After you enter a password, open file and enter all your password then save. You should see something like this click Yes.



Now you should get a verify.



Then a Auto Complete.



Now Close File. You can go ahead and delete the Pass.txt on Desktop and keep Pass.zip. The next time you want to add to file  just double click on Pass.zip. When WinZip opens double click on Pass.txt and you should see the dialog.



You now have a password protected file now so change all the easy passwords that you have and keep track all your passwords in one file. Don’t forget to keep a printed copy in a safe place.

Encrypting and Decrypting Documents

Install gnupg in Cygwin

First step is to install gnupg in Cygwin. Run setup.exe and use all default until you get to select packages. In the search type gnupg click on install then at bottom of screen click next to install. There are two Website that are good reads on the topic of GPG .

Encrypting and decrypting documents
GPG Quick Start

Generate a private key

gpg --gen-key

You’ll have to answer a bunch of questions:

What kind and size of key you want; the defaults are probably good enough.

How long the key should be valid. You can safely choose a non-expiring key for your own use. If you plan to use a key for public signing, you might want to consider a yearly expiration.

Your real name and e-mail address; these are necessary for identifying your key in a larger set of keys.

A comment for your key, perhaps to distinguish a key used for special tasks like signing software releases. The comment can be empty.

A passphrase. Whatever you do, don’t forget it! Your key, and all your encrypted files, will be useless if you do.

Export a key

After you generated a key, export it to a file so you can send in email or save on thumb drive.

gpg --armor --output pubkey.txt --export 'your@email.com'

Import a key

Import your friend’s key, which you might have received via e-mail or on a thumb drive. If the file is named pubkey.txt, then just use the –import option to add it to your keyring:

gpg --import pubkey.txt


Encrypt a file called sensitive.txt. The argument to the –recipient option should be the all or part of the name you used when generating your private key. The –output option is the name you want the gpg file called. Most likely you won’t need the –output option because it default to filename.gpg.

gpg --output sensitive.txt.gpg --encrypt --recipient jtltgl@gmail.com sensitive.txt


If someone sends you an encrypted file, the file has typically been encrypted using your public key. Decrypting it is no different than decrypting a file you have encrypted for your own use.

gpg --output sensitive.txt --decrypt sensitive.txt.gpg

Modified Makefile

# example Makefile for viewing/editing an encrypted file

GPGID = 'your.email.com'
FILEPLAIN = sensitive.txt

GPG = gpg
RM = rm -i
VI = notepad
TOUCH = touch


	@echo ""
	@echo "usage:"
	@echo ""
	@echo "* make touch -- Startup"
	@echo "* make view -- to see $(FILEPLAIN)"
	@echo "* make edit -- to edit $(FILEPLAIN)"
	@echo ""


	@umask 0077;\
	$(GPG) --output $(FILEPLAIN) --decrypt $(FILECRYPT)
	@umask 0077;\
	$(GPG) --encrypt --recipient $(GPGID) $(FILEPLAIN)

	@umask 0077; $(GPG) --decrypt $(FILECRYPT)

touch:			# Run first if FILEPLAIN doesn't exist

	@umask 0077;\

Here is Makefile for download copy to your Cygwin home directory. Download Now!  You must edit and fill in email address which was enter when you made key. To run just type:




* make touch -- Startup
* make view -- to see sensitive.txt
* make edit -- to edit sensitive.txt

When running “make view” answer y to a couple of question when quitting.

Let’s Compile in Cygwin

First you will need to install gcc, gcc-g++, gcc-fortran, gcc-java ,gccmakedep, make and cmake. I will show you how to install gcc you will have to repeat for all the rest. Run setup.exe this is the program you ran to install Cygwin. Use all the default setting until you get to the select package screen. Type gcc in search :



Under Devel click on gcc, gcc-fortran, gcc-g++ and gcc-java. Mine say’s Keep because it’s already installed most likely your’s will say Skip, click on box to install. Now repeat steps for make, cmake and gccmakedep. Now let’s compile I am going to use Notepad for demonstration purposes because that is on all Windows machine. I won’t go into great detail about the code snippets but will show you how to compile and run program. You can cut and paste but be aware sometimes illegal or invisible characters can be inserted and compiler will give error. I will have a link to examples at end of post for download. Let’s start with a C program first. Type this code snippet and save as poem.c:

/* Short Poem                                              */

#include <stdio.h>


   main ()                    /* Poem */

   printf ("Astronomy is %dderful \n",1);
   printf ("And interesting %d \n",2);
   printf ("The ear%d volves around the sun \n",3);
   printf ("And makes a year %d you \n",4);
   printf ("The moon affects the sur %d heard \n",5);
   printf ("By law of phy%d great \n",6);
   printf ("It %d when the the stars so bright \n",7);
   printf ("Do nightly scintill%d \n",8);
   printf ("If watchful providence be%d \n",9);
   printf ("With good intentions fraught \n");
   printf ("Should not keep up her watch divine \n");
   printf ("We soon should come to %d \n",0);

If everything was install right all you have to do is type:

gcc -o poem.exe poem.c

To run it type:



Astronomy is 1derful \n"
And interesting 2
The ear3 volves around the sun
And makes a year 4 you
The moon affects the sur 5 heard
By law of phy6d great
It 7 when the the stars so bright
Do nightly scintill8
If watchful providence be9
With good intentions fraught
Should not keep up her watch divine
We soon should come to 0

Notice in this code snippet has an assigned number appears at the %d. Thats just part of the printf function. You can read up on printf this is only an example. C++ is almost the same except you use g++ to compile. Type :

// 'Hello World!' program 

#include <iostream>

int main()
  std::cout << "Hello World!" << std::endl;
  return 0;

Save as hello.cpp and compile :

g++ -o hello.exe hello.cpp

To run it type:


Output :

Hello World!

Now let’s try fortran:

program count

integer :: upto = 10 ! count to 10 by default
integer :: i ! iterator
integer :: retval ! return value stores program status
character(len=32) :: arg ! buffer for command line argument

call getarg(1, arg) ! get argv[0] (how does this differ from c++?)
print*,'Inside program ',arg

if (iargc() .gt. 0) then ! use first argument
call getarg(1, arg)
read(arg, FMT='(I5)') upto

! perform my count
do i = 1,upto
end do

if (i .gt. 20) then
retval = 1
retval = 0

call exit(retval)

end program count

Save as count.f90 and compile:

gfortran.exe -o count.exe count.f90

To run it type:


Output :

Inside program

In this code snippet you can see that it’s looks for arg1 so while running you can put a number as the first argument. like ./count 20 , this will count to 20. The program defaults to 10 if no argument are given.

CMake is a family of tools designed to build, test and package software. You will need make installed to use this program.

Example file called count.cxx:



#include  <iostream.h>
#include  <stdio.h> 
using namespace std; 

int main (int argc, char** argv) {
	int upto = 10;  // count to 10 by default
	int i;          // iterator

	// Notice the use of argv[0] (how do we know its the program name?)
	cout << "Inside program " << argv[0] << endl; 	if (argc > 1) { // use first argument
		upto = atoi(argv[1]);

	// perform my count
	for (i = 1; i <= upto; i++) {
		cout << i << endl; 	} 	if (i > 20) {
		return 1;  // what effect does this have? 

	return 0; // successful execution

You will also need a file called CMakeList.txt:

PROJECT(countTo10 CXX) 

ADD_EXECUTABLE(count_cxx count.cxx)

To compile type:

Step 1) cmake .
Step 2) make

To run it type:


Output :

Inside program ./count_cxx

There are a lot more programs like PHP, Ruby, Perl, Tcl and Python all can be run from Cygwin console. I would recommend looking at an old article under cmdcenter categories called Recommended installs for use with CMDCenter. Just follow examples but instead of running with CMDCenter program just type in commands in Cygwin console. Hope you have as much fun as I do working with code and compilers. Here are the examples for download. Download Now! One note when you download from another computer Windows Blocks the file. You must right click on file under Properties and then click on Unblock. A better way is using this command “streams -s -d name_of_directory” without quotes. This is a tool I recommended in Sysinternals Suite. It will Unblock all files in the subdirectory.

Belmont Today


Without over analyzing today’s Belmont I am picking Oxbow. He is two grades above everybody else in the  field. Please try my app and tell me if the instructions make sense. This should run on any Browser just go to http://smallprogramdesign.com/myapp.Click Here For smart phones make sure you bookmark and create shortcut. I planned on finishing my  app  on Friday but there was mandatory overtime, bummer. I couldn’t finish app. There are other reasons I am picking Oxbow, but I can’t give all my secrets away.

Made HorseGrade into Mobil App


Horse Grade is a app which compares winning time against track record and grades performance. The closest to 100% or greater the better the performance. You can view source and project at http://jtltgl.github.com/Grade/. Click Here Here are example data to try out app.

ORB Race 12 PIMLICO for 1 1/4 mile

Win = 202.89(convert 2:0289 equals 202.89)

Loss = (leave this blank if horse wins race)

Record = 201.4

Press Calculate

Horse Grade is 99.27

note: Track records can be found on Web

OXBOW Race 12 PIMLICO for 1 1/4 mile

Win = 202.89

Loss = 9.5 (convert 9½ equals 9.5)

Record = 201.4

Press Calculate

Horse Grade is 98.35




For fun I made a horse Grade Calculator which will compare track record against horse time and grade the performance. The closest to track record the better performance. Track records  like this from  Churchill Downs  can be found  by searching Web.

Churchill Downs Track Records
4 1/2 Fur.	Notonthesamepage	2	118	:50.12	April 30, 2008
5 Fur.		Hot Dixie Chick 	2 	118	:56.48	June 13, 2009
5 1/2 Fur.	Cashier's Dream		2	118	1:02.52	July 7, 2001
6 Fur.		Indian Chant		4	120	1:07.55	July 8, 2007
6 1/2 Fur.	Love At Noon		3	121	1:14.34	May 5, 2001
7 Fur.		Groupie Doll		4	123	1:20.44	May 5, 2012
7 1/2 Fur.	Greater Good		4	120	1:27.97	July 3, 2006
1 Mile		Infrattini		4	121	1:33.31	Nov. 22, 2012
1 1/16 Miles	Successful Dan		6	118	1:41.04	May 4, 2012
1 1/8 Miles	Victory Gallop		4	120	1:47.28	June 12, 1999
1 3/16 Miles	Tritap			3	118	1:58.12	Nov. 17, 2012
1 1/4 Miles	Secretariat		3	126	1:59.40	May 5, 1973
1 1/2 Miles	A Storm Is Brewing	4	112	2:32.02	June 17, 2001
1 5/8 Miles	Tupolev			5	112	2:49.40	July 23, 1983
1 3/4 Miles	Eldaafer		5	126	2:59.62	Nov. 5, 2010
2 Miles		Libertarian		4	113	3:22.26	Nov. 28, 1998

Matt Winn Turf Course
5 Fur.		Silver Timber		7	124	:55.45	April 30, 2010
1 Mile		Jaggery John		4	113	1:33.78	July 4, 1995
1 1/16 Miles	Wise River		6	120	1:39.83	April 26, 2009
1 1/8 Miles	Lure			4	123	1:46.34	April 30, 1993
1 3/8 Miles	Snake Eyes		7	123	2:13.00	May 22, 1997
1 1/2 Miles	Tikkanen		3	122	2:26.50	Nov. 5, 1994

To use calculator just enter the winning time, loss length and track record for the distance of race. Please convert loss length to decimal format so 5 ½ will equal 5.50. After all data filled in  hit Calculate and it will grade the performance. I used this in the recent Kentucky Derby but no luck. On most racing forms time is written like 1:10²³, please enter time without colon and add decimal point for superscript fractions given so example is written like 110.23. One more reminder if the horse wins don’t  enter any length loss.

JSCalc Calculator


JSCalc is a calculator which has all the math functions of JavaScript. Just enter a formula using Javascript  math functions format. So Math.sqrt(16) will returns square root of 16. There are shortcuts for all  function without entering Math.blah use lowercase object name, example type “sqrt ” (note: you need space without quotes) . Once you enter the lowercase object name with a space it will be replaced with Math.object_name. Enjoy how simple just entering a formula, making this a easy and a very powerful calculator. The picture shows the formula for volume of a cylindrical canister with radius 7 cm and height 12 cm. You enter the formula (Math.PI.toFixed(3)*Math.pow(7,2)*12).toFixed(2) and press Calculate, don’t forget brackets.






So, the volume of the canister is 1847.50 cm. You can find this example at.Click Here

Notes :

var x = Math.PI; // Returns PI = (3.14159265358979)
var y = Math.sqrt(16); // Returns the square root of 16 = (4)
Instead of typing Math.blah use lowercase property plus a space name ex. "e " equals Math.E (approx. 2.718)
Declare variable with var and separate your variables by a semicolon ex. var x = 10;var y = 5;x*y

Math Object Properties
Property			Description
E			Returns Euler's number (approx. 2.718)
LN2			Returns the natural logarithm of 2 (approx. 0.693)
LN10			Returns the natural logarithm of 10 (approx. 2.302)
LOG2E			Returns the base-2 logarithm of E (approx. 1.442)
LOG10E			Returns the base-10 logarithm of E (approx. 0.434)
PI			Returns PI (approx. 3.14)
SQRT1_2			Returns the square root of 1/2 (approx. 0.707)
SQRT2			Returns the square root of 2 (approx. 1.414)

Math Object Methods		Method Description
abs(x)			Returns the absolute value of x
acos(x)			Returns the arccosine of x, in radians
asin(x)			Returns the arcsine of x, in radians
atan(x)			Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians
atan2(y,x)		Returns the arctangent of the quotient of its arguments
ceil(x)			Returns x, rounded upwards to the nearest integer
cos(x)			Returns the cosine of x (x is in radians)
exp(x)			Returns the value of Ex
floor(x)		Returns x, rounded downwards to the nearest integer
log(x)			Returns the natural logarithm (base E) of x
max(x,y,z,...,n)	Returns the number with the highest value
min(x,y,z,...,n)	Returns the number with the lowest value
pow(x,y)		Returns the value of x to the power of y
random()		Returns a random number between 0 and 1
round(x)		Rounds x to the nearest integer
sin(x)			Returns the sine of x (x is in radians)
sqrt(x)			Returns the square root of x
tan(x)			Returns the tangent of an angle

Number rounding two methods

Method One :

var original=28.453

1) 	//round "original" to two decimals
	var result=Math.round(original*100)/100  //returns 28.45

2) 	// round "original" to 1 decimal
	var result=Math.round(original*10)/10  //returns 28.5

3) 	//round 8.111111 to 3 decimals
	var result=Math.round(8.111111*1000)/1000  //returns 8.111

The formula to round any number to x decimal points is:

1) Multiple the original number by 10^x (10 to the power of x)
2) Apply Math.round() to the result
3) Divide result by 10^x

Method Two:

Definition and Usage

The .toFixed() method converts a number into a string, keeping a specified number of decimals.




Convert a number into a string, keeping only two decimals:

var num = 5.56789;
var n=num.toFixed(2);

The result of n will be:


Least and Greatest Common Factors

I like building calculators, there fun and easy to do. Here is a calculator which will determine the Greatest Common Divisor and Least Common Multiple. You need two Numericupdown , Button and two Textboxes. Here is a picture of design.



Code :

Public Class Form1
Public Function GCD(ByVal a As Integer, ByVal b As Integer) As Integer
Dim Remainder As Integer

        While (b <> 0)

            Remainder = a Mod b
            a = b
            b = Remainder
        End While

        Return a
End Function
Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCal.Click

If (nupdnValue1.Value = 0 Or nupdnValue2.Value = 0) Then
            MsgBox("You can not have zero as a compare number!")
            tbGCD.Text = GCD(nupdnValue1.Value, nupdnValue2.Value)
            tbLCM.Text = ((nupdnValue1.Value * nupdnValue2.Value) \ tbGCD.Text)
        End If
End Sub
End Class

The NumericUpDown widgets are nupdnValue1 and nupdnValue2. Button is called btnCal and the textboxes are called tbGCD for GCD and tbLCM for LCM. Both formulas use the GCD function the guts of the program. Here is a link to demonstrate Greatest Common Factor(Divisor) and Least Common Multiple. Click Here

Wallpaper Calculator

Spring is here and home improvements are in the works. Here is a Wallpaper Calculator made using Visual Basic. You will need 3 Numerical up/dn box and 3 textboxes. Here is picture of design.



Code :

Public Class Form1

 Private Sub bntCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntCal.Click

If (nupdnHeight.Value = 0 Or nupdnLength.Value = 0 Or nupdnWidth.Value = 0) Then
            MsgBox("You must have value for height, length and width!")
            Dim strips_per_roll As Double = CInt(rolllength.Text) \ nupdnHeight.Value
            Dim perimeter As Integer = 2 * (nupdnLength.Value + nupdnWidth.Value)
            Dim strips_reqd As Double = perimeter \ CInt(rollwidth.Text)
            'Number of Rolls with 5% watse
            nrolls.Text = CInt((((0.05 * strips_reqd \ strips_per_roll) + strips_reqd) \ strips_per_roll))
        End If

End Sub
End Class

The NumericUpDown widget’s are nupdnHeight. nupdnLength and nupdnWidth. The Texboxes are rollwidth and rolllength. You will need a Button called bntCal too. You always have waste for wallpaper jobs so I added 5% waste in calculation.  All calculations are  made in inches. Default common values are inputed for  roll width and roll length. You can change values but try to keep everything in inches.