Mac Mini Server NAS

October 21, 2009 – 8:15 am by Dave Elkan

I’ve been pretty unimpressed with Apple’s recent hardware upgrades. I’ve not found myself the slightest bit excited by anything since the iPhone (which I still can’t justify).

Until now.

The new Mac Mini Server is totally sweet.

I’m a big fan of having a small, energy efficient, redundant system running 24/7. This new machine would fit so easily into my (an no doubt many other people’s) home network and allow me to retire my DNS-323.

The DNS-323, bless it’s heart, is an amazing little machine, but it’s lack of memory and processing power leave it hanging in the dark ages when it comes to things like databases and webservers (it just can’t run them). The mac Mini on the other hand would be more up to the task than my current iMac!

Damn the mortgage! Bring on the Mac Mini Server.

Maximizing Javascript Minimization and Readability

October 18, 2009 – 1:43 pm by Dave Elkan

By using a combination of the YUI Compressor and the Revealing Module Pattern you can maximise the effect of minimisation and, as a bonus, improve code readability.

The YUI Compressor renames local variable names and references to a single character. It can do this as it knows these variables cannot be accessed outside their function. On the other hand, it does not rename window level variables or any variable or function reference using dot notation.

Maximising Minification

An unminifiable object.

var anObject = {
 
    property: "value",
 
    doSomething: function() {
        alert(this.property);
    },
 
    init: function() {
        this.doSomething();
    }
}

Looks like this minified (with whitespace restored).

var anObject = {
 
  property:"value",
 
  doSomething: function() {
    alert(this.property)
  },
 
  init: function() {
    this.doSomething()
  }
};

Minification ratio (before whitespace restoration): 0.67 (168 to 113 bytes).

This method of defining an object does not minify at all and offers no real benefit in performance, readability or functionality. In fact, seeing as the property and function names do not minify, the coder feels obliged to name properties with the shortest names possible. More on that below.

By utilising the Revealing Module Pattern we can create highly minifiable code.

var anObject = function() {
 
    var property = "value";
 
    function doSomething() {
        alert(property);
    }
 
    function init() {
        doSomething();
    }
};

Becomes (white space restored):

var anObject = function() {
 
    var a = "value";
 
    function b() {
        alert(a)
    }
 
    function c() {
        b()
    }
};

Minification ratio (before whitespace restoration): 0.46 (172 to 79 bytes).

That’s a fair bit better!

Variable naming

Historically, to keep file-size down, Javascript variables are named in the smallest possible way limiting readability and clarity. i.e.

var el = document.createElement("strong");

Badly named variables such as this make it hard to determine the contents and purpose of the variable.

The following well named example clearly shows that the variable stores a strong element used for a headline.

var strongHeadlineElement = document.createElement("strong");

By taking advantage of the way the YUI Compressor works you can utilise the Revealing Module Pattern to make your variable names as long (and readable) as you want. i.e.

var revealingModulePatternExample = function() {
 
    // Make all properties local variables
    var 
 
    // Define private properties
    _descriptivePropertyName = 1,
    _anotherDescriptivePropertyName = 2;
 
    // Defined private methods.
    function _addAndDisplayDescriptiveProperties() {
        var descriptivePropertySum = _descriptivePropertyName + _anotherDescriptivePropertyName;
        return descriptivePropertySum;
    }
 
    function _execute() {
        _addAndDisplayDescriptiveProperties();
    }
 
    // Return public accessors
    return {
        execute: _execute
    }
};

When minified becomes (whitespace restored):

var revealingModulePatternExample = function() {
 
    var 
 
    b = 1,
    c = 2;
 
    function d() {
        var e = b + c;
        return e;
    }
 
    function a() {
        d()
    }
 
    return {
        execute: a
    }
};

EDIT – Changed function construction in last example from
a = function() {};
to
function a() {}
As it saves two bytes (when minified) per function. Sweet!

Recipe: Tortillas

February 23, 2009 – 7:48 am by Dave Elkan

A simple recipe for a quick dinner.

Tortilas are a very basic type of bread. They are made by poor people in poor countries by the tonne every day. However in the first world, Tortillas are bloody expensive. At industrial scales these things should cost 10c each, but you’ll pay a damn-sight more than that if you go to the super market to buy them. Maybe it’s the plastic packaging and/or the transport, but in 2009 a packet of 6 can cost as much as $4!

