Skip to content

Instantly share code, notes, and snippets.

@benclark
benclark / D6MODULE_user_autocomplete.php
Created January 21, 2013 22:17
Example of how to add an autocomplete path to a textfield and convert it to the user ID before saving it to a variable via `system_settings_form()`.
<?php
/**
* @file
* Example of how to add an autocomplete path to a textfield and convert it to
* the user ID before saving it to a variable via `system_settings_form()`.
*/
/**
* Admin settings form.
@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 / gist:5134534
Created March 11, 2013 14:15
Find all database connection strings on our dev server
#!/bin/bash
find . -maxdepth 2 -type d -name public -exec drush -r /var/www/{} sql-connect \;
<?php
// Get all the node types that can post into groups, i.e. all types that would
// have og_access entries, and add to the content_access_settings variable.
$settings = variable_get('content_access_settings', array());
foreach (node_get_types() as $type_name => $type) {
if (!og_is_omitted_type($type_name)) {
if (!isset($settings['view'][$type_name])) {
@benclark
benclark / gist:5678811
Last active December 17, 2015 21:59
Return all existing node IDs from a given FeedsImportBatch object. Written to be called from an implementation of hook_feeds_after_parse(), but could be called at any point in the feed importer operation, provided that the batch still exists (i.e. can't be called from hook_feeds_after_import() because the batch is explicitly set to NULL before c…
<?php
/**
* Return all existing node IDs from a given FeedsImportBatch object.
*
* @param $processor
* Instance of FeedsNodeProcessor.
* @param $source
* Instance of FeedsSource.
*
#!/usr/bin/perl -w
use strict;
use warnings;
sub automatic_choice {
my ($n, $i, $j, $c, $u, $d, $t);
my ($win, $guess, $switch);
print STDERR "How many doors? [ > 1 ]: ";
#!/bin/bash
#
# this script should not be run directly,
# instead you need to source it from your .bashrc,
# by adding this line:
# . PATH_TO_SCRIPT/goto_repo.sh
function repo() {
reponame=$1
basedir="$HOME/Sites/$reponame"
@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"
@benclark
benclark / wordcount.php
Last active December 17, 2015 23:28
Find out which words are most commonly used in song lyrics.
<?php
/**
* @file
* Find out which words are most commonly used in song lyrics.
*/
$wordcounts = array();
$lines = file('album/song.txt');
foreach ($lines as $line_num => $line) {
<?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;
}
?>