Kategorien
PHP

PHP hates me – eine Set-Klasse

Kommentare gesperrt, weil dieses Posting Spambots magisch anzieht.

Mir ist aufgefallen, daß meine Klasse nicht abfängt wenn man zweimal dasselbe Objekt ins Set setzt. Deshalb ein kleines Update

Nils Langner von PHP hates me hat eine Aufgabe gestellt. Und hier meine spontane Lösung, vom Hirn ins Terminal 🙂

<?php
<div class="moz-text-plain" style="font-family: -moz-fixed; font-size: 13px;" lang="x-western">
<pre>class Foobar {
}

/**
 * @author Matthias Coy
 */
class Set {
    private $set = null;
    private $typ = null;
    private $className = null;

    /**
     * The method to add something to the set. The type of the set is defined by its first entry.
     * @param <type> $something
     * @public
     */
    function push($something) {
        if ($this->set == null) {
            $this->typ = gettype($something);
            $this->set = array();
            array_push($this->set, $something);
            if($this->typ == "object") {
                $class = new ReflectionClass($something);
                $this->className = $class->getName();
                echo "It's a class, with the name: '".$this->className."'\n";
            } else {
                echo "It's something else: '". $this->typ ."'";
            }
        } else {
            $myType = gettype($something);
            if($myType != $this->typ) {
                throw new Exception("Wrong Type, this set is a set of '".$this->typ."'");
            } else {
                if ($myType == "object") {
                    $class = new ReflectionClass($something);
                    if ($this->className != $class->getName()) {
                        throw new Exception("Right Type, but wrong class (is: '".$class->getName()."', should be: '".$this->className."')");
                    }
                    foreach($this->set as $entry) {
                        if ($something === $entry) {
                            throw new Exception('Right Type, but already in Set');
                        }
                    }
                }
                array_push($this->set, $something);
                echo "adding sth. (".$myType.")\n";
            }
        }
    }

    /**
     * Return the last inserted entry of the set.
     *
     * @return <type>
     * @public
     * @throws Exception if set is empty
     */
    function pop() {
        $returnValue = array_pop($this->set);
        if ($returnValue == null) {
            $this->set = null;
            $this->typ = null;
            $this->className = null;
            throw new Exception("Set is not yet defined, please add something first");
        }
        return $returnValue;
    }

    /**
     * Returns the amount of entries in the set
     *
     * @return <type> Entry of the set
     * @public
     */
    function count() {
        return count($this->set);
    }
}

$var1 = new Set();
$var2 = new Foobar();

$mySet = new Set();
$mySet->push($var1);
try {
    // Add something that is different to the types already in the set
    $mySet->push($var2); // throws execption
} catch (Exception $e) {
    print $e->getMessage()."\n";
}
try {
    // Add something which has the right type, but is already inside the set
    $mySet->push($var1); // throws execption
} catch (Exception $e) {
    print $e->getMessage()."\n";
}
while($mySet->count() > 0) {
    $mySet->pop();
}
$mySet->push($var2);
try {
    $mySet->push($var1);
} catch (Exception $e) {
    print $e->getMessage()."\n";
}
/* Output:
It's a class, with the name: 'Set'
Right Type, but wrong class (is: 'Foobar', should be: 'Set')
Right Type, but already in Set
It's a class, with the name: 'Foobar'
Right Type, but wrong class (is: 'Set', should be: 'Foobar')
 */
Kategorien
PC & Accessoires Sonstiges

Desktop anzeigen

Falls jemand™ mal aus Versehen das Icon löscht, hier eine Anleitung zum wiederherstellen:

Methode 1)

  1. Datei mit dem Namen „Desktop anzeigen.scf“ erstellen
  2. Folgenden Inhalt reinpasten:
    • [Shell]
      Command=2
      IconFile=explorer.exe,3
      [Taskbar]
      Command=ToggleDesktop
  3. Zum Ordner „%appdata%\Microsoft\Internet Explorer\Quick Launch“ gehen und dort die erzeugte Datei reinlegen

Methode 2)

  • Start -> Ausführen: regsvr32 /n /i:U shell32.dll
  • Evtl. System neustarten.

Voila. Geklaut & übersetzt von http://www.askvg.com

Kategorien
Sonstiges

FLV in WordPress hochladen

Zuerst rausfinden wo die Funktion ist die wir suchen:

