Dallas Clark

Blog about IT, Multimedia, Innovations, Internet and anything fun!

About

Dallas Clark
Software Developer
BRISBANE QLD
AUSTRALIA

Flash is definitely the platform to make games for the mass market. Unfortunate for those who use iPhones but to anyone else whether mobile or desktop, the Flash game market is in a new era.

World Golf Tour (WGT) shows some of the capabilities that Flash has to offer, Flash 10 comes with so many new 3D features that it will be pointless for me to list them all, but I'll link you to them.

Although there is high speculation that WGT is simply laying down images and using video renders for the animations, but either way it's still pretty cool.

Normally you would select an option with a server-side script like PHP which is a lot faster and doesn't require the client's browser to do the work. But on the rare occasion where you need to set an option with JavaScript, here's a small script on how to do it.

 
document.getElementById('select_box_id_here').value
 = 'the value of the one you want selected';
 

This will work if you have constructed the page the proper way. On the odd chance you've used JavaScript to pull in a whole string of HTML then use the method below.

 
var selectBox = document.getElementById('select_box_id_here');
for(i=0; i
<selectBox.options.length; i++) {
	if(selectBox.options[i].value == a_value) {
		selectBox.options[i].selected = true;
		i = selectBox.options.length;
	}
}
 

The above script simply loops through your select box and determines if the current option (in the loop) matches the value (a_value), if so then set the option to selected. The line "i = selectBox.options.length;" simply stops the 'for loop' from checking any further options.

The reason why you have to manually go through the select box yourself is because the DOM doesn't actually know the select box is on the page when you've just dumped a whole lot of HTML into the page with JavaScript. If it's possible to refresh the DOM then let me know, otherwise the above option is the solution to this problem.

You can find a lot of ways to prevent spam from your site these days but I've really tested this method and it has been 100% effective (so far). It will stop automatic bots but a human will be able to work out how to get around it pretty easily (but when do humans have time to do that).

To begin with: this script is written in PHP but you can easily translate it.

 
   session_start();
   $_SESSION["spam_prevention"] = '1';
 

First off, on the page with the form to email to you, declare a unique session variable on this page with any value you want. Why? So when the user submits this form to the script that sends the email, you know the user definitely came from the page with the form, and it's not a bot attacking your email script. So before your email script, test to see if $_SESSION["spam_prevention"] exists.

 
<input type="text" name="spam_prevention"
    style="display:none; visibility:hidden;" />
 

Another method is to put a text field on your form and hid it with CSS. 99.9% of the SPAM bots out there will disregard any CSS styles, and at the same time the SPAM bots will fill out every field within your form. So if this field is filled out, it's a good guess that it wasn't a human that filled it out.

This isn't bullet proof, but it works quite well and it doesn't require the user to fill out any spam prevention captcha fields etc.

Let me know how you go with this script if you try it.

Simple Folder Creator with PHP

October 29th, 2008

This script will detect if a folder exists as well as create the directories if the folder doesn't exist.

 
	mk_dir_recursive('the/directory/you/want/to/create');
	function mk_dir_recursive($folder_name) {
		if(file_exists($folder_name)) {
			return;
		}
		$folder_name = rtrim($folder_name, "/\\");
		$parent = dirname($folder_name);
		if(!file_exists($parent)) {
			mk_dir_recursive($parent);
		}
		mkdir($folder_name);
	}
 

If you want to create an easy photo gallery, this script will allow you to resize images on the fly. It has a few pros and cons that you should be aware of before you start using it.

Pros
* Simple and easy to use :) - even I can use it.
* It resizes on the fly, so you can modify the code and it will affect all images you pass through it immediately. Great if you're short on storage on your web server, and doesn't require you to re-render all the images if you decide to change the size of the thumbnails.
* You can call this script for any image on your site, the image doesn't have to sit in an actual photo gallery.

Cons
* If you have a high traffic website, this isn't the best solution. You're best off resizing all your images when they're uploaded, not when they're are viewed. If you choose to use this script on a high traffic website, then at least cache the results so your web server isn't creating the same image 1000's of times over.
* This script only works with JPEGs, I'll create a new version (one day) to handle others.
* If you think of more cons, let me know.

The GalleryViewer Script: Download (Right Click > Save Target/Link As)
* Rename the file to galleryviewer.php.

Usage
Create Thumbnail: galleryViewer.php?version=thumb&image=the/url/to/the/image.jpg
Create Resized Image: galleryViewer.php?version=full&image=the/url/to/the/image.jpg

