Tuesday, 25 February 2014

myChecklist: A simple application for chrome II

Now in this part I am going to talk about in a very high level manner how myChecklist (The application I mentioned in my previous post) is made using JavaScript and JQuery. Here are the basic ideas behind each functionality:

Adding new items to table: There is a basic JavaScript code snipped that adds columns to tables. You can Google it for more information but the basic syntax is something like this:

                var table = document.getElementById("myTable");
                var row = table.insertRow(-1);
  var cell0 = row.insertCell(0);
  cell0.innerHTML = task;

User interface: As you can see there are special dialog boxes, as well as a datepicker that I used in the application. They are all part of JQuery UI library that you can download form here and use.

Storing information in a database: I used localStorage functionality of JavaScript to store user information on hard-drive. localStorage is similar to cookies, but unlike cookies they are not get expired, nor can they be deleted by simply clearing cache, history, or cookies. They are basically stored in a JSON (JavaScript Object Notation which is a format to store JavaScript objects. It is similar to XML) formatted file somewhere on user`s computer and remain there forever unless damaged or deleted by the user.

Changing wallpaper: I used JavaScript id selector to change the background image to the image located in the URL you enter. This may not be a very good idea because some users are not even familiar with URIs/URLs. I may change it in later versions.

Click events: There are several click events. For example when you click on 'add' button a dialog window pops up. These events where made using JQuery powerful functions such as 'on'. Something like this:
$("#buttonId").on('click',  function(){
  //Add code here

JQuery is very powerful when making client-sided web applications. Even using AJAX is much simpler using JQuery. It has many amazing features. You may want to have a look at them here in their documentation.

Saturday, 22 February 2014

myChecklist: A simple application for chrome I

I developed this simple application during the break I had after the last academic term.  Last term I felt I was being unorganized in studying for my exams and doing my homework, so I decided to make a simple application that helps me manage my time.Here I am going to talk about features that it has. In the next topic I will talk about how it functions.

This is an application that can be used to enter tasks that you are going to do in the future. It has several features that make it easy to store your information:

- It has a date picking feature that enables you to enter date just by a single click on calendar without the need to actually enter date in text
- You can modify or delete your previous entries one by one, or by checking a group of them or deleting them all at once
- There is a cross/check mark next to each item that you can toggle to indicate whether or not the task is done (This functionally apparently has some bugs, I will work on it during my next term break)
- You can clear all the entries at once
- You can customize the wallpaper of the application
- The tasks you enter are automatically sorted based on the due date of each task
- since the information is stored on your own computer, it is safe and secure and no one else has access to them on the internet
- Finally, it works offline so you do not need to have internet connection to use this application

In below, you can see a screenshot of my own tasks that are stored in the application (I use it myself as well!)

Again, if you have Chrome, you can downlad this application from here
Source: screenshot of my computer :)

Saturday, 15 February 2014

A simple chatroom

Here, as I previously mentioned, I am going to talk about a simple chatroom that I made using MySQL, PHP, and JavaScript.
Note that here I am not actually going to talk about 'how' to make a chatroom, nor will I present any code. I am just going to talk about it in a very high level manner. I try to explain things as much as I can, but if there are things that are not very understandable, I am pretty sure that you can find out about them just by a few searches in the internet. I am also quite sure that if you do enough research, based my explanations you can make your own chatroom! So let' begin:

First of all,  once you enter the website there is a JavaScript 'alert' message that asks for your name. Once you enter your name, it is stored in a cookie (cookie is just a file stored on your computer that holds some information) on your own computer.

Second, each time you send a message, your message is stored in a mySQL remote database. So are the messages sent by the person you are chatting with. Now the issue is: How can you get to see the messages sent by you friend? Here was my solution: Do you remember in the last topics I talked about AJAX requests? (Just to remind you, AJAX is a method of communication with the server without the need to refresh the whole page).

There is a client-sided JavaScript code that sends a request to a PHP script on the server every 3 seconds and using AJAX method (Therefore the webpage will not be refreshed each time). Now, the request that is sent to the PHP script includes some information such as the name of the person who has sent that AJAX request (The name of the person is read from the cookie). The the PHP sends back all messages store in the database EXCEPT the ones that were by the sender of that request. This way you can get too see your friends messages as well.

Note that these were just very brief descriptions of the procedure ... If I want to explain everything about this it will probably take me at least 5-6 blog posts. But since I know it is going to be boring for some of you, I will not be doing it here :)

In the next topic I am going to talk about another application that I made with JavaScript. Namely myChecklist that you can use to schedule your future plans. This is an application that runs offline (no internet connection needed for it). And finally, if you are using Google Chrome, you can install it before I get to talk about it in my next post.

Image Source: <Chrome Web Store - myChecklist . Available in: https://lh3.googleusercontent.com/g0G64-L84uNn8mDfpqA2aJcH5_HtAxWT_pQ69QV2UFtELGVRI09fsg0N6cDP3Zr2qHKp0K20Mw=s640-h400-e365-rw>

Saturday, 8 February 2014

A simple Chatroom powered with php and MySQL: AJAX

A I mentioned in the previous post, in this post I am going to talk about a simple chatroom I made using php and MySQL. But before talking about how that works, I need to talk a little about AJAX (Asynchronous Javascript and Xml). The basic idea behind AJAX is reloading part of a webpage without the need to reload the whole script. Let me give you an example: A good example would be several actions that you do in Facebook. Everytime you post a comment under someone's post, you see that your comments get added to the list, and that person receives a notification (if s/he is online). Both of these functionalities (commenting, and receiving a notification) are powered by AJAX technology. As you can see the whole webpage is static while you can see that notification or comment in part of the webpage (without the need for the whole page to be reloaded).

- But how does that happen?
Now even more interesting is the way this actually happens. Every couple of seconds, your computer sends a request (known as XmlHttp request) to the server  and asks the server whether there are more notifications or messages to show, and the server responds in the same way! Isn't this amazing? It is just like humans talking to each other!

But there is one more question left to ask: Can everyone send XmlHttp requests to remote server (like the one for Facebook) and get access to user's password and usernames? Or read their messages?

In the next topics I will talk about security in AJAX requests and finally the simple chatroom I made with this technology.

Monday, 3 February 2014

A little bit about security

Now we get to security. As previously mentioned, webpages made only in HTML are not secure enough and the reason for that is that the user has access to the whole source HTML and JavaScript codes of the webpage. To resolve this issue, server-sided languages are made. In general, the way server-sided scripting works is that there is a script (piece of code that usually can be run without the need to be compiled. Like JavaScript, PHP, or Python) that is run on the server. Once the script is run, it sends the HTML+Text output back to your own browser. Of course, you can see the HTML source code sent to your browser, but you do not have access to the main script that created this HTML code (the reason that you don't have access to it is because it is run on the server side). The idea behind server-sided scripting is very interesting, and in fact once you start writing server-sided code, you have to put yourself in the shoes of the server to realize what is actually happening there. In the next topic I am going to talk about a simple chatroom that I created using PHP (my favorite server-sided language).
Image Source: <http://gkaanalkim.files.wordpress.com/2012/04/php-dili.jpeg>

Sunday, 2 February 2014

What is happening there every time you visit a webpage?

As we previously discussed, all webpages opened in your browser are in HTML codes which can be viewed by everyone who has access to those webpages. But the question is that how can they be secure enough? Before I answer this question I should I first show you briefly what is actually happening every time you visit a webpage, consider the following scenario:

- You enter a link in your browsers URL field. Once you do this, your browser sends a request (known as HTTP request) to a server in some part of the world that holds the data of that website. Basically all this means is that your browser asks the server to send it a file (could be and HTML file, image file, or any other file format)
- The server looks through a database of files to find the file you requested. The server returns back a status code along with the file (if found) to your browser. Now, several situations may happen based on the status code the server returns back to your browser. A few of them are the following:

 404: File was not found on the domain. 
    for example: you entered: www.sfu.ca/images, but in the domain sfu.ca there is no such directory
403: Permission Denied
   File exists on the domain, but the permissions deny your access to the file (for example when the files can be accessed only locally and not through the web)
200: ok
   This means that the file was found. In this case the server sends back the requested file to your browser.

In later posts I will talk about security and different server-sided languages