I am always curious in learning new programming languages and have been curious for awhile now with Ruby. I have come across various scripts and applications built upon it but have never had the professional need to utilize it. Time I guess to bite the bullet and see what if anything is special about this language built on the old but probably ever living C language.

Installing Ruby

The first thing to do, with any language is installation. What to do I guess first off since I use a Windows machine is to see if thee are any executable Ruby installers. Bingo, hello RubyInstaller a self contained ruby language installer with an inclusive execution environment built in.

Creating my first Ruby script

The common file extension to a ruby script file is .rb. So starting things out I created a test script to echo the basic “Hello World” script to verify Ruby was installed correctly.

puts "hello World!"

A couple things right off the back Ruby does not use semi-colons (;) to terminate a code statement, instead it uses the carriage return. Secondly the command to output to the console is puts… A strange word to use for outputting to the system it is simpler then the Java equivalent of System.out to be sure but the PHP use of echo seems more intuitive then puts.

Being familiar with the command prompt I decided to fire it up and run my script using the new installed ruby library. Having selected to add the library to my environments path from the installer there is no need to specify the path to the Ruby library.

ruby test.rb

I was pleasently delighted to have my script output correctly.

C:\test>ruby test.rb
Hello World!

Splitting a ruby command onto multiple lines

Now knowing that Ruby utilizes the new line character to specify the end of a command, I was curious as to how to wraps my ruby commands onto multiple lines. As an avid developer I try to follow common guidelines when writing code one of which is keeping each line of code to within 80 characters improving readability. A quick search revealed that the front slash (\) character can be used to “join” two code lines together.
For example:

test = 10 + 16 + \
9 + 3

will output:

38

Lots more to learn and explore next I’m going to tackle Classes and Methods in Ruby with the hope of gathering some insight into why some developers prefer Ruby as their language of choice.

, , , , , ,

When it comes to Search Engine Optimization (SEO) you will find numerous tips & tricks on how to increase your page ranking. When it is all said and done the most important thing you can do is write unique and informative content. Regardless of the Keyword Stuffing or shear number of articles, the best way to get search traffic to your site is to write an article/post that is purposeful and informative to it’s target audience. To help get you on your way to increasing your own page rank below are some tips on writing a good article.

1: Write with a Purpose

When writing you need to have a reason for doing so. Don’t simply feel you need you need to write an article every day or on a regular schedule. Only write an article when you have a specific information you want to get across. For example lets say you just learned ruby and have decided to write an article on it. To make a good article or set of articles decide what about ruby you want to write on. Do you want to write a beginner’s guide to using ruby? Is it a comparison of ruby vs php or another programming language? If you write your article for a specific purpose there is a greater change of someone reading the article as well as it benefiting, or answering their questions.

2: Write for your target Audience

Knowing your audience helps to define the contents of your article. If you are writing a topic for individuals knowledgeable on the subject vs beginners then your content is going to be different. For example a How to article for beginners may need additional details on each step including references to special techniques while an advanced article can be slimmer with point by point instructions that gloss over the explanations of how and why.

3: Don’t be afraid to get personal or be opinionated

This is your article, yes you are trying to get a point across but never the less it is yours. Include your own opinions say if you agree or disagree with a subject. The one caveat is to remain on task, don’t go rambling on for 2 paragraphs on a side topic that doesn’t match the purpose of your writing.

4: Keep your writing organized and easy to read

No mater how good the information is in your writing if the reader can’t follow it or understand it then it is bad. Keep your writing organized by each topic smoothly transitioning into the next. Also keep your language appropriate to the target audience so they can follow along with out having to look up words or wonder what you are trying to say.

5: Titles are important

The title of an article is supposed to give the reader an overall glimpse of what they can find or will learn in the article. Be sure to keep them brief but also informative. Some writers find it easier to write the title after an article, while some find it is easier to write it first then jump into the article. Whichever works for you just remember that article and page titles are used in calculating your page rank and also are viewable to searchers on Search Engines.

6: Understanding how to use Keywords

Keywords are an important part of any article, by including them in your writing you are helping to associate your article to specific searches. However this does not mean you need to force keywords into your article. After you write your first draft simply review and you should find that main keywords already are present simply revise and add in any others when they are appropriate and flow seamlessly within your article. If your keywords don’t seem to fit then leave them out or add them into the keywords META tag.

