Archive for September, 2010

Using custom fonts with CSS

Since starting at my new place the design team have been developing website designs for me to implement. In the past the designers I have worked with have been web designers and so have accepted that you can only use a few fonts, verdana, arial, times, etc. However the new team are graphic designers and as such love using custom fonts in the layouts.

Previously I would have just picked the closest web safe font and used that but being new and wanting to create a good impression, I thought I’d do some research and find out if it was possible. Turns out it is. The first thing you need to do is get your font in the correct format. Depending on what format your font is in you should be able to convert it to the two types you need, TTF (True Type Font) and EOF (Embedded Open Type) using the excellent Online Font Converter website. Once done all you need is to use some CSS in your stylesheet.

@font-face
{
font-family: "font_name";
src: url('font_name.eot');
src: local(font_name), url('font_name.ttf') format('opentype');
}

All you then need to do is declare it for the various CSS definitions:

body,p
{
font-family: font_name, Verdana, Arial, Helvetica, sans-serif;
}

And there you go. I’ve tested this on my Mac using Firefox and Safari, Windows using IE8 and my iPhone. It didn’t work on the iPhone but using the above example, defaulted back to Verdana which is close to the test font I was using, Myriad-Pro. As long as you choose a similar looking font to specify after your custom font in the font-family you should be OK.

Using COUNT in the WHERE clause of MySQL statements

I’ve got a huge report for the Medicology MTI that has been running extremely slow due to the amount of data and queries. I’ve been trying to speed it up to make accessing and analysing the results easier.

The users have to answer 56 questions to complete the survey. This means that most for the calculations there’s currently an “if” statement to check they completed all 56 questions and then skip the row of the mysql result set if they haven’t.

I haven’t checked if it will make it quicker but surely checking the amount of answers completed in the SQL query will result in less data and a speed increase. The problem is that the COUNT(*) I’m using to get the number of answers is in the SELECT part of the statement which is executed after the WHERE clause, which is where it needs to be:

SELECT id, COUNT(id) AS cnt FROM answers WHERE cnt>=56 GROUP BY id

The above returns an error. What you need to do is modify the query as follows:

SELECT id, COUNT(id) AS cnt FROM answers WHERE cnt>=56 GROUP BY id HAVING cnt>=56

That will return the required result set.

Hibernate a Mac Book Pro

As mentioned previously I’ve started working for a new company which exclusively uses Macs and I’ve got to say, they are superior to PCs in every way I’ve found so far.

I’ve had to get used to bits but on the whole I’m never ever going to back to a PC or laptop. Today’s challenge for the Mac was how to get my MacBook Pro to hibernate. I used to it on my Windows laptop all the time – it was invaluable. Being able to press the power button and wait for it to turn off then press the power button again and have all your documents and applications still running was an invaluable time saver.

So I wondered if the same was possible on the Mac and did some Googling. It turns out something similar is possible – it’s called Safe Sleep. With any Mac Book Pro made in the last 5 years or so all you have to do is close the lid and it puts it into Safe Sleep. Then you just open the lid again later, press any key and it restores to the state it was in. Perfect.

Since I’ve got a background in electronic engineering it’s obvious that this would require some power consumption and therefore had a limited time span to work. I asked my boss, Phil, if he’d done it and he said he’d unplugged his, closed the lid and taken it home for a three day weekend and when he came back in on Tuesday it still had about 50% power left. Perfect.

It’s only been two weeks but let’s see if there’s anything that the Mac doesn’t do better. Well worth the extra costs.