« Archives in June, 2011
26
June

How to: Javascript Introduction

Hello, all.

By request, I’ve got planned out a small series on Javascript (or, as it’s called now, ECMAscript). As a bit of background, Javascript is a web scripting language used primarily as client-side code. As such, it’s interpreted by the browser instead of being compiled, which makes it easier to build and test a script. Modern browsers are starting to compile Javascript as it’s being run on the page, though, which allows the code to run a fair bit faster (as it’s native code, instead of having to be interpreted).

Javascript allows you to do a lot of dynamic things to a webpage, which I will be demonstrating in later how-to’s. For now, I thought I better start with the basics. Javascript is a C-style language, with Objects making up a majority of what you use. You don’t need to create your own classes like you do in Java, though. In fact, creating classes is nowhere near as simple as in other Object Orientated languages. I will leave that lesson for another tutorial, though.

There are a number of predefined classes in javascript, which include:

  • Object;
  • Function;
  • String;
  • Number;
  • Boolean;
  • Array;
  • Date; and
  • RegExp (regular expression).

Object is obviously the root of all objects within the language. Every other class extends from Object.

Function is the type given to all variables defined as a function (which I will demonstrate later on). It allows you to create callable functions, as well as class prototypes.

String is obviously for strings of characters within the language. You can define a string using double (“) or single (‘) quotes for string literals.

Number encaspulates both integer and double precision types available in most other languages. These can be defined as normal number literals (using decimal or hexadecimal values).

Boolean destinguishes truth values, just like in most languages. You define it with the literals true or false. You can also use other objects as booleans, which I will cover in a later tutorial.

Array is self-explainitory. Arrays can contain mixed datasets, as well as grow and shrink as you use it.

Date is a complex class. It contains information about the current date and time of the system the code is running on.

RegExp is the regular expression class. Most of the time you won’t need to use this class, unless you are creating code in which it’s necessary.

There’s also another object called Math, which contains mathematical operations. Math acts like a static class in Java (in which all methods in the class are static).

Now I guess you’re wondering, how do you define these objects within actual code? It’s actually quite simple, using the var keyword:

var obj1 = new Object();
var obj2 = {};
 
var func1 = new Function();
var func2 = function(){};
function func3(){}
 
var str1 = new String();
var str2 = "test";
var str3 = 'test';
 
var num1 = new Number();
var num2 = 123;
 
var bool1 = new Boolean();
var bool2 = true || false;
 
var arr1 = new Array();
var arr2 = [];
 
var date1 = new Date();
var date2 = new Date(milliseconds);
var date3 = new Date(timeString);
var date4 = new Date(year, month, day, hours, minutes, seconds, milliseconds);
 
var re1 = new RegExp(pattern, modifiers);
var re2 = /pattern/modifiers

You can also define variables as global by simply not using the var keyword. The third version of defining a function above is simplest way, and is what you’d usually use when creating a simple script. This is the way I will be using for the next tutorial, to give you an idea of how functions work. Also, you may notice the two ways of creating Objects and Arrays. The second way for both of them is called JSON (JavaScript Object Notation). I will cover JSON in a later tutorial.

Javascript also contains the usual C-style if/else if/else and switch statements, as well as while and for loops. There is also a for each loop, which iterates over public variables within an Object. Plus, exceptions are possible within Javascript using throw in try/catch blocks.

I think that’s about it for the introduction to Javascript. Stay tuned for more tutorials coming soon.
Robert

25
June

What now? and General Catchup

Hey, everyone.

After 17 posts, I seem to be at a loss as to what to write about. You could say I have writers block. I admit, I didn’t think I’d be posting too often (as I stated within my first post), but it’s kind of been eating at me to write something interesting for you all. After a fair bit of thinking about it, all I can come up with is asking you all to give me topics to talk about. This doesn’t seem like the best solution in my mind, though. So I won’t expect any of you to do so, but feel free to give suggestions in the comments below, if you wish.

As a general catchup (aside from my Weekly Catchup series), not a lot has been happening for myself as of late. The majority of my time I’ve been spending either playing games or studying. So far I’ve completed my first exam, which was for Programming Techniques. I don’t think I did the best, but I should at least pass. It wasn’t what I expected. The games I’ve been playing are Minecraft, Call of Duty: Modern Warfare 2, and Call of Duty: Black Ops. I’ve finished both Call of Duty games at least twice each since the start of the holidays. Shows how bored I am, doesn’t it?

Last Monday I went into university to catch up with a couple of friends to study. The major part of our time we spent talking about Programming Techniques, but we also spent a couple of minutes on Computer Networks and Applications. It was good to catch up with the guys, and I feel it was helpful for me to go over topics of the courses with them. It helped clarify what we needed to know. Unfortunately for PT, we didn’t go over one thing that we really needed to know for one question on the exam. But I’m not too fussed, as long as I pass.

