Tips 4 developers by me :)

July 6, 2010

Blog updates. New stuff coming!

Filed under: Uncategorized — fehro @ 12:52 am

Sorry for the big delay in responses and new posts. I’ve recently made a complete career change from full time to contracting (which is awesome!) and I have a whole bunch of new stuff on the way.

I’ve also been busy training and learning all the new .net 4 stuff and studying for a multitude of Microsoft Certifications to further advance my career.

May 11, 2009

MS SQL Date formats. How they work and how to change them

Filed under: Uncategorized — fehro @ 1:54 am

MS SQL keeps it’s date formats on a user account level not on the local machine or server regional settings as some other resources may have you believe. To change the setting from US to say British (I’m in Australia so I do not want US dates) run the following in a new query.

ALTER LOGIN sa WITH DEFAULT_LANGUAGE = British

Alternatively log in to the server and under Security -> Logins locate the account you are using, in it’s properties will be a field called ‘Default Language’, change that to ‘British English’

It is generally best not to change these settings on a server as a good programmer should have code that converts this date at run time, however our data access layer lacks this feature thus making this a requirement.

March 17, 2009

Adjusting a parent SWF’s speed to match that of the loaded child SWF

Filed under: Uncategorized — fehro @ 5:17 am

A custom ad loader was developed by my company to handle a large quantity of paid ads across out websites. I discovered a problem in that if a client submitted a movie at a different frame rate than our parent loader’s own frame rate their ads played either too slowly or too quickly.

This is easily fixed with the following Action Script.

private function LoadComplete(e:Event):void {
    [...]
    stage.frameRate = e.target.frameRate;
    [...]
}

So after the LoadComplete event is called the stage (parent movie) frame rate is adjusted to match that of the loaded child movie. Be sure to set it back to your default when required (i.e. when the loading animation for the next ad kicks in).

December 9, 2008

RFC822 email validation in C#

Filed under: Uncategorized — fehro @ 4:19 am

