Skip to content

Instantly share code, notes, and snippets.

dougalcampbell /
Created May 27, 2011 13:25
gitzip -- create a zip file of a git project
## I usually put this in my .bashrc
## When in a git project dir, run 'gitzip foo' to get a '' in the parent
## directory.
gitzip() { git archive HEAD --format=zip --prefix="$*/" > ../"$*.zip"; }
dougalcampbell / phpfpm-mon.cron
Created February 14, 2012 19:45
Crontab entry to monitor for php-fpm problems
View phpfpm-mon.cron
## Auto-restart PHP when it's returning errors
# Make sure that http://localhost/test.php is an actual PHP script. If it starts returning
# 500 errors, restart the PHP-FPM service
* * * * * /usr/bin/curl --head -sf http://localhost/test.php -o /dev/null || /usr/sbin/service php5-fpm restart
dougalcampbell / opengraphbookmarklet.js
Last active April 8, 2019 20:23
OpenGraph Bookmarklet
View opengraphbookmarklet.js
dougalcampbell / utfluv.js
Created March 12, 2012 19:44
Handle invalid JS character sequences
View utfluv.js
* encode to handle invalid UTF
* If Chrome tells you "Could not decode a text frame as UTF-8" when you try sending
* data from nodejs, try using these functions to encode/decode your JSON objects.
* see discussion here:
* see also, for browsers that don't have native JSON:
* Any time you need to send data between client and server (or vice versa), encode before sending,
dougalcampbell / test-21-actual.html
Created April 12, 2012 20:56
Plates bug with nested objects
View test-21-actual.html
<div id="entries">
<div class="entry">
<div class="created">2001-01-01</div>
<div class="user">
<div class="name">John Q. User</div>
<div class="city">Atlanta</div>
<div class="state">GA</div>
<div class="custid"></div>
dougalcampbell / actual-output-2.html
Created May 4, 2012 15:06
Simple example of bug in plates iteration
View actual-output-2.html
<div id='complex'>
<div class='one'>subvalue one</div>
<div class='two'>subvalue two</div>
<div id='simple'></div>
<div id='simple'>simple value</div>
dougalcampbell / drupal-sf-touch.js
Created August 14, 2012 17:52
Make Drupal Superfish dropdowns touch-friendly
View drupal-sf-touch.js
// adapted from:
Drupal.behaviors.touchdevice_dropdowns = function(context) {
// see whether device supports touch events (a bit simplistic, but...)
var hasTouch = ("ontouchstart" in window);
// hook touch events for drop-down menus
if (hasTouch && document.querySelectorAll) {
var i, len, element,
dropdowns = document.querySelectorAll(".sf-menu .menuparent > a");
dougalcampbell / gist:3417835
Created August 21, 2012 17:50
WordPress snippet: get single post custom value
View gist:3417835
* Get a single text value for a post custom field in WordPress, bypassing the normal array return.
* From a discussion on Twitter, which prompted me to post this. Many people seem to be
* unaware of PHP's `list()` operator (it's not, technically, a function).
* If you are not in the loop, you can pass a post ID as a second parameter.
list( $val ) = get_post_custom_values( 'key' );
dougalcampbell / uploadables.php
Created September 28, 2012 03:36
WordPress snippet: add uploadable file types
View uploadables.php
* Add uploadable mime types / file extensions
function dc_add_uploadables($arr = array()) {
$new = array(
// Add file extension => mime type mapping here
'keynote|key' => 'application/',
'numbers' => 'application/',
'pages' => 'application/'
dougalcampbell / sweet-git-log
Created October 11, 2012 14:41
A sweet git alias for pretty pretty log listings
View sweet-git-log
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
# use: git lg