Categories
CSS PHP WordPress

Changing the font of code blocks with geshi syntax highlighter

By default, geshi-derived syntax highlighters use a serif font to display code blocks.  Many people find serif fonts less clear than the visually simpler sans-serif fonts.

A good choice is Lucida Console.  Consolas is even better because it has a slashed zero, which is easier to distinguish from the capital letter "O", though not as many computers have Consolas installed. To account for this, list the fonts in order of preference, the browser will use the first one that it can display.

To change the default font for code blocks, find the geshi code folder (usually under plugins), open geshi.php and look for the following code:

1
2
3
4
5
    /**
     * The overall style for this code block
     * @var string
     */
    var $overall_style = 'font-family:monospace;';

And modify is as seen here. Note that two word font names must be quoted, and the quote marks may need to be escaped, as seen below;

1
2
3
4
5
    /**
     * The overall style for this code block
     * @var string
     */
    var $overall_style = 'font-family:Consolas, \'Lucida Console\', monospace;';
Categories
Database MySQL

Adding a UNIQUE constraint to a database column

Sometimes we may need to make a column unique in a database table.  For instance we can't have two employees with the same employees with the same employee number or pension plan id.

To prevent this, run a query like the following to place a constraint on the attribute or attributes;

ALTER TABLE Employee ADD UNIQUE (EmpID, PensionID)

There are many other uses of the ALTER command that will help us modify our existing tables.  See this article for more useful applications of the ALTER command.

Categories
Database MySQL

Pulling database values in multiple formats

When we pull a value from MySQL or another database, there's nothing stopping us from pulling the same value in different ways within the same query.

For instance, say we want to pull dates in their raw format, which is suitable for sorting but may not be the most useful formatting for display.  We might find a format like "Jan-13-2009 · Wed" more useful for display purposes, though it's useless for sorting on.

We could massage the data in PHP to alter the date format, but it would be much faster and more efficient to let the database server deal with that.  You'll also have cleaner PHP code if you deliver attributes from your database server ready to use.

Here's an example of a query that pulls all values (the asterisk) followed by additional formats of two dates.  Note that the additional formats are manipulations of data which have already been pulled in their raw format by the asterisk in the select statement.  Note also that I've adopted the convention of  prepending "fmt_" to these derived attributes.

1
2
3
4
5
SELECT
  *,
  DATE_FORMAT(date_received,'%Y-%b-%d · %a') AS fmt_date_received,
  DATE_FORMAT(date_dispatched,'%Y-%b-%d · %a') AS fmt_date_dispatched,
FROM packages

You're now free to use date_received and fmt_date_received independently throughout your code.

Categories
Uncategorized

Going directly to a specific page in a PDF file

When accessing a PDF file through a web browser, it's possible to go to a specific page by adding a parameter to the URL.

www.mysite.ca/docs/mydoc.pdf#page=100

This is great for bookmarking a specific page in a PDF.  Unfortunately, it doesn't seem to work for accessing a PDF from the command line.

Keep in mind that the counter goes from the cover page, so to reach page 100 you may to increase the number to account for the cover page, table of contents, and other content wihch comes before the page labelled "page 1".

Now isn't that handy?

Categories
Graphics

Vector Conversion for Graphics

(Excerpted from Jake Ludington's Digital Lifestyle, 2007-11-08 www.jakeludington.com)

LineTracer – Vector Conversion
If you're a great freehand artist and want to get your drawings on your computer, scanning is an obvious solution. Scanning only gets you a gigantic image file of your drawing; it doesn't get you a way to work directly with your drawing. To manipulate your drawing you need to convert it to a vector format first. LineTracer offers a free solution for taking hand drawn sketches and converts them to EPS format vector images. You scan your drawing at 200-300dpi, then import that scanned image into LineTracer. The simple interface supports cleaning up the drawings you made before conversion, by defining all the tracing points of your lines. The EPS file is then compatible with applications like Adobe Photoshop Elements, Adobe Illustrator, and Flash. [Windows 2k/XP/Vista $0.00]
Download