« Archives in July, 2011
29
July

Weekly catchup – Week seven

Welcome to week seven of my weekly cachup series. Since I’ve started semester two, I thought it might be a good idea to continue doing these for those that are interested. Lets get into it, shall we?

Monday: It wasn’t much of a university day on Monday, since I have that day off this semester. I spent most of the day in bed sleeping, or working on some of my coding projects (most to do with this blog). For those that haven’t noticed yet, there is a new theme to check out. Soon enough I’ll be updating the main theme to this one, once I fix any bugs that may be hidden from me (so if you find any, please tell me).

Tuesday: My first day back for this semester. I had to get up and go in somewhat early, which kind of sucked. But it was good to catch up with everyone again. I had to go in early for a meeting with the course coordinator and lecturer for Software Engineering Group Project (SEGP). We were given a fair bit of information about what is expected of us during the course, and what we will be doing as part of the project. We will be designing a building a Lego Mindstorms mine detector, which sounds like a very interesting project. Unfortunately, the requirements we’ve been given so far are very vague, so we will need to ask many questions of what’s expected during our weekly meetings with the lecturer. Other than the meeting, I had a 2 hour lecture later in the day. This lecture was for Event Driven Computing (EDC), which seems like a very interesting course already. Part of that is to do with the lecturer being a very funny guy, but it also seems fairly simple to follow along with.

Wednesday: This would have been another early day for me, but because the first three lectures of the day are all for SEGP (combined with Software Engineering and Project), I decided not to bother. This is because I, along with the other software engineers, have already had the lectures for the course, and don’t have any exam this semester. I did go in later in the day for the other lecture, Distributed Systems (DS). This also seems like a very interesting course, since we’re dealing with calling methods on remote servers while making it look like we’re doing local method calls. Plus, this lecturer is also fairly funny, but doesn’t go over the top like the lecturer in EDC. Wednesday night I had my slotcar racing, which was a fairly good night. There were fewer of us there, though. Out of 8, I finished 6th after the first set of heats and 2nd after the seconds set.

Thursday: Once again, an early day. At least this one was for an actual lecture, this one being Operating Systems (OS). The course seems fairly relevant to my degree, but I’m not particularly a fan of the lecturer or his methods. The whole two hours he seemed to mainly just talk to the first 2 or 3 rows of people (which included myself). It was very off-putting. I think next week I’ll try to sit further back in the lecture theatre. After this lecture I had a meeting with my SEGP group, to start nutting out the requirements, work out what needs to be done and what questions we need to ask the lecturer. This is when we worked out the requirements are very vague. After the meeting I spent the next couple of hours chatting with people and working on my first EDC assignment. I believe I’ve almost completed this, but just need to wait for the lecturer to give us direction on the fuzzy edges of the requirements.

Friday: Today is another lazy day, since I don’t have anything on. In following weeks I will have either a tutorial or a group practical session. I have so far done more of my first EDC assignment, which I hope is almost complete, and written up this blog post for you all. What does the rest of the day hold? Probably just some games or more coding.

Well, that’s it for this week. Thank you for reading.
Robert

24
July

How to: Javascript Globals and Quirks

Welcome to another of my Javascript tutorials. I realised I’ve missed out on a fairly crucial part of the language – the global variables and methods (which are available at all times), and some of the quirks. Lets begin with the quirks.

First quirk is, unlike most C-style languages, you do not need to include a semicolon after each instruction if they are on seperate lines. This means that:

var one = 'test';
var two = 0;
two++;

and:

var one = 'test'
var two = 0
two++

will both run, not throw any exceptions, and result in the variables one and two having the same values.

The second quirk, that follows a little from C and C++, is that any variable can be used as a boolean. For example:

var test = 0;
if(!test){
   // do something
}

will result in the statements within the if block being executed.

These are really the only quirks that are of use in Javascript, so now to move onto the major part of this post – the globals.

The first major global variable is the ‘Window’ object, which contains references to all other global variables and methods, as well as many other useful (and maybe not so useful) variables and methods. It also has a reference to itself.

The second major variable, which you may find you’d use the most for programming in Javascript, is the ‘Document’ object. This object contains methods and variables that help with most things to do with accessing and modifying the DOM.

Another major global is the ‘Location’ object, which allows you to access and change things to do with the current URL. For example, you can redirect users to a new page, or include hash parameters.

The other three global objects are the ‘Navigator’, ‘Screen’, and ‘History’ variables, which provide access to information about the user’s browser, screen and recent history respectfully.

There are four other global variables – Infinity, NaN, undefined, and null. Each one is exactly what you’d think it is, in that Infinity represents any number greater than the largest positive float value, NaN represents a non-legal number, undefined represents an non-defined variable, and null representing a defined variable with no value.

One of the global functions accessible is ‘eval’, which evaluates a string as Javascript code and returns the result. Many Javascript coders try to avoid it’s use, though, as it can do more harm than good if provided malicious code.

