Thursday, November 20, 2008

My thoughts on game consoles

If you are confused between Wii, Playstation 3 or Xbox 360 here is what I have to tell you, by the end of this short article you should have a good idea of what you want

If you are a kid, a grand parent who hasn't played any video games, gay (I hate to say this but the games are pretty damn gay!), a retard who can't learn to play complex games you should go for Wii. Wii only has stupid games, graphics simply sucks, it has the best browser among all of the game consoles though. The controllers are creatively designed, if you have a kid you better buy a wii so that he can move his body when he plays and he doesn't become fat. Wii doesn't play dvds and etc unless you crack it using third party software which is stupid

If you are not any of the above, then you are stock between Xbox and PS3
It has been said by many people that Xbox has better graphics, but the difference is not really that high unless you are a gaming freak, in which case you will own both won't you?

If there are games that you are obsessed with and are only available in either one of these two consols then your choice is also clear, why are you even reading this?

If you still haven't gotten your answer, then go for PS3 because:

  1. PS3 gives you blu-ray! Get HDMI cable and you will get the best damn picture quality ever! I'm sure you don't mind being able to play 50GB blu ray disks beside your games, or do you? While PS3 plays DVDs, Divx and Xvid files, Xbox doesn't even play dvds you'll have to buy an extra kit for that, isn't that a rip off?
  2. PS3 gives you free online game playing while Xbox charges you for that
  3. PS3 gives you larger hard disk compared to Xbox for the same price

This short review was written in November 2008, things might have changed by the time you read it

How to hide php extensions

Hiding php extensions is a really good thing to do. Not only it makes your website more search engine friendly and professional looking but it makes it safer!

Why does it make it safer one might ask? My answer is because it hides your php pages and doesn't let the attackers directly communicate them and test passing different parameters as variables to your pages and test result!

Let me make it more clear, let's say you have a page that shows a pice of news, your page should look like this news.php?id=85

Now an attacker can simply change that id to anything that he wants, he can change it to a string instead of a number, he can try to do some SQL injections or other nasty things, but if you hide your page, the same page will look something like news/85 or even news/85.html

Now many attackers will just assume your page is a html file and stop trying to hack you to begin with. However if they continue, they will not be able to see any desirable results because trying a string instead of 85 will give them a 404 error!

In other words you are adding another security layer to your php files, there are good ways to stop sql injection within php but adding another security layer is always better especially if your website is under heavy attack! It's like having more rows of soldiers in a war!

You can hide your php extensions by using apache's .htaccess file capabilities, you should also know regular languages to use this feature effectively. Here is a sample I have used for one of my projects

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([0-9]+)\.aspx$ foo.php?id=$1

Here the users will see news/85.aspx in their browsers, but apache will redirect 85 to my foo.php file and then show the results from that page!

So not only I have kept my foo.php save from visitors, and not only hackers have no chance of passing anything but one numerical value to my php, I have also made hackers think I'm using asp.net instead of php, so they will be trying to use their asp.net knowledge to hack a php based application, which is a hard thing to do.

Application path in vb.net

Dot net had made a total mess in giving you the path that your application is running

There are many ways to get your current path, unfortunately some of them work for some types of programs but don't work for others. I have tried this one and this one.

I have had to write programs that work in every one of the following types of applications
  • Windows applications
  • Dll files
  • Dll files registered as COM objects
  • Windows Services
  • Web based applications
  • Web services
And I realized the following way of getting the application path works for all of them

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)

So people should use this instead of anything else.

I have noticed some people make the horrible mistake of mistaking "current directory" with what I have been referring to as "application path". They are VERY different things, current application may change if the user does something like opening his browser and going to c:\foo, the programmer may not notice this since he hasn't opened any folders when he was coding, so be careful of that too

Tuesday, April 1, 2008

Infix, Postfix and Prefix Algebraic Notations

Infix notation: Operations are written between operands.
A * (B + C)
Usually used by human beings, Infix notation is quite simple to understand, but has one drawback which is you need to use brackets to show the order in which operations should be performed and if you don't do so, you'll get different results and have multiple outcomes for each operation.

Prefix notation: Aka Polish notation, Operations are written before operands.
*A+BC
Can simply be interpreted as start from the first operation and apply it to the next two operands. In order to evaluate the given example and change it to infix notation one would consider:
  1. *A+BC: Apply * to A and +BC => A * (+BC)
  2. +BC: Apply + to B and C => (B+C)
And then follow from 2 to 1 to evaluate the expression.

Postfix notation: AKA Reverse Polish notation, Operations are written after operands.
ABC+*
Can simply be interpreted as "apply the last operation to the first and second operands". In order to evaluate the given example and change it to infix notation one would consider:
  1. ABC+*: Apply * to A & BC+ => A * BC+
  2. BC+: Apply + to B & C => B + C
And then follow from 2 to 1 to evaluate the expression.

Saturday, February 23, 2008

Relationships between clases in a UML Diagram

Introduction

I realize a lot of people have a hard time understanding UML Class diagrams because they confuse the kinds of relationships between classes. I decided to list these relationships and write a short description for each one. These relationships could exist between other objects too (e.g. an interface and a class).


Discussion
The relationship between two related classes can only be one of the followings:

Dependency- One class uses or knows about the other. changes to the definition of one class (the supplier) may cause changes to the other class (the client). Is usually thought as "...uses..." and is the weakest relationship between two classes.

