Skip to content

Instantly share code, notes, and snippets.

View aderowbotham's full-sized avatar
👽

Adrian Rowbotham aderowbotham

👽
View GitHub Profile
# Copied from http://kly.no/varnish/regex.txt
# Thanks to Kristian Lyngstøl / @KristianLyng for putting this together
Regular expression cheat sheet for Varnish
Varnish regular expressions are NOT case sensitive. Varnish uses POSIX
regular expressions, for a complete guide, see: "man 7 regex"
Basic matching:
@aderowbotham
aderowbotham / mobile_not_implemented.css
Created July 3, 2013 09:19
mobile layout not implemented notification message (for sites in development)
/* mobile
============================================================================================== */
@media screen and (min-width: 0) and (max-width: 700px) {
/* hide everything */
div, span, p
{
display: none;
}
body:before {
@aderowbotham
aderowbotham / php_argv_environment.php
Created November 25, 2012 17:37
PHP / Codeigniter - set environment when running in CLI mode
<?php
# in public_html/index.php
/*
* Where your CodeIgniter ENVIRONMENT is normally defined by the server environment
* variables, and assuming your database settings are automatically set based on
* that environment, this causes a problem when running the application through
* PHP on the command line e.g. in order to run CodeIgniter Migrations
*
@aderowbotham
aderowbotham / Cache-bust Gruntfile.js
Last active May 11, 2020 10:11
Set cache-busing file revision using Grunt
/*
Example using grunt-contrib-concat, but this should work with any package
Inject string-based timestamp into an output filename, e.g. vendor-min.ka2bct2u.js
*/
module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.initConfig({
@aderowbotham
aderowbotham / replace-content-not-attributes.js
Created September 6, 2021 16:25
Javascript replace HTML text but not affect attribute values in double quotes
// javascript (ES5)
function highlight(content, term, startWrapper, endWrapper){
// negative match for the pattern surrounded by quotes ""
// followed by positive match for the term on its own
// the required pattern is as follows but we have to use RegExp() to set the term dynamically
// regex = /(?!"*term*")(?:term)/ig
var expression = new RegExp('(?!"*' + term + ' *")(?:' + term + ')', "i");
return content.replace(expression, startWrapper + content.match(expression) + endWrapper);
}
@aderowbotham
aderowbotham / django_ami.md
Created June 7, 2012 14:19
Django stack setup on EC2 AMI

Django Stack

Overview

This is a set of instructions to setup a Django Nginx Gunicorn MySQL/Postgres stack on a single Amazon EC2 instance.

Server - AWS

@aderowbotham
aderowbotham / stripe-intent.php
Last active April 29, 2022 08:13
PHP / Stripe payment
<?php
// uses "stripe/stripe-php": "6.37.0",
// this is in the body of an API controller function that my stripe form posts to
// frontend uses https://js.stripe.com/v3/
// **the js posts a body with `payment_method_id` or `payment_intent_id` depending on the step of the process**
// this is captured as a property of $input
function the_post_method()
{
@aderowbotham
aderowbotham / purge-ban-domain-varnish.md
Last active May 24, 2022 19:55
Purge (ban) an entire domain in Varnish Cache 3

How to purge ('ban') an entire domain in Varnish Cache 3

#####EDIT: NB Ban is technically different from Purge. Banned objects remain in memory but banning is faster than purging. Read the Varnish 3 documentation here and here.

Purge may be a more appropriate action for your use-case; although the examples in the gist below work, it's not necessarily the best way of doing this.


@aderowbotham
aderowbotham / formatted-print_r.php
Last active July 5, 2023 13:36
PHP debugging shortcut for '<pre>' + print_r() + die(), that formats keys in red and values in blue.
# colour-formatted print_r shortcut
if ( ! function_exists('prd')){
function prd($object,$die=TRUE){
# insert span tags
$output = '<span class="die_value">'.$output;
$output = str_replace('[', '<span class="die_key">[', print_r($object,TRUE));
$output = str_replace(']', ']</span>', $output);
$output = str_replace('=> ', '=> <span class="die_value">', $output);