Skip to content

Instantly share code, notes, and snippets.

@andybeak
andybeak / addContentSecurityPolicy.php
Last active August 29, 2015 14:07
Adding content security policy (PHP / Apache)
<?php
/**
* addContentSecurityPolicy
*
* Read : https://www.owasp.org/index.php/List_of_useful_HTTP_headers
* https://www.owasp.org/index.php/Content_Security_Policy_Cheat_Sheet
* http://www.html5rocks.com/en/tutorials/security/content-security-policy/
* https://www.owasp.org/index.php/Content_Security_Policy
* http://content-security-policy.com/
*
@andybeak
andybeak / Log.php
Created January 27, 2015 10:57
Simple implementation of Monolog
<?php
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
class Log
{
public static $log;
<?php
/**
* Class Cache
*
* Facade class to wrap the basic cache functions we use to the Memcached extension so that
* we can decide to use a different cache and just rewrite this file instead of changing
* all the usages.
*
* @author Andy Beak
@andybeak
andybeak / gist:74ed62b090c464e41426
Created March 20, 2015 14:57
Downloadable Excel charts in PHP with Laravel
composer.json
=============
For Laravel 4.x : "maatwebsite/excel": "1.*"
For Laravel 5 you can use the newer version.
HTML
====
<form action="/ppd/download-excel" method="POST" id="download-ppd">
<input id="form-filter-data" name="filter-data" type="hidden">
@andybeak
andybeak / gist:750afee1bccd3e3fddf3
Created March 30, 2015 14:59
Ignore duplicate inserts in Postgre SQL
CREATE OR REPLACE RULE db_table_ignore_duplicate_inserts AS
ON INSERT TO db_table
WHERE (EXISTS ( SELECT 1
FROM db_table
WHERE db_table.tbl_column = NEW.tbl_column)) DO INSTEAD NOTHING;
@andybeak
andybeak / app.start.global.php
Created April 9, 2015 07:39
Laravel logging - change level for production
/*
|--------------------------------------------------------------------------
| Application Error Logger
|--------------------------------------------------------------------------
|
| Here we will configure the error logger setup for the application which
| is built on top of the wonderful Monolog library. By default we will
| build a basic log file setup which creates a single file for logs.
|
*/
@andybeak
andybeak / partition_uk_land_registry_data.sql
Created April 10, 2015 16:09
Partitioning a table in Postgres
CREATE TABLE price_paid_data
(
id character varying(255) NOT NULL,
price integer NOT NULL,
purchase_date date NOT NULL,
postcode character varying(7),
property_type character varying(1),
new_build character varying(1) NOT NULL DEFAULT 0,
estate_type character varying(1),
paon character varying(255),
#!/bin/bash
# Script from http://www.cyberciti.biz/tips/howto-linux-unix-write-to-syslog.html
result=$(echo -e "ping\n\r" | nc localhost 6082|grep PONG|wc -l);
if [ "${result}" -lt "1" ];
then
/etc/init.d/varnish stop;
sleep 5;
@andybeak
andybeak / get_post_from_body.php
Created May 21, 2015 12:49
Get post from body in Laravel
/**
* getPostFromBody
*
* Returns an array obtained from reading and decoding the post body
* Optionally supply an array of fields that are required to be present
*
* @version 1.0.0
* @author Andy Beak
* @since 1.0.0
@andybeak
andybeak / s3 bucket policy
Last active August 29, 2015 14:21
Amazon S3 allow global access to read bucket
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",