As some of you may know, I’ve got three exams left. Two of them are in the morning again, which is a real pain. I hate having to get up early to go to an exam. It’s painful to have to think at that time of morning. We’ll see how I go, though.

That’s about it for now.
Robert

20
June

Reaper Quicky #2

Hey all. Here’s another quicky for you.

Who else hates it when they accidentally misspell words when they’re chatting to friends (online or through other means), and turn the word into something dirty? I’ve heard it can happen a fair bit. For example, I was chatting with a friend on msn a few days ago, and they accidentally said “tight” instead of “right”. It was actually quite funny at the time. The same friend also told me about a conversation they had with someone else, where they said “dick” instead of “disk”. Does anyone else do this? If so, post in the comments what you’ve said and what you were meaning to say.

Robert

19
June

Reaper Quicky #1

Hey all. Just thought I’d do a quick post for you all.

How do I still have any sanity? A lot has been happening for me lately, as many of you would know. I’m just really surprised I still have any sort of sanity left from it all. I think I have a few friends to thank for it, though. So thanks guys and girls (you know who you are). I think I’m making more and more mistakes, though. I’m starting to regret more and more that I’m doing. But I think it’s probably good for me. I guess I’ll find out sooner or later, if I manage to somehow lose all my sanity.

That’s all for now.
Robert

16
June

Random Rant

Hey all.

What is with people making something out of nothing, or making out something’s bigger than it really is? It’s amazing how many people do it (and I admit, I can be guilty of it too – eg. with this post). But seriously, there’s some things that should just be left alone, or at least being seen for what it really is. For example, games. It’s just a game, there’s no need to get so worked up over it. I admit, there’s nothing wrong with a little friendly rivalry, but there is such a thing as going too far (eg. rage quitting). But nobody seems to get that it’s just for fun, anymore. It’s entertainment, not life.

Another example is sporting. People seem to get so worked up when two rival teams are against each other, when the two teams probably don’t really give a crap. Yeah, ok. Be happy when your team wins, but don’t start saying the other team cheats when you lose. So what that they lost? Just shows they’ve gotten over-confident in themselves, and need to work harder to get that win. An example of this is the Port Adelaide Football Club. Back a few years ago they won the AFL grand final, which would have been a real confidence boost for them (as they’d never won before). The next year they were able to make it to the grand final again, but were slaughtered by around 100 points (from memory). It happened because they got cocky and over-confident in themselves. Also, sports teams put a lot of trust into the opposing team just by playing. The players could, accidentally or otherwise, incapacitate a player in a fairly nasty tackle (for contact sports). But they trust each other not to, just for the fun of the game.

This seems to happen for board games too. People get so worked up cause they’re behind other players, or that they weren’t able to get a certain thing inside the game. As I said before, friendly rivalry is fine, but having a go at the other players then storming off when you don’t get your way isn’t. A good example of this is Monopoly. You can complain all you like about not having enough money to buy everything on the board, but that doesn’t matter. You can just buy as many properties as you can, then wait until you get more money after passing “GO!” or when someone lands on one of your properties to buy more. As the saying goes, you have to spend money to make money.

I think that’s about enough for my rant. Feel free to give your own points of view in the comments below.
Robert

p.s. For those following along, 24 hours until stage three.

10
June

A Random Look Back on Life

Hello everyone.

I was sitting in my chair, just relaxing and having a look around my room at all my stuff and I started thinking about how far I’ve come. It feels like just a couple of year ago that I started high school, when, in fact, that was over 7 years ago now. I’ve come a long way since then. I used to be this fairly happy, simple-minded kid back in high school. I was probably one of the few people that actually kind of enjoyed going in nearly every day to learn something new. Since then I’ve sort of made other things a priority in my life, and slowly lost them (either by choice, or by them being taken away). An example being a passion I used to have for ten-pin bowling. At the end of year 11 I made the choice to give it up for at least a year to focus on my year 12 studies. At the time, I believed it was the right choice for me, and I’m still standing by it now.

At the start of year 11, I was slowly becoming a bit more confident in myself. In all honesty, I don’t know why I was, but I was. I think I may have gotten a bit too confident in myself, in fact. Until one day when I was basically told to back off by (who I’d consider now) a friend. Admittedly, I wasn’t close to this person, but what they said made me take a step back and look at myself over the rest of the year. And it made me realise, I wasn’t being myself. So I changed, which some people may not believe is the best thing to do, but it can actually be a little helpful in showing you who you really are.

Midway through year 12, I met an amazing, smart, funny, and just awesome girl through an application on Facebook. Yeah, ok. Not the best way to meet people, but that’s what happened. Since meeting her, I’ve very slowly regained the confidence that I used to have back in year 11. Unfortunately, I think I got back to the stage of being over confident again, and subsequently (as some of you may have read in my “Untitled” posts) lost her. That was over two months ago now (as of the publishing of this post). I’m slowly realising that it may be for the best, at this stage of both our lives.

