Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -eu
_UID=$(id -u)
GID=$(id -g)
# give lxd permission to map your user/group id through
grep root:$_UID:1 /etc/subuid -qs || sudo usermod --add-subuids ${_UID}-${_UID} --add-subgids ${GID}-${GID} root
# set up a separate key to make sure we can log in automatically via ssh
# with $HOME mounted
@nottrobin
nottrobin / setup-lxc-shared-directory.sh
Last active January 20, 2017 16:03
How to set up a *writeable* shared directory in an LXC/LXD container
[robin@xps ~ ]$ lxc launch ubuntu:16.04 my-xenial # Create & start a new container
[robin@xps ~ ]$ getfacl ./share/ # Check extended permissions on "share" directory
# file: share
# owner: robin
# group: robin
user::rwx
group::rwx
other::r-x
[robin@xps ~ ]$ sudo ls -ld /var/lib/lxd/containers/my-xenial # Find the user ID for my container (165536)
[sudo] password for robin:
@noodlehaus
noodlehaus / php-recipes.markdown
Last active August 10, 2017 14:41
Some patterns I use in plain old PHP apps

pulling values from arrays

$name = @$_POST['name'];
# => null or the value for name

defaults for associative arrays

@eddmann
eddmann / SecureSessionHandler.php
Created April 9, 2014 12:18
Secure session handler implementation.
<?php
class SecureSessionHandler extends SessionHandler {
protected $key, $name, $cookie;
public function __construct($key, $name = 'MY_SESSION', $cookie = [])
{
$this->key = $key;
$this->name = $name;
<?php
/**
* procedural wrappers for web request/response variables
*
* @author Jesus A. Domingo <[email protected]>
* @license MIT
*/
/**
* Gets a request parameter (from $_GET over $_POST combination)
@sukei
sukei / Router.php
Created February 19, 2014 15:21
A Router in a Tweet
<?php
/**
* The Router class is a fast and lightweight router (yes it is). It can handle
* a path and call the matching controller. If there is no match, then an
* exception will be throwned.
*
* ...and it fits in a tweet.
*
* @author Quentin Schuler aka Sukei <[email protected]>
@sukei
sukei / Container.php
Last active April 20, 2022 08:44
A Service Container in a Tweet
<?php
/**
* The Container class is a lightweight service container.
*
* ...and it fits in a tweet.
*
* @author Quentin Schuler aka Sukei <[email protected]>
*/
class Container{private $s;function set($k,$c){$this->s[$k]=$c;}function get($k){return(is_a($v=$this->s[$k],'Closure'))?$v($this):$v;}}
@sukei
sukei / Template.php
Last active August 24, 2021 12:05
A Template Engine in a Tweet
<?php
/**
* The render function is a lightweight template engine, that allows string
* interpolation and output escaping.
*
* ...and it fits in a tweet.
*
* @author Quentin Schuler aka Sukei <[email protected]>
*/
@sukei
sukei / Signal.php
Last active August 24, 2021 11:08
An Observer in a Tweet
<?php
/**
* The Signal class is the smallest and fastest observer written in PHP 5.6 and
* using some new features such as the variadic functions and the arguments
* unpacking.
*
* ...and it fits in a tweet.
*
* @author Quentin Schuler aka Sukei <[email protected]>
@mathiasverraes
mathiasverraes / TestFrameworkInATweet.php
Last active September 24, 2024 14:47
A unit testing framework in a tweet.
<?php
function it($m,$p){echo ($p?'✔︎':'')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);}