Saturday, 28 May 2011

BMQ LAND 0907

So i am back for a few days before i head back to work. In my last post i did not mention what i was doing. I was currently finishing off my military boot camp course. The second portion of it. Also known as BMQ Land (Soldier Qualifications). So i will keep this post short, as my writing skill has diminished a little. "BMQ" stands for "Basic Military Qualifications". "Land" means what side of the military I am on. In this case Land is well land and not air or naval.

Course details(what i learned):

M72 Rocket Propelled Grenade (SRAAW (L))
C13 Fragmentation grenade
C9 Light Machine Gun
C6 General Purpose Machine Gun

Platoon Attacks
Section Attacks

Recce Patrols

Offensive and Defensive Operations

How to dig and man a trench and not sleep for a week straight


The last point was the highlight of the course. Now i will display a picture of myself and the killing tools I was trained on.

Thursday, 21 April 2011

Leave of Absence

Hi there fellow views and followers. I am sad to inform you that I will no longer be blogging for the next 3 months. This is mainly due to I need work to pay for school. Now your probably wondering and saying, "well i work and i can blog". This may be true, but for myself I will not have the privilege of internet and computer access.  In my line of work which I will not disclose with you.

On those regards, I shall be returning August 1st or sooner. Thus you can expect to read more programming math related posts around that time. Also for the voting post.

What Language to explain and possibly teach?


Total votes per language:

C: 0
C++:7
Java: 7
HTML: 2
CSS: 0
Javascript: 0
PHP: 2
Other(aka Ruby): 1

So as you can see it is a tie between Java and C++. Thus we need to take into consideration my vote.
I myself would like to learn and teach Java in the process. So in august before my object oriented programming starts. I will be getting a head start by learning java. So this is my last post. Have a good summer.

Tuesday, 19 April 2011

Portal 2

So finally Portal 2 came out. For those who have not even heard of Portal. You have to crawl out of your cave and game it. It has won all sorts of awards and is quite possibly the most original game I have played.

Here is a quick writeup from our good friend Wikipedia.

The game consists primarily of a series of puzzles that must be solved by teleporting the player's character and simple objects using the Aperture Science Handheld Portal Device (ASHPD, also dubbed the "portal gun"), a unit that can create inter-spatial portals between flat planes. The player character, Chell, is challenged by an AI named GLaDOS(Genetic Lifeform and Disk Operating System) to complete each puzzle in the Aperture Science Computer-Aided Enrichment Center using the portal gun with the promise of receiving cake when all the puzzles are completed.

In short summary for anyone who has played. The cake is a lie. This was quite possibly the best game of 2007.



So besides Portal being an awesome game. Such an awesome game as a sequel. Portal 2. Now i have not played the game yet. As i am waiting for my younger brother to get off the Xbox 360, and go to bed which should have been 2 hours ago.  I will soon be playing this game. I am extremely excited and I think after this post i will be kicking my brother off. Oh and obviously I will have to beat it all in one sitting.

The game description on the back of the game case.


The single-player portion of Portal 2 introduces a cast of dynamic new characters, a host of fresh puzzle elements, and a much larger set of devious test chambers. Players will explore never-before-seen areas of the Aperture Science Labs and be reunited with GLaDOS, the occasionally murderous computer companion who guided them through the original game.
The game's two-player cooperative mode features its own entirely separate campaign with a unique story, test chambers, and two new player characters. This new mode forces players to reconsider everything they thought they knew about portals. Success will require them to not just act cooperatively, but to think cooperatively.


Screenshot of one of the game's test chambers, showing the deterioration over the years (plant overgrowth, damaged panels and floors, etc.) Also demonstrates the crazed art left by the "Rat Man" character that reviews the events of the first game.

Monday, 18 April 2011

What Language to explain and possibly teach?

So starting this week, depending on how well comments go. I will be interacting with my fellow followers a bit. I want to see what you my followers want to see me talk about. To do this I will obviously ask you the reader to leave a nice comment/vote to determine what I talk about next. The topics I will be talking about will either be a programming language that i have not explored yet, or one that I am extremely familiar with. So this will be both a fun experience for myself and for the reader. I will hopefully brush up on some programming, or possibly learn a new language or at least better understand a language. I will also be referencing this post in my other posts so that you can get a chance to vote/comment. So I will now lay down the options for you to decide.

******* Please comment with the language you would like me to talk about*********
  1.  C
  2.  C++ 
  3. HTML
  4. CSS
  5. JavaScript
  6. PHP
  7. Java
  8. Other (state what language in comment)
Voting will be over by Wednesday or Thursday. 

 So I look forward to talking about one of these. Also even though school is over for myself. I have always wanted to learn Big "O" in math. So i think I will teach myself that and post it about that sometime.

Sunday, 17 April 2011

Javascript Tricks

I have read a few tricks across my travel through the Internets in regards to Javascript.

JavaScript, also known as ECMAScript is a prototype-based, object-oriented scripting language that is dynamic, weakly typed and has first-class functions. - http://en.wikipedia.org/wiki/JavaScript

