Skip to content

Instantly share code, notes, and snippets.

View lloc's full-sized avatar
🏠
Working from home

Dennis Ploetner lloc

🏠
Working from home
View GitHub Profile
@lloc
lloc / trait.php
Last active March 23, 2018 10:26
<?php
namespace wctrn\realloc;
trait Logger {
public function log_error( string $msg ) : bool {
return error_log( $msg );
}
}
<?php
abstract class aFoo {
abstract function baz( int $foobar );
}
abstract class aBar extends aFoo {
// expected type of foobar is still int
abstract function baz( $foobar ) : int;
}
<?php
function variadic_sum( int ... $args ) {
return array_sum( $args );
}
// echoes 6
echo variadic_sum( 1, 2, 3 ), PHP_EOL;
$a = [ 1, 2, 3 ];
<?php
function xrange( $start, $limit, $step = 1 ) {
for ( $i = $start; $i <= $limit; $i += $step ) {
yield $i;
}
}
/*
* An array is never created or returned
<?php
// Sort an array of objects by name
usort( $arr, function ( $a, $b ) {
return strcmp( $a->name, $b->name );
} );
function callback_function_name() {
// do something
}
@lloc
lloc / nvm-update.sh
Created February 16, 2018 11:32
Use nvm for node-update
nvm ls-remote
nvm install --lts
@lloc
lloc / nvm-install.sh
Last active February 16, 2018 11:18
Ubuntu 16.04: install nvm
sudo apt update
sudo apt install build-essential libssl-dev
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
@lloc
lloc / node-npm-install.sh
Last active February 16, 2018 11:14
Ubuntu 16.04: install node and npm
sudo apt update
sudo apt install nodejs nodejs-legacy npm
@lloc
lloc / changelog.php
Created January 2, 2018 23:31
Script for the changelog.php post
<?php
namespace lloc\changelog;
exec( 'git fetch --tags' );
$cmd = 'git tag -l --format="%(creatordate:iso8601)|%(refname:short)" | sort -r';
$arr = ( new ArrayOutput( $cmd ) )->get();
$tags = new Tags( $arr );
@lloc
lloc / Logs.php
Created January 2, 2018 23:29
Class of the changelog.php post
<?php
namespace lloc\changelog;
class Logs {
/**
* @var array
*/
protected $logs = [];