Skip to content

Instantly share code, notes, and snippets.

#!/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"
#!/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 ]: ";
@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) {
@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.
*
<?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: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 \;
@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 / D6MODULE_textarea_to_array.php
Created January 21, 2013 22:16
Example of how to take a textarea form element and explode it into an array before saving it to a variable via `system_settings_form()`.
<?php
/**
* @file
* Example of how to take a textarea form element and explode it into an array
* before saving it to a variable via `system_settings_form()`.
*/
/**
* Admin settings form.
@benclark
benclark / gist_tag.rb
Last active December 11, 2015 08:58 — forked from BinaryMuse/gist_tag.rb
# Gist tag Jekyll plugin
#
# From:
# http://brandontilley.com/2011/01/30/gist-tag-for-jekyll.html
require 'cgi'
require 'digest/md5'
require 'net/https'
require 'uri'
@benclark
benclark / theme_D7MODULE_table_form.php
Created January 8, 2013 20:04
Theme a series of form elements into a table (Drupal 7)
<?php
/**
* Theme a series of form elements into a table (Drupal 7).
*/
function theme_D7MODULE_table_form($variables) {
$form = $variables['form'];
$header = array();
$rows = array();