Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Williams nilliams

  • Leicestershire, UK
View GitHub Profile
@nilliams
nilliams / jekyll-prettify.md
Last active Jan 24, 2020
Add client-side syntax highlighting to static sites (such as Jekyll w/ Pygments disabled), with Google-Code-Prettify.
View jekyll-prettify.md

Note: One alternative is to use this Prism.js Jekyll Plugin, the advantage of using google-code-prettify is that it can be used with standard markdown (indented code blocks) rather than using liquid tags like {% prism %}. Prettify will guess which language your code blocks contain and highlight appropriately.

Grab the google-code-prettify sources and include them in the <head> of your page template, for Jekyll you will want to edit layouts/default.html (tailor paths to directory structure):

<link rel="stylesheet" href="/css/google-code-prettify/prettify.css">
<script src="/js/google-code-prettify/prettify.js"></script>

This JS snippet adds the prettyprint class to <pre> tags and runs prettify:

@nilliams
nilliams / package.json
Last active Jun 25, 2017
Minimal Quick-Start package.json for Browserify & Sass
View package.json
{
"name": "project-quick-start",
"version": "1.0.0",
"description": "npm install; npm run base; npm start",
"main": "",
"scripts": {
"start": "npm-run-all --parallel js:watch css:watch",
"base": "npm-run-all base:dirs base:js base:css base:html",
"base:dirs": "mkdirp src",
@nilliams
nilliams / index.js
Last active May 7, 2017
requirebin sketch
View index.js
const html = require('choo/html')
const choo = require('choo')
function Body(state, emit) {
let input;
return html`
<body>
<ul>
${state.todos.map(todo => (
@nilliams
nilliams / index.js
Created Oct 21, 2016
requirebin sketch
View index.js
var Promise = require('rsvp').Promise;
function foo() {
return new Promise(function(resolve, reject) {
console.log("We're running...");
// We totally resolve and all is good ...
resolve();
});
}
@nilliams
nilliams / index.js
Created Oct 21, 2016
requirebin sketch
View index.js
var Promise = require('rsvp').Promise;
new Promise(function() {
console.log("We're running...");
// nothing happens, this error is silently swallowed. and yes this could just as
// well be a typo. issue: https://github.com/stefanpenner/es6-promise/issues/70
throw 'err';
console.log("We'll never get here.");
@nilliams
nilliams / index.js
Created Oct 21, 2016
requirebin sketch
View index.js
var Promise = require('rsvp').Promise;
function MyCoolErr() {}
function foo() {
return new Promise(function(resolve, reject) {
console.log("We're running...");
// Resolve and all is good ...
resolve();
@nilliams
nilliams / index.js
Created Oct 21, 2016
requirebin sketch
View index.js
var Promise = require('es6-promise').Promise;
function MyCoolErr() {}
function foo() {
return new Promise(function(resolve, reject) {
console.log("We're running...");
// Resolve and all is good ...
resolve();
@nilliams
nilliams / index.js
Created Oct 21, 2016
requirebin sketch
View index.js
var Promise = require('yaku');
function MyCoolErr() {}
function foo() {
return new Promise(function(resolve, reject) {
console.log("We're running...");
// Resolve and all is good ...
resolve();
@nilliams
nilliams / index.js
Last active Oct 21, 2016
requirebin sketch
View index.js
var Promise = require('es6-promise').Promise;
function foo() {
return new Promise(function(resolve, reject) {
console.log("We're running...");
// We totally resolve and all is good ...
resolve();
});
}
@nilliams
nilliams / index.js
Last active Oct 19, 2016
requirebin sketch
View index.js
var Promise = require('bluebird');
new Promise(function() {
console.log("We're running...");
// A crazy error is thrown here, but you will see this in your Chrome console.
// Seems like Bluebird has the right default here!
throw 'Nice job Bluebird';
console.log("We'll never get here.");