Abosolute vs. Relative Path

March 12, 2010 2 comments

When we create a web-page at which there are some links (URLs) to images or other pages, links are written either in an absolute or relative way (commonly known as absolute and relative paths).

Suppose that we’ve a website whose domain name is http://www.shoubraeng.com and there’s a web-page that’s in the directory http://www.shoubraeng.com/pages/project/index.html.

Let’s also assume that there’s a subdirectory of the project directory called images.

Here’s a description of the hierarchy (directories are written in bold):

|___ pages

____|____ picture1.jpg

____|____ project

_________|_____ picture2.jpg

_________|_____ index.html

_________|_____ images

_______________|_____ picture3.jpg

The index.html page is the web-page of interest. We’re trying to make a background picture to it from the available 3 pictures. picture1.jpg is in the pages directory, picture2.jpg is in the project directory and picture3.jpg is in the images directory.

Now let’s see the different ways to link to any of these pictures.

Absolute Path

The easy way is to use the absolute/full path of the image that looks like:

<body background=”http://www.shoubraeng.com/pages/picture1.jpg“> or

<body background=”http://http://www.shoubraeng.com/pages/project/images/picture3.jpg“>

You might have guessed that it’s called absolute/full because it contains the very specific path to the image.

One more note about absolute paths is that if the file is on the same domain of your web-page then you may not write the domain name but just start with a slash (/) like:

<body background=”/pages/picture1.jpg“>

Relative Path

It’s called relative because it’s described relative to the path of your web-page regardless of its position.

1- If you are linking to picture2.jpg that’s in the same directory of your index.html web-page then – using relative path – you may just write its name as follows:

<body background=”picture2.jpg“>

Writing only the name of the image in the path tells the browser that it’s in the same directory of the web-page that is being loaded now.

2- If you are linking to picture3.jpg that’s in a subdirectory of your index.html webp-page, it will then look like:

<body background=”images/picture3.jpg“>

It should also be noticeable that starting with a directory name (with no / at the beginning) tells the browser to find the image in the subdirectory located in the directory of the web-page that’s being loaded now.

3- If you are linking to picture1.jpg that’s up on directory from the web-page it will then look like:

<body background=”../picture1.jpg“>

The double dots (..) here tells the browser to go up on directory to find the image.

Which is better … absolute or relative path?

Each is preferred at certain conditions.

Absolute path is better when what you link to is used in multiple pages across your website so that it doesn’t matter where your page is. Suppose that there’s a banner image that you use for all pages in your website … is it good to replicate the image in every folder of your website to use a relative path of it in every web-page there? Of course not.

Relative path is better when what you link to is very specific to the web-page and is located in the same directory containing that web-page or a subdirectory of it. Suppose a situation where you are writing an article web-page that contains many related pictures inside it. You’ve made a directory containing your article and a subdirectory containing all the article-related images. Now you are going to link to these images using either absolute or relative paths and you wonder which is better! Ask yourself the following question and it should reply you …. what if you later moved the article to a different domain? If were’re linking to images in an absolute way then you will have to change all paths again to the new domain but if you were using relative paths then you will not have to change anything.

This is because what is relative here is relative there!

Ahmed Abdullah Hussein

Microcontroller

August 30, 2009 5 comments

This is my first experience with Microcontrollers (µC).

Before I know about µC, I’ve already had a lot of experience about computer architecture and the story of running a software on a PC. I’ve then attended a summer training introducing Microcontrollers with a hands-on practice. Let’s get started…

microcontroller_ATMega32

What is a Microcontroller?

Microcontroller is actually a computer but a small one. It’s simply a computer on a chip. It has all the 3 main elements of any stored-program computer system. It has a processor, a storage memory and some I/O facilities.

Read more…

What is a Software Technology?

August 6, 2009 2 comments

What is a technology?

Here’s how Wikipedia defines technology:

Technology is a broad concept that deals with an animal species’ usage and knowledge of tools and crafts, and how it affects an animal species’ ability to control and adapt to its environment.

Designer thinking

Arrr … What animals!!!

But that is not what I was searching for. I was searching for that word “technology” that I always see in my study about Computer Software. I heard for example about Java technology, .NET technology, JDBC technology and many others.

Today I could make a very close definition of what is a technology when it’s related to software.

So the question now should be: What is a software technology?

I think that a software technology is simply a set of software libraries or classes (from an OO view) written in some programming languages to facilitate the ability to manipulate something. Having such technology should provide abstraction or hide the very specific details of dealing with this thing to make it easier for the developer.

I’ll say that Java, the programming language., is a software technology indeed.

Another example that I’ve read about it today and gave me the intuition about this topic is JDBC or Java DataBase Connectivity. It’s mentioned that JDBC is a technology that enables database access and manipulation of different database drivers like those for MySql, Oracle, MSSQL, … while JDBC is simply some software classes written in java!

