Skip to content

Instantly share code, notes, and snippets.

View .profile
alias now='/bin/date +%s'
# Convert a timestamp
unixtime() {
php -r 'if (isset($argv[1]) && is_numeric($argv[1])) print date(DATE_RSS, $argv[1]) . "\n";' $1
}
# Local VM config
export localvmname="Debian32"
View memcached-tool
#!/usr/bin/perl
#
# memcached-tool:
# stats/management tool for memcached.
#
# Author:
# Brad Fitzpatrick <brad@danga.com>
#
# License:
# public domain. I give up all rights to this
@benclark
benclark / default.vcl
Created May 14, 2012
Varnish config file w/ basic auth
View default.vcl
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}
acl purge {
"localhost";
@benclark
benclark / gist:4667006
Created Jan 29, 2013
Mobile detection in .htaccess file
View gist:4667006
###
# BEGIN MOBILE REDIRECTS
###
# If the skipMobileDetection cookie is set, and we're on the mobile domain,
# return to the normal domain. Do this only for SSL as Varnish will handle
# for port 80.
RewriteCond %{HTTP_COOKIE} skipmobiledetection [NC]
RewriteCond %{HTTP_HOST} ^m\. [NC]
RewriteCond %{SERVER_PORT} =443
@benclark
benclark / my.cnf
Created Aug 21, 2012
MySQL config
View my.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
@benclark
benclark / default.vcl
Created Jul 25, 2012
Varnish config file w/ mobile redirect
View default.vcl
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}
acl purge {
"localhost";
@benclark
benclark / gist:3974958
Created Oct 29, 2012
SQL snippet for estimating Drupal cache table sizes
View gist:3974958
-- Use this query when preparing to move cache tables into memcache bins
-- to estimate how big the bins should be (or how many will be necessary).
SELECT count(*) tables,
concat(round(sum(data_length)/(1024*1024),2),'M') data,
concat(round(sum(index_length)/(1024*1024),2),'M') idx,
concat(round(sum(data_length+index_length)/(1024*1024),2),'M') total_size
FROM information_schema.TABLES
WHERE table_schema LIKE '<<DRUPAL DATABASE NAME>>'
AND table_name like "cache%"
-- Exclude any cache tables you know won't be in memcache:
@benclark
benclark / basicauthtest.sh
Last active Dec 30, 2015
Test for basic auth on all Apache virtual host sites
View basicauthtest.sh
#!/bin/bash
vhosts=/etc/apache2/sites-enabled/*
for f in $vhosts
do
servername=`grep ServerName $f | sed 's/\s*ServerName\s*//g' - | head -n1`
for s in $servername
do
url="http://$s https://$s"
for protocol in $url
@benclark
benclark / theme_D6MODULE_table_form.php
Last active Dec 18, 2015
Theme a series of form elements into a table (Drupal 6), with optional tabledrag.js support
View theme_D6MODULE_table_form.php
<?php
/**
* Theme a series of form elements into a table (Drupal 6), with optional
* tabledrag.js support.
*/
function theme_D6MODULE_admin_table_form($form) {
$header = array();
$rows = array();
View gist:5706405
<?php
if ($order_id = db_result(db_query("SELECT order_id FROM {fundraiser_webform_order} WHERE sid = %d", $_GET['sid']))) {
$order = uc_order_load($order_id);
$order_total = isset($order->order_total) ? $order->order_total : 0;
}
?>