Have you ever written a piece of code that works, but the amount of redundancy and inefficiency drove you nuts? Always had the itch to go back and pretty it up? Well, that’s exactly what I did. I recently wrote a script for a people directory, it contained 3 parts
An database storing the information of the people (i.e. name, states, country, etc etc.)
the html input file (see example below)
The data processor using PHP
input file (input.html)
The idea is that you will be able to select a last name or a state and find the corresponding results. For example, finding someone in the state of Virginia, finding someone with last name start with W, or a combination of both.
This was the first attempt for selecting the matching last name:
HERE
HERE
By using arrays, here are the code for selecting the matching last name and state and generate the SQL query
This is not an endorsement or advertisement but hulu.com is one of the recent website that has impressed me as well as becoming addicted to it. Among many of the video streaming websites (youtube.com, veoh.com, etc) hulu stands because it stays away from mostly low quality home videos and making it exclusively a live TV show and movie streaming service. It is 100% free to its viewers. Thanks to the partnering ship with mainly FOX, NBC and other TV channels, hulu is able to deliver hundreds of TV shows in one place. More impressively, it also had deal with NBA and have NBA games as well as college football games for a sports nut like myself.
The service divides mainly into 3 parts: TV, movies, and video clips. Although the movie selection was not impressive, it did offer 480p DVD quality option which was much to my pleasant surprise. I enjoyed watching the girl next door, Titan A.E. and other movies. It did require registration for movies that were rated PG. As for video clips I find them to be refreshing as well, like mentioned before, these video clips are pretty high quality as well, some featured one include SNL skids, late night show segments etc.
Lastly, hulu is also experimenting with HD as they have a section called HD gallery, it is mainly streaming movie previews and very short clips, unlike apple trailer hulu uses flv format instead of quick time. It is likely using H.264 or even better encoding techniques.
There are some drawback to hulu though, for example, going from a 3.0 mbps cable connection to a slower: 768 kbps connection, streaming was skiddish not to mention play a movie in 480p DVD quality. That means that hulu eats a lot of bandwidth, with current residential average connection speed it is likely only the higher connection speed users can enjoy the full benefits. There were commercials but I did not mind them that much. Also, many of hulu’s TV selections are incomplete, bringing only the most recent TV episodes. The HD gallery is also in very infant stage because it requires extremely fast connection to be able to stream a movie in 1080p as of current network technology.
The promise hulu brings is impressive, as of right now, I’m going to enjoy astroboy, hell’s kitchen and many of my other favorite shows there!
A while back one of my project was to create a joomla based content management website. Afterwards I was asked to make a backup mechanism that would back up all of the content on the website. There were plenty of third party plugins available on joomla’s extension directory but I found them either too complicated for normal users to operate or costed money. Another option was to use PhpMyAdmin to backup the entire joomla database, however that was too
complicated for the user in this situation as well. Therefore I decided to write a custom php script made just to handle the content backup.
Some file you need download: (PHP ZIP library: PHP zip library, contains: Zip.php and PEAR.php)
1st: I had to find where the content was stored, luckily for joomla based CMS all contents are stored in the database under the table “jos_content” or whatever the pre-fix: “xx_content” in the joomla database you created.
2nd: I had to create the basic MySQL connection script: here are the following:
openning the database:
//******************************************************************************** //opendb $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
Here are the basic scripts for openning and closing a mySQL database connection in php, for more information on them, visit w3schools to learn more
Now comes the meat of the script:
//************************************************ //include the php library for zip file compression //************************************************ include('Zip.php');
//************************************************************************************* //Querying the database table containing the contents of the website, notice we used a //concat function to combine the introtext and fulltext together //************************************************************************************* $query = "SELECT id, title, concat(introtext, concat('\n', `fulltext`)) content FROM jos_content"; $result = mysql_query($query);
//***************************************************************** //Displaying the SQL querying result in html using a form text area //***************************************************************** echo"<label>
<textarea name=\"content\" id=\"content\" cols=\"60\" rows=\"8\">"; $number = 1;
//***************************************************** //Return every row of query into an associative array //***************************************************** while($row = mysql_fetch_assoc($result)) {
//Strip out of the following symbols from the title of the content $symbols = array("\"", "...", "!", "#", " ", "=", ":", "'", ",", "?"); $row['title'] = str_replace($symbols, "", $row['title']);
//create html files that contain the content ID, title under the backup directory $file = "backup/id_" . $row['id'] . "_" . $row['title'] . ".html"; $Saved_File = fopen($file, 'w') or die("can't open file"); fwrite($Saved_File, $row['content']); fclose($Saved_File);
//create the zip package $file_date = date('m-d-y'); $zipfile = new Archive_Zip('backup' . $file_date . '.zip'); $list = $file; $zipfile->add($list);
//displaying result echo"id_" . $row['id'] . "_" . $row['title'] . ".html" . "\n"; $number++; } echo"</textarea></label>"; echo"<br /> <h3>$number files created under /help/backup</h3>";
//providing download link echo"<br /><a href=\"backup" . $file_date . ".zip\" target=\"_blank\" />Click here</a> to download the backup package";
As some of you can tell, this script is still in very immature stage, future updates could include SQL injection prevention measures, validation of the backup directory and also deletion of the html files once they have been packaged. Anyways I hope this have been useful.
It’s very exciting isn’t it, in the second program, We are attempting to create a customized simple internet browser. My program consist of the following controls:
1 WebBrowser (the web content area)
Name: BrowseWindow
3 buttons (HomeButton, BackButton, Button_1)
Some thoughts: The browser is very simple, address does not address content of the web. Maximize, content area does not, future considerations.
Code
PublicClass Form1
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
BrowseWindow.Navigate(TextBox1.Text)
EndSub
PrivateSub BackButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles BackButton.Click
BrowseWindow.GoBack()
EndSub
PrivateSub HomeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles HomeButton.Click
Just recently, I really wanted to pick up and start to learn visual basic again. It is a relatively simple and fun programming language that’s easy to learn. I’ll be using visual basic express 2005. The programs I will be coding will be posted regularly as well as the program code.
To download Microsoft Visual Basic Express 2005, you can click here
To download the SP1 (Service Pack 1), click here.
To download all visual studio express 2005 (ISOs), click here
Recent Comments