Skip to content

Instantly share code, notes, and snippets.

View akrabat's full-sized avatar

Rob Allen akrabat

View GitHub Profile
@akrabat
akrabat / CorsMiddlewareFactory.php
Created October 21, 2017 13:12
Expressive factory to use CORS middleware
<?php declare(strict_types=1);
namespace App\Factory;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Tuupola\Middleware\Cors;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\JsonResponse;
use Zend\ProblemDetails\ProblemDetailsResponseFactory;
use Zend\Stratigility\Middleware\CallableMiddlewareWrapper;
@akrabat
akrabat / rock-paper-scissors.swift
Created September 13, 2017 21:02
OpenWhisk Rock-Paper-Scissors game
// Rock Paper Scissors game
// To install:
// $ wsk action update rock-paper-scissors rock-paper-scissors.swift
//
// To play:
// $ wsk action invoke rock-paper-scissors -r -p shape rock
import Foundation
func main(args: [String:Any]) -> [String:Any] {
@akrabat
akrabat / .bash_profile
Last active March 9, 2017 09:25
Swap OpenWhisk credentials
# OpenWhisk
function owibm() {
wsk property set --apihost openwhisk.ng.bluemix.net --auth {auth key here}
wsk property unset --namespace
}
function owlocal() {
(
cd ~/Projects/openwhisk/openwhisk/tools/vagrant && \
@akrabat
akrabat / README.md
Last active March 7, 2017 16:30
Slim PR workflow summary

Assumptions:

  1. You have hub (https://github.com/github/hub) installed
  2. You have your own fork of Slim as origin and have added slimphp/slim as a remote called upstream

Process:

  1. Update:

$ git checkout 4.x && git pull upstream 4.x

@akrabat
akrabat / Makefile
Created February 11, 2017 19:50
Makefile for building rst2pdf presentations, creating a PDF and a Keynote file
.PHONY: all clean keynote
# name of the PDF to create
pdf = ../2017-02-22-PHPOxford-Slim-OAuth2.pdf
# Aspect ratio of Keynote file
# common choices:
# 1024 x 768
# 1280 x 720
aspect_ratio = 1280 x 720
@akrabat
akrabat / test.php
Created December 7, 2016 16:09
Playing with code
<?php
class CustomerMaintenanceControllerFactory
{
public function __invoke($c) {
$customerMapper = $c->get('CustomerMapper');
$deleteForm = $c->get('CustomerDeleteForm');
$editForm = $c->get('CustomerEditForm');
return new CustomerMaintenanceController($customerMapper, $deleteForm, $editForm);
}
@akrabat
akrabat / test.php
Created December 6, 2016 14:18
Using ControllerPluginManager factories to inject dependencies into a controller in ZF2 and ZF3
<?php
// Using ControllerPluginManager factories to inject dependencies into
// a controller in ZF2 and ZF3
namespace My;
use Zend\Mvc\Controller\PluginManager as ControllerPluginManager;
class BookControllerFactory {
public function __invoke($container) {
// in ZF2, $container is an instance of ControllerPluginManager
@akrabat
akrabat / zend-service-manager-3-example.php
Created December 6, 2016 10:33
Example use of Zend\ServiceManager 3
<?php
require('vendor/autoload.php');
use Zend\ServiceManager\Factory\InvokableFactory;
//--------------------------------------------------------
// classes that we are interested in
class Letter {
public function __construct($paper, $envelope) {
$this->paper = $paper;
@akrabat
akrabat / index.php
Created November 17, 2016 17:52
Use original request in Slim 3 middleware
<?php
$app->add(function ($request, $response, $next) {
// use the original request and ignore the one passed into us
$request = $this->get('request');
// do something here
// continue
return $next($request, $response);
});

Things to do before leaving

  • Slides to USB key
  • Backup laptop & ensure Dropbox has sync'd
  • git push all the things!
  • Charge camera batteries

Tech stuff

  • Laptop