Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
<?hh
class B {
public function doB() : string {
return "b";
}
}
class C extends B {
public function doC() : string {
@ircmaxell
ircmaxell / a.php
Created May 8, 2014 17:35
PHP Is Drunk
<?php
class a {
const a = b::c;
const b = b::d;
}
@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()
<?php
function ackersum($a, $b) {
if ($a == 0) {
return $b;
} elseif ($b == 0) {
return $a;
} elseif ($a == 1) {
return $b + 1;
}
<?php
define('CRYPT_SALT_LEN_MAX', 16);
define('CRYPT_ROUNDS_DEFAULT', 5000);
/**
* A PHP shim for crypt sha256 and sha512
* to workaround bug 62372
* @see https://bugs.php.net/bug.php?id=62372
*/
@ircmaxell
ircmaxell / gist:6fa2ea9417056be7aba7
Created July 25, 2014 21:35
Dump of #php.pecl convo
13:11 <ajf> I’m mostly happy with it as-is, but given that I made int/float/numeric/string not accept NULL, I think booleans shouldn’t be accepted for them either.
13:19 → arty joined ⇐ DaveRand quit
13:49 → sonotos and lonnylot joined ⇐ dmitry and RemiFedor quit
14:41 <ircmaxell> ajf: that sounds sane (consistency wise). So it means that `int/float/numeric` only accept int/float/valid-number-string, and string only accepts string/int/float
14:43 <ajf> ircmaxell: Yeah
14:43 <ajf> Also, we don’t accept int/float/string for bool, so we shouldn’t accept bool for int/float/string
14:43 <ircmaxell> yeah, makes perfect sense
14:44 <ajf> Another point someone raised was that FALSE is a common error value alongside NULL.
14:44 <ajf> So, should I go ahead and amend the patch and RFC to do that?
14:44 <ircmaxell> I think that's the direction we're going, so that's valid
<?php
/**
* @param int
* @param int
* @return int
*/
function foo($a, $b) {
$c = 0;
if ($a) {