Rational Rose definition:
A dependency is a relationship between two model elements in which a change to one model element will affect the other model element. Use a dependency relationship to connect model elements with the same level of meaning. Typically, on class diagrams, a dependency relationship indicates that the operations of the client invoke operations of the supplier.

In UML this is indicated by a dashed line pointing from the dependent (or client) to the independent (or supplier) element.

Examples with UML Diagrams:
World population and population of Germany










Association
-Semantic connection between two classes. An association could be unidirectional or bidirectional. Could be reflexvie (1). Can be named and could have multiplicity. (3)

Rational Rose definition:
An association provides a pathway for communication. The communication can be between use cases, actors, classes or interfaces. Associations are the most general of all relationships and consequentially the most semantically weak. If two objects are usually considered indepen
dently, the relationship is an association

The UML graphical representation of an association relationship is simple line between two objects or an unfilled arrowed lines that connects. Direction of the arrow shows the direction of traversal.

Examples with UML Diagrams:

Bank telelr - customer









Aggregation
-Strong whole-part association. Typically thought as has-part. Could be reflexive.

Rational Rose definition:
An aggregate relationship is conceptually the same as an association with the aggregate adornment set. The aggregate association adornment denotes a whole or part relationship. Aggregate adornments are purely conceptual and have no effect on code generation, nor reverse engineering. Thus, the code generated for an aggregate relationship is the same as for an association relationship.
The aggregate association may be navigable on both ends, and data members are generated for the associated classes on the navigable side(s).

In UML, it is graphically represented as a clear diamond shape on the containing class end of the tree of lines that connect contained class(es) to the containing class.

Examples with UML Diagrams:
Hand and finter







Composition
-Whole part association, Also called Composition Aggregation. The difference between Aggregation and Composition is that in composition the part could only be part of ONE whole. in other words in composition a part must be for only one whole but in aggregation the whole may have any multiplicity. Also in composition parts and wholes are contingent (2). In other words-in composition, when the owning object is destroyed (the whole), so are the contained objects (Parts), however in aggregation, this is not necessarily true.

The UML graphical representation of a composition relationship is a filled diamond shape on the containing class end of the tree of lines that connect contained class(es) to the containing class.

Examples with UML Diagrams:
Coffee table and its legs.



Another example to show the difference between composition and aggregation :A university owns various departments (e.g., chemistry), and each department has a number of professors. If the university closes, the departments will no longer exist, but the professors in those departments will continue to exist. Therefore, a University can be seen as a composition of departments, whereas departments have an aggregation of professors.








Generalization
- One class is more general than the other class. Refers to the concept of inheritance in OOP programming. Usually are not named and don't have multiplicity. Usually thought of as "..is a/an..."


Rational Rose definition:
A generalize relationship is a relationship between a more general class or use case and a more specific class or use case. A generalization is shown as a solid-line path from the more specific element to a more general element. The tip or a generalization is a large hollow triangle pointing to the more general element.


Examples with UML Diagrams:
Animals and cats and dogs















Realization- is between a class and an interface class. And shows that the class is implementing the interface.

Definition of an interface according to Rational Rose: An interface specifies the externally-visible operations of a class and/or component, and has no implementation of its own. An interface typically specifies only a limited part of the behavior of a class or component.

Example:
Let's assume we have two servers (a voice server and a video server), and we want to hire some developers to implement these two servers, we could give them an interface so that they know what methods and attributes they should implement.

In UML the graphical representation of realization is a dashed line with an empty arrow at the end that connects a class to its interface. However in rational rose when you change the stereo type of a class into an interface it will automatically draw a continues line and remove the arrows.




For a tutorial on Java interfaces visit:
http://java.sun.com/docs/books/tutorial/java/concepts/interface.html


This is a neat diagram that shows all
these relationships in a single picture.

I stole it from:
http://www.actionscript.com/Article/tabid/54/ArticleID/an-introduction-to-uml-key-concepts-applied-to-flash-development/Default.aspx

It's a good idea to print it and look at it while you are getting used to UML diagrams.














Practice

It's a good idea to search for class diagrams in Google image search, you should be able to understand all diagrams if you read this articles carefully. So, go search here:

http://images.google.ca/images?um=1&q=class+diagrams


References

I have used examples, definitions and ideas from the following books/resources in this article:

UML 2.0 in a Nutshell, By Dan Pilone, Neil Pitman, O'Reilly ,June 2005, ISBN 0-596-00795-7

Sams Teach Yourself UML in 24 Hours, Third Edition, By Joseph Schmuller, Sams Publishing, March 15, 2004, ISBN 0-672-32640-X

Mastering UML with Rational Rose 2002, Wendy Boggs Michael Boggs, Sybex, 2002, ISBN 0−7821−4017−3

Applying UML and Patterns, Second Edition, Craig Larman

UML Distilled Third Edition, Addison Wesley

Rational Rose Help

Wikipedia


Notes

1) By reflexive I mean it could have the same relationship with itself. For example in a linked list ADT we usually use at least one instance of the linked list class.

2) By contingent I mean their existence and non-existence exist on each other-one can not exist without the other. In other words existence of one implies existence of the other and non-existence of one implies non-existence of the other. For example if there are no table legs, there is no coffee table and also if there is no coffee table, there are no table legs.

3) Multiplicity denotes the number of objects of one class that can relate to one object of an associated class. For example 11 players could be associated with a soccer team.