Skip to content

Instantly share code, notes, and snippets.

View bpacholek's full-sized avatar

Bartosz Pachołek bpacholek

View GitHub Profile
@bpacholek
bpacholek / empty_test.php
Created March 17, 2015 13:42
Magic methods and the `empty` trap
<?php
class foo {
protected $bar;
public function setBar ($val) {
$this->bar = $val;
}
public function __get ($var) {
return $this->$var;
@bpacholek
bpacholek / precision.php
Last active August 29, 2015 14:14
php precision
<?php
$toSum = array(0.2,2.5,0.5,0.2,0.1,0.2,2.5,1.8);
$sum = 0;
$run = 0;
foreach($toSum as $value) {
$sum += $value;
switch(++$run) {
case 0:
@bpacholek
bpacholek / simple_progressbar_example.php
Created July 10, 2014 22:08
simplest ever progress info example with escape symbol for unix console
<?php
echo "Postep : ";
for ($i=0 ; $i<=100 ; $i++) {
echo "\033[5D"; // cofnij kursor 5 pozycji (move cursor 5 positions left)
echo str_pad($i, 3, ' ', STR_PAD_LEFT) . " %"; // wyjsie ma zawsze 5 znakow (output is always 5 symbols)
sleep(1); // lekka przerwa co by widac animacji (little pause to show animation)
}
<?php
class dummyCollection {
protected $data = null;
function __construct() {
$this->data = array();
}
public function add($element) {
<?php
/**
* Description of EnumEmulator
*
* @author Bartosz
*/
abstract class EnumEmulator {
private static $constCache = NULL;
private static $hasDefault = NULL;