Monthly Archives: February 2011

Proto.Spy

A while back a friend of mine mentioned this site to me: It checks which porn sites you have been on.

The technology used to achieve this is quite simple. It inserts links to a bunch of porn sites in the page and uses Javascript to check the link color, abusing the fact that browsers by default use different colors for links you have visited or have not.

Some days ago I came across a blog post by David Walsh in which he described how to perform the above described check using jQuery. I was amazed how easy that was and thought it must be equaly easy to do the same using Prototype. Well, here we go:

I’ve set up a demo that checks a small number of sites (no porn, sorry).

Here is the small function I use to do the checks:

Event.observe(window,'load',function(){
 siteList.each(function(site){
  var a = new Element('a', { href: 'http://' + site, }).addClassName('check').insert(site);
  if(a.getStyle('color') == '#800080' || a.getStyle('color') == 'rgb(0, 128, 0)') {
   $('link-list').insert(a.addClassName('highlight').removeClassName('check').wrap('li'));
  } else {
   var b = new Element('a', { href: 'http://www.' + site }).addClassName('check').insert(site);
   if(b.getStyle('color') == '#800080' || b.getStyle('color') == 'rgb(0, 128, 0)') {
    $('link-list').insert(b.addClassName('highlight').removeClassName('check').wrap('li'));
   } else {
    $('link-list').insert(a.removeClassName('check').wrap('li'));
   }
  }
 });
},false);

with siteList being an array of sites that will be checked. The basically creates an anchor element for each site in the array and checks that elements color. If it matches my defined css style for visited links, than I add the class name ‘highlight’ to the element, otherwise I don’t. That’s pretty much what David Walsh does aswell, but additionally to that I check both http://example.com and http://www.example.com as some might have visited the one but not the other. If none were visited, I show the http://example.com link.

Any questions? No? Then start abusing this ;)

P.S.: This is an older post I copied from my old blog. Thought some of you might find this useful.

Extended logging of database errors in CodeIgniter

Some of you might and now and then have run into a database error while working with CI. Such errors are mostly caused by errors in your querys like not escaping user input or your fields or simply syntax errors.

In small applications that not much of a problem, but the bigger the application the harder it get’s to find the part where the bad query is hiding.

dootzky from the CodeIgniter Forum had exactly that problem and with a little help from wiredesignz we were able to add some more detail to the error messages!

Simply add this to the body of ‘application/errors/error_db.php’:

if($_SERVER['HTTP_HOST'] == 'localhost') {
   $trace = debug_backtrace();
   echo "The error occured in file ".$trace[4]['file']." on line ".$trace[4]['line']."";
}

Now additionally to the error you already know, you will be shown in which file and on which line the error occured (the db->get() method was called)! As this might pose a security risk on live systems, dootzky added the check for localhost.

I know that with CI 2.0 this might be obsolete because the error messages were enhanced, atleast the database errors now show filename and line, but someone still using some older version of CI (like I do for most of my older projects) might still find this handy.

P.S.: This is an older post I copied from my old blog. Thought some of you might find this useful.

I’m back!

It took me quite a while but now it’s official: I’m back in the blogging business!

My old blog was running on my own blogging software, dBlog, but as development wasn’t coming along as well as I hoped it would (mostly due to me constantly running out of time) I finally came around to switching to WordPress and setting this thing up properly. It still needs some work, e.g. a different theme and maybe some header image,  but it’s running and I’ll improve on the rest in the following few weeks.

So what’s to expect of this one? Pretty much what I blogged about before: coding :) Propably less about my own projects than more general stuff that might be handy for some of my readers (do I even have any? haha) like code-snippets, tutorials and whatever else I might stumble upon.

If I find the time I’ll copy some of my old entries and post them here, but I won’t promise anything ;)

So long!