Skip to content

Instantly share code, notes, and snippets.

@mcenirm
mcenirm / show_recent_files.bash
Created June 5, 2014 20:39
For a set of directories, show the most recent files found.
#!/bin/bash
for d in "$@" ; do
echo
echo "${d}"
find "${d}" -type f -printf '%T+ %P\n' | sort | cat -n | tail -3
done
@mcenirm
mcenirm / xx2a
Created June 4, 2014 18:48
Wrapper script for jp2a that will attempt to convert other image formats to JPEG. Requires ImageMagick's convert (or compatible).
#!/bin/bash
JP2A=$(dirname "$0")/jp2a
declare -a jp2aopts
while [[ $# -gt 0 ]] ; do
case "$1" in
-) break ;;
--) shift ; break ;;
-*) jp2aopts+=( "$1" ) ; shift ;;
Mirroring a Git repostory
The firm I recently stated working at just moved to Git and I am the only resource then knows Git. I get asked so many times a day on how to mirror a git repostory.
From the birds eyes very its very easy:
git clone --mirror [email protected]:project project
cd project
git remote add github [email protected]:username/project.git
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+' '))
@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.
@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 / 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 / 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 / .bash_profile
Created November 12, 2013 18:36
Get python distutils working in a home directory
...
export PYTHONPATH=${HOME}/lib/python
@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',