Archive for the ‘Development’ Category

Webmontag in Frankfurt

Friday, December 5th, 2008

Anfang dieser Woche fand der letzte Webmontag für dieses Jahr statt. Ich war dabei. Ich suche bereits seit mehreren Monaten Bar Camps oder ähnlichen Veranstaltungen im Raum Frankfurt, leider bis jetzt immer vergeblich. Na ja, vielleicht war ich ja auch bei der Suche nicht so fleißig ;)

Mein Eindruck? Es hat mir sehr gefallen. Es hat viel Spaß gemacht, auch wenn ich ein Frischling in der Szene bin. Die Atmosphäre war sehr locker und alle haben sich von vorne rein geduzt. Das half mir natürlich sehr, um mich schneller zu entspannen. Der andere Trick war, sofort zu den Rauchern zu gehen. Da gingen die Gespräche sofort los. Na, wer sagt’s denn? Rauchen ist immer noch sozial, auch wenn es vom Gesundheitsministerium als asoziale und uncoole Angewohnheit propagandiert wird :) .

Mir gefiel aber nicht, dass es nach den Vorträgen keine Q&A-Session gab. Nicht dass ich mich bei meinem ersten Event getraut hätte, Fragen zu stellen, aber immerhin ich hatte einige. Beim Networking nachher hat mir aber Thorsten verraten, dass es gezielt so ist, weil der Webmontag an einem breiteren Publikumskreis ausgerichtet ist und nicht etwa nur an Techies. Das sei auch der Grund, weswegen in keins der Vorträgen technische Details dran kamen. Dafür aber gibt es ein anderes Event, dass wohl nur für Techies: DevDusk. Es findet demnächst in Januar. :thumbsup:

Sonst hat mir der Vortrag von Darren sehr gut gefallen. Er ist nicht nur ein unterhaltsamer Sprecher, sondern hat auch ein interessantes Projekt vorgestellt: tellagain, das leider anscheinend noch im closed alpha ist. Allerdings hatte ich die Möglichkeit beim Networking ein bisschen mit ihm zu chatten, ob ich eventuell mit meinen bulgarischen Kenntnissen helfen könnte. Ich muss aber noch schauen, wie ich das ganze bei mir persönlich organisiere, ich habe sehr viel am Kopf. Ach, übrigens, verkauft denn jemand Zeit? Ich brauche dringend einiges, so ca. zwei bis drei Wochen, bin bereit sogar einen überhöhten Preis zu zahlen …

Also, wir sehen uns nochmals im Januar auf dem DevDusk. Und am nächsten Montag, den. 08.12, findet die girl geek dinner. Männer sind da auch herzlich eingeladen, müssen aber in Begleitung von mindestens einer Frau erscheinen.

P.S. Mein erster Posting auf Deutsch. Stößchen.

nofollow Bookmarklet

Saturday, June 14th, 2008

Here is a smallish bookmarklet that highlights all links that are marked with the nofollow attribute. Just drag and drop it to your bookmarks bar.

show nofollow

In its current version the bookmarklet is very very simple: it just highlights nofollow-links and reports back the total number. However it only works on frameless documents.

Here’s the code in a readable <code>-block:

javascript:(function(){
  for (var i = 0, a = document.getElementsByTagName('a'), b = a.length, c = b; i < b; i++) {
    a[i].rel.match(/nofollow/i) ? a[i].style.backgroundColor = '#ff0066' : c--;
  }
  alert(c);
})();

That’s the shortest I could get. Have fun :).

P.S. You can test-drive it right away on this page: the about-link in the footer is a nofollow-link.

P.P.S. It’s the browser that turns a double minus into a single long dash.

Unobtrusive Smilies :)

Wednesday, February 20th, 2008

I don’t know whether you may find use for this, it might be a complete overhaul, but anyway.

Smilies are small inline images that represent a mood like being sad :( or help enrich the context with some emotion like winking after a joke ;). Everybody uses them but no one actually puts down those img-tags: we rely on our smart CMS’s to the job. Smilies are accessible since screen readers use either the title or the alternative text attributes of the img-tag. The problem is that such inline images aren’t semantically correct: they should be part of the text as text and not as images.

I’ve put down a small (~2KB minified) mixture which filters all smilies and replaces them with images in an unobtrusive way.

Download uns v. 0.2

What is the basic?

Default behavior is to query the document for span-tags that have the class smiley. Each one option is customizable.

What’s the compatibility?

It’s known to work with Firefox 2, Firefox 3, IE5.5, IE6, IE7, Safari 3 and Opera 9 under Windows, Safari 3 under Mac OS X and Konqueror 3.5 under Kubuntu.

How to trigger it?

Use it just as any other unobtrusive JavaScript out there:

window.onload = function() {
  uns.parse();
};

Or gain performance by providing a node where smilies are to be found, like the main content div-block:

window.onload = function() {
  uns.parse({node: document.getElementById('content')});
};

You can also provide an onfinish callback:

window.onload = function() {
  uns.parse({
    node: document.getElementById('content'),
    onfinish: function() {
      alert('finished');
    }
  });
};

Or you can add additional smilies:

window.onload = function() {
  uns.smilies({
    ':cska:': 'images/cska.gif'
  });
  uns.parse();
};

You can also AJAX load new content into some poor div and run the parser afterwards:

xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    var comments = document.getElementById('comments');
    comments.innerHtml = xhr.responseText;
    uns.parse({node: comments});
  }
};

Where can it be seen?

I’ve put down a small demo.

Log

20.02.2008: 0.1 Initial release.
22.02.2008: 0.2 Added support for native getElementsByClassName and tested with Firefox 3, added support for IE5.5 and IE6.