<img src="galleryViewer.php?version=thumb
    &image=the/url/to/the/image.jpg" alt="Thumbnail" />

Full Usage

The query string 'image' needs to be relative to the script.

Just a small tip for some people who might be modifying arrays during a loop, where the array is used in the condition of the loop. Just be a little bit careful on what you do with the array when looping through.

 
var testArray = Array('1','2','3','4','5');
for(var j=0; j<testArray.length; j++) {
    alert(testArray[j]);
    if(testArray[j] == '3') {
        testArray.splice(j,1);
    }
}
 

The above array loop is written in JavaScript, whether you're using JavaScript or not this is still something small to keep in mind. It will produce an alert of '1', then '2', then '3', and then '5'.

The length of the above array is 5, you start at position 0 and testArray[0] doesn't equal '3' so move on, same thing with position 1 (testArray[1] doesn't equal '3'). You then move onto position 2 where testArray[2] does equal '3', so we splice the array at position 2 which removes testArray[2] from the array, making the rest of the array drop down a position.

j still equals 2, so when it loops through again, j will equal 3. When it looks at what position 3 equals (testArray[3]) it will now be '5' as the array's position dropped down by one from the splice.

So we missed out on alerting '4' after going through that loop and you might be doing something important with the loop rather then simply alerting the values, there is 2 ways to get around this. One, put the 'something important' function after the loop in its own separate array. Or two, even easier, if the 'if condition' is true and you modified the array, simply affect the value of j so that the next loop through will be correct (like below).

 
var testArray = Array('1','2','3','4','5');
for(var j=0; j<testArray.length; j++) {
    alert(testArray[j]);
    if(testArray[j] == '3') {
        testArray.splice(j,1);
        j--;
    }
}
 

One day this will be useful.

October 8th, 2008

Gmail has introduced a new feature called 'Mail Goggles' which will activate at a certain time at night (assuming a late Friday or Saturday night) when you might have had a drink or two. Mail Goggles will ask you some simple maths questions before you send an email, which might give you enough time to think about the email you're about to send.

This feature will be annoying and I hope there will be an option to deactivate it, one day it might save you from sending an email to an ex-girlfriend, or your boss that you might regret the next morning.

Will 5 simple maths questions really make you think twice before the email is sent?

If I ever receive a nasty email, and I'll be honest and say I have received a couple in the past, I normally walk away and don't respond immediately. In general, don't write emails or chat messages when you're not in such a good mood and you won't get into trouble.

To any IT developers, this is old news, or you may not have put 1 and 1 together. Web applications are slowly taking over the desktop application market as more features and tools are added to desktop browsers.

We‘re often used to installing all the necessary software after installing our operating system, but these days all the software you used to install can be found a "click away" on the Internet. Which only requires an Internet connection and a browser.

Webtops, online office applications and communication applications have been around on the Internet for quite some time now, and we will be influenced soon if not already to follow this trend.

Why? Because it‘s simpler to the average user. IT developers will not make the transition as quickly but soon will.

Anything that a desktop application can do, a web application can do better.

Current & Twitter have teamed up for the very first time to integrate real-time Twitter messages (aka "tweets") over major portions of a live television broadcast of the next presidential debate.

Current will broadcast as many of your debate tweets as possible right over the candidates, in real time, on their live broadcast.

How to PARTICIPATE:
1. Tune in on October 7th at 9pm EST/ 6pm PST for the Live Presidential Debate. Find Current TV on your local cable/satellite provider or come here to watch the live stream of our broadcast.
2. Make sure you’ve registered with Twitter to participate.
3. During the debates, chime in by including "#current" in your tweet. Example: "This discussion about universal healthcare makes me want to pop some pills! #current"
4. We won't be able to air every single tweet on TV, but you can see all of the #current tweets by searching #current on Twitter search.
5. If you have any questions about participating, send us a tweet @current.

For more information, visit Hack the Debate.

At the moment, Adobe are making a Flash plugin for the Apple iPhone with their belief that if they make it good enough, Apple will publish it. Unfortunately for Adobe and the rest of the world, the likely hood of Flash being available on the iPhone will be very slim.

To begin with, the applications that are available to download through Apple's iPhone App Store are making millions of dollars for Apple and a little for the developers making the applications. If Flash was available on the iPhone, it would be able to avoid the whole App Store process and developers can sell their applications themselves and receive 100% of the sales.

There would be very little chance of the iPhone ever having Flash available unless there is another phone that is taking a substantial amount of the iPhone sales away, and of course this phone runs Flash. In my own point of view of the iPhone, the only 'wow' factor is the interface which has been replicated on Windows Mobile phones already.

