Posts

Showing posts from May, 2009

MRAM - Magnetoresistive Random Access Memory

Every now and then I like to catch up on the latest developments in current and emerging technologies. Reading through various blogs and journals I recently came across a relatively new type of memory called Magnetoresistive Random Access Memory, or MRAM for short.
To see where this fits and and why this is an exciting development, you need to consider current solid state memory devices of which there are two main types: the volatile Random Access Memory used in all computing devices (i.e. RAM) and non-volatile memory comonly used in USB Flash drives, memory-cards and even solid-state hard disks.
I'm not an expert on the subject matter so I'll describe this the way I understand it. Basically RAM is very, very fast to read and write. Data is stored in what can be thought of as millions of tiny capacitors inside a small chip. A full capacitor represents a one whereas an empty capacitor represents a zero. If left alone however, capacitors lose their charge over time. So to keep the…

Windows 7 Slow Transfer/Copy Speed

I just tried copying a folder from a DVD to a second partition in Windows 7 RC (7100) and it's taking forever...

The directory contains ~42,000 files, mostly just a few kilobytes in size. Total size of content being copied is 2.96GB. The file copy operation has been going on for almost two hours now and says it has 45 minutes remaining... Transfer speed is averaging ~400KB/s. The target hard-drive is a 7200rpm SATA with 32MB cache. The DVD drive is a brand new Pioneer SATA. All IDE/ATA channels have UDMA enabled in device manager.
At first I thought it might be a hardware issue (and I suppose it's still possible) but doing a Google search shows slow transfer speeds have been a very common problem in Windows Vista which never got resolved, and I've found a few people reporting the same thing in W7RC, so I'm not alone.
For reference, my rig is an AMD AM3 810 Quad-Core with 4GB DDR2 RAM.
The problem seems to be caused by some operation that executes on each file being copied,…

Large Fibonacci Numbers in Java

The Fibonacci Sequence is a series of numbers that increases at a highly exponential rate. Implementing a Fibonacci algorithm is a classic computer science programming exercise as it touches on many important concepts. The standard implementation involves a recursive function and looks something like this:static int fib(int n) {
return n <= 2 ? 1 : fib(n-1) + fib(n-2);
}
Whilst this works and is all very exciting at first, the implementation introduces two classic programming errors: Integer Overflow: The Fibonacci sequence expands rapidly and will quickly throw an integer overflow error if trying to compute for numbers greater than 46 (i.e. fib(47) will throw an error or cause an overflow).Recursive Blowout: Notice that for numbers greater than two, each function call makes two recursive calls. This leads to an exponential number of recursive function calls which will cause a stack overflow for large numbers (this depends on the execution environment). In Java, the first problem can be…

Threading, Parallelism, Multi-Core CPUs and Windows 7

As a software developer, I don't normally get the chance to stay up to date with all the latest hardware developments. I'm not into the overclocking scene either (I know enough to build a system but not enough to tweak frequency multipliers and voltage levels) and I usually only brush-up on my knowledge whenever I put together a new rig (I had no idea the HTPC acronym even existed two weeks ago, and I was suprised to see mini-ITX boards and even some picos going mainstream).
Nevertheless, putting together a new general-purpose desktop PC got me thinking about what CPU I should invest in: a Dual-Core with a higher clock speed and more L2 cache per core, or a more expensive Quad-Core with a lower clock speed and less cache... The CPU market used to be much simpler (or more deceptive) 5 years ago, you'd just go for the highest clock speed you could get your hands on. Those in the know knew that clock-speeds were only part of the story, L1/L2/L3 cache and bus-speeds also made a…

The picoPSU - a HTPC builder's best friend

I recently bought the AYWUN A1-8989 case for my new mini-ITX HTPC build. I chose this case primarily because it supports a full size 3.5" internal hard drive and a full size 5.25" internal optical drive, which means I can stick in cheap parts rather than having to fork out crazy prices for a slim-drive blueray, etc. The case also comes with an internal 150W PSU and only costs $89 (AU), which is very cheap compared with some of the big-name alternatives.
The case is actually quite good: small enough to place next to a PS3 under the TV, stylish enough to impress and roomy enough to fit in a mini-ITX board with a standard-sized cooler, full-size PCI-e card and the full-size drives. The PSU however is somewhat loud. No louder than a standard ATX power-supply, but a little disappointing for a HTPC build where silent operation is desirable. 
I started looking for some alternative silent PSUs I could install in this case, but finding one that fit was proving difficult. The PSU is a C…

PC Hardware Hunting

I've been buying a few parts last couple of weeks for two new systems that I'm building and I thought I'd take this opportunity to share my experiences with computer chop-shops in Sydney, Australia.
Whenever I begin researching a new build, I typically start out on either IJK (formally umart),auspcmarket or the infamous MSY. These sites give me a good idea of current local market prices and availability for the various components. After reading some reviews and performance benchmarks, I start putting together a spreadsheet with all the parts I want along with price and location.
MSY is the McDonalds of computer parts in Australia. They have the lowest price average across all parts, so if you're looking for the best bargain, you can't go too wrong here. Having said that though, the MSY service leaves a lot to be desired. Their online website is terrible, with only a highly condensed PDF parts list to go on. You need to know exactly what you're looking for and do …

Recover Images from Corrupt Memory Card

Image
Earlier today I was faced with recovering data from a corrupt Memory Stick Pro card. The camera (a Sony Cybershot) was unable to preview a large number of files and when connecting to a computer, many of the file names and directory names were garbled.
Some image files could still be opened, but around half could not. What I intended to do was copy everything to a local directory on my PC, then use some freeware tools to try and recover as much as possible. Unfortunately, many of the files refused to copy across using Windows Explorer. This made a manual backup very difficult as Windows Explorer will simply give up on the first error when copying a large list. Manually copying every 'healthy' file was out of the question (thousands of images).
I instead decided to write a simple Java program that would recurse through the memory card and copy as many files as it could to a local folder, logging and ignoring any errors. A few minutes later, my first version of the script was comp…

Installing Windows 7 RC on Lenovo X300

Having installed Windows RC (Build 7100) on my home desktop, and being happy with what I've seen, I thought I'd give it a try on my Lenovo X300 as well.
I popped in the DVD, rebooted my PC and started the installer. Just after loading all the files and asking for your region settings, the following error prompt came up:
"A required CD/DVD drive device driver is missing. If you have a driver floppy disk, CD, DVD, or USB flash drive, please insert it now.
Note: If the Windows installation media is in the CD/DVD drive, you can safely remove it for this step."
The immediate irony is that Windows managed to boot from the DVD and load all its files just fine, why does it need a driver all of a sudden? I imagine the reason for that is due to different operating modes, i.e. the installer loader probably uses some form of low-level DOS driver whereas the installation environment is running as a different OS with different abstraction layers and a different driver architecture...

Very Basic JavaScript xml2array

The following JavaScript code is a very basic function for converting an XmlHttp.responseXml object into a simple array:
function xml2array(xmlDoc) {
var node = new Object();

if(xmlDoc.nodeName == "#document") {
node[xmlDoc.childNodes[0].nodeName] = xml2array(xmlDoc.childNodes[0]); //assume always only 1 child node of a document
} else {
if(xmlDoc.childNodes.length == 0) { //no children and no value, set to null
node = null;
} else if(xmlDoc.childNodes.length == 1 && xmlDoc.childNodes[0].nodeName == "#text"){
node = xmlDoc.childNodes[0].nodeValue;
} else {
var hasAttribute = false;
for(var i = 0; i < xmlDoc.childNodes.length; i++) {
var child = xmlDoc.childNodes[i];
if(child.attributes && child.attributes.length) {
hasAttribute = true;
break;
}
}

if(hasAttribute) { //nodes in this series have attri…

YUI Dialogs

Image
The standard JavaScript alert() and confirm() dialog boxes look so 1995... (although it hasn't stopped Google from using them in Blogger, Gmail and Docs).
For those who don't remember what they look like, here are two examples:

YUI (Yahoo User Ineterface) to the rescue! This Ajax/JavaScript library comes with a few nicely styled visual components, including support for modal dialogs.
The following functions may be used to display YUI styled alerts:
function yuiErrorAlert(title, message) {
return yuiAlert(title, message, YAHOO.widget.SimpleDialog.ICON_BLOCK);
}

function yuiWarnAlert(title, message) {
return yuiAlert(title, message, YAHOO.widget.SimpleDialog.ICON_WARN);
}

function yuiInfoAlert(title, message) {
return yuiAlert(title, message, YAHOO.widget.SimpleDialog.ICON_INFO);
}

function yuiAlert(title, message, icon) {
modalDialog = new YAHOO.widget.SimpleDialog(title,
{ width: "300px",
fixedcenter: true,
modal:true,
visible: false,
draggable: true,
close: false,
text: message,
icon: i…

Redirect with POST parameters

I came across a requirement recently where I wanted to redirect a user to a new page and pass along a few parameters. The Zend Framework redirector helper gotoSimple() function takes an array of parameters as the 4th argument, so this seemed fairly easy at first. The parameters however are simply appended to the end of the redirect URL. I didn't want this to happen as I was redirecting users to a dynamic error page. So, naively, I stared looking for a way to force the redirect to use POST parameters...
This of course is not possible if you think about how a redirect works. The Zend gotoSimple function simply sets the HTTP location header to the specified action-controller URL, and appends the parameters to the URL if supplied. This header is sent to the client as a simple string. When a client browser encounters the location header in a response, it performs a GET on the location URL. There is no way to tell the client to perform a POST instead (the URL is just a simple query stri…

Zend Controller Action Helper

Zend Controller Action Helpers allow you to abstract common functionality into classes that are callable from any controller action. I won't go into detail as to why you'd want to use this, except to say that it's sometimes more flexible than extending your own abstract controllers.

Looking through the Zend Framework documentation and some online tutorials, there seems to be a little confusion on exactly how to initialize these. This post aims to clear up any confusions and help get you started as quickly as possible.

Step 1: Create a directory somewhere in your application folder, for example /application/helpers.
Step 2: Create a file called HelloWorld.php and save it in the helpers directory, i.e. /application/helpers/HelloWorld.php
Step 3: Write the source code of the HelloWorld file as below. Pay special attention to the class name: <?php
class MyHelpers_HelloWorld extends Zend_Controller_Action_Helper_Abstract {
public function sayHello($name) {
return 'Hello' . …

Quest for the ultimate HTPC

When it comes to home entertainment we're now spoilt for choice in media formats. Whilst traditional broadcast TV and radio are still around, we now have game consoles, music CDs, DVDs, Blue-Ray, streaming online radio, online video, digital image libraries, music libraries, etc. Whilst the variety is all well and good, it can become frustrating when you can't access a particular content source the way you want. That is, you download a video file from the internet and want to watch it on you big-screen TV, what do you do?Convert is to mpeg2 format and burn it to a DVD to watch in DVD player?Convert it to a specific DivX version that your DVD player may support?Try to stick it on a USB and play it directly on the PS3, if supported?Try to transcode and stream it using TVersity or similar to your PS3/XBox?Use Xbox XBCM (if you have an Xbox that is)?There's many options possible, but the option most suitable to you depends on what's at hand. In my case I have a PS3, which …

Windows 7, MCE & WinFast DTV1000

I recently installed Windows 7 RC on my home desktop to see what all the fuss is about. Microsoft is offering a one-year unrestricted license-free evaluation of Windows 7 Ultimate for everyone to download and try straight from their site. And I do suggest downloading it straight from Microsoft as there have been reports of hijaked torrents floating around (Windows image is pre-loaded with spyware/trojans). 
The installation process was very smooth and Microsoft has made some much needed improvements compared to XP. Namely, you just answer a few simple questions on startup (like picking a partition, choosing to format, etc.) then the installer runs unattended until done. I'm not sure if Vista is the same, I've never bothered with it, but it means I don't need to muck around with nLite/vLite to make unattended disks.
Once I was up and running I went over to the control panel to check what devices were not installed. Disappointingly, my Gigabyte wireless card was undetected and…

YUI Tips - Destroy!

I've been using YUI and Ajax techniques quite extensively in my latest project. Overall the YUI library is great, especially when paired with your own wrapper helper functions to show dialogs, busy prompts, etc.

One use-case that's common in my design is to use YAHOO.util.Connect to asynchronously download mixed HTML/CSS/JavaScript content and dynamically add it to the DOM. This gives a lot of flexibility and allows for very modular design as each module is a self-contained unit of logic (HMTL/JS/PHP).

Whilst this works surprisingly well in general, I have come across some peculiarities:
If you're dynamically retrieving a MenuBar module (markup + JS initialization), you can only insert this in a div in your DOM once. If you dump the div and try to retrieve and reinitialize the MenuBar again, it won't work. You need to hold a reference to the JS MenuBar variable in your code and call the destroy() method before dumping the div and re-initializing.It's a good idea to do…

Dynamic JavaScript via Ajax and innerHTML

I may be shot down for this for bad design or evil JavaScript usage, but nevertheless...consider the following architecture:You have a complex page that drives a lot of functionality via Ajax.Clicking on a 'Create User' link for example will perform an async call on a back-end create-user HTML widget and display this content in a div panel.The create-user widget is self-contained, i.e. it's a mixture of HTML and JavaScript.The JS portion of create-user is responsible for driving validation logic and perhaps making other Ajax calls. So how do you implement this? Simply retrieving the mixed create-user content and sticking it in a div's innerHTML property won't work as the retrieved content is just text and the <script> tags won't be parsed by the browser or added to the DOM, meaning all the JS is inaccessible. To get things working you need to do this yourself as follows:

//ajax call to get create-user content as rsp
div = document.getElementById('targetD…

2-Stage Ajax File Download with YUI

Consider the following scenario:You create a page with a Download PDF link.When the user clicks the link, this invokes a back-end process that first generates the pdf then streams it back to the client.The PDF generation step can take 10 seconds or more, during which time your page will appear slow and unresponsive to the user.A better solution would be: User clicks Download PDF link.User is shown a 'Please wait, generating PDF' modal dialog while your back-end process is busy.Once the PDF is available, the modal dialog disappears and the browser Download File dialog appears. This can be achieved quite easily with some simple Ajax. The basic process is to split the download task into two discrete operations. The first will generate the actual PDF file and store it on the back-end server, returning to the user a filename, file hash or some other ticket id. The second operation takes this ticket id and streams the file content to the user's browser. The file is downloaded usin…