Skip to content

Instantly share code, notes, and snippets.

View lloc's full-sized avatar
🏠
Working from home

Dennis Ploetner lloc

🏠
Working from home
View GitHub Profile
@lloc
lloc / factory-method-using.php
Created October 1, 2011 15:53
Factory Method Using
<?php
/* gibt z.B. 'Am 05.03.2007 um 12:12 Uhr wurde die Datei geaendert.' aus. */
$obj = Factory::create (__FILE__);
print $obj->repr ();
/* gibt 'Es ist ein Fehler aufgetreten!' aus */
$obj = Factory::create ("nicht-existierende-datei");
print $obj->repr ();
@lloc
lloc / eaie2.php
Created October 1, 2011 10:57
Extract and include Example 2
<?php
function scope_include ($file) {
if (is_file ($file)) {
include ($file);
return (get_defined_vars ());
}
return (FALSE);
}
@lloc
lloc / array_key_exists_test.php
Created October 1, 2011 11:15
Test array_key_exists()
<?php
function getmicrotime () {
list ($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
define ("TESTARRAY_MIN", 1);
define ("TESTARRAY_MAX", 10000);
define ("WINNERARRAY_MAX", 10);
@lloc
lloc / mysql-example1.php
Created October 1, 2011 15:04
MySQL Example 1
<?php
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die("Keine Verbindung möglich: " . mysql_error());
echo "Verbindung zum Datenbankserver erfolgreich";
mysql_select_db("Meine_Datenbank") or die("Auswahl der Datenbank fehlgeschlagen");
$query = "SELECT * FROM Meine_Tabelle";
$result = mysql_query($query) or die("Anfrage fehlgeschlagen: " . mysql_error());
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
@lloc
lloc / mysql-example2.php
Created October 1, 2011 15:07
MySQL Example 2
<?php
define('MySQL_DB_HOST', 'mysql_host');
define('MySQL_DB_USER', 'mysql_user');
define('MySQL_DB_PASSWORD', 'mysql_password');
define('MySQL_DB_NAME', 'Meine_Datenbank');
class MySQL {
var $conn;
@lloc
lloc / mysql-example3.php
Created October 1, 2011 15:10
MySQL Example 3
<?php
include_once ("db.php");
$db = new MySQL;
$db->sql ("SELECT * FROM Meine_Tabelle");
$result = $db->result ();
if (!empty ($result)) {
echo "<table>\n";
@lloc
lloc / gist:1256177
Created October 1, 2011 15:24
Python slot example
>>> class example(object):
__slots__ = ["x", "y", "z"]
>>> example = example()
>>> example.x = 0
>>> example.y = '0'
>>> example.z = 'Null'
>>> example.a = 0
Traceback (most recent call last):
File "", line 1, in ?
@lloc
lloc / gist:1256180
Created October 1, 2011 15:27
slotObject in PHP
<?php
class slotObject {
function set ($input) {
$slot = array_keys (get_class_vars (get_class ($this)));
if (is_array ($input)) {
foreach ($input as $key => $value) {
if (in_array ($key, $slot)) {
$this->$key = $value;
@lloc
lloc / gist:1256186
Created October 1, 2011 15:31
slotObject php extends
<?php
class example extends slotObject {
var $x;
var $y;
var $z;
}
class exampleChild extends example {
var $a;
@lloc
lloc / factory-method-example.php
Created October 1, 2011 15:46
Factory Method Example
<?php
class Factory {
function create ($file) {
if (file_exists ($file) && ($mtime = filemtime ($file))) {
return new CMtime ($mtime);
}
return new CError ();
}