Wrapping it all up

The most important rule to increasing your page rank is to write good informative content for your website. Don’t be fooled into thinking that SEO techniques will push your site’s traffic to number 1 in its category. Instead focus on writing purposeful content for your audience and the rest will take care of itself.

, , , ,

Remembering the correct command prompts across different platforms can be confusing. To make things easier on myself I have compiled a short list of the commands and their options that are commonly used to create and delete files and folder in DOS. Including how to delete a folder and all its contents.

How to Delete a file

Deleting files from the DOS prompt is done by the del command. To use it you simply specify the single file you want deleted or the wild card pattern to match files against.

Deleting a Single file

del example.txt

Deleting all .jpg files

del *.jpg

In addition to deleting files in a single directory you can delete files from subfolders as well by using the /s switch. This option says to delete files matching the pattern in a ll subfolders. I highly suggest using this switch only if you know what you are doing.

Deleting all files within a folder and its subfolders

del  /s testFolder/*

The most important thing to remember is that the del command will delete files but will leave the folder structure intact.

How to delete Folders

There are two commands available to delete folders rd and rmdir. Both commands perform the same functionality so you can use which ever comes more natural to you. To delete a folder you will first have to delete its contents.

Deleting a Single Folder

rd myFolder
rmdir myFolder

To delete a folder as well as its contents including files and sub folders you will use the /s switch. If you don’t want to have the command line prompt you with are you sure you want to delete each file you can also use the /q switch. This causes the command to run in quiet mode meaning it will assume y for all the prompts.

Deleting a Folder and all its contents

rd /s /q myFolder
rmdir /s /q myFolder

Creating a new Directory or Folder

To create a folder you use the md or mkdir commands. When running the command simply type the name of the folder you want to create. If you want to create a sub folder as well simply pass in the full path and it will create the parent folders if they don’t exist.

Creating a single Folder

md myFolder
mkdir myFolder

Creating a sub Folder and its parents

md myFolder/Folder2/Folder3
mkdir myFolder/Folder2/Folder3

To be sure creating and deleting files and folders is a command that by far is done mostly through the Operation Systems User Interface. However there are times that working from the dos prompt (command line) is a necessity, in those case simply remember del, rd, and md commands.

, , , , , , ,

Ever wonder how you can persist data for a user in your Flash SWF applications? The simple answer is to use a local SharedObject or as it is commonly known the Flash Cookie. These objects are stored to the users local machine much like a cookie with it’s access limited to current domain and optional path, allowing you to save data that can be shared between different SWFs on your site if you so desire.

Shared Objects storage on the local computer

The Shared Object is stored in an .sol file on the users local computer. These files are stored in the Flash Player directory of the users profile and much like cookies are accessible only to by SWFs with the same domain and local path. The default size limitation for a .sol file is usually around 100Kb however this can be modified by the user and if more space is required they will have to approve it. Don’t worry to much about that part right now we’ll touch on that later.

Obtaining a Shared Object

To create or obtain an existing Shared Object we utilize the getLocal method. This method returns the Shared Object with the given name and path for the domain. If for some reason the Shared Object could not be created then an error will be thrown, some possible reasons for this would be that 3rd party storage is disabled.

Understanding the getLocal function

The getLocal function takes up to 3 parameters with only the name being required.

  • name: The identifier of the Shared Object
  • localPath: The full or partial path to the swf that determines where it is stored locally. By setting this to a generic path that is used by multiple swfs in your domain you can have saved data from one swf be read and used by another swf.
  • secure: Boolean identifying if the SWF is accessible only over HTTPS. If true then an HTTP request to the SWF will not allow the Shared Object to be created or read from. (default value is FALSE)

To create/obtain a Shared Object with a specified name you would use the following code:

try {
    var sharedObj:SharedObject = SharedObject.getLocal( "user_settings" );
} catch(e:Error) {
    // Shared Object could not be created
}

If we wanted to create/obtain a Shared Object that had a defined localPath and was accessible only by HTTPS then we would use the following code:

try {
    var sharedObj:SharedObject = SharedObject.getLocal( "user_settings", "/shared/", true );
} catch(e:Error) {
    // Shared Object could not be created
}

Reading and Writing data to the Shared Object

Now that you have instantiated your local Shared Object you will want to store and read that data you wish to persist across usages of your SWF application. Access of the data stored in the Shared Object is done through the data property. You simply specify the named property and set a value to it or output it into another variable or parameter.

To illustrate lets assume we want to save the Users high score into the Shared Object.

sharedObj.data.high_score = 1000;

If we wanted to read the saved high_score value then we simply would access it the same way:

var highScore = sharedObj.data.high_score;

Write Immediately with Flush

When the SWF application quits or exits is when the Shared Object would normally get written to the local file system. However if you want to save your data immediately you can utilize the flush method. This method will cause the data to be written immediately. If the write could not be performed an error will be thrown, or if the size of the Shared Object is above the the users defined maximum size then they will be presented with a dialog box to confirm/deny the additional space. If this occurs then a pending status will be returned and you will need to listen for a netStatus event to determine if the save was successful. Please note that the dialog boxes minimum size is 215 x 138 and your SWF will need to be larger then this to display the full dialog box.

Sample basic example

try {
    var status:String = sharedObj.flush();
    if( status == SharedObjectFlushStatus.FLUSHED ) {
        // Successfull
    }
} catch(e:Error) {
    // Shared Object could not be saved
}

If your Shared Object has a maximum size that it can grow to you can pass this value to the flush value. What this does is make it so that Flash will ask for the inputted amount of space so that it doesn’t ask with each save as the size of the Shared Object increases.

try {
    var status:String = sharedObj.flush( 4096 );
    if( status == SharedObjectFlushStatus.FLUSHED ) {
        // Successful
    }
} catch(e:Error) {
    // Shared Object could not be saved
}

Erasing your Shared Object

To delete your Shared Object you utilize the clear method. When called it empties the data in your SharedObject instance and will also delete the file saved on the user’s local computer.

sharedObj.clear();

Saving user data in Flash is a relatively simply task. Although you may not utilize them in all applications they can come in handy with games and user settings. Allowing you to present the user with a consistent experience in that application as well as other applications in that domain.

Resources

, , , , , , , , , ,

FlashVars are a great way to pass information to your swf. The most common usage is to pass along the root path to use when looking up resources or configuration information. These parameters can then be accessed within your application by the use of ActionScript and are a great way to increase the customization and re-usability of your code.

To start things off lets look at a few possible ways to pass FlashVars into your SWF application. The first way is by use of the Object or EMBED tags. This is only for those developers still out there that haven’t started utilizing SWFObject to embed their SWFs into the page.

Object Tag Example

When using the Object tag you need to specify a param with the name FLashVars that has its values set to name=value pairs with an & separating the variables.

<PARAM NAME=FlashVars VALUE="base-url=www.mdbitz.com/&mode=single"/>

Embed Tag Example

To use FlashVars in an EMBED tag you simply define a FLASHVARS attribute with the values set the same as in the object tag.

<EMBED href="mySWF.swf" FlashVars="base-url=www.mdbitz.com/&mode=single" ></EMBED>

Most Flash Developers do not however still utilize the the Object and Embed Tags to display SWFs instead they most often use JavaScript libraries like SWFObject that handle the code output.

SWFObject Example

With SWFObject you simply pass an associated array that contains named values into your embedSWF call, and the library will take care of outputting the correct code.

var flashvars = {baseURL: "www.mdbitz.com", mode: "single"};
		var params = {wmode: "transparent", allowFullScreen: "false"};
		var attributes = {};
		swfobject.embedSWF("mySWF.swf", "mySWF", "800", "200", "9.0.0", "flash/expressInstall.swf", flashvars, params, attributes);

Obtaining the FlashVars in ActionScript 3

Now that you are passing variables into your Flash application you need to obtain and use those values. In ActionScript 3 we need to get the parameters out of the root LoaderInfo object.

var paramObj:Object = null
try {
    paramObj = LoaderInfo(this.root.loaderInfo).parameters;
} catch (error:Error) {
    // Flash Vars could not be loaded
}

The parameters property of the LoaderInfo class returns an Object that can be treated similar to an associated array. All you need to do to get your named properties is:

var baseURL = paramObj["baseURL"];

That is all there is to using FlashVars. You will find that once you start using them it will greatly enhance the re-usability of your applications and also reduce deployment issues from path errors.

, , , , , ,