Modeling Chess using SQL
Saturday, July 28th, 2007Here's an interesting use of SQL: SQLChess – A tutorial on thinking in sets.

Here's an interesting use of SQL: SQLChess – A tutorial on thinking in sets.
I write a lot of documentation for various articles and projects. Usually, I'll use DocBook for writing that documentation. DocBook is an SGML/XML dialect for writing articles, books and other writings. It's pretty extensive, and it can do a lot. It can export to LaTeX, HTML, PDF and a variety of other formats. But it's also somewhat tedious to write, with the many and long tag names.
Some time ago I searched for an alternative to DocBook. Something more simple. My wish was for something as simple to write as, say, Wikipedia's Wiki syntax.
During my quest for the ultimate document markup tool, I came across reStructuredText; a simple text-based format used by (amongst others) Python programs to put document markup in Python source code. Though reStructuredText is pretty good, I found it a bit limiting. It doesn't seem to support exporting to PDF (unless you want to pass the generated HTML through a HTML2PDF converter) and its syntax is kind of limited. Another problem is the fact that it's not easy to distinguish different headings because they all use a bunch of '='s, '-'s, '~', etc surrounding the headings.
Just the other day I found AsciiDoc. AsciiDoc is very similar to reStructuredText, but it supports more formats. It can convert to HTML, PDF en DocBook (which in turn can be converted to many other formats). It also supports Wikipedia-like '== heading ==' headings. It's very readable. It's also a lot faster than DocBook.
Here's a little example of a document marked up with AsciiDoc:
PHLite User Guide ================= Ferry Boender v0.1, Jul 2007 About ----- This document serves as the User Guide for PHLite v0.1. Introduction ------------ PHLite is a lightweight, no-nonse, easy to use web development framework for PHP. Most of the currently big frameworks focus on Web2.0, design patterns, REST-fullness, MVC and other 'hip' paradigms. Often, they are too strict in enforcing these methods and therefor restrict the developer. Getting Started --------------- This chapter should help you get started using PHLite. === Requirements === PHLite requires: * PHP 5.1.0 or higher === Basics ===
Very clear, isn't it? The example above produces this HTML document. And, yes, it can also generate automatic Table of Contents for documents (including HTML), something that seems to be missing from many documentation generators.
Here are some true facts about Microsoft Vista:
Amazingly enough, I've never had the need to find duplicate rows in a table before. But in this case, I somehow forgot to add a key to a particular table in a database and, naturally, duplicates where accidentally inserted. Of course you'll want to put a key on the table, but first you'll have to remove the duplicate rows. As is usually the case, it's pretty easy using SQL.
Suppose you have the following data in a table:
firstname lastname Age ---------------------------- Jane Doe 21 John Doe 25 John Smith 43 Jane Doe 55 Jane Smith 22 John Doe 19 Jane Doe 21
The superkey in the above table is (for example) <firstname, lastname>. To find duplicates for this superkey, you can use the following query:
SELECT COUNT(*), firstname, lastname FROM Address GROUP BY firstname, lastname HAVING COUNT(*) > 1
This will give the following results:
COUNT(*) firstname lastname --------------------------------- 2 John Doe 3 Jane Doe
This means the combination 'John' + 'Doe' appears two times and 'Jane' + 'Doe' appears thrice. People with a little SQL experience will find this straightforward, but I'll explain anyway:
We select a "COUNT(*)" in order to count all the rows, plus we select firstname and lastname fields so we can see which are actually the duplicates. We use the fields firstname and lastname on the GROUP BY clause because that's our superkey. GROUP BY will tell aggregate functions (COUNT(), SUM(), etc) in the SELECT clause that it should count grouped by certain fields, not just all the results returned. Basically, it counts all the unique values of a concatenation of firstname + lastname. The HAVING COUNT(*) > 1 is purely to weed out stuff that's not duplicate.
I'm not quite sure how to automatically delete duplicates while leaving one in place though ;-)
Update: I do now! Here's how to delete duplicates in place: SQL: Remove duplicte rows

