Skip to content

Instantly share code, notes, and snippets.

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.
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=""+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 / 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.
View hsl2rgb
l<=0.5: PUT l*(s+1) IN m2
ELSE: PUT l+s-l*s IN m2
PUT l*2-m2 IN m1
PUT, m2, h+1/3) IN r
PUT, m2, h ) IN g
PUT, m2, h-1/3) IN b
RETURN (r, g, b)
dougalcampbell / ds-duino.ino
Created September 10, 2013 17:37
Digispark and nodejs - talking to the Digispark Arduino-compatible microcontroller via USB with the node-hid library
View ds-duino.ino
* Accept control commands via USB.
* Commands start with '!' and end with '.'
* Commands have three parts: action, pin, value: !AAPPVV.
* E.g. '!01p101.' is DigitalWrite, Pin1, value = 1
* Note: This is currently *very* crude. Much improvement could be made.
* I think the use of strncpy is eating a lot of memory. Refactor?
dougalcampbell / NeoPixelTest.ino
Created October 31, 2013 03:29
Example of driving an Adafruit NeoPixel Ring with the Digispark Arduino-compatible board
View NeoPixelTest.ino
#include <Adafruit_NeoPixel.h>
#define PIN 1
#define STRIPSIZE 16
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
dougalcampbell / tabifytextareas.js
Created November 12, 2013 19:34
Bookmarklet: allow tabs in textareas (requires jQuery) Create a toolbar bookmark with this code. Click it when you want to be able to use tabs in a textarea.
View tabifytextareas.js
javascript:$(document).delegate('textarea', 'keydown', function(e) { var keyCode = e.keyCode || e.which; if (keyCode == 9) { e.preventDefault(); var start = $(this).get(0).selectionStart; var end = $(this).get(0).selectionEnd; $(this).val($(this).val().substring(0, start) + "\t" + $(this).val().substring(end)); $(this).get(0).selectionStart = $(this).get(0).selectionEnd = start + 1; }});void(0);
dougalcampbell / toType.js
Created December 10, 2013 21:33
Really get an object's type in JavaScript
View toType.js
function toType(obj) {
var systype = ({})\s([a-zA-Z]+)/)[1];
if (systype === "Object") {
* See if this is a custom user type, a la:
* function Foo() {}
* foo = new Foo();
* toType(foo); // returns "Foo"
* toType(Foo); // returns "Function"
dougalcampbell /
Last active March 22, 2022 20:18
Keybase verification

Keybase proof

I hereby claim:

  • I am dougalcampbell on github.
  • I am dougalcampbell ( on keybase.
  • I have a public key whose fingerprint is 9692 F34E 074B 52B9 919F 9180 A9A9 336D F0C4 0C65

To claim this, I am signing this object:

dougalcampbell / multilinestrings.js
Created July 30, 2014 15:03
Multiline strings in JavaScript
View multilinestrings.js
* See:
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
dougalcampbell / .bashrc
Created February 15, 2016 19:23
Set terminal title in bash
View .bashrc
# set title of current terminal
function _set_term_title() {
echo -ne "\033]0;${1}\007"
alias trmtitle=_set_term_title
dougalcampbell /
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.