Write an XML File

<?php
require("config.php");

// version and encoding;
$dom = new DomDocument("1.0", "ISO-8859-1");

// we create a XML Node 
$usersElem = $dom->createElement('users');

// Select all the rows in the names table
$query = "SELECT * FROM names";
$result = mysql_query($query);

if (!$result) {
die('Invalid query: ' . mysql_error());
}
// Loop through the rows, adding XML nodes
while ($row = @mysql_fetch_assoc($result)){

$usersElem->appendChild ( $dom->createElement('firstname', $row['firstname']) );
$usersElem->appendChild ( $dom->createElement('lastname', $row['lastname']) );
$usersElem->appendChild ( $dom->createElement('password', $row['password']) );
}
// add $usersElem to dom
$dom->appendChild( $usersElem );

// $dom has entire XML
$dom->formatOutput = true; // this adds spaces, new lines 
// save it as XML
$xmlSave = $dom->save('users.xml'); // returns true/false upon failure or success

if($xmlSave == false)
echo " Sorry you had a problem! ";
else
{
echo " File created! " . "<br>";

}

?>
<html>
<head>
<title> Demo : Write XML File </title>
<style>
li.L0, li.L1, li.L2, li.L3,
li.L5, li.L6, li.L7, li.L8
{ list-style-type: decimal !important }
</style>
</head>
<body>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<pre class="prettyprint linenums">
<code class="language-xml"><?php echo htmlspecialchars(file_get_contents("users.xml"), ENT_QUOTES); ?></code>
</pre>
</body>
</html>

This is basic example of writing an XML file in php. You can pretty it up with prettify.js.

JavaScript Calculator

JavaScriptCal

 

This is a mobile app which is a JavaScript Calculator. It has all the properties and methods options available. The result will be  displayed as you’re typing in a formula. An example is var a = 85; var b=72;Math.max(a,b) will result in 85. This calculator could easily be used for  algebra and most formulas. This is still in beta stage but has been released  for feedback.View Now!

Snapshot 3

Snapshot3I revamped Snapshot and made a delay timer and automated the whole snapshot process. I felt that all I really wanted was the end result the difference between Snapshot1 and Snapshot2.. With this change now all you need to know is how much delay do you want between the two snapshots. I find I can install new programs in less then 8 minutes but you can set a delay up till an hour. This program is ideal to use during any new program to monitor where and what is being installed. You still need Cygwin and some of the default basic install to use this program but it’s well worth it. To download just click on Download link. Download Now!

 

Insert MYSQL data into HTML Textarea

mysql_into_textarea
Follow the link below, the link will open new page to my demonstration.Insert MYSQL into Textarea

The concept is very easy and the main PHP code is below.

<html>
<head>

<?php
//make an object array
$arrayobj = new ArrayObject();
//connect to database
$con=mysqli_connect("localhost","username","password","db");
//check connection
if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL:".mysqli_connect_error();
}

$result=mysqli_query($con,"SELECT * FROM table");

while($row=mysqli_fetch_array($result))
{
$arrayobj->append($row['firstname']);
}

mysqli_close($con);
?>

</head>
<body>
<textarea id="myTextarea" rows="25" cols="25"><?php foreach($arrayobj as $value){
echo $value . "\n";}?>
</textarea>
<br>

</body>
</html>

As you can see connecting to database is as usual. The key is the $arrayobj = new ArrayObject() which make this string into an array and the $arrayobj->append (appends) to that array.

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:

<?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
$q=$_GET["q"];

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

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

//output the response
echo $response;
?>

Now create showteams.html:

<html>
<head>
<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>
<script>
function showTeams(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtTeams").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_teams.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

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

</body>
</html>

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.

DesktopNewTextFile

 

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

SendCompressedFolder

 

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.

WinZip

 

You will get a warning just click OK.

Warning

 

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.

EnterPassword

 

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

Update

 

Now you should get a verify.

Verify

 

Then a Auto Complete.

AddComplete

 

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.

Decrypt

 

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

Encrypting

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

Decrypting

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
FILECRYPT = $(FILEPLAIN).gpg

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

all:

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

edit:

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

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

touch:			# Run first if FILEPLAIN doesn't exist

	@umask 0077;\
	$(TOUCH) $(FILEPLAIN)
	$(VI) $(FILEPLAIN)

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

Output:

usage:

* 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 :

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:

./poem.exe

Output:

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:

./hello.exe

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
endif

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

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

call exit(retval)

end program count

Save as count.f90 and compile:

gfortran.exe -o count.exe count.f90

To run it type:

./count.exe

Output :

Inside program
           1
           2
           3
           4
           5
           6
           7
           8
           9
          10

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:

./count.cxx.exe

Output :

Inside program ./count_cxx
1
2
3
4
5
6
7
8
9
10

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

Grade

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

HorseGrade

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