Now when i say tricks i mean something that manipulates the code of a site in a non harmful way to create personal enjoyment. You can also use these to benefit yourself or show off to friends. What ever order comes first.

All of the code presented can be copied and pasted into the URL bar. Hit enter and enjoy. Also it may help if JavaScript is turned on in your browser. 

Master Editor:

So anyhow here is some code to help you edit your site faster, or pretend to be editing a site in real time.

javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

My personal favorite. Takes all images off the site and creates a Ferris wheel with them. 

Image Vortex:


javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("img"); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}setInterval('A()',5); void(0);

 If you look carefully in the above code, its rotating the HTML “img” tag. Just replace it with “a” or “p” and watch some links or text rotate instead of images.

 Tremors:

Your screen is going to love this one.

avascript:function flood(n) {if (self.moveBy) {for (i = 200; i > 0;i--){for (j = n; j > 0; j--) {self.moveBy(1,i); self.moveBy(i,0);self.moveBy(0,-i); self.moveBy(-i,0); } } }}flood(6);{ var inp = "D-X !msagro na dah tsuj resworb rouY"; var outp = ""; for (i = 0; i <= inp.length; i++) {outp =inp.charAt (i) + outp ; } alert(outp) ;}; reverse 

 Sketchy Site, Inspect it:

If you find a site that you feel you cannot trust. You want to verify that it is authentic. You can with this.

javascript:alert("The actual URL is:\t\t" + location.protocol + "//" + location.hostname + "/" + "\nThe address URL is:\t\t" + location.href + "\n" + "\nIf the server names do not match, this may be a spoof.");

Roll up your broswer Katamari style:

javascript:var h='http://dl.dropbox.com/u/1881429/Katamari/',i,n,ss=['http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js',h+'Renderables.js',h+'Game.js'];for(i=0;i<ss.length;i++){n=document.createElement("script");n.src=ss[i]+'?'+Date.now();document.head.appendChild(n);}

This code only works for chrome and safari.  Thanks to "mac and me" for posting a comment about this.

Basic Calculator:
 Possibly the most helpful out of these tricks. 

javascript: alert(69696-76543+555);

Change the numbers inside the alert function to create your own equations. You can also not include numbers in the function, but instead write any comment that you want displayed like. Your computer will self destruct in 10 seconds. Freak your friends out. Have fun.





Saturday, 16 April 2011

PHP: File Input and Output

So i was meddling around today will File input and output functions. These functions are relatively the same as what i have dealt with in C and C++. One thing that's bothering me is the newline command is still acting weird for me. Another thing I experimented with was getting a string or value from a user input. This involves HTML forms. Which i have very little experience with too. So today was very hectic trying to learn and correct a lot of mistakes and errors while trying to code and learn new things. I also noticed what i was coding actually required a server this time. So i used a nice program called xampp to set up a PHP server for me. So testing the code on that has been splendid. So anyhow on to the coding.

Source Code
-------------------------------------------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=us-ascii" />

    <title>form.htm</title>
</head>

<body>
    Form site
    <br />

    <form action="fileio.php" method="post">
        username:<input name="name" type="text" /> <input type="submit" />
    </form>
</body>
</html>
----------------------------------------------------------------------------------------------------------------
Now the code that makes the least amount of sense is this.

Source Code
-------------------------------------------------------------------------------------------------
    <form action="fileio.php" method="post">
        username:<input name="name" type="text" /> <input type="submit" />
    </form>
---------------------------------------------------------------------------------------------------
 Now you are probably wondering what in the world is this. Well, I will start with saying it is a form. If you haven't figured that out then i don't know if programmings right for you. What this form does is allows the user to enter a string into a box. Then hit a little submit button. This is appropriate for numerous situations and can be used as a login.

In this codes case it's to check the availability of a username. If it is free, it allows the user to use it.
Another important part of the form is the top where it says

action="fileio.php" method="post"

the action part is when the user clicks the submit button.It will bring them to another page i called fileio.php. I will show the code for that soon. The next important thing is the method="post". This takes whatever the user entered into the text box and transfers it over to the fileio.php page. Now this may be explained poorly and i am sorry if it is. This is how i understand it. So if this is not the case as to what is going on correct me in a comment.  So the user clicks submit after filling out the forms.

Now on to the fileio.php page.

Source Code
-------------------------------------------------------------------------------------------------

<?php

$fp = fopen("usernames.txt", "r") or die("Could not open requested file");

$usrname = $_POST['name'];
$used = 0;
while ($str = fgets($fp)) {
    if ($usrname == $str) {
        print ("This username has already been used");
        $used = 1;
        break;
    }
}
fclose($fp);

if ($used == 0) {
    $fp = fopen("usernames.txt", "a");
    fwrite($fp, "\r\n$usrname");
    fclose($fp);
}

?>
----------------------------------------------------------------------------------------------------------
Okay so we have lots going on here in this code. I will try and touch on all bases.

