Skip to content

Instantly share code, notes, and snippets.

Dennis Ploetner lloc

Block or report user

Report or block lloc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View factory-method-using.php
<?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 / eaie1.php
Created Oct 1, 2011
Extract and Include Example 1
View eaie1.php
<?php
$template_dir = dirname (__FILE_) . '/templates';
extract ($_REQUEST);
include ($template_dir . '/header.html');
print_r (get_defined_vars ());
include ($template_dir . '/footer.html');
?>
@lloc
lloc / eaie2.php
Created Oct 1, 2011
Extract and include Example 2
View eaie2.php
<?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 Oct 1, 2011
Test array_key_exists()
View array_key_exists_test.php
<?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);
View mysql-example1.php
<?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)) {
View mysql-example2.php
<?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;
View mysql-example3.php
<?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 Oct 1, 2011
Python slot example
View gist:1256177
>>> 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 Oct 1, 2011
slotObject in PHP
View gist:1256180
<?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;
View factory-method-example.php
<?php
class Factory {
function create ($file) {
if (file_exists ($file) && ($mtime = filemtime ($file))) {
return new CMtime ($mtime);
}
return new CError ();
}
You can’t perform that action at this time.