Skip to content

Instantly share code, notes, and snippets.

@asm89
asm89 / a.php
Created February 19, 2014 21:40
Generators in HHVM and PHP
<?php
function xs() {
$i = 0;
while (true) {
yield $i++;
}
}
$xs = xs();
<?php
mb_internal_encoding("UTF-8");
function λ($fn) {
list($args, $body) = explode('=>', $fn, 2);
$args = trim($args);
$args = ltrim($args, '(');
$args = rtrim($args, ')');
<?hh
function addOne(int $x): int {
return $x + 1;
}
function main() {
addOne(42);
addOne('foo');
}
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
@asm89
asm89 / magic
Created February 11, 2013 13:04
<?php
mb_internal_encoding("UTF-8");
$  = 'foo';
$x = 'bar';
echo $ . $x;
@asm89
asm89 / gist:5797852
Last active December 18, 2015 14:29
Rerun PHPUnit on file changes in a given dir (defined in my .bashrc)
# watch files and rerun phpunit on changes
phpunitwait() {
while inotifywait $(find $1 -name '*.php');
do
clear;
phpunit --colors $2;
done;
}
@asm89
asm89 / gist:6164748
Created August 6, 2013 14:05
Search for messages in certain channels in your weechat log files (defined in my .bashrc) Usage: `channelgrep <channelname> keyword`
# grep messages from weechat logs
channelgrep() {
channel=$1
search=$2
channelFiles=~/.weechat/logs/*#$channel*
grep "$search" $channelFiles
}
@asm89
asm89 / gist:6183370
Created August 8, 2013 10:02
Tail a file using react/socket
<?php
require_once __DIR__ . '/vendor/autoload.php';
$file = __DIR__ . '/testfile';
$client= popen('tail -f ' . $file, 'w');
stream_set_blocking($client, 0);
$loop = React\EventLoop\Factory::create();
@asm89
asm89 / gist:7108079
Last active December 26, 2015 06:29
mysum :: Num a => [a] -> a
mysum [] = 0
mysum (x:xs) = x + mysum xs
<?php
class App
{
public $callables = [];
public function __construct()
{
register_shutdown_function([$this, 'run']);
}