Skip to content

Instantly share code, notes, and snippets.

<?php
function ackersum($a, $b) {
if ($a == 0) {
return $b;
} elseif ($b == 0) {
return $a;
} elseif ($a == 1) {
return $b + 1;
}
@ircmaxell
ircmaxell / template.pseudo
Created July 8, 2014 17:34
Go return polymorphism pseudo-code
interface Foo1 {
public function bar()
}
interface Foo2 {
public function bar()
}
interface Foo3 {
public function bar()
@ircmaxell
ircmaxell / a.php
Created May 8, 2014 17:35
PHP Is Drunk
<?php
class a {
const a = b::c;
const b = b::d;
}
<?hh
class B {
public function doB() : string {
return "b";
}
}
class C extends B {
public function doC() : string {
@ircmaxell
ircmaxell / php_zpp.php
Last active March 1, 2023 23:48
Zend Parse Parameters. In PHP
<?php
namespace ZPP;
const IS_STRING = "string";
const IS_BOOL = "boolean";
const IS_LONG = "integer";
const IS_DOUBLE = "double";
const IS_ARRAY = "array";
const IS_OBJECT = "object";
@ircmaxell
ircmaxell / HashCipher.php
Created March 24, 2014 20:10
A hash based cipher built using a Feistel Network
<?php
class HashCipher {
protected $hash = 'sha512';
protected $hashLen = 64;
protected $rounds = 16;
public function __construct($hash, $rounds = 16) {
$this->hash = $hash;
// run a test hash, to get the proper hash length
@ircmaxell
ircmaxell / keybase.md
Created March 24, 2014 14:40
keybase.md

Keybase proof

I hereby claim:

  • I am ircmaxell on github.
  • I am ircmaxell (https://keybase.io/ircmaxell) on keybase.
  • I have a public key whose fingerprint is D620 2127 D88F 66C2 10A3 BFEB 6A7C A4E4 A190 DC6B

To claim this, I am signing this object:

@ircmaxell
ircmaxell / index.php
Created March 21, 2014 23:11
Tick Profiling
<?php
declare(ticks=1);
$__stack = [];
function getArrayKey(array $haystack, $needle) {
return isset($haystack[$needle]) ? $haystack[$needle] : '';
}
@ircmaxell
ircmaxell / gist:8182303
Created December 30, 2013 13:51
Example of expecting different arguments at different function calls
<?php
$shard = $this->getMock('Solarium_Query_Select_Component_DistributedSearch');
$shard->expects($this->exactly(2))
->method('addShard');
$shard->expects($this->at(0))
->method('addShard')
->with('k1', 'u1');
$shard->expects($this->at(1))
->method('addShard')
<?php
if ($foo == 1) {
echo "1";
} elseif ($foo == 2) {
echo "2";
} elseif ($foo == 3) {
echo "3";
} else {
echo "4";