Kategorien
Linux PC & Accessoires

su unter Windows

Gerade gefunden:

Muss ich bei Gelegenheit mal ausprobieren 🙂

Kategorien
Diplomarbeit

Javascript: getter und setter

Nix spektakuläres, bin ich gerade rübergestolpert. Nachdem ich mich ja schon über Sichtbarkeit ausgelassen habe, kommt jetzt der Trick wie man getter und setter definiert.

Bisher hab ich das immer so gemacht:

function Field(val){
    /** @private */
    var value = val;

    /** @public*/
    this.getValue = function(){
        return value;
    };

    /** @public*/
    this.setValue = function(val){
        value = val;
    };
}

Ist auch wunderbar, allerdings bissle lästig das immer zu schreiben. Deshalb hier das ganze im „Mozilla Style“:

function Field(val){
    var value = val;

    this.__defineGetter__("value", function(){
        return value;
    });

    this.__defineSetter__("value", function(val){
        value = val;
    });
}

Potthässlich in der Tat, aber macht genau dasselbe wie der Code drüber. Wenn man jetzt ignoriert das „value“ umbedingt private sein muss, dann sieht das sogar „schön“ aus:

function Field(val){
    this.value = val;
}

Field.prototype = {
    get value(){
        return this._value;
    },
    set value(val){
        this._value = val;
    }
};

Bringt mir jetzt nicht so besonders viel, aber vielleicht brauchts ja jemand anders.

Links:

Kategorien
Diplomarbeit Linux PC & Accessoires

Unix vs. Dos

Jaja, UNIX („\n“) und DOS („\r\n“) Zeilenenden … FALSCH:

./funD.reinstallExtension.sh
: No such file or directoryh: line 3: cd: /cygdrive/c/Dokumente und Einstellungen/matthiasc/Eigene Dateien/Diplomarbeit/
./funD.reinstallExtension.sh: line 4: $'\r': command not found
: No such file or directorysion.sh
: No such file or directory.sh
: No such file or directorynsion
./funD.reinstallExtension.sh: line 8: $'\r': command not found
: No such file or directoryh: line 9: cd: /cygdrive/c/Dokumente und Einstellungen/matthiasc/Eigene Dateien/Diplomarbeit

RICHTIG:

11:20:34 matthiasc@fungdenhut /cygdrive/c/Dokumente und Einstellungen/matthiasc/Eigene Dateien/Diplomarbeit $ ./funD.reinstallExtension.sh
11:20:36 matthiasc@fungdenhut /cygdrive/c/Dokumente und Einstellungen/matthiasc/Eigene Dateien/Diplomarbeit $ 
Kategorien
PC & Accessoires

Itunes: Nie gehörte Musik wiederentdecken

Da mein iPod irgendwie immer dasselbe spielt, hab ich jetzt mal eine „intelligente Wiedergabeliste“ erstellt. Anforderungen waren ganz simpel: Der interne Abspielzähler der Lieder soll kleiner als 5 sein und es soll nur Musik sein (also keine Podcasts, Videos oder sonstiger Schmuh). Hier die Einstellungen:

itunesnie-gehoert-liste

Kategorien
PC & Accessoires Sonstiges

OpenXML als HTML

Sowas find ich klasse. Microsoft stellt ein Firefox-Addon zur Verfügung mit dem man OpenXML-Dokumente als HTML anschauen kann. Sehr praktisch wenn man gerade kein Microsoft Office zur Hand hat, oder auch kein Openoffice. Einfach das Firefox-Addon installieren, die Datei auf den Firefox ziehen und fertig. Klasse.

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