Designer workstation after

Got it!!!

One more thing … Don’t you think that there’s some similarity between a software technology the way I defined it and a general technology definition as Wikipedia mentioned?

Wikipedia said it’s a Concept or set of concepts and I’ve said it’s a a set of Classes.  Do you know what’s a class in software? it is actually an abstraction of a Concept. There’s even more similarity between the two definitions but I’ll leave it to you as a homework 😉

– Ahmed Abdullah Hussein

Categories: Software Develeopment

أقصر طريق لمعرفه الله

August 2, 2009 5 comments

إن التفكر في خلق السماوات والأرض هو أقصر طريق لمعرفة الله

وهو أوسع باب ندخل منه علي الله لأنه يضعك وجها الي وجة أمام عظمة الله

قال الله تعالى: ” إن في خلق السموات والأرض واختلاف الليل والنهار لآيات لأولي الألباب (190) الذين يذكرون الله قياماً وقعوداً وعلى جنوبهم ويتفكرون في خلق السموات والأرض ربنا ماخلقت هذا باطلاً سبحانك فقنا عذاب النار (191) “. سورة آل عمران

ولعلك ستجد في المقطع التالي أحد آيات الله في خلقة

روي أن عائشة أم المؤمنين رضي الله عنها سئلت عن أعجب ما رأته من رسول الله صلى الله عليه وسلم فبكت ثم قالت: كان كل أمره عجباً، أتاني في ليلتي التي يكون فيها عندي، فاضطجع بجنبي حتى مس جلدي جلده، ثم قال: ياعائشة ألا تأذنين لي أن أتعبد ربي عز وجل؟ فقلت: يارسول الله: والله إني لأحب قربك وأحب هواك- أي أحب ألاّ تفارقني وأحب مايسرك مما تهواه- قالت: فقام إلى قربة من ماء في البيت فتوضأ ولم يكثر صب الماء، ثم قام يصلي ويتهجد فبكى في صلاته حتى بل لحيته، ثم سجد فبكى حتى بلّ الأرض، ثم اضطجع على جنبه فبكى، حتى إذا أتى بلال يؤذنه بصلاة الفجر، رآه يبكي فقال يارسول الله: مايبكيك وقد غفر الله لك ماتقدم من ذنبك وماتأخر؟ فقال له: ويحك يابلال، ومايمنعني أن أبكي وقد أنزل الله عليّ في هذه الليلة هذه الآيات : (إن في خلق السموات والأرض واختلاف الليل والنهار لآيات لأولي الألباب ….) فقرأها إلى آخر السورة ثم قال: ويل لمن قرأها ولم يتفكر فيها.

هذه الآيات التي أبكت نبينا صلى الله عليه وسلم أيها الأحبة وأقضت مضجعه ولم تجعله يهنأ بالنوم في ليلته تلك فكان يقرأها في صلاته ويبكى قائماً وساجداً وبكى وهو مضطجعاً، نعم إنها لآيات عظيمة تقشعر منها الأبدان وتهتز لها القلوب ، قلوب أولى الألباب الذين يذكرون الله قياماً وقعودا وعلى جنوبهم ويتفكرون في خلق السموات والأرض وليست كل القلوب كذلك ! فهلا تفكرنا في ملكوت الله ؟ وهلا أكثرنا من ذكر الله ؟ واستشعرنا عظمته سبحانه وتعالى ؟ لو فعلنا ذلك لبكينا من خشية الله عند سماع أو قراءة هذه الآيات ولكن لله المشتكى من قسوة في قلوبنا وغفلة في أذهاننا. اللهم أنر قلوبنا بنور القرآن ، اللهم إنا نسألك قلباً خاشعا ولساناً ذاكرا وقلباً خاشعاً وعلماً نافعاً وعملاً صالحاً.

Categories: Life

How many things between X and Y?

July 31, 2009 4 comments

I’ve noticed that there are 3 possible answers for the question “How many things between X and Y?”.

I’ll give 3 examples to explain what I mean:

1. How many hours do you take between 2 PM and 7 PM?

The answer is 5 hours which is 7-2.

2. How many numbers are there between 2 and 7?

The answer is 4 numbers (The numbers 3, 4, 5, 6) which is 7-2-1.

3. How many numbers would you speak out if you count from 2 to 7?

The answer is 6 numbers (The numbers 2, 3, 4, 5, 6, 7) which is 7-2+1.

So why is the answer different in each case?

In the first question, you are asked to count the number of hours between 2 and 7. Actually the hour meant in the question is a period. From 2 to 3 is a period of hour, from 3 to 4 is another period and so on. The answer then is Y-X that gives you the number of steps (periods) that you’ll take from X to Y.

