Skip to content

Instantly share code, notes, and snippets.

View matthewblewitt's full-sized avatar

Matt Blewitt matthewblewitt

View GitHub Profile

Git Cheatsheet

What changed in the last commit

git show --name-status

Log one line

.flex {
display: flex;
}
// Direction
.flex-row {
flex-direction: row;
}
.flex-row-reverse {
flex-direction: row-reverse;
// Shape - superclass
// x,y: location of shape's bounding rectangle
function Shape(x, y) {
  this.x = x;
  this.y = y;
}

// Superclass method
@matthewblewitt
matthewblewitt / nunjucks-cheatsheet.md
Last active September 6, 2018 10:38
Nunjucks ternary cheatsheet

Ternary

{{ 'true' if conditional else 'false'  }}

Dump

{{ variable | dump }}
@matthewblewitt
matthewblewitt / jQuery-to-ES6.md
Last active June 13, 2018 08:02
jQuery to ES6

A note on NodeLists and HTML Collections

An HTMLCollection is a list of nodes. An individual node may be accessed by either ordinal index or the node’s name or id attributes. Collections in the HTML DOM are assumed to be live meaning that they are automatically updated when the underlying document is changed.

A NodeList object is a collection of nodes. The NodeList interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented. NodeList objects in the DOM are live or static based on the interface used to retrieve them

const $header = document.getElementById('#header');
const $headings = document.getElementsByTagName('h1');
@matthewblewitt
matthewblewitt / chrome-dev-tools-js.md
Last active June 20, 2018 13:14
Chrome dev tools javascript tips

Find any file CMD+P Find function by keyword CMD+SHIFT+O Go to any location in dev tools CMD+SHIFT+P

Console tips

Clear console CMD+L.

Get event listeners by selector

@matthewblewitt
matthewblewitt / TDD-pa11y-express.js
Last active July 12, 2018 11:51
pa11y automated accessibility testing with mocha
const pa11y = require('pa11y');
const request = require('supertest');
const mocha = require('mocha');
const { expect } = require('chai');
const server = require('./server');
const url =
process.env.NODE_ENV === 'testing'
? 'http://localhost:3000'
: 'http://example.com';
@matthewblewitt
matthewblewitt / util.promisify.js
Created July 18, 2018 14:33
Node util.promisify
const fs = require('fs')
const util = require('util')
const readFile = util.promisify(fs.readFile)
readFile('./test/test.md', 'utf8')
.then(text => {
console.log(text)
})
.catch(err => {
console.log('Error', err)
@matthewblewitt
matthewblewitt / sql-cheatsheet.md
Last active September 6, 2018 10:12
SQL-cheatsheet
CREATE DATABASE app;
USE app;

CREATE TABLE users (
    id int,
    last_name varchar(255),
    first_name varchar(255)
);
@matthewblewitt
matthewblewitt / PromiseQueue.js
Created November 22, 2018 08:39
Promise Queue
var delay = (seconds) => new Promise((resolves) => {
setTimeout(function(){
console.log(seconds);
resolves();
}, seconds*1000);
});
var tasks = [
delay(2),
delay(4),