Two more functions to help with numbers are ‘parseInt’ and ‘parseFloat’, which parses numbers from a string for you.

Before I start just going on about every method available, I think I’ll just point you all to the w3schools website, which has a complete reference on all standard objects/classes, methods and variables. Next post I will be going into how to create your own classes and objects. Until then, keep coding.
Robert

21
July

Reaper Quicky #6

Hello all,

Has anyone else ever felt better after doing something you felt you should have done earlier than you did? Cause I feel a hell of a lot better right now, after posting a box of stuff that I should have sent a while ago. I won’t go into detail about what’s in the box, but just say that it may change things for the person receiving it.

As a side note, I believe I did a hell of a lot better on my supplimentary exam for Computer Architecture. So I should now get a passing grade for the course.

15
July

Inside the head of a Reaper

Hello, everyone.

I was just sitting and thinking, like I usually do, and I got to wondering what I’m doing with myself. I’ve been fairly down on the inside lately, even though I may not show it on the outside. I’m usually happy because I put others before myself, and try to make them happy before myself. This may not seem like a good thing to some people, but I honestly enjoy it. It makes me happy to know others are happier because of something I’ve done. But lately, because of the many changes going on around me, I’m finding it hard to get the satisfaction of others being happy from something I’ve done to make them be happy. It hasn’t stopped me from acting happy, joking around with friends, laughing, and having a good time. But on the inside, I feel as if I’m slowly dying.

Just to put it out there, I enjoy my life. People may not think I have much of one, because I don’t get out that often and instead spend most of my time on coding, playing computer/console games, or sleeping. And to those people, I say “grow up”. I’ve chosen to live a life that I enjoy, and that I feel suits me more than one where I’d go out all the time. And, to be honest, I don’t get how people can live like that. What do you gain from spending as much time as you can going out? Don’t get me wrong. Spending time with friends or family isn’t a bad thing. But I feel there’s a point where it’s just too much.

You, the reader, may think differently about what I’m saying. And that’s fine with me. You’re entitled to your opinions, just like I’m entitled to mine. But I feel I have a valid point in saying that, in the end, it doesn’t matter how you spend your life, the results are always the same. You’re born, you live a life, and you die. What happens in that life is completely up to you, with the situations that you choose to place yourself into. The only side effect of your choices in life is how you’re remembered by those that are left behind, and what lessons you’ve taught them. That’s why I’ve chosen a life of never drinking alcohol, because I’d like to be remembered as someone that always had the clear head to make ‘better’ decisions throughout my life (depending on the viewpoint). And as someone that took the road less travelled to end up making a difference.

If today was your last day and tomorrow was too late, could you say goodbye to yesterday? (‘If today was your last day’, Nickelback, 2008).
Robert

11
July

Reaper Quicky #5

Hey, everyone.

Tonight I found out my final course marks for university. Turns out I’m going to have to spend the next week re-studying for a supplimentary exam, which sucks. The course I need to study for is Computer Architecture, which I’m not too fond of as a course. I barely failed it, with a 49F. My other courses I passed, with two being Passes and the other a Credit. I’m happy enough with them.

Wish me luck, guys and girls.

09
July

Reaper Quicky #4

Hello, all.

Today I went out with a few friends for some laser skirmish. It was just awesome! Got a really good workout while having fun with some great people. Unfortunately, there were kids parties on at the same time. But that didn’t break the fun, as it gave us more targets to shoot at. Overall, it was nice seeing everyone again, and spend time kicking their arses with laser guns.

I’m thinking I might organise another get-together for more laser skirmish with more people sometime soon, which should be fun. I don’t know how far this idea will go, though. I’ll find out as the weeks go by.

Robert

05
July

How to: Javascript and the HTML DOM

Welcome to part two in my series of javascript tutorials. As the title suggests, it is about the HTML DOM (HyperText Markup Language Document Object Model).

A major benefit of javascript is the ability to manipulate parts of a webpage, to make it seem more dynamic. To do this, there obviously needs to be a way for the language to access HTML elements. And it seems we’re in luck, because there are many ways to do this. We can create new elements (one at a time), select existing elements (one or more at a time), and also delete elements (a full tree at a time).

Creating elements is done with the method document.createElement, like so:

var elem = document.createElement("div");

The passed parameter to the createElement function is the name of the tag that you are wanting to create, which can be just about anything (even tags not defined by HTML or XHTML). The returned value is a HTML DOM object, in this case a HTMLDivElement. Notice, though, that the element is not actually placed into the document after this call. The function only creates a javascript object. To actually place it into the document, you need to tell the browser where to put it in the DOM:

document.body.appendChild(elem);

This function will add the div element created above to the body tag of the document, or whatever other element it gets called on. The div element then gets rendered by the browser, but only after the javascript engine has finished executing the current call stack. You can also append many elements into another element, then append that parent element into the document, and all the child elements will get rendered at the same time.

There is more than one way to select an element within the HTML DOM. Some of the simpler techniques are:

