Skip to content

Instantly share code, notes, and snippets.

View bzikarsky's full-sized avatar

Benjamin Zikarsky bzikarsky

View GitHub Profile
@bzikarsky
bzikarsky / vm.js
Created December 6, 2011 07:17
Solution to canyoucrackit#2
String.prototype.lpad = function(length, padString) {
var str = this;
if (padString == undefined) {
padString = ' ';
}
while (str.length < length) {
str = padString + str;
}
@bzikarsky
bzikarsky / NumberToWordConverter.php
Created December 21, 2010 23:13
Verboce-/OO-Version of a numer to german word algorithm
<?php
class NumberToWordConverter
{
private $numbers = array(
'', 'ein', 'zwei', 'drei', 'vier', 'fünf', 'sech',
'sieb', 'acht', 'neun', 'zehn', 'elf', 'zwölf'
);
private $numbersSingle = array(
@bzikarsky
bzikarsky / numbers.php
Created December 21, 2010 20:45
Codegolf: Convert numbers up to 999'999 into german numbers
Minified, 411 Bytes, with umlauts
Run with `php -d display_errors=Off` to hide DEPRECATED errors on 5.3
See OO-Version at <https://gist.github.com/750787>
<?function n($n,$a=0){$e=array(2=>'zwan','dreißig')+$d=split(':',':ein:zwei:drei:vier:fünf:sech:sieb:acht:neun:zehn:elf:zwölf');$t=$n%10;return$n<1000?($n<100?($n<20?($n<13?($d[$n].(($n-7)?(($n-1||$a)&&$n-6?'':'s'):'en')):$d[$t].'zehn'):n($t,1).($t?'und':'').$e[$n/10].(ceil($n/10)-4?'zig':'')):n((int)($n/100),1).'hundert'.n($n%100)):n((int)($n/1000),1).'tausend'.n($n%1000);}while($i<10000)echo n(++$i),"\n";
# verbose (some slight changes for readability)
function n($n, $prefix=0)
{
@bzikarsky
bzikarsky / Enum.examples.php
Created October 21, 2010 12:51
Several examples for Enum.php {@see http://gist.github.com/638407}
<?php
class Gender extends Enum
{
protected static $enum = array(
'MALE' => array('male', 'm', 'Dear Mr.'),
'FEMALE' => array('female', 'f', 'Dear Ms.')
);
@bzikarsky
bzikarsky / Enum.php
Created October 21, 2010 12:44
Provides an enum-like type (as in Java) for PHP, @see http://gist.github.com/638426 for example usage
<?php
/**
* This class provides an enum-like type (as in Java) for PHP
*
* To create an enum, the enum has to extends this Enum class and defined
* a static protected array $enum with its entites.
* This array can be either a normal collection, e.g.
*
* <code>