Posts

Showing posts from 2009

Flex -- The Singleton Design Pattern

One of the design patterns in the Object-Oriented-Programming languages like ActionScript 3.0. The Singleton design pattern is used to limit a class to one instance and provide global access to that instance Common examples include classes that manage resources that are intrinsically singular such as 1. Selection focus 2. Navigation history 3. Window depth 4. Class that manages the state of user?s cursor 5. Class that loads application setting from an XML file and provide access to those settings Essential features of Singleton class ? A private static property that holds the single instance of the class ? A public static method that provides access to the single instance if it?s created and creates the single instance if it hasn?t been created yet ? A way of restricting access to instantiating the class ActionScript 3 does not support private or protected constructors preventing common implementation techniques for the singleton pattern. By using a static initializer and a check in th...

SQL Injection Test

Ok here you go a quick test to see if you are vunerable to sql injection. In your login form use Username: admin'-- This will cause the sql query to comment out everything after the username is passed. example: * SELECT * FROM members WHERE username = 'admin'--' AND password = 'password' This is going to log you as admin user, because rest of the SQL query will be ignored.

Flex Auto Complete / Predictive Text Example

Ok this basically works with a change event placed on a textInput or other component you can modify it to your needs Now create a variable that will be your dictionary this can come from a query or whatever --> private var xDictionary:Array = ["Alan","Brad","Cindy","Dana","Elizabeth","Frank"]; private var regexp:RegExp; private function xTestInput():void{ var i:int = 0; var temp:Array = xDictionary.filter(filter); txInput.text = temp[0]; } private function filter(element:*,index:int,arr:Array):Boolean{ regexp = new RegExp(txInput.text); return (regexp.test(element as String)); } And in your MXML -->

Optimizing SQL Queries

From simple expressions to string expressions or even in joins there are some simple yet effective things you can do to make you SQL Queries run a bit faster. Simple Expression Example: A good rule of thumb when using where/and to query for values put the most restrictive ones first. SELECT * FROM Students WHERE sex = ‘female’ AND grade = ‘A’ The above query would run faster if you checked for the A first because less students will have an Another words SELECT * FROM Students WHERE grade = ‘A’ AND sex = ‘female’ Another Example: SELECT COUNT(*) FROM Students Might not be as fast if student_ID is the primary key SELECT COUNT(student_ID) FROM Students For Strings minimize using % or _ in LIKE statements another words don’t use LIKE ‘%Tom%’ if LIKE ‘Tom%’ is all you really need. Carefully chosen indexes speed up SQL queries without slowing updates too much. Almost all tables can benefit from an index, and experience has shown that the "ideal index" is almost never the primary ke...

Creat a ColdFusion collection with the cfcollection tag

On occasion a developer may not have access to ColdFusion Administrator, for example, if you use a virtual hosting company. If you want your ColdFusion application to be able to create, delete, and maintain a collection you will need to use the cfcollection tag. The following will show you how to create a collection index it then index it to include a MS Access database this code works great for use with a serch function for your shopping cart site. You will need to create an Access database with a table named Products and you will need the following fields ItemID, ProductID, ProductName, BriefDescription, Details.   To create a simple collection form page: Create a ColdFusion page with the following content: [html] [head] [title]Collection Creation Input Form[/title] [/head] [body] [h2]Specify a collection[/h2] [form action="collection_action.cfm" method="POST"] [!--- The following can be changed to your needs ---]   [p]Collecti...

Calling a flex Remote Object with Actionscript

Our .AS file   package model {       import mx.rpc.remoting.RemoteObject;       import mx.core.Application;       public dynamic class ResultsRO extends RemoteObject       {                 private var _appUrl:String;             private var domainUrl:String;             private var app:Application = Application.application as Application;             public function ResultsRO (destination:String= null )             {                   super (destination);  ...

Nice Flex export to Excel ActionScript file

THE ACTION SCRIPT // ActionScript file       import mx.controls.Alert;       import mx.core.UIComponent;       import mx.core.Container;       import mx.events.ItemClickEvent;       import mx.utils.ObjectProxy;       import flash.errors.*;       import flash.events.*;       import flash.external.*;                  import flash.net.URLLoader;       import flash.net.URLVariables;       import flash.net.URLRequest;       import mx.controls.DataGrid;                 //The location of the excel export file       ...