Skip to content

Instantly share code, notes, and snippets.

@asm89
asm89 / magic
Created February 11, 2013 13:04
<?php
mb_internal_encoding("UTF-8");
$  = 'foo';
$x = 'bar';
echo $ . $x;
@asm89
asm89 / gist:5704166
Created June 4, 2013 07:17
.xinitrc detecting and enabling right amount of monitors and awesome configuration
# switch to dvorak, set key repeat etc
/home/alexander/.fixkb
# Add local fonts
xset fp+ /usr/share/fonts/local &
## Gnome keyring
source /etc/X11/xinit/xinitrc.d/30-dbus
eval $(/usr/bin/gnome-keyring-daemon --start --components=gpg,pkcs11,secrets)
@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();
<?php
class NestedFunctions
{
public function fn1()
{
function nested_fn() { echo 'yay' . "\n"; }
nested_fn();
}
@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']);
}
@asm89
asm89 / gist:8386608
Created January 12, 2014 16:12
"Inside out" approach to sqrt with convergence as described in https://news.ycombinator.com/item?id=7043943
<?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));
<?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]);