var elem1 = document.getElementById("element_id");
var elem2 = document.body;
var elem3 = document.body.childNodes;
var elem4 = document.getElementsByTagName("div");

After these four calls, elem1 will contain a reference to the DOM object for the element with id=”element_id” (as all elements within a HTML document require their ids, if defined, to be unique), elem2 will contain a reference to the body element within the HTML document, elem3 will contain a reference to the array of children elements of the body element, and elem4 will contain an array of all elements on the page that are divisions (divs).

Deleting an element from a document is just as simple as creating and placing an element within a document. It’s made up of two steps, selecting the element you want to remove and removing that element from it’s parent:

var elem = document.getElementById("anElement");
elem.parentNode.removeChild(elem);
elem = null;

The final line of the above code is not required, but decreases a memory leak problem within some versions of Internet Explorer (I’ve never encountered this problem myself, though). After the code has completed, elem and all it’s children will be removed from the document.

“Creating, selecting and deleting elements is good and all, but how do I add text to my document?” I hear you ask. Well, there’s a few different ways. You can go about creating a text node and appending that to an element:

var text = document.createTextNode("some text that you want inside the node");
document.getElementById("paragraph").appendChild(text);

I feel this way is overkill, though. You can always just use elem.innerText or elem.innerHTML, like so:

var elem = document.getElementById("paragraph");
elem.innerText += "some text";
elem.innerHTML += "<br />some more text on a second line";

Obviously, innerText sanitises what you put into it, transforming HTML entities (eg. ‘<‘ becomes ‘&lt;’ and ‘>’ becomes ‘&gt;’). innerHTML, on the other hand, lets you create even more elements without going through the process of creating the physical DOM element yourself.

Some of the fields on elements you’ll want to know for creating dynamic pages are elem.className, which is a string of all the classes of an element (defined with the class attribute), and elem.id, which is the id of the element (again, defined with the id attribute). You can both get and set these fields. There are many more fields on most objects that may be of interest, but talking about them all here would make this post much longer than it needs to be. For those interested, you can check out the HTML DOM in most browsers using the integrated developer tools (or the Firebug addon for Firefox).

In the next tutorial I will be showing you how to create your own classes, so that you can design and construct an object orientated script. Until then, happy coding.
Robert

03
July

Weekly catchup – Week six (exam special)

Hello all,

Well, exams are over, so it’s time for my exam special of Weekly catchup. I’ll just get straight into it.

Friday 24th June – My first exam, which was Programming Techniques. Leading up to the exam, I did a fair bit of cramming and believe that payed off. It wasn’t as hard as I expected, either. I’m confident I should pass the exam, and the course (obviously, since I passed all the assignments). After the exam I just caught a bus into the city then another home.

Tuesday 28th June – Exam two, Computer Networks and Applications. The few days I had to study for it, I believed I crammed enough to get through everything fairly well. It turned out a fair bit harder than I expected, though. But I got through most of the exam, and feel I should at least pass it. If so, I should do fairly well overall. After the exam I took the tram into the city with a couple of friends, had some McDonalds for lunch with them (taking it over to Adelaide University), and just chatted with them for a while before going home.

Friday 1st July – Exam three was Computer Architecture. With only two days studying for it, I think I did alright. I’ll be surprised if I do very well, though. It was a lot harder than I expected, but I believe I got enough done to get the marks I need. If i did, my final result really depends on how I did with assignment 2. I will pass the course, but by how much I don’t know. After the exam my dad picked me up out the back of the showgrounds (the location for exams) and took me home. That night my family’s dog had trouble breathing. We took him to the only emergency vet open at that time of night, which was a 40 minute drive away. To find out what happened, check this post.

Saturday 2nd July – My final exam, Software Engineering Group Project. This was the best exam I’ve had this semester, even though I never even studied for it. I am very, very confident I will pass, and will most likely get at least a Destinction. Everyone else I talked to after the exam felt the same way, which may be a little worrying. But as long as I pass, I’m happy. After the exam I went into the city on the tram with a friend again. This time we got KFC for lunch, and chatted in the Software Engineering lab at university about Minecraft (mostly). Around 2 we went over to Rundle Mall to catch up with another friend, since we had organised to see Transformers at 3:30. It was just AMAZING!!! I won’t spoil it for those still wanting to see it. After the movie my dad picked me up again, and took me home.

Overall, exam season hasn’t been too bad this semester. There’s been ups and downs, but now the holidays are here and I’m happy. I don’t have too much planned, but I think I’m going to enjoy it anyway.

Thanks for reading.
Robert

01
July

Reaper Quicky #3 – Dedicated to Jasper

Hello everyone,

Tonight my dog, Jasper, was having problems breathing. My father and I took him to the only vet close enough to us that was still open to get him checked out. After being put on oxygen he started to pick up a bit, but we were told there was probably nothing we could do to permanently fix the problem (as to do anything may not help at all). So we had to make the decision to put him down. He was always full of life, even as he grew older. But it seems his age has finally caught up with him.

Rest In Peace, Jasper. You will be remembered.