Skip to content

Instantly share code, notes, and snippets.


Rob Attfield rattfieldnz

View GitHub Profile
rattfieldnz / run_phpunit
Created Oct 17, 2019
Script to run PHPUnit tests in a Laravel-based project, with keys not stored in phpunit.xml.
View run_phpunit
if [ -z "$1" ] && [ -z "${GOOGLE_API_KEY}" ]; then
echo 'Please provide a Google API key.'
if [ -z "$2" ] && [ -z "${CODECOV_TOKEN}" ]; then
rattfieldnz / config.yml
Last active Nov 2, 2019
Sample CircleCI config of my latest Laravel project, stored in a private BitBucket repository.
View config.yml
version: 2
- image: circleci/php:7.3-fpm
parallelism: 4
rattfieldnz /
Last active Oct 16, 2019 — forked from mahemoff/
circleci mysql upgrade
set -x
set -e
export DEBIAN_FRONTEND=noninteractive
sudo apt-get --purge autoremove -y mysql-server-5.6
sudo apt-key adv --keyserver --recv-keys 8C718D3B5072E1F5
rattfieldnz / GoogleApiException.php
Last active Aug 26, 2017
Return a Google_Service_Exception as a collection (good for API usage with Laravel framework)
View GoogleApiException.php
* Return a Google_Service_Exception as a collection (good for API usage with Laravel framework).
* This example is used in a Laravel (v 5.4.34) app with spatie/analytics package.
* @param \Google_Service_Exception $e
* @see
* @see
* @see
rattfieldnz / Http.php
Created Aug 6, 2017
A class containing a function which checks if a URL can be shown in iframes. Revisions, suggestions, and optimization tips are very welcome!
View Http.php
* Class Http
* A class to manage HTTP-related functionality.
* @author Rob Attfield <> <>
* @package App\Helpers\Functions
rattfieldnz / cspheader.php
Created Aug 6, 2017 — forked from phpdave/cspheader.php
CSP Header for PHP or Apache or .htaccess - Content Security Protocol
View cspheader.php
//CSP only works in modern browsers Chrome 25+, Firefox 23+, Safari 7+
$headerCSP = "Content-Security-Policy:".
"connect-src 'self' ;". // XMLHttpRequest (AJAX request), WebSocket or EventSource.
"default-src 'self';". // Default policy for loading html elements
"frame-ancestors 'self' ;". //allow parent framing - this one blocks click jacking and ui redress
"frame-src 'none';". // vaid sources for frames
"media-src 'self' *;". // vaid sources for media (audio and video html tags src)
"object-src 'none'; ". // valid object embed and applet tags src
"report-uri;". //A URL that will get raw json data in post that lets you know what was violated and blocked
View gist:20fdf11a10820d0cbf2fcd33f47ece46
Verifying that "" is my Blockstack ID.
View convertDegreesToCompass.js
* A function to convert direction in degrees to general compass direction.
* @param {Number} deg The value to be converted, in degrees.
* @return {String} The converted compass direction.
function convertDegreesToCompass(deg){
// The 16 general compass directions
var compassDirections = ["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"];
View fizzbuzz2.php
* Task:
* Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz".
* For numbers which are multiples of both three and five print "FizzBuzz".
* Instructions:
* This file (fizzbuzz.php) can be uploaded to a webserver that's running PHP4+ and executed with "php fizzbuzz.php" from the command line.
* Alternatively, this file can be accessed directly (if webserver permissions allow) via your browser.
You can’t perform that action at this time.