Fetching Dilbert Comic stripts from rss feed

10:17PM Apr 17, 2009 in category PHP by Alexander Pirsig

This is a php script to fetch dilbert images out of a feedburner feed. Its a quick an dirty implementation it works and I'm sure there are bug's in it.

Enjoy! :D ... ah you can find the testside here -> testside or download it here
<\?php
/**
 * Make Sure XML is cached for couple of minutes
 */
$tmpfile = '/tmp/dilbert.rss';
$gap = 60*60*1; # 1 hour(s)

if(file_exists($tmpfile)===true && (filemtime($tmpfile)+$gap)>time())
{
  # Use locale cached dilbert Content
  $xmlStr = file_get_contents($tmpfile);
}
else
{
  # Reload Cached DilbertFeed
  if(!file_exists($tmpfile))
  {
    touch($tmpfile);
  }
  $xmlStr = file_get_contents('http://feeds2.feedburner.com/DilbertDailyStrip?format=rss');
  file_put_contents($tmpfile,$xmlStr);
}
$xml = new simpleXMLElement($xmlStr);
$content = $xml->xpath('//item');
\?>








  • ".$content[0]->title.""; ?> <\?php preg_match($expr,$content[0]->description,$matches); \?> enclosure['url'] = $matches[1]; \?> <\?php echo "".$content[0]->title.""; \?> <\?php echo "
    Fetched: ".date('Y-m-d H:i:s', filemtime($tmpfile)); \?>

Kommentare[0] Tags: php simple xml dilbert xpath coding labs rss

Handle debug output ... not

01:33AM Apr 15, 2009 in category PHP by Alexander Pirsig

First of all remember you should NEVER EVERY PUT DEBUG OUTPUT ON LIVE SITES. In my time as php developer I came across a couple of NOT-Solutions. They are very funny but you should not use it (even in development) :)

The if($_SESSION['user']=="LAMMO") - method


intention: Your think it's not smart to use a logging facility.
implication:It's only a good solution if customers have the chance to review your code. To see how smart you are hidding everthing in a session. WOHOWW. It's also fun to have this extra performance sucking code snippets in your source code for presentation purpose to make sure they see the debug output!
implementation:

if($_SESSION['user'] == "LAMMO") echo $debug;
// * plz make sure not using any brackets! to get the best lammo result :)

I hide my content in the side something - tactic


intention: Your're smart ass and like to be cool so your place a font tag a round you debug output
implication: Google and Co. will index your site
implementation:

<\?php echo debug("asdf"); \?>

Use the Debug Pixel


Use the debug pixel

intention: don't get indexed by a search engine
implication: everyone can see you're debug output
implementation:




Okay okay the last one is just a prove of concept, we discused this while we've tried to find the best baddest solution to put debug output in a live environment

hope you had fun ;)

Kommentare[0] Tags: labs php coding antipattern log output logger debug

Subversion's beginners essentials auf der Kommandozeile

07:20PM Apr 02, 2009 in category Hello World by Alexander Pirsig

Vorraussetzungen

Subversion braucht wirklich wenig voraussetzung um zu laufen. Eigentlich im einfachsten fall ein Repository und einen Benutzer mit Zugriff auf dieses. Der Zugriff auf ein Subversion Repository kann in über mehrere wege erfolgen. Die gängisten sind
  • http/https über mod_dav
  • SSH
  • direkt über das filesystem
Ich bevorzuge den weg über Mod_dav da die meisten Leute HTTP bzw. HTTPs zugriff haben und die User keinen direkt zugriff auf den Repository server haben müssen um ein Checkout zu machen. Um dann letzt entlich mit einer Arbeitskopie aus dem Repository arbeiten zu können benötigen wir ein Checkout dieser ist nichts anderes als ein bestimmter stand des Sourcecodes zu im Repository als copy auf dem lokalen Rechner. Einen checkout legt man mit folgenden befehl an:
   svn co https://mein.server.example.com/repository/calculator /mein/lokaler/pfad/calculator

Die Basics: Aktualisieren, Löschen, Hinzufügen

Der folgende Befehl holt alle änderungen aus dem Repository in den lokalen checkout:
   cd /mein/lokaler/pfad/calculator
   svn up
Ordner und Dateien Löschen:
   cd /mein/lokaler/pfad/calculator
   svn rm mein_Ordner
   svn rm meinedatei.txt
Ganz wichtig ist, änderungen werden erst durch ein Commit in das Repository zu rück gespielt, d.h. wenn man will das ändere Entwickler die modifikationen erhalten sollen, müssen diese Commited werden, das ganze geschieht mit folgendem befehl
   svn co -m "Ein Kommentar über Änderungen" /mein/lokaler/pfad/calculator

Branchen und Mergen

Ein Branch ist ein Seitenast der Hauptentwicklungslinie, da Subversion nur sogenannte "CheapCopys" kennt, ist ein Branch eigentlich nur eine Kopie eines Projekts ab einer bestimmten Revisionsnummer.

Branch anlegen

Einen Branch legen wir also Folgerichtig mit einem Copy-Befehl an z.B. so
  svn --username=XYZ copy -m "Erzeuge Branch " https://mein.server.example.com/repository/calculator/trunk https://mein.server.example.com/repository/calculator/branches/t_NNNN_AAAA

