Skip to content

Instantly share code, notes, and snippets.

@benclark
benclark / theme_D6MODULE_table_form.php
Last active December 10, 2015 20:18
Theme a series of form elements into a table (Drupal 6)
<?php
/**
* Theme a series of form elements into a table (Drupal 6).
*/
function theme_D6MODULE_table_form($form) {
$header = array();
$rows = array();
foreach (element_children($form) as $i) {
@benclark
benclark / gist:4205910
Created December 4, 2012 16:36
Phoshare link-only backup of iPhoto library to Dropbox
#!/bin/sh
nice -n 20 /Applications/Phoshare.app/Contents/MacOS/Phoshare -o -d -u -l -e . --export ~/Dropbox/Photos/Phoshare\ Backup/
@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 / gist:3974821
Created October 29, 2012 16:50
Memcache config for settings.php (D6)
<?php
/**
* Memcache config
*/
// Check that one of the two memcache extensions are loaded.
if (extension_loaded('memcache') || extension_loaded('memcached')) {
if (!is_array($conf)) {
$conf = array();
@benclark
benclark / gist:3948044
Created October 24, 2012 18:50
Bash function to go to a specified git repo in $HOME/Sites
# Go to a specified git repo in $HOME/Sites
repo() {
local reponame=$1
local jumpto_type=$2
local jumpto_which=$3
local basedir="$HOME/Sites/$reponame"
local cd_to
if [ -z $reponame ]; then
echo "usage: repo reponame [type [which]]"
@benclark
benclark / apache_syslog.pl
Created October 24, 2012 14:01
Perl script that is capable of sending httpd logs to syslog
#!/usr/bin/perl
use Sys::Syslog qw( :DEFAULT setlogsock );
openlog('httpd', 'cons,pid', LOG_LOCAL0);
while ($log = <STDIN>) {
syslog(LOG_NOTICE, $log);
}
closelog
@benclark
benclark / lighttpd-vhosts.pl
Created October 4, 2012 21:14
Lighttpd vhosts config script
#!/usr/bin/perl -wl
use strict;
use File::Glob ':glob';
my $sitesdir = shift || "/mnt/Sites/";
sleep 1 while (!(chdir($sitesdir)));
my @sites = bsd_glob('*/{repo,trunk}');
@benclark
benclark / nodequeue_create.php
Created September 21, 2012 18:25 — forked from brockboland/nodequeue_create.php
Drupal: Create a nodequeue if it doesn't exist already
drupal_load('module', 'nodequeue');
// Homepage Features
$queue = nodequeue_load_queue_by_name('homepage_features');
if (empty($queue)) {
$queue = new stdClass();
$queue->title = 'Homepage Features';
$queue->name = 'homepage_features';
$queue->size = 4;
$queue->owner = 'nodequeue';
@benclark
benclark / gist:3639991
Created September 5, 2012 17:01
Howto one-off install Ubercart zones for a country
drush php-eval "include_once('sites/all/modules/springboard/ubercart/uc_store/countries/japan_392_1.cif'); japan_install();"
@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.