Skip to content

Instantly share code, notes, and snippets.

View jmsfwk's full-sized avatar

James Fenwick jmsfwk

View GitHub Profile
@jmsfwk
jmsfwk / Computus.php
Created March 25, 2017 15:23
A couple of algoritms for calculating the date of Easter
<?php
class Computus
{
public static function gauss(int $year)
{
$a = $year % 19;
$b = $year % 4;
$c = $year % 7;
@jmsfwk
jmsfwk / Context.php
Created February 5, 2018 11:55
Class to send data to template that tries to avoid exceptions when data does not exists
<?php
use ArrayAccess;
use ArrayIterator;
use IteratorAggregate;
class Context implements ArrayAccess, IteratorAggregate
{
/** @var array */
private $data;
@jmsfwk
jmsfwk / .gitlab-ci.yml
Created February 7, 2018 12:23
Gitlab Ci configuration for simple PHP projects
before_script:
# Install dependencies
- sh docker_install.sh > /dev/null
cache:
paths:
- vendor/
php:7.1:
image: php:7.1-alpine
@jmsfwk
jmsfwk / listbox.html
Last active February 28, 2018 14:59
<html>
<head>
<meta charset="UTF-8">
<script src="vue.js"></script>
<script>
const data = [
{
"id": "739d8b36-e80f-4c04-9188-757a5bd64e70",
"headline": "Liverpool initiative for renewing housing stock to benefit local contractors"
},
@jmsfwk
jmsfwk / suggestion.md
Last active July 13, 2018 10:37
PSR-15 Middleware vs HttpKernelInterface implemented as middleware

Different middleware implementations for comparison

PSR-15 Middleware

<?php

use Psr\Http\Server\{MiddlewareInterface, RequestHandlerInterface};
use Psr\Http\Message\{ServerRequestInterface, ResponseInterface};

class Middleware implements MiddlewareInterface
<?php
abstract class Factory
{
/** @var \Illuminate\Database\ConnectionInterface */
private $database;
/** @var \Faker\Generator */
protected $faker;
protected $attributes = [];
@jmsfwk
jmsfwk / default.conf
Last active February 20, 2019 10:23
Nginx conf for an app in different places in different containers
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
@jmsfwk
jmsfwk / default.conf
Created January 31, 2019 16:11
Laravel docker compose configuration
server {
listen 80;
root /usr/share/nginx/html;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
@jmsfwk
jmsfwk / git-cleanup
Created June 6, 2019 13:46
Git delete merged branches
#!/bin/bash
set -ue
git fetch
git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d
@jmsfwk
jmsfwk / pre-push
Last active June 6, 2019 15:38 — forked from jgosmann/pre-push
Prevent pushing fixup, squash, and WIP commits to master.
#!/bin/sh
# An example hook script to verify what is about to be pushed to master. Called
# by "git push" after it has checked the remote status, but before anything has
# been pushed. If this script exits with a non-zero status nothing will be
# pushed.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done