~> grep -n "function wp_check_filetype" wp-includes/functions.php
2034:function wp_check_filetype( $filename, $mimes = null ) {

Dann verändern:

// Zeile 2034:
function wp_check_filetype( $filename, $mimes = null ) {
        // Accepted MIME types are set here as PCRE unless provided.
        $mimes = ( is_array( $mimes ) ) ? $mimes : apply_filters( 'upload_mimes', array(
                'jpg|jpeg|jpe' => 'image/jpeg',
                'gif' => 'image/gif',
                'png' => 'image/png',
                'bmp' => 'image/bmp',

Dort einfach noch ein ‚flv‘ => ‚video/x-flv‘, einfügen und dann kann man auch wieder flv-Dateien in WordPress hochladen

Kategorien
Diplomarbeit

Einmal mit Profis

Wie soll ich so arbeiten:

Kategorien
Sonstiges Spass

Rumpfkluft

… so heisst der Laden von Katz&Goldt. Bis zum September diesen Jahres hab das noch nicht mal gekannt, jetzt hab ich schon ein ganzes T-Shirt bestellt 🙂

Link zum Artikel im Shop

Kategorien
Diplomarbeit

jQuery, Tooltip, show() und hide()

Nunja, endlich hab ich das Problem gelöst das ich hatte. Schön wenn man auf Banalitäten hingewiesen werden muss …

var _PendingHideLink;
var _PendingHideDiv;
$("#someDivId").hover(function() {
    if (_PendingHideLink) {
        clearTimeout(_PendingHideLink);
    }
    if (_PendingHideDiv) {
        clearTimeout(_PendingHideDiv);
    }
}, function() {
    _PendingHideDiv = setTimeout(function() {
        $("#someDivId").hide();
    }, 2000);
});
$(".someLinks").hover(function(e) {
    $("#someDivId").show();
}, function() {
    _PendingHideLink = setTimeout(function() {
                $("#someDivId").hide();
            }, 5000);
});

Das macht: Beim positionieren des Mauszeigers übern einen Link („mouseover“) mit der Klasse „someLinks“ wird das div mit der Id „someDivId“ eingeblendet und nach 5 Sekunden wieder ausgeblendet. AUSSER man geht auf das eingeblendete div, dann bleibts offen, solange bis man das div wieder verlässt („mouseout“). Dazu sollte man noch wissen das jQuery „hover“ als Kombination versteht ($().hover == ($().mouseover; $().mouseout;)). Nunja, UND man sollte wissen das setTimeout eine Id zurückliefert die man mit „clearTimeout“ wiederverwenden kann

Kategorien
Sonstiges Spass

Schrödinger …

Man merkt das heute Freitag ist, ich blogge zuviel 🙂

Kategorien
PHP

Netbeans 6.5

… ist inzwischen schon ne Weile draussen, aber jetzt hat sich mal jemand die PHP-Unterstützung genauer angeschaut:

Kategorien
Diplomarbeit PC & Accessoires

MochiTest-Lite

Just a reminder to myself, because I want to try that extension:

Mochitest is a unit testing framework created by contributors to Mozilla projects. Mochitest is based on MochiKit , the incredibly useful Javascript library. MochiKit as the basis for writing unit tests has been proven very useful to developing Mozilla applications because of the thick layers of Javscript code in applications like Firefox.

What then, is Mochitest-Lite?
Mochitest, as it is used at Mozilla, requires Python to drive the command line interface, and automate the testing. Python is a very powerful tool for this purpose because, along with automation, it can overwrite and then rewrite configuration files like manifests and preferences, all while having a minimal impact on the application being tested. Mochitest also uses a client-server architecture to serve test documents to the application being tested. On top of that, an application needs to be built with the Mozilla build system to work with Mochitest.

This makes sense for large applications like Firefox, but what about a unit testing framework for developers of small XULrunner applications and extensions for existing Mozilla applications? These developers have different requirements. Mochitest-Lite is a way to get the same test writing tools and automation without the overhead of running Mochitest the same way it is used to test Mozilla code.

Kategorien
PC & Accessoires Sonstiges

Thunderbird 3

Ich teste nebenher gerade mal die pre-Beta von Thunderbird. Heute ist dann der Dateiname von
thunderbird-3.0b1pre.en-US.win32.zip
zu
thunderbird-3.0b2pre.en-US.win32.zip
verändert worden. Wow. eine neue Beta. Vielleicht wirds noch was dieses Jahrzehnt mit TB3.

UPDATE: Jetzt gibt es bereits den RC-1: mozillamessaging.com