Skip to content

Instantly share code, notes, and snippets.

Alexander asm89

Block or report user

Report or block asm89

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:f8e2227d3e017cf1dd4f54202104ee80
View gist:57a81c17b5317a746c1f9074aa852f83
<?hh
function f(?int $x): ?int {
if ($x === null) return $x;
else return $x * 2;
}
function x(): ?int {
return null;
}
View Dockerfile
FROM ubuntu
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y install wget
RUN wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | apt-key add -
RUN echo deb http://dl.hhvm.com/ubuntu trusty main | tee /etc/apt/sources.list.d/hhvm.list
RUN apt-get update
RUN apt-get -y install hhvm
View checked.php
<?hh
function addOne(int $x): int {
return $x + 1;
}
function main() {
addOne(42);
addOne('foo');
}
View lambda.php
<?php
mb_internal_encoding("UTF-8");
function λ($fn) {
list($args, $body) = explode('=>', $fn, 2);
$args = trim($args);
$args = ltrim($args, '(');
$args = rtrim($args, ')');
@asm89
asm89 / a.php
Created Feb 19, 2014
Generators in HHVM and PHP
View a.php
<?php
function xs() {
$i = 0;
while (true) {
yield $i++;
}
}
$xs = xs();
@asm89
asm89 / gist:8622724
Created Jan 25, 2014
Memory leak in hhvm?
View gist:8622724
<?php
class Foo
{
private $bar;
public function __construct(Bar $bar)
{
$this->bar = $bar;
}
}
View gist:8490526
<?php
$xs = array(42);
foreach ($xs as $x) {}
var_dump(current($xs));
$ys = array(42);
foreach ($ys as &$y) {}
var_dump(current($ys));
$it = new ArrayIterator([42]);
@asm89
asm89 / gist:8386608
Created Jan 12, 2014
"Inside out" approach to sqrt with convergence as described in https://news.ycombinator.com/item?id=7043943
View gist:8386608
<?php
function _sqrt($n) {
$x = 1.0;
$y = 0.5 * (1.0 + 1.0/$n);
$z = 1e-10;
while (abs($x/$y - 1) > $z) {
$x = $y;
$y = (0.5 * ($y + $n/$y));
View gist:8256280
<?php
class App
{
public $callables = [];
public function __construct()
{
register_shutdown_function([$this, 'run']);
}
You can’t perform that action at this time.