Skip to content

Instantly share code, notes, and snippets.

View cosimo's full-sized avatar
🇳🇴

Cosimo Streppone cosimo

🇳🇴
View GitHub Profile
@cosimo
cosimo / x-forwarded-for.vcl
Created January 13, 2012 18:03
Varnish X-Forwarded-For VCL snippet
# See http://www.varnish-cache.org/trac/ticket/540
sub inject_forwarded_for {
# Rename the incoming XFF header to work around a Varnish bug.
if (req.http.X-Forwarded-For) {
# Append the client IP
set req.http.X-Real-Forwarded-For = req.http.X-Forwarded-For ", " regsub(client.ip, ":.*", "");
#unset req.http.X-Forwarded-For;
}
else {
@cosimo
cosimo / find-5.010-isms.pl
Created February 21, 2012 09:47
Finds if a perl file contains 5.10-isms but lacks the "use 5.010" at the top
#!/usr/bin/env perl
#
# Finds if a perl file contains 5.10-isms
# but lacks the "use 5.010" at the top
#
use strict;
use warnings;
use Data::Dumper ();
@cosimo
cosimo / mytap_exception.my
Created April 2, 2012 19:04
mytap.dies_ok() ?
DELIMITER //
DROP PROCEDURE IF EXISTS populate_table //
CREATE PROCEDURE populate_table ()
BEGIN
DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' BEGIN
SELECT tap.ok(
0,
@cosimo
cosimo / default.vcl
Created May 30, 2012 13:34
Attempt to transpose libvmod-shield to varnish 2.1
include "/etc/varnish/reset-connection.vcl";
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
if (req.http.CloseMe) {
C{
@cosimo
cosimo / find-unused-css-selectors.pl
Created July 26, 2012 14:09
Find unused CSS selectors across a list of URLs
#!/usr/bin/env perl
#
# Find unused CSS selectors by crawling a list of URLs
# (--url, even more than one) and matching all elements in
# a page to find out which selectors are never used across
# all given URLs
#
# Usage:
# ./find-unused-css-selectors.pl --css file.css --url http://some.url [--url http://some.other.url ...]
#
@cosimo
cosimo / custom-head.html
Created August 25, 2012 08:57
OSQA responsive layout
<meta name="viewport" content="width=device-width, initial-scale=1">
sub vcl_fetch {
# ...
if (beresp.http.Cache-Control ~ 'no-cache') {
set beresp.ttl = 0s;
return (deliver);
}
# ...
@cosimo
cosimo / parse-options.sh
Created September 21, 2012 09:31
Example of how to parse options with bash/getopt
#!/bin/bash
#
# Example of how to parse short/long options with 'getopt'
#
OPTS=`getopt -o vhns: --long verbose,dry-run,help,stack-size: -n 'parse-options' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
echo "$OPTS"
@cosimo
cosimo / anyevent-udp-server.pl
Created January 13, 2013 11:12
Simple AnyEvent UDP server
#!/usr/bin/perl
=head1 NAME
anyevent-udp-server.pl - Simple AnyEvent::Handle::UDP UDP server
=head1 DESCRIPTION
Starts a UDP server that listens on a given port for
input (incoming udp packets).
@cosimo
cosimo / squeeze-backports-kernel.sh
Created January 25, 2013 12:30
Upgrade Debian Squeeze with backports kernel (3.2.0)
#!/bin/sh
echo 'deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free' > /etc/apt/sources.list.d/squeeze-backports.list
apt-get update
apt-get -t squeeze-backports install linux-base initramfs-tools linux-image-3.2.0-0.bpo.4-amd64