Ingredients (10-12 Tortillas):
1 Cup water
3 Cups flour (Substitute 1 cup for corn meal if you have some)
3/4 tsp salt
2 tsp baking soda.

I usually whack the ingredients in the bread machine on the knead cycle and go for a swim, but if you don’t have a beach or bread machine handy, feel free to knead it by hand until it gains a shiny consistency.

Once kneaded let the dough rest for 10 minutes before cutting into 10-12 equal segments. On a lightly floured bench, roll each out into your desired size. I tend to put extra effort in to make them as thin as possible. These Tortillas are very strong and stretchy, so there’s no need to make them thicker for the sake of strength.
Use a rolling pin to roll on the bench and carefully flip and turn 90 degrees before repeating. I find letting the dough stick to the bench a little(by not adding too much flour) makes the job easier.

Once they’re all rolled, heat up your (preferably non-stick) frying pan and pop a tortilla on, pressing down with a spatula. I usually wait till I’ve flipped them once before pressing down. This prevents the spatula from sticking. Once both sides are hot, the tortilla will start expanding. It’s your job to play whack-a-mole to prevent this from getting out of hand.

Once the tortila is golden, place it inside a plastic bag lined with a tea towel to steam as you cook the others. Take the bag straight to the table and enjoy stuffing them full of your fav ingredients. You can really get into the stuffing bit as as I said before, they’re damn strong!

Enjoy!

Recipe: Fresh pasta the easy way.

February 23, 2009 – 7:36 am by Dave Elkan

I battled for years to make fresh pasta by hand, until Jamie Oliver showed me the easy way. Up until that point I thought he was just an empty celebrity chef!

Ingredients per person:

1 x egg at room temperature.
100g plain white flour.

Limiting yourself to four people’s worth of ingredients at a time, place the flour and eggs into a food processor and mix with the sharp blade until the flour and eggs reach a cous cous-like consistency.
Tap out the mixture onto bench-top and knead until formed into a solid ball.
Cut the ball into two or three portions and roll through your pasta machines rollers on the widest setting, folding the dough each time you pass them through. For each portion, do this around 6 – 10 times or until the dough reaches a shiny, springy texture. Aim to have square edges. I achieve this by turning the folded dough 90 degrees before rolling again.
Lay the rolled dough segments under a tea towel until all are ready to cut.

If you’re lucky like me, you’ll have your significant other cooking sauce whilst you make the pasta. If this is not the case, you may wish to cut the pasta before you start making the sauce.

To cut the pasta, roll the dough to the desired thickness. All machines are different, but my Atlas number, I generally go to #5 for fettuccine or #6 for spaghetti. Roll out one sheet at a time and cut it in half if it is too long to handle easily. Super long pasta is more hassle than it’s worth.

Dave making pasta

Dave making pasta

Place eash cut sheet on a single tea towel and sprinkle with a little flour. If the pasta sticks now it’s no biggie as it’ll come undone when it goes into the boiling water.

Ensure you have ample water to boil the pasta. Fresh pasta tends to float when you cook it, so a big pot is best. Add SALT to the water. This prevents the pasta from sticking. Oil is not necessary.

Once all sheets are complete and the water is boiling, place the pasta into the water and stir to separate. Ensure the pasta rotates during cooking. If your pot is too small or the pasta is too long, then it will simply float and the top parts will not cook as quickly as the bottom. If this is the case, make sure you stir it frequently.

Fresh pasta takes much less time to cook than dried packet pasta. Ensure you sample as you go to ensure you don’t over-cook it.

Enjoy!

837 billion australian dollars

September 23, 2008 – 9:04 am by Dave Elkan

The US federal reserve bank has decided to put together a ‘package’ of $USD700 billion to help prevent the greed of stock brokers destroying the modern world. That is, of course, with special clauses which will ensure that they have a controlling hold on it’s future.

Going back a couple of decades we’d find people talking of money as a tangible thing, “backed by gold” they’d say. Whatever happened to that? I don’t know about you, but I’d prefer something tangible backing my investments, be it property or some other sort of physical object which is of value to another person other than myself.

So how much gold is $AUD837 billion (on the 23rd of September, 2008) ?

The current value of gold per kilogram is $34316.42.

$837,000,000,000 / $34,316.42

=

24,390,656.10 kilograms (orĀ 24,390 tonnes) of gold.

What would you do with 24,390 tonnes of gold? Is there 24,390 tonnes of gold available?