Skip to content

Instantly share code, notes, and snippets.

@dougalcampbell
dougalcampbell / gitzip.sh
Created May 27, 2011
gitzip -- create a zip file of a git project
View gitzip.sh
#!/bin/bash
##
## I usually put this in my .bashrc
##
## When in a git project dir, run 'gitzip foo' to get a 'foo.zip' in the parent
## directory.
gitzip() { git archive HEAD --format=zip --prefix="$*/" > ../"$*.zip"; }
@dougalcampbell
dougalcampbell / phpfpm-mon.cron
Created Feb 14, 2012
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
View opengraphbookmarklet.js
javascript:$=jQuery;if(0!==$("#myogdiv").length)$("#myogdiv").hide().remove();else{var%20myogdiv=$('<div%20id="myogdiv"/>');$("body").append(myogdiv);$('head%20meta[property^="og:"],head%20meta[property^="fb:"],head%20meta[name^="twitter:"]').each(function(d,b){var%20a=$(b).attr("property"),c=$(b).attr("content");void%200==a&&(a=$(b).attr("name"));$(myogdiv).append("<div><b>"+a+":</b>"+c+"</div>");"og:image"==a&&$(myogdiv).append('<br/><img%20src="'+c+'"%20style="max-width:250px"/>');"twitter:image"==a&&$(myogdiv).append('<br/><img%20src="'+c+'"%20style="max-width:250px"/>')});$(myogdiv).css("position","absolute").css("top","0").css("zIndex",9999999).css("padding","0.5em").css("border","1px%20solid%20red").css("backgroundColor","white")}void%200;
@dougalcampbell
dougalcampbell / utfluv.js
Created Mar 12, 2012
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: http://code.google.com/p/v8/issues/detail?id=761#c8
* see also, for browsers that don't have native JSON: https://github.com/douglascrockford/JSON-js
*
* Any time you need to send data between client and server (or vice versa), encode before sending,
@dougalcampbell
dougalcampbell / test-21-actual.html
Created Apr 12, 2012
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>
<div class="custid"></div>
</div>
@dougalcampbell
dougalcampbell / actual-output-2.html
Created May 4, 2012
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>
<div id='simple'></div>
<div id='simple'>simple value</div>
@dougalcampbell
dougalcampbell / drupal-sf-touch.js
Created Aug 14, 2012
Make Drupal Superfish dropdowns touch-friendly
View drupal-sf-touch.js
// adapted from: http://snippets.webaware.com.au/snippets/make-css-drop-down-menus-work-on-touch-devices/
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
dougalcampbell / gist:3417835
Created Aug 21, 2012
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
dougalcampbell / uploadables.php
Created Sep 28, 2012
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/vnd.apple.keynote',
'numbers' => 'application/vnd.apple.numbers',
'pages' => 'application/vnd.apple.pages'
);
@dougalcampbell
dougalcampbell / sweet-git-log
Created Oct 11, 2012
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
You can’t perform that action at this time.