Tech Guide Blog

Tech Guide Programming Tutorial Tips Tricks

Archive for the ‘Tutorial’ 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% [?]

Boyer Moore String Searching Algorithm

Posted by Admin On June - 23 - 2009

This time, we will talk about Boyer Moore string searching. It’s not like brute-force, it will search a substring from the back and go forward till the first char of string. For example, we search a substring EXAMPLE within HERE IS A SIMPLE EXAMPLE string. I can’t explain it well, so this below maybe rather confusing.

EXAMPLE
HERE IS A SIMPLE EXAMPLE
's' is not in EXAMPLE substring, jump for EXAMPLE length = 7
       EXAMPLE
HERE IS A SIMPLE EXAMPLE
'e' is not same as 'p', so jump for the last char of EXAMPLE to 'p' EXAMPLE = 2
         EXAMPLE
HERE IS A SIMPLE EXAMPLE
'a' != 'i', jump for distance from 'e' SIMPLE to the front 'e' EXAMPLE sub string = 6
               EXAMPLE
HERE IS A SIMPLE EXAMPLE
'e' is not same as 'p', so jump for the last char of EXAMPLE to 'p' EXAMPLE = 2
                 EXAMPLE
HERE IS A SIMPLE EXAMPLE
compare till end, found.

For the code, it’s a little weird, made by myself with many helps. It just find the index of string if it found the sub string within the string. You can use a table to save all chars shift value.

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

void main()
{
	char string[1000], substring[1000];
	int strvalue[256], i, j, diff = 0, count = 0;

	printf("Input string: ");
	gets(string);
	printf("Input substring: ");
	gets(substring);
	for (i = 0; i < 256; i++)
	{
		strvalue[i] = -1;
	}
	for (i = strlen(substring) - 1; i >= 0 ; i--)
	{
		if (strvalue[substring[i]] == -1)
			strvalue[substring[i]] = i;
	}
	for (i = 0; i < 256; i++)
	{
		if (strvalue[substring[i]] == -1)
			strvalue[substring[i]] = strlen(substring);
	}
	i = strlen(substring) - 1;
	while (true)
	{
		for (j = strlen(substring) - 1; j >= 0 ; j--)
		{
			if (substring[j] == string[i - diff])
			{
				count++;
				diff++;
			}
			else
				break;
			if (count == strlen(substring))
			{
				printf("%d", i - diff + 2);
				getch();
				exit(0);
			}
		}
		diff = strlen(substring) - strvalue[string[i - diff]] - 1 - count;
		if (diff > 0)
		{
			i = i + diff;
			diff = 0;
			count = 0;
		}
		else
			i++;
		if (i > strlen(string) + strlen(substring) + 2)
			exit(0);
	}
}

Popularity: 67% [?]