Branch auf den neuesten Stand aus dem HEAD bringen: (HEAD--> BRANCH)

Wenn wir einen Branch mit den änderungen aus der Hauptentwicklungslinie updaten wollen machen wir folgendes:
  cd /mein/lokaler/pfad/wo/der/calculator/branch/liegt
  svn merge -r rev:HEAD https://mein.server.example.com/repository/calculator/trunk .
Anmerkung: . ist das Verzeichnis, mit dem aktuellen Branch als Inhalt rev# is dabei die Revisionsnummer als der Branch angelegt wurde, bzw. als er das letzte Mal mit dem HEAD gemergt wurde.

Branch mit HEAD mergen: (BRANCH --> HEAD)

Wenn ein Entwickler seine Arbeit beendet kann er/soll er seine Änderungen in die Hauptentwicklungslinie zurück führen dies geht folgender massen.
  cd /mein/lokaler/pfad/wo/der/calculator/trunk/liegt
  svn merge -r rev:HEAD https://mein.server.example.com/repository/calculator/branches/BRANCHNAME .
Anmerkung: . ist das Verzeichnis , mit dem Trunk(HEAD) als Inhalt rev# is dabei die Revisionsnummer als der Branch angelegt wurde, bzw. als er das letzte Mal mit dem HEAD gemergt wurde.

Zum Schluss

Das ganze soll wirklich nur ein kleiner einblick sein wie man mit Subversion anfängt natürlich gibt es wie gesagt einige voraussetzunge wie z.B. ein Repository, Benutzer usw. ... Wer jetzt etwas mehr wissen sollte sich aufjedenfall das Subversion Buch anschauen.

Kommentare[0] Tags: merge versioning coding branch subversion

Ten usefull tipps to save your job in IT crisis!

07:30AM Mrz 30, 2009 in category Hello World by Alexander Pirsig

If someone would ask me, how can I make sure I'm not fired in economy crisis and loose my job as a programmer. I would tell him:

Documentation

  • Lie in the comments: You don't have to actively lie, just fail to keep comments as up to date with the code.
  • Documentation Gotchas: Never document gotchas in the code. If you suspect there may be a bug in a class, keep it to yourself. If you have ideas about how the code should be reorganised or rewritten, for heaven's sake, do not write them down. Remember the words of Thumper in the movie Bambi "If you can't say anything nice, don't say anything at all". What if the programmer who wrote that code saw your comments? What if the owner of the company saw them? What if a customer did? You could get yourself fired. An anonymous comment that says "This needs to be fixed!" can do wonders, especially if it's not clear what the comment refers to. Keep it vague, and nobody will feel personally criticised.
  • Document How Not Why: Document only the details of what a program does, not what it is attempting to accomplish. That way, if there is a bug, the fixer will have no clue what the code should be doing.

Program Design

  • Avoid Encapsulation: In the interests of efficiency, avoid encapsulation. Callers of a method need all the external clues they can get to remind them how the method works inside.
  • The Magic Of Global Variables: Instead of using exceptions to handle error processing, have your error message routine set a global variable. Then make sure that every long-running loop in the system checks this global flag and terminates if an error occurs. Add another global variable to signal when a user presses the 'reset' button. Of course all the major loops in the system also have to check this second flag. Hide a few loops that don't terminate on demand.
  • No Secrets: Declare every method and variable public. After all, somebody, sometime might want to use it. Once a method has been declared public, it can't very well be retracted, now can it? This makes it very difficult to later change the way anything works under the covers. It also has the delightful side effect of obscuring what a class is for. If the boss asks if you are out of your mind, tell him you are following the classic principles of transparent interfaces.

Nameing

  • Use Plural Forms From Other Languages: A VMS script kept track of the "statii" returned from various "Vaxen". Esperanto , Klingon and Hobbitese qualify as languages for these purposes. For pseudo-Esperanto pluraloj, add oj. You will be doing your part toward world peace.
  • Names From Other Languages: Use foreign language dictionaries as a source for variable names. For example, use the German punkt for point. Maintenance coders, without your firm grasp of German, will enjoy the multicultural experience of deciphering the meaning.

Testing

... and the best at the end ... lol!

  • Never Test: Never test any code that handles the error cases, machine crashes, or OS glitches. Never check return codes from the OS. That code never gets executed anyway and slows down your test times. Besides, how can you possibly test your code to handle disk errors, file read errors, OS crashes, and all those sorts of events? Why, you would have to either an incredibly unreliable computer or a test scaffold that mimicked such a thing. Modern hardware never fails, and who wants to write code just for testing purposes? It isn't any fun. If users complain, just blame the OS or hardware. They'll never know.
  • Never, Ever Do Any Performance Testing: Hey, if it isn't fast enough, just tell the customer to buy a faster machine. If you did do performance testing, you might find a bottleneck, which might lead to algorithm changes, which might lead to a complete redesign of your product. Who wants that? Besides, performance problems that crop up at the customer site mean a free trip for you to some exotic location. Just keep your shots up-to-date and your passport handy.

And if that's not enought try the following link where I took those examples from, thx to Roedy Green and Canadian Mind Products

Kommentare[0] Tags: economy web2.0 antipattern performance standards crisis coding