Skip to content

Instantly share code, notes, and snippets.

@jlem
jlem / 0_reuse_code.js
Last active August 29, 2015 14:11
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jlem
jlem / ShouldBeValidated.php
Last active November 23, 2016 19:00
Sloppy Validation Wrapper
<?php
// Assign this to models and implement these methods
interface ShouldBeValidated
{
/**
* Returns an array of key => value rules (as per normal Laravel validation)
*
* @return array
@jlem
jlem / git_export_to_folders.sh
Last active August 29, 2015 14:19
Exporting contents of git branches into separate folders
#!bin/bash
folder=$1
if [ -z $1 ]
then
echo 'Please provide the root destination of the export:'
read folder
fi
git fetch --all
@jlem
jlem / command
Created May 18, 2015 14:54
Source all .sql files in a directory into database
cat *.sql | mysql
@jlem
jlem / swwwwwwwwwwwwwwwwwwwwwwwt
Created May 26, 2015 14:23
swwwwwwwwwwwwwwwwwwwwwwwt
swwwwwwwwwwwwwwwwwwwwwwwt
@jlem
jlem / BottomNavTest.php
Last active August 29, 2015 14:23
Example unit test
class BottomNavTest extends PHPUnit_Framework_Testcase
{
public function test_buttons_are_constructed_from_php_config_and_have_the_given_order()
{
// Defined in JSON, mocked here
$buttonOrder = ['home', 'pages', 'pierce', 'map', 'on-scene'];
// Configuration for buttons lives in PHP for now
@jlem
jlem / Clan.php
Created August 20, 2015 06:40
Model usage
<?php namespace GR\Clan;
use Illuminate\Database\Eloquent\Model;
use GR\Section\SectionInterface;
use GR\Member\MemberInterface;
use GR\Lib\ModelCache;
use GR\Member\Member;
class Clan extends Model implements ClanInterface
{
@jlem
jlem / ApplicationsServiceProvider.php
Created August 21, 2015 14:35
Laravel 5 App Skeleton
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Request;
use View;
use App;
abstract class ApplicationsServiceProvider extends ServiceProvider
{
public function register()
@jlem
jlem / Member.php
Created August 25, 2015 03:19
Eloquent model caching
<?php
class Member extends Model implements CurrentMember
{
use ModelCache;
public function getLeaguePlayer(SectionInterface $section)
{
return $this->cache(function(SectionInterface $section) {
return $this->leaguePlayers()
->where('section_id', $section->getID())
@jlem
jlem / policies.php
Created September 1, 2015 02:46
Policy definitions
<?php
use ... // folded for brevity
return [
'league.enable' => [
'rules' => [
AtLeastAdmin::class,
HasJurisdiction::class,
LeagueIsNotEnabled::class