2009
04.27

FOUC (or Flash of Unstyled Contents) is where the page loads the boring normal text for a split second each page before it gets replaced with the proper text.  Which looks a bit crap.

Luckily the fix is ridiculously simple.  This usually occurs in IE, but this may fix it for other browsers also. Simply put:

<script type=”text/javascript”>
Cufon.now(); <!– avoid the fouc in ie with cufon –>
</script>

Somewhere just before the closing </body> tag and the problem is solved.  If only everything in life was that simple :)

1 comment

2009
04.27

I see this quite a lot, for example if you want to pull the value of the column `name` from a table using the ID:

$sql = “SELECT `name` FROM `tablename` WHERE `id`=’45′”;
$res = mysql_query ($sql);
$row = mysql_fetch_assoc ($res);
$name = $row['name'];

But if you use list () and mysql_fetch_array () you can trim it down somewhat…

$sql = “SELECT `name` FROM `tablename` WHERE `id`=’45′”;
$res = mysql_query ($sql);
list ($name) = mysql_fetch_array ($res);

Since mysql_fetch_array returns a numerically indexed list, and list () pulls the values of the resulting array to the specified variables, you don’t need to get the return and then extract the value from the array since you can do it all in one line.

In fact I generally abstract this whole block out to a function such as:

function sql_get_element ($table, $column, $value, $search=’id’)
{
$value = mysql_real_escape_string ($value);
$sql = “SELECT `$column` FROM `$table` WHERE `$search`=’$value’ LIMIT 1″;
$res = mysql_query ($sql);
list ($name) = mysql_fetch_array ($res);
return $name;
}

So if you wanted to fetch the name from a table with a specific ID you could do this:

$name = sql_get_element (‘tablename’, ‘name’, 45);

Thus cutting out a lot of the nonsense SQL calls, plus you centralise the data escaping to help ward off those troublesome SQL injection exploits.

Add Comment

2009
04.23

Linux and it’s promoters have no interest in impartiality, in being ‘fair and balanced’, of fact checking and of getting to the bottom of something rather than going for dramatic impact, truth be damned.

Any fact or comment that paints Microsoft or any company that is on the designated ‘evil’ list in a bad light is jumped on voraciously, and outright lies and fabrications circle for months and are largely applauded by other members of the community when they are told.  Truth is secondary to a good bashing.

Anything that paints Linux or FOSS in a bad light is automatically seen as being lies, astroturf and anyone who holds an opinion that doesn’t agree with the above is labelled a troll, a shill, and is accused of being paid by MS to spread lies.  In the early days of Ubuntu I was chased out of town by zealots with pitchforks for daring to suggest having a bootsplash. Defend the program at all costs.  Anyone who doesn’t agree with us (that’s 99.5% of the computing world) is obviously an uneducated idiot as the problem is certainly not with Linux – it’s FOSS thus perfect.

I’ve pretty much given up going to Slashdot for this very reason.  It’s pretty much guaranteed that any thread that mentions MS (and a large percentage of those that don’t) will have at least a few ‘chair throwing’ jokes, not to mention the oh-so-humerous  ‘but does it run Vista’ joke, and the bulk of the other comments from people living in a fantasy land where Linux is taking over the desktop, and where all software will soon be open source.  I’ve even seen a start of the ‘But will it run Windows 7*’ jokes.

Here’s some news for you, if you have made the same joke THOUSANDS OF TIMES (seriously that many!) it loses it’s punch.  It is no longer funny.  Sure one joke out of every 200 or so is genuinely amusing, but now it’s just partisan MS bashing disguised as ‘humour’.  Hell, you still see the constant BSOD jokes despite the only time I have ever seen one in the last 5+ years was due to hardware failure.  It’s 2009, and the Linux community are still making jokes about a problem that hasn’t existed for years from a kernel that’s nearly 15 years old.

Basically, if you grasp at any reason to attack your opponent, and will defend your cause no matter the validity of the criticism then your opinion is  no longer worth anything as you have sacrificed the truth, reality and essentially your credibility as you are no longer interested in facts and what is true – only in pushing an agenda.

I don’t use Linux and do you want to know why?  Of course you don’t as I am wrong, or misinformed, or I just do not ‘understand’ and require having things explained to me like I am three years old**.  As is everyone who doesn’t use Linux.

Zero attempt is made to ask the most important question: “Why don’t you use Linux?” as it is automatically assumed any problem is with the user, not the software.  After all 0.5% of the population can’t be wrong.  And nobody in the community has a problem.  It’s not like pretty much everyone with any critical opinions left years ago.  Is it?

* Windows 7 is going to ruin Linux.  It’s everything Vista should have been.  Of course if you live in Linux fantasy la-la land it’s nothing more than a Vista service pack.

* * I am 29 years old, I work as a programmer and yes, I do understand what the command line is as it is all you really had on an 8086.

*** I am not American so I am not really biased.  If I was American I’d be a fiscal Conservative (and a traditional Republican).  That being said the Neocons are a total joke and the complete antithesis of what the party should be about (Hint: It’s not about God, Guns and Gays).  This isn’t about politics though so I won’t get into it!

5 comments

2009
04.07

Speeding up Cufón

If you are not aware, Cufón is a font replacement system, similar to sIFR, with the advantage that it uses only Javascript rather than and Flash (As well as Javascript).

Don’t get me wrong, load times are not that horrible at all – in fact if you have only a couple of transformed elements on the page it’s nearly instant, but it does slow down in proportion to the amount of transformed items so if you do everything it’ll basically grind to a halt for a few seconds every time the page refreshes.  This is obviously not really acceptable.

The problem I was having was that there are about 10 main menu items with about 10 sub menus each.  This means it takes about 2 seconds to load in IE (it’s the slowest, unsurprisingly).  The plan was to transform only the top level items and then only do the dropdowns (it’s an accordion but that shouldn’t make a difference) when the user hovers on the top level item, rather than doing everything on page load.

Here’s the code, assuming that the main <ul> is in a <div> called #products-menu, and it follows the standard ul li a format, with the sub ul’s nested in the li’s.

    <script type="text/javascript">
        $(document).ready(function(){
            // Dynamically load cufon on drop downs
            $('#products-menu>ul>li').hover(function() {
                $(this).addClass('cufon');
                Cufon.replace('.cufon ul li a');
                $(this).removeClass('cufon');
            });
        });
        // Load Cufon on top level items only
        Cufon.replace('#products-menu>ul>li>a');
    </script>

It also uses jQuery, so you’ll need to include that in the header also.  Anyway I hope this helps someone!

Add Comment