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 / my_msls_blog_collection_get.php
Last active March 14, 2021 07:01
Multisite Language Switcher: Howto use the "msls_blog_collection_get"-filter
<?php
function my_msls_blog_collection_get( $objects ) {
$objects = array();
$blogs = array( 1 => 'Override English', 2 => 'Override Deutsch', );
foreach ( $blogs as $id => $description ) {
$details = get_blog_details( $id );
if ( is_object( $details ) ) {
$objects[$id] = new MslsBlog( $details, $description );
}
@lloc
lloc / _example.php
Last active December 22, 2017 10:42
Generic Decorator in PHP
<?php
require_once 'bar.php';
require_once 'foo.php';
$foo = new Foo;
$bar = new Bar( $foo );
$foo->set_foo( 123.4 );
$foo->set_bar( 123.4 );
@lloc
lloc / eaie1.php
Created October 1, 2011 10:51
Extract and Include Example 1
<?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 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;