Skip to content

Instantly share code, notes, and snippets.

func createTestContext(t *testing.T) (context.Context, context.CancelFunc) {
if deadline, ok := t.Deadline(); ok {
return context.WithDeadline(context.Background(), deadline)
}
return context.WithTimeout(context.Background(), 10*time.Second)
}
@RobinThrift
RobinThrift / feed.hbt
Created April 11, 2014 21:24
Metalsmith RSS feed Handlebars template
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ sitename }}</title>
<description>{{ description }}</description>
<link>{{ baseUrl }}</link>
<atom:link href="{{ baseUrl }}/feed.xml" rel="self" type="application/rss+xml" />
{{#each collections.entries}}
@RobinThrift
RobinThrift / handlbars-limit-helper.js
Created April 10, 2014 12:14
A Handlebar.js helper that returns a given number of items in an array starting from a given index
Handlebars.registerHelper('limit', function(collection, limit, start) {
var out = [],
i, c;
start = start || 0;
for (i = c = 0; i < collection.length; i++) {
if (i >= start && c < limit+1) {
out.push(collection[i]);
c++;
@RobinThrift
RobinThrift / randStr.js
Last active December 21, 2015 14:09
SImple random string of 5 characters (JS/PHP) src: http://stackoverflow.com/a/8084248
function randStr() {
return Math.random().toString(36).substring(7);
}