In the second question, you are asked to count how many numbers there are between 2 and 7. This time you’re asked to count the numbers themselves that you would visit between 2 and 7 … not the steps you’ll take. If you’re taking 5 steps from point 2 to point 7, then there are 4 points between them (that’s excluding the first and last point). So the answer is Y-X-1.

In the third question, it’s asked to count numbers that you speak out when counting from 2 to 7. This is to say in other words, “How many numbers between 2 and 7, inclusive?”. Let’s conclude the answer in a new style … Do you mind that a one step forward needs 2 points and 2 steps forward need 3 points and so on…? This is true! … Well if you got how I explained the answer of question 1 then the answer to this question is Y-X+1 because the number of steps is Y-X between X and Y!

Conclusion:

The answer for the question “How many things between X and Y?” is either Y-X, Y-X-1, or Y-X+1 and the answer depends on what things you are trying to count!

Challenge Failed, I succeeded

July 16, 2009 13 comments

2 years ago and days before I’m enrolled in the department of Computer Engineering in my faculty, I had a big challenge with myself.

The challenge is very simple to describe, it’s being of rank 1 on that department. I had that dream and I promised myself to do my best to achieve that.

And here comes the day, 16/07/2009, where the challenge result is declared that I’m not that one of an overall grade of rank 1 on my department.

Of course I felt so sad towards that but the fact that this challenge gave me a lot of benefits made me think again about it and find that even if I failed to achieve it, I succeeded!

How did I succeed?

I had a rank of 5 when I first got into that department with a difference of 245 marks than that mark of rank 1.

In the 1st year in the department (Computer 3rd), I could make a big jump from the 5th place to the 2nd place after ranking 1st on that year being the only student with a grade of Excellent (1326/1500) in that year.

And in the second year which is the 5th and last year of college, I couldn’t make that big jump of the previous year, but I could be again ranked 1st on that year being again the only student with a grade of Excellent (1291/1500).

In short, I’ve been the only student who could get a grade of Excellent in the 3rd year and also in the 4th year of the Computer Department. I could reduce the difference between me and the first place from 245 to 69 and jump from the 5th place to the 2nd place.

On the other hand, I think I had some other achievements that make me think of success. I’ve been ranked 1st on TopCoder, Programming and Algorithms Contests website, during the last 3 years and could make it to blue which has been also a recent challenge.

I’ve also been to the ACM/ICPC ANARC 2008 Programming contest locally and regionally. That was the first time my faculty contributed in that contest and I believe we did a great job. BTW I should thank Abdullah Saad and Marwa Yusuf, my elder brother and sister and TA’s in the faculty, for being with me … I wouldn’t make it without you guys!

I was first employeed in my transition from the 3rd year to the 4th year as a Software Developer in Bedaya TV in the EMPC and had about 2 months in that job.

Finally, I have been elected by the faculty staff and IEEE members to be the IEEE Student Branch Chairman in my faculty in the last year. I had been involved in organizing a lot of activites and still working on some.

I’m not going to stop at this point. Life should be full of challenges, otherwise it’s of no use to live it.

Alhamdulillah for that result, I dedicate it to my dear mother … I’ll be a man of my word!

Categories: Life

Topcoder Return

June 29, 2009 2 comments

It’s been a long while since I participated in a TopCoder algorithm contest. I decided to stop competing for 3 months during the final exams period of my last year in the college. I’ve also been so busy working on my graduation project.
I had completed my final exams and then discussed my graduation project on 20/06/2009.
Three days later, I got back to do another algorithm contest on TopCoder. I’ve been afraid that this long period of inactivity could have affect my performance badly especially because I was competing in Div I.
This contest had some circumstances that made it kinda a special one:

  • The contest was the first after 3 months of inactivity
  • The contest started at 4:00 AM
  • I woke up 10 mins before the contest
  • I had Petr in the same room of mine
  • I could solve the 300 problem faster than anytime before in Div I SRMs
  • After the contest, I had a new max. rating than ever before [1336] and ranked 15th on Egypt with this rating

A funny story in this match is that when I asked Petr about his solution to the 300 problem that seemed too long while mine was very short, This was the discussion between us:

Mindhunter74 > Petr: Does it really need all this code in the 300?
Mindhunter74 > Petr: Do I miss anything in my solution?
Petr > Mindhunter74: no 🙂
Petr > Mindhunter74: Your solution seems to be correct as well
Petr > Mindhunter74: I’m just too stupid

Petr is too stupid that makes him ranked first all over the world on Topcoder 😉
This my rating graph after this contest:

With this rating, I might hit the yellow area with a lucky next contest. But I do not think I’ll make it very soon, I have to work harder to make it to yellow and be able to stay there too.

Categories: Life