In my first year of university, I was basically alone. No one I knew went into the same university/degree as myself, which honestly made me feel a little lonely. Fortunately I made a friend in one of my courses fairly quickly, and we became fairly close. It actually surprises me how quickly we did become friends. But I’m glad we did, and I’m honoured to call them a mate. I did make more friends in semester two, but I don’t feel I’m as close to them as yet. They’re still great people, though. Since starting uni, I’ve actually slowly sort of lost interest. I still enjoy what I’m doing, but I’m just finding that I don’t care so much about the courses anymore. In all honesty, the only reason I still go in most days is to catch up with friends that I’ve made.

Who else would say 17 years is a long time? That’s how long the friendship between my best mate and myself has lasted. Since high school finished we haven’t been catching up or talking as much as we used to, but we’re still very good mates. We decided to catch up a couple of weeks ago, and we got along as if there’d never been a break. It was really nice to know we could still interest each other, and laugh over the same sort of things that we used to, but also new things that have come into our lives.

I’ve grown up a lot in the past few very short years. To be honest, I’m actually finding it a little scary to have as much responsibility as I do. But in saying that, I’m excited to be the person I’m growing into. And I’m glad to have my friends supporting me through the ups and downs of my life.

Thank you for taking the time to read this post.
Robert

03
June

Weekly catchup – Week five

Hello everyone.

As many of you would know, I didn’t start this week fairly well. To be honest, I’m still not coping with what’s going on, but I’m starting to push through. I would just like to say thanks to those that have shown their support, and made sure I’m ok. It means a lot, and shows me that there are people out there that do care. So thank you.

Anyway, time to move onto my week, I believe.

Monday: Yet another early morning. When I got into university I just went over to the SE lab to spend a bit of time checking if there were updates on the group project, and chat with a mate (when they turned up). Then we both went over to our first lecture, CNA. My goodness, that was boring. I’m really glad it was the last content lecture for the semester, cause I don’t know if I’d be able to handle any more lectures like that. It was on internet security, which isn’t the most interesting thing ever. Next up was SEGP, which was also on security. It was slightly more interesting, though. Still nearly fell asleep, though. The rest of the day I just spent at home, working on my CA assignment 2, which is to extend the MIPS instruction simulator we built for assignment one with cache. I’m not going too badly, I think.

Tuesday: I didn’t get up until late, cause I was still down in the dumps. When I did decide to get up, I just went into university for the group meeting and lecture. At the meeting, we got more coding done and started testing out our mock elevator system. It works really well, from what I can tell. It was very exciting to see the elevators moving between floors, stopping and opening/closing the doors. Now we’re just waiting for our GUI guru to finish up his code so we can see the actual simulator fully working. Next a couple of us went to the CA lecture, which was just as boring as CNA. I’m pretty sure I zoned out more than once. The lecture was on the end of storage followed by multicore processors. I thought about leaving early, but ended up staying for the whole thing.

Wednesday: I actually didn’t have any university Wednesday, but I did go in to meet up with a friend. It was really good to see them, and I had a fairly good time walking up and down Rundle Mall. We even stopped to watch one of the buskers doing his act. He was a real showman, doing all his tricks. But it was good. Most of our time was spent in JBs, because my friend wanted to have a look at some stuff in there then had a long talk with one of the staff (about what they were looking at). I also had my slotcar racing Wednesday night, which was kinda fun. Took my mind off some things. Overall I came 6th after the first set of races, and 4th after the second, out of 12 racers.

Thursday: I had to get up Thursday, because of my group meeting. Unfortunately, the lecturer didn’t even turn up! That was really annoying. But it wasn’t like there was anything that we needed to talk about, so it wasn’t too bad. As it got closer to midday, some of the guys decided to just leave, as we didn’t have any lecture later in the day. I just went over to Rundle Mall to catch up with an old mate. It was good to see him. We mainly just chatted about what’s been going on for both of us (relationship-wise, and other things). While we were chatting we did a huge loop of the city, walking all the way down Hindley Street, over to the opposite side of the Torrens River then around to Adelaide Uni. Along the path next to the Torrens, a small bird decided to have a go at my eye. Fortunately the bloody bird didn’t actually get it, but it did leave a mark just under my right eye. After showing my mate where I spend most of my time, we went back to Rundle Mall then made our way over to where he works as a volunteer. It was a good walk.

Friday: Ah, my day off. I didn’t wake up until really late this morning. Just couldn’t bring myself to move from my bed, until 11:30. Thought it may be a good idea to get up sometime. Apart from that, I haven’t done too much.

Well, that’s my week done. As a side note, this may be the last of this series for a couple of weeks, since university is coming to an end for this semester. So, unless I actually get up to much between now and the start of semester two, don’t expect many posts (if any). Thank you reading.
Robert