Tech Guide Blog

Tech Guide Programming Tutorial Tips Tricks

Archive for the ‘Programming’ Category

Validate XHTML YouTube Embed Video

Posted by Admin On August - 20 - 2009

What can I get by validating XHTML in my blog? Well, some people say it can help Uncle Google to read and crawl your site, because Uncle is older and older and more hard to do reading. Before I use this code, my blog home page is always not valid due to a reason, after I insert a video from YouTube, some warnings and errors always occur. I search and find some tips to make YouTube Embed Video that you’ve insert is valid. Let’s take a look first with YouTube default Embed Code.

<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/sJi6amKnNNE&hl=en&fs=1&"></param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/sJi6amKnNNE&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>
</object>

That code above is not valid by W3C XHTML validator. So you have to change that code into something different than above.

<object type="application/x-shockwave-flash" style="width:310px; height:260px;"
data="http://www.youtube.com/v/XFcLU7hOeQI&hl=en&fs=1">
<param name="movie" value="http://www.youtube.com/v/XFcLU7hOeQI&hl=en&fs=1" />
</object>

This format above now is valid by XHTML Validator, but as you can see now, every YouTube Embed Code are always have ‘&’ ampersand. This is another problem that make your Embed Video is still not valid by XHTML Validator. For this problem, you have to change every ‘&’ to ‘&amp;’

<object type="application/x-shockwave-flash" style="width:310px; height:260px;"
data="http://www.youtube.com/v/XFcLU7hOeQI&amp;hl=en&amp;fs=1">
<param name="movie" value="http://www.youtube.com/v/XFcLU7hOeQI&amp;hl=en&amp;fs=1" />
</object>

That’s it. It’s working on my blog, may this tips can help you to validate your site when you insert an Embed Video from YouTube. You can comment if you want to ask or share about this article.

Popularity: 21% [?]

Recursion in Programming

Posted by Admin On August - 9 - 2009

What exactly recursion is in programming? Recursion is a function that calls the function itself. Thus, in the body of function there is a command that called the function itself. If you use it well, it can solve a problem much more simple and easy. Recursion itself uses a large amount of memory, so be aware not to use it if not necessary. To make a good recursion, of course the functions must have a condition that makes it stop, so the function will not do an infinite looping. I’ve tried it without a stop condition, I compiled it and wow, NOD32 detected my .exe as a virus, I don’t know if the NOD32 made a false detection or not, but if it’s true, then it’s not too difficult to make a virus, eh? Just a little mistake in a program that you’ve made for good reasons and you’ve made a virus.

This code below is an example of how recursion function is working.

#include <stdio.h>
#include <conio.h>

void letter(char alp)
{
	if (alp <= 'e')
	{
		printf("%c ", alp);
		letter(alp + 1);
	}
}

void main()
{
	char temp = 'a';
	letter(temp);
	getch();
}

We call the function and it will print letters from ‘a’ to ‘e’. From the start of the program at void main, we fill a variable with char type called temp with ‘a’. We then call the letter function with temp as parameter, into the letter function, the variable named alp will be filled with ‘a’. Here’s the stop condition, if alp is lower or equal than ‘e’, the function will continue its routine, the function will print what is in the alp variable. After the function printed what is in the alp variable, it call itself with alp + 1 as the parameter, thus this looks like the function is going down 1 level. This routine ended when alp variable is filled with ‘f’, it will go up to the upper level and so on until back to the top level.

It’s a little confusing for me, so I made a ‘level’ for this explanation. Every time a function (you can say function1) called another function (function2), I decided to make a function2 as level 2 function, below the level 1 function (function1). So when letter function with temp as parameter called a letter function with alp + 1 parameter, I set in my mind the letter function with temp parameter as level 1 function and letter function with alp + 1 parameter as level 2, letter function with (alp + 1) + 1 parameter as level 3 function respectively. I hope this tutorial can help.

Popularity: 10% [?]

Circular Queue C++

Posted by Admin On July - 16 - 2009

Let’s get to the point, what’s the different beetwen Circular and Linear? Just like previous post, the different is the head is always move around or you can say dynamic. The first and the last data is likely become linked to another one. If we do enqueue, the tail will be point to the new data. If you can see the picture below, you will know that the data are never move like linear queue, but the head node. This head node always move when you do dequeue and enqueue new data.

Circular Queue

Circular Queue

While we using circular queue, we can use mod (%) to help us for the head movement. Here is the example of Circular Queue. This code is the class of Queue, it’s just made for keep integer data up to small size, it’s just for simple example program of Circular Queue.

#include <iostream.h>
#include <conio.h>
#include <windows.h>

#define MAX 5

class Cqueue
{
private:
	int element[MAX];
	int head;
	int tail;
public:
	Cqueue()
	{
		head=0;
		tail=0;
	}
	void enqueue(int x)
	{
		if(!full())
		{
			element[(head+tail)%MAX]=x;
			tail++;
		}
	}
	int dequeue()
	{
		if(!empty())
		{
			int temp;
			temp=element[head];
			head++;
			head=head%MAX;
			tail--;
			return temp;
		}
	}
	int full()
	{
		if(tail==MAX)
			return 1;
		else
			return 0;
	}
	int empty()
	{
		if(tail==0)
			return 1;
		else
			return 0;
	}
	void view()
	{
		for(int i=0;i<tail;i++)
			cout<<element[(i+head)%MAX]<<endl;
		getch();
	}
};

Popularity: 50% [?]