Skip to content

Instantly share code, notes, and snippets.

@benclark
benclark / gist:4667006
Created January 29, 2013 19:37
Mobile detection in .htaccess file
###
# 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 / .profile
Created June 1, 2013 01:37
My .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"
#!/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 17:17
Varnish config file w/ basic auth
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 / my.cnf
Created August 21, 2012 14:30
MySQL config
#
# 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 July 25, 2012 13:56
Varnish config file w/ mobile redirect
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 October 29, 2012 17:12
SQL snippet for estimating Drupal cache table sizes
-- 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 December 30, 2015 23:39
Test for basic auth on all Apache virtual host sites
#!/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 December 18, 2015 16:09
Theme a series of form elements into a table (Drupal 6), with optional tabledrag.js support
<?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();
<?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;
}
?>