TOCoholic

Tuesday, January 1st, 2008

I’ve had the other day some referrers from a site listing a bunch of WordPress plugins about TOCoholic. So I decided to dig it out. Here it is:

What’s new about the plugin? Nothing. I’ve just dropped it in the plugins directory and … it worked. This tells me two things:

  1. WordPress’ developers had made some nice efforts to make it backwards compatible and this is great, kudos
  2. I’ve been more than a decent developer 18 months ago :roll:

I have plans to make some changes to plugin’s features and to optimize it a bit, but for now it’s fine just as it is. So stay tuned.

Zebra Stripes with PHP

Wednesday, October 31st, 2007

I find the second implementation of zebra stripes much cleaner and better, and I prefer it. Though both have the same complexity, so no significant performance gains really.

$class1 = 'odd';
$class2 = 'even';
$class3 = $class1;
echo '
    '; foreach ( $rows as $index => $row ) { echo '
  • ', $row, '
  • '; $class1 = $class2; $class2 = $class3; $class3 = $class1; } echo '
';
$odd = TRUE;
echo '
    '; foreach ( $rows as $index => $row ) { echo '
  • ', $row, '
  • '; $odd = !$odd; } echo '
';

Iterating over few elements delivers these results:

  • over 10 000 with echo: 0,0159 seconds for my favorite and only 0,0158 for the other one;
  • over 10 000 without echo: 0,0077 seconds for my favorite and only 0,0041 for the other one;
  • over 100 000 with echo: 0,44 seconds for my favorite and only 0,27 for the other one;
  • over 100 000 without echo: 0,189 seconds for my favorite and only 0,188 for the other one;
  • over 1 000 000 with echo: 87,23 seconds for my favorite and only 86,51 for the other one;
  • over 1 000 000 without echo: 4,84 seconds for my favorite and only 4,78 for the other one;

So despite my preference the first one is faster. But lesson learned here is that it is always a good practice to have as few as possible I/O’s.

The million dollar question is: what are the spec’s of my computer? :)

A Very Simple PHP Encrypter and Decrypter

Thursday, October 25th, 2007

Today I’ve looked around the php.net site for some basic encryption and decryption functions but unfortunately all there is only base64. So I’ve put together a smallish one myself. You can use it to exchange securely data between two entities, but keep in mind that this is a synchronous cryptography, ie. all communication partners must share a common secret.

function encrypt( $plain ) {
  $salt = 'xn237 8789123AZSBJK#$$#^ fdopi][{}463bv5%#&! si8d 5642 v4189sda44181!#$%!S08F09DQXMlkjhYHUsad';
  $cypher = '';

  // expand the salt to meet the length of the plain text
  if ( strlen($plain) > strlen($salt) ) {
    $loop = true;
    while ( $loop ) {
      $salt .= $salt;
      if ( strlen($salt) >= strlen($plain) ) { $loop = false; }
      }
  }

  // encrypt
  for ( $i = 0; $i < strlen($plain); $i++ ) {
    $char1 = $plain{$i};
    $char2 = $salt{$i};
    $ascii1 = ord( $char1 );
    $ascii2 = ord( $char2 );
    $cypher .= chr( $ascii1 + $ascii2 );
  }
  return $cypher;
}

function decrypt( $cypher ) {
  $salt = 'xn237 8789123AZSBJK#$$#^ fdopi][{}463bv5%#&! si8d 5642 v4189sda44181!#$%!S08F09DQXMlkjhYHUsad';
  $plain = '';

  // expand the salt to meet the length of the cypher text
  if ( strlen($cypher) > strlen($salt) ) {
    $loop = true;
    while ( $loop ) {
      $salt .= $salt;
      if ( strlen($salt) >= strlen($cypher) ) { $loop = false; }
      }
  }

  // decrypt
  for ( $i = 0; $i < strlen($cypher); $i++ ) {
    $char1 = $cypher{$i};
    $char2 = $salt{$i};
    $ascii1 = ord($char1);
    $ascii2 = ord($char2);
    $plain .= chr( $ascii1 + $ascii2 );
  }
  return $plain;
}

Hmm ... both functions seem to be quite ... the same. Yes, they are the same.

function decenc( $in ) {
  $salt = 'xn237 8789123AZSBJK#$$#^ fdopi][{}463bv5%#&! si8d 5642 v4189sda44181!#$%!S08F09DQXMlkjhYHUsad';
  $out = '';

  // expand the salt to meet the length of the  $in
  $inlen = strlen($in);
  if ( $inlen > strlen($salt) ) {
    while ( $inlen > strlen($salt) ) {
      $salt .= $salt;
    }
  }

  // perform operation
  for ( $i = 0; $i < $inlen; $i++ ) {
    $char1 = $in{$i};
    $char2 = $salt{$i};
    $ascii1 = ord( $char1 );
    $ascii2  = ord( $char2 );
    $out .= chr( $ascii1 + $ascii2 );
  }
  return $out;
}

The most important part of this algorithm is the salt. It must be as random as possible. But it must be known to all communication partners. Which, of course, means that at some point, before exchanging data, the salt must be passed over on a secure line.

String chunking and parts shuffling won’t strengthen the method, because the method is static: strlen(input) == strlen(output) and if input1 == input2 then output1 == output2.

This approach of encrypting data is quite simple and insecure, so it should be avoided. However there might be few scenarios, where a much simpler solution is preferred over AES, Diffie-Hellman or any PKI.

And one last thing: I’m not using it, I’ve been just thinking simplistic and minimalistic today.