Skip to content

Instantly share code, notes, and snippets.

@jpstacey
jpstacey / drush-field-clone.sh
Created June 20, 2017 19:27
Drush field clone equivalent for Drupal 8
#!/bin/bash
# @file
# Untested: use at your own risk!
# Entity type, bundle name, field name.
# Different entity types are currently unsupported (will always use "node").
IFS='.' read -r -a from <<< "$1"
IFS='.' read -r -a to <<< "$2"
# Support Linux & OSX < 10.11
@jpstacey
jpstacey / copy_with_dirs.py
Created November 28, 2016 19:34
Copy a file, preserving all directories, with a horrible mixture of python shutil and os.system('mkdir -p')
#!/usr/bin/env python
#
# Usage: copy_with_dirs.py <file> [file] [...]
# OR ... | xargs -d '\n' /tmp/copy_with_dirs.py
import shutil
import urllib
import sys
import os
@jpstacey
jpstacey / contract-builder.py
Last active December 26, 2015 19:39
Parse a markdown-based contract and replace tokens in square brackets.
#!/usr/bin/env python
"""
Parse a markdown contract and replace selected [tokens] with custom values.
Define some custom tokens and default values in a file ~/.contract-builder.yml,
but permit command-line overrides.
Example usage:
contract-builder.py < my_contract_template.md > contract_for_ann.md --customer-name "Ann Other"
@jpstacey
jpstacey / freelance drupal killer contract.md
Last active December 26, 2015 13:09 — forked from manarth/drupal killer contract.md
Contract between a freelance Drupal developer and another party

Freelance Technical Consultancy Contract

Between me: [my name]
and you: [customer name]

Summary

@jpstacey
jpstacey / country_flags_imagemagick.sh
Created August 6, 2013 10:47
Adding country flags to the corner of a generic icon
# Country flags on icons
for i in uk us au; do composite -geometry wxh+top+left $i.png original-icon.png icon-$i.png; done
@jpstacey
jpstacey / gist:5720430
Last active December 18, 2015 03:48
Initial attempts to run computerminds:parrot VM
...
[default] Running Puppet with /tmp/vagrant-puppet/manifests/bootstrap.pp...
stdin: is not a tty
err: /Stage[main]//Node[default]/Package[puppet]/ensure: change from purged to latest failed: Could not update: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install puppet' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
augeas-lenses debconf-utils facter libaugeas-ruby1.8 libaugeas0 libreadline5
libruby libruby1.8 libshadow-ruby1.8 puppet-common ruby ruby1.8
@jpstacey
jpstacey / .bashrc_snippet_git_branch
Created October 28, 2011 11:20
Display git branch in your command prompt
# Via rjmackay
# Add git ps1 $(__git_ps1 " (%s)")
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[0;33m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 " (%s)")\$ '
fi
force_color_prompt=yes
@jpstacey
jpstacey / gist:1133723
Created August 9, 2011 10:29
Causing MySQL to raise an exception from a trigger
-- MySQL does not implement raising exceptions within triggers. Here's a hacky model for doing so.
-- This permits unwanted conditions to bubble up to the application layer, to be dealt with
-- Only use this during debugging. Don't rely on this in production code as it's a hack.
DELIMITER $$
-- Procedure guaranteed to raise an exception
CREATE PROCEDURE die_horribly() SQL SECURITY INVOKER DETERMINISTIC
BEGIN
INSERT INTO does_not_exist (nid) VALUES (NULL);
@jpstacey
jpstacey / db_search.php
Created June 27, 2011 11:42
Search all tables in a Drupal database using Drupal bootstrap to get a db connection
<?php
/**
* Search all Drupal database tables for a string
* Uses simple concat(), so could
* (a) have false positives through concat or
* (b) have false negatives through TEXT trimming
*/
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
@jpstacey
jpstacey / .gitconfig
Last active February 7, 2024 04:35
Sample git config
# See the following for references:
# * http://www.metacircus.com/hacking/2011/02/18/play-git-like-a-violin.html
# * http://cheat.errtheblog.com/s/git/
# * http://pyrtsa.posterous.com/aligning-your-git-logs
# * http://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
# Git >v1.7.10 lets you include external files
# Put your user configuration in here, so it never
# accidentally gets checked in
[include]