The little blue-yellow fish (a Spanish Hogfish) in the picture on the right looks like it doesn't have long to live, doesn't it?
But nothing's farther from the truth. This fish is hard at work. The fish surrounding it (called Grunts, apparently) are inviting, or rather begging, the Spanish Hogfish to clean them. This is happening at a so called 'Cleaning station'. A cleaning station is where fish go when they need a good scrubbing. Kind of a car-wash for fish, where they'll get cleaned of bacteria, dead skin and parasites. Even fish that are normally enemies of the cleaning fish go to the cleaning stations to get themselves cleaned by their, otherwise, enemies.
These cleaning stations are beneficial for both the cleaner and the fish being cleaned. One gets parasites and other stuff cleaned and the other gets free food and some rest at the 'neutral zone'.
Apparently, they even provide services to humans.
More information:
When writing a document, you'll probably want to refer to another section in the document. For instance: "See chapter 5 for more information". However, when you insert a new chapter before chapter 5, you'll have to read through your entire document and update every mentioning of "Chapter 5" to "Chapter 6". Tedious and prone to error. But you don't have to do it by hand! There's a way in OpenOffice Writer to refer to another chapter so that when the document changes, you can easily update all references:
A reference to the bookmark will now be inserted at the current location. The text that will be displayed depends on what you chose under Format.
If changes in your document occur that have an impact on what's displayed at the reference, you can update all references by choosing Tools → Update → Update All.
Firefox 2.x has a built in session manager. When the browser is restarted after a crash, it re-opens every window/tab that was open before the crash. This behaviour is very annoying to me, as I never properly close Firefox, but always just halt my machine.
If you want to disable session managing in Firefox, type about:config in the URL bar. Next search for the 'browser.sessionstore.enabled' key and double click it so it's set to 'false'.
If you're running the Tab Mix Plus extension, you'll also want to disable its session management in the Tab Mix Plus options dialog (Tools → Tab Mix Plus Options → Sessions → Disable 'Enable Session Manager').
Interesting review of a book:
Misquoting Jesus: The Story Behind Who Changed the Bible and Why: A review.
Thus, the KJV [King James Version of the bible] consists of Jesus' words twice refracted through the prism of translation. Second, Erasmus's Greek New Testament was based on handwritten copies of copies of copies of copies, etc., going back over a millennium, and today is considered one of the poorer Greek New Testaments.
[...]
Many people have a vague notion that all the original biblical texts are preserved in vaults somewhere, and translators work from those original texts. Unfortunately, that isn't the case. The earliest surviving versions of the gospels are handwritten copies dating from centuries after the original texts were written. Also, we don't just have a single version of each gospel; we have many versions, and even more fragments. The trouble is, none of the versions agree with each other. As Ehrman puts it, there are more points of disagreement between manuscripts than there are words in the Gospels.
[...]
Also, we may have a document from the fourth century and one from the eighth; but the latter might have been copied from a second-century document, making it closer to the original.
And yet, some religious people base their entire faith on the Bible, and regularly use it to deprive other people of the right to live their life the way they want to. Mankind's lack of intellect sometimes really amazes me.
Thanks Mafkees. :-)
Gravitronic lets us know that a patch that implements namespaces in PHP has now been committed.
The last time I took a look at the roadmap for PHP6, it was still undecided if namespaces would make the cut. Seems like they have now (although they could still revert the commit, like they did with namespaces in PHP5 if I recall correctly).
The main idea of the proposal is to attack one target and this target only – the Super_Long_Really_Annoying_Enormous_Class_Names that lately became the bane of big project developer. All other things are considered secondary to this goal – no attempt to make some different include model, packaging model, etc.
– Namespaces – can we keep it simple?
Some examples of how it currently works:
Defining namespaces
<?php namespace Zend::DB; class Connection { } function connect() { }
Referring by full namespace name
<?php require 'Zend/Db/Connection.php'; $x = new Zend::DB::Connection; Zend::DB::connect(); ?>
Importing
<?php require 'Zend/Db/Connection.php'; import Zend::DB; import Zend::DB::Connection as DbConnection; $x = new Zend::DB::Connection(); $y = new DB::connection(); $z = new DbConnection(); DB::connect(); ?>
Though I can't quite put my finger on it, it somehow still seems like a bolt-on to me. Ah well, better than nothing, right?