Skip to content

Instantly share code, notes, and snippets.

View ThijsFeryn's full-sized avatar

Thijs Feryn ThijsFeryn

View GitHub Profile
@ThijsFeryn
ThijsFeryn / update_find_and_replace_by_last_occurrence.sql
Last active June 9, 2016 10:14
Update statement that does a find and replace based on the last occurrence of a string
UPDATE `table` SET `somefield` = CONCAT(TRIM(TRAILING 'feryn.eu' FROM `name`),'thijs.be') WHERE 'otherField' = 'value'
@ThijsFeryn
ThijsFeryn / find_and_replace_by_last_occurrence.sql
Last active June 9, 2016 10:13
Find and replace in MySQL by last occurrence
SELECT CONCAT(TRIM(TRAILING 'feryn.eu' FROM 'feryn.eu.bla.feryn.eu'),'thijs.be')
@ThijsFeryn
ThijsFeryn / wordpress.vcl
Created June 3, 2016 07:51
Typical Wordpress VCL for Varnish 4
vcl 4.0;
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
.max_connections = 300;
.first_byte_timeout = 100s;
.connect_timeout = 10s;
@ThijsFeryn
ThijsFeryn / varnish_proxy_support_custom_headers.vcl
Created January 20, 2016 13:02
Send custom headers to the application to check client.ip, server.ip, local.ip & remote.ip
vcl 4.0;
backend default {
.host = "10.10.10.53";
.port = "80";
}
sub vcl_recv {
set req.http.x-clientip = client.ip;
set req.http.x-serverip = server.ip;
@ThijsFeryn
ThijsFeryn / varnish_proxy_support.php
Created January 20, 2016 13:00
Print custom headers set by Varnish to display the different IP's and print the X-Forwarded-For header
<?php
echo "Client IP: " . $_SERVER["HTTP_X_CLIENTIP"]. "<br />".PHP_EOL;
echo "Server IP: " . $_SERVER["HTTP_X_SERVERIP"]. "<br />".PHP_EOL;
echo "Local IP: " . $_SERVER["HTTP_X_LOCALIP"]. "<br />".PHP_EOL;
echo "Remote IP: " . $_SERVER["HTTP_X_REMOTEIP"]. "<br />".PHP_EOL;
echo "X-Forwarded-For: " . $_SERVER["HTTP_X_FORWARDED_FOR"]. "<br />".PHP_EOL;
@ThijsFeryn
ThijsFeryn / haproxy_proxy_protocol_support.cfg
Created January 20, 2016 12:52
Combine HTTP backends & PROXY backends in HAProxy
global
daemon
defaults
mode http
frontend http-in
bind *:80
default_backend servers
backend servers
@ThijsFeryn
ThijsFeryn / varnish_proxy_support_startup_options.txt
Created January 20, 2016 12:44
Adding PROXY protocol support by adding an extra listener on a separate port. Explictly add the PROXY keyword to enforce the protocol
/usr/sbin/varnishd -a :6081 -a :6083,PROXY -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,5g
@ThijsFeryn
ThijsFeryn / 11_int_div.php
Created November 30, 2015 14:18
PHP 7 integer division
<?php
/**
* Integer division
*/
var_dump(
intdiv(10, 3),
(10/3)
);
@ThijsFeryn
ThijsFeryn / 10_dirname.php
Created November 30, 2015 14:18
PHP 7 dirname levels
<?php
/**
* Dirname levels
*/
echo dirname('/usr/local/bin').PHP_EOL;
echo dirname('/usr/local/bin',1).PHP_EOL;
echo dirname('/usr/local/bin',2).PHP_EOL;
echo dirname('/usr/local/bin',3).PHP_EOL;
@ThijsFeryn
ThijsFeryn / 9_throwable.php
Created November 30, 2015 14:17
PHP 7 throwables
<?php
/**
* Throwable interface
*/
//Error as Throwable
try {
sqdf();
} catch (Throwable $t) {