Skip to content

Instantly share code, notes, and snippets.

@andybeak
andybeak / xssTest.php
Last active April 23, 2020 16:17
PHPunit test for a permissive xss routine
<?php
/**
*
* There are use cases where using filter_var( FILTER_SANITIZE_STRING ) is not desireable because it is too greedy.
* In the event that you have written a more permissive xss cleaning routine this unit test can be used to test your
* cleaning routine. The list of attack vectors is not comprehensive but should give you a good start.
*
* The detection routine below is based on https://github.com/symphonycms/xssfilter/blob/master/extension.driver.php
* and on https://gist.github.com/mbijon/1098477
@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 / entityProvider
Created February 12, 2015 13:03
This fixes the "“class” is not a valid entity or mapped super class". See https://stackoverflow.com/questions/15099060/doctrine2-class-is-not-a-valid-entity-or-mapped-super-class
<?php
/**
* Configures and provides an Entity Manager
*/
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Annotations\AnnotationReader;
@andybeak
andybeak / nginx.conf
Last active February 27, 2023 23:39
An nginx config for Wordpress #nginx #config #wordpress
# Read http://codex.wordpress.org/Nginx
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://www.queryadmin.com/854/secure-wordpress-nginx/
# http://tautt.com/best-nginx-configuration-for-security/
# https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
#
# Generate your key with: openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
# Generate certificate: sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
@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),