|
|
Saturday, July 12. 2008
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-- Richard Cook, read on FSM
Sunday, July 6. 2008
[...] as we all know, premature optimization is the root of all evil.
-- from a cocoa-dev email
amen!
Wednesday, July 2. 2008
Windows Vista demand is so strong that Dell is offering a Windows Vista Bonus to its customers.
What is it?
It's the option to have Windows XP pre-installed, of course!
Friday, June 20. 2008
If you're using LogMiner to analyse your Apache/IIS logs, here's an easy recipe to be notified of sites that send visitors your way.
First, let's define a Pg/PLSQL function to extract the new referrers:
CREATE TYPE new_referrer AS ( site_id int8, site_name text, referrer text, hits int );
CREATE OR REPLACE FUNCTION get_new_referrers() RETURNS SETOF new_referrer AS $body$ DECLARE rec new_referrer; lastRef int8; BEGIN
SELECT INTO lastRef CAST( value AS int8 ) FROM catalog WHERE name = 'LastReferrer';
IF lastRef IS NULL THEN INSERT INTO catalog ( name, value ) VALUES ( 'LastReferrer', 0 ); lastRef := 0; END IF;
FOR rec IN EXECUTE 'SELECT s.id AS site_id, s.name AS site_name, r.referrer, tmp.hits ' || 'FROM ( ' || ' SELECT site, referrer, COUNT(*) AS hits ' || ' FROM accesses ' || ' WHERE referrer > ' || lastRef || ' GROUP BY site, referrer ' || ') tmp ' || 'JOIN sites s ON s.id = tmp.site ' || 'JOIN referrers r ON tmp.referrer = r.id ' || 'WHERE r.extern = true ' || 'ORDER BY s.name, tmp.hits DESC, r.referrer' LOOP
RETURN NEXT rec;
END LOOP;
UPDATE catalog SET value = ( SELECT MAX( id ) FROM referrers ) WHERE name = 'LastReferrer';
RETURN; END; $body$ LANGUAGE plpgsql;
Then, a little PHP script to run the query and format the results:
#!/usr/local/bin/php<?php $lines = array(); $lastSite = ''; // quickest and dirtiest way to execute a query in PHP ;-) exec ( "echo 'SELECT r.* " . "FROM get_new_referrers() r " . "LEFT JOIN search_engines se ON ( r.referrer ~* se.pattern AND r.referrer ~* se.query_pattern )" . "WHERE se.id IS NULL' | /usr/local/pgsql/bin/psql -U logminer -At logminer", $lines ); foreach( $lines as $line ) { $parts = explode( '|', $line, 4 ); if( $lastSite != $parts[ 0 ] ) { printf( "\n\n\n\n" . "-------------------------------------------------------\n" . "Referrers for %s\n" . "-------------------------------------------------------\n\n", $parts[ 1 ] ); $lastSite = $parts[ 0 ]; } printf( "[%d] %s\n\n", $parts[ 3 ], $parts[ 2 ] ); }?>
The query above grabs the referrers for every site available in the DB, filtering requests coming from known search engines to reduce the level of "noise".
This script is finally invoked by the cron job that processes the logs:
referrers_report.php | mail -s 'New referrers report' email@example.com
Saturday, June 7. 2008
Intelligence is the ability to avoid doing work, yet getting the work done.
-- Linus Torvalds
Wednesday, June 4. 2008
Suppose you want to create an application which you want to limit to a single running instance, like some image viewers do for example. Also, you need different users on a Terminal Server not to conflict with each other. Oh, and you're coding in C#.
A possible solution to the problem is the one described in this Flawless Code post.
What I didn't like is, it requires the 3.5 version of the framework, while I preferred to be able to run on machines with only 2.0 installed. So I've replaced the NamedPipeClientStream/NamedPipeServerStream with a P/Invoke-based implementation based on this example.
Also, I create a different pipe per user session, since I haven't found a way to create a "local" pipe. An article at Dr Dobb's suggests that it's possible, while MSDN doesn't mention this possibility...
I've zipped up my test solution in case someone else has the same needs.
Monday, June 2. 2008
I've just added LogMiner to Ohloh, a site that offers an interesting feature: it can analyse a project source code and estimate how much it would cost to hire a development team to recreate the project from scratch.
I think that it's a simple way to estimate the effort you put over the time in open source projects.
Here's the resulting figure for LogMiner:
Thursday, May 29. 2008
I'm starting to suspect that spammers try to collect and verify email addresses from PAD files using bogus sites as honeypots.
In fact, lately I've received several mails which are all based on the same template:
Hello, my name is John, and I am an associate of
SITEURL
Briefly, here is what we do. We specialize in
software reviews and downloads. While browsing the
web we came across your software and I must say
that we were stunned. We were so amazed by its
outstanding features that we decided to give you
our prestigious 5 stars award and put your
software on our editors choice list. We would be
delighted if you would consider posting it in your
awards section. To find the award please go to
http://SITEURL/adownloadIDOFSOMEKIND.html
If you have time please leave a comment, so that
others can view your remarks.
I would like to take a moment to thank you for
all your devoted work in the software field and
wish you success in your business.
The suspicious points are:
- all the sites have the same structure
- they don't even pretend not to be fake: the search function never works, the content appears only in some pages and never point to valid files, etc...
- IDOFSOMEKIND could be used just to verify that the mail reached an user that actually reads the mail and clicks on URL's
Am I paranoid?
Monday, May 19. 2008
Here's another interesting piece of code I've just digged up in a C# application I'm reviewing.
If you can come up with a bright idea about what those try/catch blocks are supposed to do, you've got more imagination than me...
class Foo { private int bar;
// ...snip...
public int GetNewBar() { int ret = 0;
lock (this) { try { bar++; ret = bar; } catch { try { bar++; ret = bar; } catch {} } }
return ret; }
// ...snip... }
Wednesday, May 14. 2008
Sometimes when you're reviewing someone else's code, you find interesting pieces of " art". Like the following loop construct in a C# application:
int i = anArray.Length - 1;
while (true) { if (i < 0) break; else { ... i--; } }
Doh.
You might be tempted to rewrite it as:
for( int i = anArray.Length - 1; i >= 0; i-- ) { ... }
but it would be too simple, too boring, wouldn't it?
Sunday, May 11. 2008
It's been more or less forever since I've decided to setup a Flickr account. Finally, I did.
There are just a handful of photos there at the moment, but it's a start.
Wednesday, May 7. 2008
I shot this picture a couple of days ago, while returning home from Budapest. It's now my desktop wallpaper.
Friday, April 18. 2008
I always assumed the designers of the Objective-C language and Cocoa frameworks trust me to know what I'm doing while I find very elegant ways to shoot myself in the foot.
-- from a mail sent to Cocoa-dev
|
|