Archive for

January, 2011

Adding a number of random generated unique strings into db

Today I accidentally got to a piece of code I have written long ago and really got surprised from me. I have created a not conventional solution to a interesting problem. Imagine you have to add a bunch of rows into a db table, for example promo codes, that has column holding randomly generated strings. The strings should be unique of course, so we have unique key in the db! So instead of generating the string, checking if it is already in the table and if not -> adding it to the table, I have just written this:

$j = 0;
for($i=0; $i<$count; $i++)
{
	while(true)
	{
		try
		{
			$code = str_makerand();
			$codeID = $this->addItem(
				$this->tableNameCodes,
				array('code'),
				array($code)
			);

			break;
		}
		catch(Exception $e){
			$j++;
			if($j=10) break;
		}
	}
}

YouTube’s policy for inappropriate content and the embed function

Recently I noticed something in the way YouTube manages the videos flagged as inappropriate by some users. You know such videos you want to watch but you must be logged in. This way you accept and confirm you are older than 18 years. On my facebook profile I had a post with such a video – it is embed of the video as you know. And guess what – everyone can play it. It doesn’t matter it you are logged in or not. Here is the example: Read more