$fp = fopen("usernames.txt", "r") or die("Could not open requested file");

This line of code has created a variable that points to a file. That file is usernames.txt and the "r" signifies that we have open that file for reading only. fopen stands for file open and takes two parameters a string and what you want to do to the file.

$usrname = $_POST['name'];

Remember that method="post" code from earlier. This is where that comes into play. What ever the user typed into that box is now a string held by the variable $usrname. As far as I know this is the only way to prompt the user for a variable. How neat.

 $used = 0;
while ($str = fgets($fp)) {
    if ($usrname == $str) {
        print ("This username has already been used");
        $used = 1;
        break;
    }
}

Now this big ugly control structure. The variable $used is just there to keep track of whether or not the username has been used already. where it says while( $str = fgets($fp) ). This is a loop, and the condition for that loop is keep looping while there is still a string for use to get from the file.

$str = fgets($fp)

in other words the condition above is using fgets(). fgets() is a function that reads a line from a file. So what is happening is it is reading a line from the file and storing that string into the variable $str. Now this function fgets will keep being called until it finds no more lines left in the file. In this case it will stop running and when this happens the loops stops looping.

if ($usrname == $str) {
        print ("This username has already been used");
        $used = 1;
        break;

This line of code is saying hey! if the username is equal to a string already in the file then lets alert the user, change the value of the variable used to one, and then stop the loop by using break. Simply right.
 
So after this comes an important function for files once they are open.

fclose($fp);

fclose just closes your file that is opened.  In this case our file pointer $fp which points to usernames.txt.

if ($used == 0) {
    $fp = fopen("usernames.txt", "a");
    fwrite($fp, "\r\n$usrname");
    fclose($fp);
}

This last piece of code is saying. Hey if the username was not already used. Then lets store it in the file so it can't be used again. We determine if the username has been used already from the while loop statement and by using the variable $used. Also you will notice we are pointing to the same file again. But the difference being this time. We are opening the file for appending. Denoted by "a" in the second parameter.

What is happening here is we have opened the file to add on to the file without erasing anything.

The last line of code we have not seen is

fwrite($fp, "\r\n$usrname");

fwrite() is a function that adds a string to the file. So we are adding the username to the file in this line of code. We are also creating a newline so the username is spaced out among the others.

So hopefully that was not too confusing and I will be adding onto this code as  i progress and get better.

Thursday, 14 April 2011

PHP: Declaring and Printing Variables

So i decided to go ahead and learn how to declare and display my variables in PHP. First thing i noticed is when declaring a variable you do not need to specify what type of data your variable is. Such as an integer, string, character, etc. Which i found really weird, but I got use to it. Next thing i noticed was I had a hard time using \n to create a newline in PHP. Which is a command. I just found it was a syntax error(aka parse error in PHP). But anyhow here is some code I created in order to test some things. Feel free to read the English parts of my code for non programmers. It might amuse you.

Source Code
----------------------------------------------------------------------------------------------------------------------------

<html>
   
   <body>Welcome to my PHP Test Page
    <?php /*Declaring and printing variables*/
        $var = 5;
        $name = "Hello World";
        $test = array("Hello","this","is","an","array");
    ?>

    <p>
    Testing out, printing declared variables <br />
   
    printing 5 to the screen from variable <?php print('$var ');?>  <br /><br />
   
   
    <?php print("$var");?> <br /><br /> 
   
    Well that seemed to have worked out nicely, Now wth is the code to print print a newline. <br />
    instead of having to use HTML's "br" to create a new line out of my php scope<br /><br />
   
   
    Time to print a string using echo and print command<br />
   
    <?php echo "$name"; print("   $name   "); ?> <br /><br />
   
    Time to print an array<br />
   
    <?php print_r($test); ?><br />
   
    Well that was really unexpected so much for that command being of any use.<br />
    Maybe i used it wrong oh well time to find another way to print an array.<br />
   
    <?php for($i = 0; $i<5; $i++){print("$test[$i] ");} ?><br /><br />
  
  
    Well that seemed to have worked out a lot nicer. Using a loop and accessing each index of the array was nicer then print_r.<br />
    I think I will end the tests for this blog. Thanks for reading!<br />
   

    </p>

</body>
</html>
 --------------------------------------------------------------------------------------------------------------------------
End of Source Code


 What is actually displayed here. So you can see what exactly I did. 

Welcome to my PHP Test Page
Testing out, printing declared variables
printing 5 to the screen from variable $var

5

Well that seemed to have worked out nicely, Now wth is the code to print print a newline.
instead of having to use HTML's "br" to create a new line out of my php scope

Time to print a string using echo and print command
Hello World Hello World

Time to print an array
Array ( [0] => Hello [1] => this [2] => is [3] => an [4] => array )
Well that was really unexpected so much for that command being of any use.
Maybe i used it wrong oh well time to find another way to print an array.
Hello this is an array

Well that seemed to have worked out a lot nicer. Using a loop and accessing each index of the array was nicer then print_r.
I think I will end the tests for this blog. Thanks for reading!