The iPhone has a lot of restrictions and I believe it is only popular because of Apple's Marketing strategies, and the popularity they gain with younger audiences. I have an iMate JasJam which has more features then the iPhone and it's nearly 2 years old, so I'm expecting more features will be available in the latest models which puts the iPhone lower on the features list.

Using TinyMCE with AJAX

September 13th, 2008

What is TinyMCE?
TinyMCE is a platform independent web based Javascript HTML WYSIWYG editor control released as Open Source under LGPL by Moxiecode Systems AB. It has the ability to convert HTML TEXTAREA fields or other HTML elements to editor instances. TinyMCE is very easy to integrate into other Content Management Systems. Please visit their website for more details.

 
tinyMCE.init({ //settings go here });
 

Starting TinyMCE

 
tinyMCE.triggerSave(false,true);
tiny_mce_editor = tinyMCE.get('your_textarea_name');
var newData = tiny_mce_editor.getContent();
tinyMCE.execCommand( 'mceRemoveControl', false, 'your_textarea_name' );
 

Getting the Textarea Text and Closing TinyMCE
The new data that the user would enter into TinyMCE is now stored in the variable newData.

You need to specify a trigger save like this for 2 reasons:-
* You can't simply get content from your textarea once TinyMCE has taken over it, as the text in the textarea isn't actually stored in that field name you know.
* You need to remove the control properly so that TinyMCE doesn't make another instance of the same textarea, or otherwise you will run into issues.

This dominant company is ahead of it's market because of three reasons, competitive pricing/marketing, support, and because they keep up with the latest trends of the communication. Dell are always looking at new ways to advertise or keep in touch with their potential customers by trendy communication methods.

The latest trend they're using is Twitter, a short message service that alerts you on what people and companies are doing. Dell has listed all their twitter accounts at http://www.dell.com/twitter for everyone to peruse.

Currently, only tech-savvy people use twitter (slowly growing out of this trend), but you will find that the majority of people who are ordering bulk lots of computers (5+) are the tech-savvy people. So to be able to target those users is definitely an asset to the point of view of Dell.

This is an issue I see every so often, particularly with calendar scripts or anything that works with dates and times. When you store your timestamp or date-time in a database and do a search between 2 values, most scripts leave out something very crucial.

Lets us the following data as an example.

Row | Start of Event         | End of Event
---------------------------------------------------------
1   | 15/05/2008 12:00:00    | 15/05/2008 17:30:00
2   | 24/05/2008 09:00:00    | 24/05/2008 17:30:00

 

If we perform the following search, we will only get the first row (15/05/2008) and not the second row (24/05/2008).

WHERE `Start of Event` >= '15/05/2008'
 AND `End of Event` < = '24/05/2008`

 

The reason is simple and most people won't realise this issue at first but will eventually find the issue once they have debugged their application to bits. When you perform a search between timestamps or date-time values using dates only, you are in fact doing a search between the dates and midnight as the default time value.

For example the above will in fact be searching for:

WHERE `Start of Event` >= '15/05/2008 00:00:00'
 AND `End of Event` < = '24/05/2008 00:00:00`

 

Because the second event "24/05/2008 09:00:00" starts after the "24/05/2008 00:00:00" it won't be included in the results. It's a simple mistake and very easy one to make.

There are many ways to get around it, the most simple way is to get the last date eg; "24/05/2008" add one day, and minus one second. So you end up with "24/05/2008 23:59:59".

Credit for this conversation: monk-ee

I was riding home on the train as I do every weekday from the city and came across something I thought interesting. A leaked document from the federal government reveals customs are planning to search everyone's iPods, media players, CD collections, and notebooks for pirated music/videos in any form.

If the process of going through customs wasn't long enough already, they are now going to search through our 'virtual' worlds to catch illegal music and videos. But, one thing that has me stumped? How will they know that it is illegal?

Digital rights management (DRM) has been thrown out the window and thus making your legal music collection look just like an illegal collection. I do believe that the law needs to catch up with modern-technology but this will just cause chaos at the customs.

In Europe, Virgin Media is already collecting statistics/data from Internet users who are illegally downloading music through their Internet Service Provider (ISP) and writing to them to warn them about their actions. Australia will probably catch up to these standards soon, and so will America.

In a collaboration between Microsoft and Lynda.com, whether you're a developer or a designer you can get a head start on how to create Microsoft Silverlight applications.

Check out the Silverlight Video Tutorials and don't forget to show me what you've made.