Archive

Archive for August, 2009

Server Motherboard Meltdown

August 28th, 2009 No comments

MSI P4N Diamond MotherboardUnfortunately the server Bytearray is hosted on had a relatively major meltdown. The heatsink that sits on top of the northbridge chipset on the motherboard has a small aggressive fan… which completely melted, hence the northbridge chipset got a little hot and toasted it’s self. Removing the heatsink from the motherboard was quite difficult as the thermal pasted and turned into “concrete”. Once off there were clear signs of scorching around the chip, fortunately the CPU and RAM are still fully functional as are the disks in the machine so no data was lost :)

I guess I got 3-4 years good server use out of my MSI P4N Diamond Motherboard. Originally the motherboard was replaced with an Asus board due to stability issues during over-clocking (motherboard was originally used for gaming). Overall not overly impressed with the motherboard, I should have stuck with my instinct and brought Asus originally.

The replacement board is an Asus P5N-D nForce 750i (fanless), which offered the path of least resistance in terms of a quick fix.

Asus P5N-DToasted Fan

Melted Fan

Toasted Northbridge

Northbridge

Categories: General Tags: , , ,

Perl: Unbuffered File Logging Module

August 21st, 2009 No comments

This an old Perl module I dug up which is quite a handy, there is no file write buffering so if you do a tail -f on the log file while it’s writing you can see real time what is going into the log file.


Logger Module

package Logger;
# Logger.pm
#---------------------------------------------------
#
# Basic module to log to file
#
#---------------------------------------------------
# Constructor for logger module

sub new{
    my $class = shift;
    my $args = shift;
    
    # Default is to create a new logfile, NOT to append to it
    my $append = 0;
    if (defined($args->{append})){
		$append = $args->{append};
    }

    my $disable = 0;
    if (defined($args->{disable})){
		$disable = $args->{disable};
    }
    
    my $self = { filename => $args->{filename},
		 		 append => $append,
		 		 line_no => 0,
		 		 disable => $disable
	     };
    
    bless($self,$class);
    $self->_init();
}

#---------------------------------------------------
# Initialise the log file

sub _init{
    my $self = shift;
    if (!$self->{disable}){
		$filename = $self->{filename};
	
		if ($self->{append}){
	    	# Open a file for appending in write mode 
	    	open(LOG,">> $filename");
	    	select LOG; 
	    	$| = 1;
	    	select STDOUT;
	    	$self->{log_handle} = *LOG;
		}
		else{
	    	# Create a new file in write mode
	    	open(LOG,"> $filename");
	    	select LOG; 
	    	$| = 1;
	    	select STDOUT;
	    	$self->{log_handle} = *LOG;
		}
    }
    
    return $self; 
}

#---------------------------------------------------
# Add to the log file

sub add{
    my $self = shift;
    if (!$self->{disable}){
		my $str = shift;
	
		my $handle = $self->{log_handle};
		my $timestamp = localtime(time);
		my $line_no = ++$self->{line_no};
		print $handle "[$timestamp#$line_no]: " . $str . "\n"; 
    }
}

#---------------------------------------------------
# Close log file

sub close{
    my $self = shift;
    if (!$self->{disable}){
		my $handle = $self->{log_handle};
		close($handle);
    }
}

#---------------------------------------------------
1;


Logger Module Usage

#!/usr/bin/perl -w

use strict;
use lib 'MyPerlLibDir/';
use Logger;

my $myLogString = 'This text will appear in the log file';

my $loggerObj = new Logger({ append => 0, disable => 0, filename => 'MyLogFile.txt'  });
$loggerObj->add($myLogString);
$loggerObj->close();

Flex: View Source Code

August 21st, 2009 No comments

If you want to publish your application source code by right-clicking on the application SWF and you’re using FlexBuilder then from the top menu bar select:

  • File->Export->Release Build
  • Right click you project folder and select “Export”

Alternatively if you want to format the source code your self then you can set the “viewSourceURL” attribute in the Application tag which should enable the “View Source” option on the right-click menu. And of course when you click “View Source” you should be navigated to the value of “viewSourceURL”.

For more information: www.adobe.com

Flex: High Definition MP4 with Flex VideoDisplay

August 21st, 2009 No comments

HD Firstly I just like to say it’s not really true “High Definition” but rather “Higher Definition”. However if you are are looking to improve playback via the Flex VideoDisplay component then make sure you encode your mp4 (which is in fact not really an mp4) using the H264 codec, sometimes referred to as AVC or AVC1. It’s not really a big issue as there are plenty of free H264 encoders around, like www.h264encoder.com

You ‘ll soon know if the mp4 is encoded correctly as you’ll probably get a black square box with no video and only audio if the mp4 is not compatible.

Flex: ExternalInterface – The Flex Javascript Bridge

August 21st, 2009 No comments

It is really very easy to gain access to Javascript via Flex, the Javascript API is made available via flash.external.ExternalInterface flex class. There are a couple of methods you can use, you can either:

  • Make calls to pre-existing functions (yours or exists JS ones) using the flex ExternalInterface.call function where the argument to call is a string which represents the normal Javascript function invocation.
  • Defined a whole Javascript function inside Flex as a string and pass that string to call, ExternalInterface.call will then automatically execute the function.

There is of course no real use in passing in arguments if you are pre-defining the Javascript function as a string because you can just use those value during the generation of the string.

Below is an example of creating and fetching a Javascript cookie, you never know it might come in handy :)

// ************************ START EXAMPLE *****************************

/**
 * Flex class ExternalInterface does all the magic
 */

import flash.external.ExternalInterface;

public function createCookie(name:String,value:String,days:int=0):void{

    var js:String = "function createCookie(){" +
                     "var expires = '';" +

    "if (" + days + " > 0){" +
        "var date = new Date();" +
        "date.setTime(date.getTime()+(" + days + "*24*60*60*1000));" +
        "expires = 'expires = ' + date.toGMTString();" +
        "}" +
        "document.cookie = '" + name + "=" + value + "; expires=' + expires + '; path=/';" +
    "}";
 
    ExternalInterface.call(js);

}

public function getCookie(cookieName:String):String {

   var r:String = "";

    var search:String = cookieName + "=";
    var js:String = "function getCookie(){return document.cookie;}";
    var cookieVariable:String = ExternalInterface.call(js).toString();

    if (cookieVariable.length > 0) {
        var offset:int = cookieVariable.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            var end:int = cookieVariable.indexOf(";", offset);
            if (end == -1){
                end = cookieVariable.length;
            }
            r = unescape(cookieVariable.substring(offset, end));
        }
    }

    return r;

}

// ************************ END EXAMPLE *****************************