Skip to content

Instantly share code, notes, and snippets.

@dougalcampbell
dougalcampbell / multilinestrings.js
Created July 30, 2014 15:03
Multiline strings in JavaScript
/**
* See: https://github.com/isaacs/node-tap/blob/master/bin/tap.js#L65
*/
console.log({/*
This is a multiline string.
That is, a single string, spread out over many lines,
without the need to escape quotes or end-of-line
characters.
@dougalcampbell
dougalcampbell / test-21-actual.html
Created April 12, 2012 20:56
Plates bug with nested objects
<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 15:06
Simple example of bug in plates iteration
<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 August 14, 2012 17:52
Make Drupal Superfish dropdowns touch-friendly
// 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 August 21, 2012 17:50
WordPress snippet: get single post custom value
/**
* 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 September 28, 2012 03:36
WordPress snippet: add uploadable file types
/**
* 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 October 11, 2012 14:41
A sweet git alias for pretty pretty log listings
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
@dougalcampbell
dougalcampbell / print_gh_markdown.js
Last active December 20, 2015 19:59 — forked from binarybana/print_gollum.js
Browser bookmarklet to remove GitHub chrome, for printing Markdown documentation files.
javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f=e.jQuery)%7C%7Cg>f.fn.jquery%7C%7Ch(f))%7Bc=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function()%7Bif(!b&&(!(d=this.readyState)%7C%7Cd=="loaded"%7C%7Cd=="complete"))%7Bh((f=e.jQuery).noConflict(1),b=1);f(c).remove()%7D%7D;a.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,"1.3.2",function($,L)%7B$('%23header, .pagehead, .breadcrumb, .commit, .meta, %23footer, %23footer-push, .wiki-actions, %23last-edit, .actions, .header, .repository-sidebar, .file-navigation, .site-footer, .repository-meta, .overall-summary, .files-bubble').remove(); $('%23files, .file').css(%7B"background":"none", "border":"none"%7D); $('link').removeAttr('media');%7D);void(0);
@dougalcampbell
dougalcampbell / hsl2rgb
Last active December 22, 2015 00:29
For future reference... The W3C-suggested algorithm for converting HSL color to RGB. In the funky ABC pseudo-code. http://www.w3.org/TR/2011/REC-css3-color-20110607/#hsl-color
HOW TO RETURN hsl.to.rgb(h, s, l):
SELECT:
l<=0.5: PUT l*(s+1) IN m2
ELSE: PUT l+s-l*s IN m2
PUT l*2-m2 IN m1
PUT hue.to.rgb(m1, m2, h+1/3) IN r
PUT hue.to.rgb(m1, m2, h ) IN g
PUT hue.to.rgb(m1, m2, h-1/3) IN b
RETURN (r, g, b)
@dougalcampbell
dougalcampbell / wxrsplit.pl
Created March 1, 2016 17:21
A perl script to split WordPress WXR export files into multiple, smaller files
#!/usr/bin/perl -w
#
# wxrsplit - Split a WordPress WXR file into multiple output files, each
# with a maximum filesize.
#
# NOTE: Because this tool attempts to keep items intact within each output
# file, it is possible to exceed the specified max filesize. Comments are
# contained within a post item, so a post with many comments could
# conceivably generate a very large item size. There probably is not a
# practical way around this.