radiant.matrix

A collection of thoughts and links from the minds of geeks

Entries Comments



Category: Technology


Wow, Win 7 looks a lot like a Mac

30 October, 2008 (11:28) | Technology | By: radiantmatrix

Via DaringFireball: A first look at Windows 7 from ArsTechnica.

I’m struck by how many of the ‘new and innovative features’ are essentially re-implementations of OS X features.

  • The new taskbar is an awful lot like the Dock
  • The “peek” feature is a lot like Exposé (yeah, a different interface to it, but substantially similar)
  • New Explorer features mimic the Finder pretty well
  • New Tray features ‘common tasks like switching wireless networks’: similar to OS X’s menu-bar functionality

Not that MS might not improve the implementation of some of these things (not holding my breath on that, but…), but there’s nothing truly “brave” or “innovative” here. Sad, because MS has some great engineers — I wonder what holds them back.

The right way to code SQL statements

12 September, 2008 (11:06) | Technology | By: radiantmatrix

SQL statements in code should always be written using binding. There are a very few edge cases where this is not possible: if you encounter one, you need to re-think your approach so that you don’t need to use that edge case (e.g. perhaps a stored proc or trigger is more appropriate).

SQL statements in Python

Wrong way:

curs = connection.cursor()
curs.execute("SELECT col1, col2 FROM atable WHERE id = " + id_var)
curs.execute("""
    UPDATE atable SET col1 = %s
    WHERE id = %d" % (new_value, id_var))
""")

Both statements make SQL injection easy. What if idvar or newvalue were ; SELECT * FROM atable ; --?

The first .execute uses string concatenation, the second uses string formatting to accomplish the same goal.

Right way:

curs = connection.cursor()
curs.execute(
    "SELECT col1, col2 FROM atable WHERE id = ?", 
    (id_var)
)
curs.execute(
    "UPDATE atable SET col1 = ? WHERE id = ?", 
    (new_value, id_var)
)

This way, the database driver uses binding to pass the values where the ‘?’ characters are in the statement. The driver takes care of checking for safety and proper datatypes, quoting and escaping characters as needed. This entirely avoids SQL injection.

SQL statements in Perl

Wrong way: $sth = $dbh->prepare(”SELECT col1, col2 FROM atable where id = $id_var”); $sth->execute();

Avoid variable substitution, concatenation, and sprintf.

Right way:

$sth = $dbh->prepare('SELECT col1, col2 FROM atable where id = ?');
$sth->execute( $id_var );

Use the ‘?’ prototype in the prepare call, then execute with the variables, in order, to bind to the prototypes.

FrogLight: 30-year LED “lightbulb”

4 September, 2008 (15:31) | Technology | By: radiantmatrix

Frog Design has come up with a concept for a 30-year LED-based “lightbulb” that is dim-able, draws less energy than a CFL, and fits in any standard incandescent light socket. They say they’re trying to bring it to market, but I wasn’t able to find any information on timing of that release or what it will cost.

HOWTO install DBD::mysql on Cygwin

20 May, 2008 (09:48) | Quotation, Random Thoughts, Technology | By: radiantmatrix

Based on the official instructions from the DBD::mysql maintainer, here’s a fast summary for people who know their way around compiling and installing software on Unix-like systems:

  1. Download the MySQL Linux sources
  2. Unpack them to your cygwin home directory:

    $ cd ~ ; tar xzf mysql-5.0.51b.tar.gz

  3. Configure and install:

    $ cd mysql-5.0.51b
    $ ./configure && make && make install

  4. Check the above for errors. If there are none, continue.

  5. Download the DBD::mysql distribution from CPAN
  6. Unpack this into your cygwin home directory:

    $ cd ~ ; tar xzf DBD-mysql-4.007.tar.gz

  7. Build the makefile

    $ cd DBD-mysql-4.007
    $ perl Makefile.PL --mysqlconfig=/usr/local/bin/mysqlconfig –testhost=127.0.0.1

  8. Make, and optionally make test — note that ‘make test’ may produce some failures, but DBD::mysql may still work

    $ make
    optional: $ make test
    $ make install

  9. You’re done!

Enjoy!

Hey Safefunds: “Non-standard” does not mean “more secure”

24 April, 2008 (12:19) | Technology | By: radiantmatrix

There’s a company called Safefunds, which is essentially a transaction-escrow service. Since you are giving them potentially large sums of money, and quite literally banking on their security to protect the transaction, the following statement on their site is somewhat troubling:

The Safefunds’ patent pending system uses a non-standard computer protocol making it more secure from “hacker” attacks. — Safefunds’ page on security

How do I know that their “non-standard” protocol is any better than “standard” ones? I can certainly think of standard protocols that are plenty secure enough for me to trust my transactions to — but how do I know if theirs is better or worse?

I don’t think I’ll be giving them any of my money.