Skip to content

Instantly share code, notes, and snippets.

View madfriend's full-sized avatar

Alex Chuchunkov madfriend

  • Yandex, OpenCorpora
  • St. Petersburg, Russia
View GitHub Profile
@madfriend
madfriend / gist:2704897
Created May 15, 2012 20:31
How to treat the most stupid thing in PHP
<?php
// Assume this function definition:
function foo($bar, $baz = 'qux') {
return $bar.$baz;
}
// Oh crap, something went wrong, and we call it without arguments:
$foo = foo();
@madfriend
madfriend / libtraits.php
Created April 29, 2012 21:27
PHP 5.4 Pattern Traits
<?php
namespace traits;
trait Singleton {
// Для тех, кто не предусмотрел конструктор в классе
private function __construct() {
}
def isPalindrome(word):
if len(word)<2:
return boolean(word)
return (word[0] is word[-1]) ? IsPalindrome(word[1:-2]) : False
@madfriend
madfriend / lazystring.php
Created March 15, 2012 20:08
Lazy Strings class
<?php
// accepts default string and test function.
// test function is tweaked everytime object of class LazyStrings is casted to string,
// if test function returns FALSE/NULL default string is returned, otherwise the result of
// test.
class LazyString {
private $_default, $_tweak;