StringBuilder pattern = new StringBuilder();
pattern.Append(“(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t]”);
pattern.Append(“)+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:”);
pattern.Append(“\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(“);
pattern.Append(“?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ “);
pattern.Append(“\\t]))*\”(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\”);
pattern.Append(“31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\”);
pattern.Append(“](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+”);
pattern.Append(“(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:”);
pattern.Append(“(?:\\r\\n)?[ \\t])*))*|(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z”);
pattern.Append(“|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)”);
pattern.Append(“?[ \\t])*)*\\<(?:(?:\\r\\n)?[ \\t])*(?:@(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\”);
pattern.Append(“r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[“);
pattern.Append(” \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)”);
pattern.Append(“?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t]”);
pattern.Append(“)*))*(?:,@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[“);
pattern.Append(” \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*”);
pattern.Append(“)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t]”);
pattern.Append(“)+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)”);
pattern.Append(“*:(?:(?:\\r\\n)?[ \\t])*)?(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+”);
pattern.Append(“|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r”);
pattern.Append(“\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:”);
pattern.Append(“\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t”);
pattern.Append(“]))*\”(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31″);
pattern.Append(“]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](“);
pattern.Append(“?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?”);
pattern.Append(“:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?”);
pattern.Append(“:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*)|(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?”);
pattern.Append(“:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?”);
pattern.Append(“[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*)*:(?:(?:\\r\\n)?[ \\t])*(?:(?:(?:[^()<>@,;:\\\\\”.\\[\\] “);
pattern.Append(“0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|”);
pattern.Append(“\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>”);
pattern.Append(“@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\””);
pattern.Append(“(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t]”);
pattern.Append(“)*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\”);
pattern.Append(“\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?”);
pattern.Append(“:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[“);
pattern.Append(“\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*|(?:[^()<>@,;:\\\\\”.\\[\\] 0-“);
pattern.Append(“\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(“);
pattern.Append(“?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*)*\\<(?:(?:\\r\\n)?[ \\t])*(?:@(?:[^()<>@,;”);
pattern.Append(“:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([“);
pattern.Append(“^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\””);
pattern.Append(“.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\”);
pattern.Append(“]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*(?:,@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\”);
pattern.Append(“[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\”);
pattern.Append(“r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] “);
pattern.Append(“0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]”);
pattern.Append(“|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)*:(?:(?:\\r\\n)?[ \\t])*)?(?:[^()<>@,;:\\\\\”.\\[\\] \”);
pattern.Append(“00-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\”);
pattern.Append(“.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,”);
pattern.Append(“;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?”);
pattern.Append(“:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*))*@(?:(?:\\r\\n)?[ \\t])*”);
pattern.Append(“(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.”);
pattern.Append(“\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t])*(?:[“);
pattern.Append(“^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]”);
pattern.Append(“]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(?:\\r\\n)?[ \\t])*)(?:,\\s*(“);
pattern.Append(“?:(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\”);
pattern.Append(“\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(“);
pattern.Append(“?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[“);
pattern.Append(“\\[\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t”);
pattern.Append(“])*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t”);
pattern.Append(“])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?”);
pattern.Append(“:\\.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|”);
pattern.Append(“\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*|(?:”);
pattern.Append(“[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\”);
pattern.Append(“]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*)*\\<(?:(?:\\r\\n)”);
pattern.Append(“?[ \\t])*(?:@(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\””);
pattern.Append(“()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)”);
pattern.Append(“?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>”);
pattern.Append(“@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*(?:,@(?:(?:\\r\\n)?[“);
pattern.Append(” \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,”);
pattern.Append(“;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:\\r\\n)?[ \\t]”);
pattern.Append(“)*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\”);
pattern.Append(“\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*)*:(?:(?:\\r\\n)?[ \\t])*)?”);
pattern.Append(“(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.”);
pattern.Append(“\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])*)(?:\\.(?:(?:”);
pattern.Append(“\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z|(?=[\\[“);
pattern.Append(“\”()<>@,;:\\\\\”.\\[\\]]))|\”(?:[^\\\”\\r\\\\]|\\\\.|(?:(?:\\r\\n)?[ \\t]))*\”(?:(?:\\r\\n)?[ \\t])”);
pattern.Append(“*))*@(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])”);
pattern.Append(“+|\\Z|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*)(?:\\”);
pattern.Append(“.(?:(?:\\r\\n)?[ \\t])*(?:[^()<>@,;:\\\\\”.\\[\\] 0-\31]+(?:(?:(?:\\r\\n)?[ \\t])+|\\Z”);
pattern.Append(“|(?=[\\[\”()<>@,;:\\\\\”.\\[\\]]))|\\[([^\\[\\]\\r\\\\]|\\\\.)*\\](?:(?:\\r\\n)?[ \\t])*))*\\>(?:(“);
pattern.Append(“?:\\r\\n)?[ \\t])*))*)?;\\s*)”);

Match m = Regex.Match(emailaddress, pattern.ToString());
return m.Success; 

 

 

October 2, 2008

Using code cross control in C#

Filed under: Uncategorized — fehro @ 6:43 am

Imagine the following situation. You have a masterpage with a side user control to house your page tabs and a controlplaceholder showing input fields to modify some data on each tab. Now the placeholder also has a next and previous button and you want the data to autosave when either of theses buttons are clicked. Easy enough but what if we want this data to also save when you click a different tab on the left menu?

The way to do this is with ‘delegates’. A delegate is like a reference to a function or variable that can be stored inside a variable itself (kind of like a pointer in C++) So what we do is create a delegate in the left menu of our ‘save’ function in the contentplaceholder.

In your left control, add the following:


Delegate m_savedelegate;
public Delegate SaveDelegate
{
    set { m_savedelegate = value ; }
}

Now in your contentplaceholder page add the following:

public delegate void SaveDataDelegate();

And in the PageLoad event of your contentplaceholder page for example:

protected void Page_Load(object sender, EventArgs e){
    SaveDataDelegate savedatadelegate = new SaveDataDelegate(SaveSurveyPage);
    UserControl usercontrol = ((UserControl)Master.FindControl("plcLeft_control")); 

    Type myType = usercontrol.GetType();

    PropertyInfo controlproperty;
    controlproperty = usercontrol.GetType().GetProperty("SaveDelegate");
    controlproperty.SetValue(usercontrol, savedatadelegate, null);
}
 

Note: plcLeft_control is the id of my usercontrol on the masterpage and SaveSurveyPage is the function in my contentplaceholderpage to save the tab data.

Now you can invoke this delegate like so in your usercontrol (I called mine on the SelectedNodeChanged event of a treeview).

 
protected void trvQuestions_SelectedNodeChanged(object sender, EventArgs e){
     m_savedelegate.DynamicInvoke();
     Response.Redirect(((TreeView)sender).SelectedNode.Value);
}

August 18, 2008

Installing Plone 3.1.4 in a windows environment

Filed under: Uncategorized — fehro @ 7:52 am

If like me you prefer developing in a Windows Environment then here is some useful information getting Plone setup properly.

  1. Download Plone 3.1.4 here.
  2. Run and install, the password you provide is to login to your ZMI (i.e. your root account).
  3. Open your command prompt (Start -> Run and type cmd) and navigate to your Plone install directory and execute the following command:
    Python\Scripts\easy_install.exe -U ZopeSkel

    It will download a bunch of items and complete.

  4. Now run:
    Python\Scripts\paster create -t plone3_buildout YOURINSTANCENAME

     Replace YOURINSTANCENAME with the name of the instance you would like to create.

  5. Answer the questions and wait for it to complete (ensure you set debug mode to true only if this is your development environment).
  6. Now CD to your new instance directory and run:
    ..\python\python.exe bootstrap.py

    Wait for it to complete.

  7. Finally run:
    bin\buildout

    Wait for it to complete.

You have now installed you Plone instance. You can run it as an instance by installing it with

bin\instance install

and starting with:

bin\instance start

or as a console with:

bin\instance console

for development purposes.

Blog at WordPress.com.