Skip to content

Instantly share code, notes, and snippets.

@mcenirm
mcenirm / stormy.info
Created November 5, 2013 14:53
Example of using batch operations in Drupal 7
name = Stormy
description = Deals with storms.
core = 7.x
package = ZZZZ Stormy
@mcenirm
mcenirm / convert_list_to_object_keys.js
Created November 6, 2013 21:39
Javascript: Convert list to object keys
function convert_list_to_object_keys( the_list ) {
return the_list.reduce(
function ( the_object, a_key ) {
the_object[a_key] = true;
return the_object;
},
{}
);
}
// $0 is for inspected element in recent browsers' development tools
var myObj = Ext.getCmp($0.id);
// Capture
Ext.util.Observable.capture(myObj, function(evname) {console.log(evname, arguments);})
// Release
Ext.util.Observable.releaseCapture(myObj);
@mcenirm
mcenirm / extjs_expand_siblingless_child_nodes_in_tree.js
Last active December 27, 2015 15:09
ExtJS: Recursively expand tree nodes as long as there is a single child.
function expand_siblingless_child_nodes_listener( parent_node ) {
if ( parent_node.firstChild === parent_node.lastChild ) {
if ( parent_node.firstChild !== null ) {
parent_node.firstChild.expand();
}
}
}
var the_store = Ext.create(
'Ext.data.TreeStore',
@mcenirm
mcenirm / .bash_profile
Created November 12, 2013 18:36
Get python distutils working in a home directory
...
export PYTHONPATH=${HOME}/lib/python
@mcenirm
mcenirm / sshbg.sh
Created November 14, 2013 16:39
Create background SSH connection. Useful for ControlMaster=auto (pre-OpenSSH-5.6's ControlPersist option) and for tunnels.
#!/bin/sh
TIMEOUT=3600
if [ $# -lt 1 ] ; then
cat >&2 <<EOF
Usage: $0 [SSH_OPTIONS] [user@]host
Background SSH connection, using -f and sleep $TIMEOUT
EOF
exit 1
else
ssh -f "$@" sleep $TIMEOUT
@mcenirm
mcenirm / action.bash
Created November 21, 2013 21:47
Action: Bash function to log and then execute an external command.
# Log and run an external command
# Usage: Action [redirections] command arguments...
# Redirections:
# --stdin=file redirect input from file
# --stdout=file redirect output to file
# --stderr=file redirect error to file
function Action() {
if [[ $# -gt 0 ]] ; then
@mcenirm
mcenirm / _mymodule_watchdog.inc
Created December 3, 2013 20:15
Drupal watchdog wrapper that applies var_export to variables marked with '@@' and '%%'.
<?php
/**
* Module-specific watchdog wrapper.
*
* Apply var_export to variables where key starts with '@@' or '%%'.
* (Keys in message should not have doubled sigils.)
*/
function _mymodule_watchdog($message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
$vars = array();
@mcenirm
mcenirm / mimic_perl_gmtime.php
Created December 10, 2013 17:26
Mimic perl's gmtime in PHP.
<?php
/**
* Mimic perl's gmtime function.
*
* From ctime(3):
* The members of the tm structure are:
* tm_sec The number of seconds after the minute, normally in the
* range 0 to 59, but can be up to 60 to allow for leap seconds.
* tm_min The number of minutes after the hour, in the range 0 to 59.
* tm_hour The number of hours past midnight, in the range 0 to 23.
from itertools import permutations
WORD_FILE = '.../words'
words = set(x.strip() for x in open(WORD_FILE).readlines())
LETTERS = 'abcdefg'
perms = set((''.join(x).split())[0] for x in permutations(LETTERS+' '))