Skip to content

Instantly share code, notes, and snippets.

View 4lun's full-sized avatar

Alun Davey 4lun

View GitHub Profile
@4lun
4lun / output
Last active August 29, 2015 14:21
Generates solutions for the maths puzzle for Vietnamese eight-year-olds. UPDATE: Missing quite a few answer combinations, see comment thread here: http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/20/can-you-do-the-maths-puzzle-for-vietnamese-eight-year-olds-that-has-stumped-parents-and-teachers#comment-52484375
8, 9, 6, 1, 3, 4, 7, 5, 2
8, 9, 3, 6, 5, 1, 2, 7, 4
7, 9, 3, 1, 2, 5, 6, 8, 4
9, 8, 2, 4, 5, 7, 6, 1, 3
7, 6, 1, 9, 5, 4, 2, 8, 3
9, 8, 6, 4, 5, 1, 7, 2, 3
7, 6, 1, 4, 3, 8, 9, 5, 2
5, 7, 1, 3, 4, 9, 8, 2, 6
7, 6, 4, 1, 3, 8, 5, 9, 2
8, 9, 6, 3, 5, 1, 2, 7, 4
@4lun
4lun / PageController.php
Created June 1, 2015 15:24
Controller for Laravel 5 that loads views from the filesystem based on the URL
<?php namespace App\Http\Controllers;
class PageController extends Controller
{
/**
* Loads page from the filesystem
* @param String $page
* @return Response
*/
while :; do say "This speech is my recital, I think its very vital. " \
"To rock a rhyme thats right on time. " \
"Its Tricky is the title, here we go. " \
"Its tricky to rock a rhyme, to rock a rhyme thats right on time. " \
"Its tricky, its tricky, tricky. " \
"Tricky, tricky. " \
"Its tricky to rock a rhyme, to rock a rhyme thats right on time. " \
"Its tricky, tr-tr-tricky, tricky. " \
"Tricky. " \
"I met this little girlie, her hair was kinda curly. " \
@4lun
4lun / setup.sh
Last active August 29, 2015 14:25
Initial VM setup for dev work (Ubuntu 14.04). Mainly for Laravel and such
# Run as root, change below variables
export PROJECT_NAME='project'
export DEBIAN_FRONTEND="noninteractive" # Supress mysql-server password dialog (set password during mysql_secure_installation command instead)
apt-get install nginx php5-fpm php5-cli php5-mysql mysql-server nodejs nodejs-legacy npm -y
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
sudo -u www-data -H mkdir -p /var/www/$PROJECT_NAME/public
@4lun
4lun / Model.php
Created September 23, 2015 12:06
Laravel 5.1 Base Model - adds defaults to $casts property on __construct
<?php
namespace App;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Model extends Eloquent
{
/**
* Create a new Eloquent model instance.
@4lun
4lun / HasRoles.php
Created October 6, 2015 16:15
Basic role implementation for Laravel 5
<?php
namespace App\Traits;
use Illuminate\Support\Str;
use App\Role;
/**
* Adds roles to a model
* Note: requires a Role model pivot table {model}_roles and a role table with
@4lun
4lun / log_deprecated_method.helpers.php
Created October 16, 2015 10:45
Laravel helper log_deprecated_method
<?php
/**
* Writes to the log that a deprecated method was called, and where it was called from.
*/
function log_deprecated_method()
{
list($x, $current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
$currentMethod = (isset($current['class']) ? $current['class'].'::' : '').$current['function'].'()';
$callerMethod = (isset($caller['class']) ? $caller['class'].'::' : '').$caller['function'].'()';
@4lun
4lun / cmus-osx.md
Last active February 20, 2016 14:57
cmus on OSX (inc. mediakeys and lastfm integration)

cmus

Install

brew install cmus

cmusfm

Install

git clone git@github.com:Arkq/cmusfm.git

cd cmusfm

@4lun
4lun / index.php
Created December 7, 2015 16:28
Simple script to help demo load balancing.
<?php
$id = sha1(getenv('HOSTNAME'));
function rgbcode($id){
return '#'.substr(md5($id), 0, 6);
}
?><html>
<style>
body { padding: 30px; background-color: <?php echo rgbcode($id); ?>; font-family: sans-serif; }
h1 { background: #000; color: #fff; margin: 0; padding: 5px; float: left; }
@4lun
4lun / unifi.sh
Last active December 17, 2015 15:55
Start UniFi Controller from CLI (OSX)
cd /Applications/UniFi.app/Contents/Resources;
java -jar /Applications/UniFi.app/Contents/Resources/lib/ace.jar ui