Skip to content

Instantly share code, notes, and snippets.

@dougalcampbell
dougalcampbell / multilinestrings.js
Created Jul 30, 2014
Multiline strings in JavaScript
View multilinestrings.js
/**
* 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 / 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 / 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
@dougalcampbell
dougalcampbell / print_gh_markdown.js
Last active Dec 20, 2015 — forked from binarybana/print_gollum.js
Browser bookmarklet to remove GitHub chrome, for printing Markdown documentation files.
View print_gh_markdown.js
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 Dec 22, 2015
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
View hsl2rgb
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)
You can’t perform that action at this time.