Skip to content

Instantly share code, notes, and snippets.

View spiralx's full-sized avatar

James Skinner spiralx

View GitHub Profile
@spiralx
spiralx / angular-injector.js
Created November 15, 2016 15:55
Gets the injector for the application's root module
/* jshint asi: true, esnext: true */
(() => {
'use strict'
const ROOT_MODULE = 'app'
const rootElement = angular.element(document)
const mockApp = angular.module('mockApp', []).provider({
@spiralx
spiralx / default-map.js
Created November 15, 2016 15:53
Map sub-class that defines a default value for missing keys
/* jshint asi: true, esnext: true */
(() => {
'use strict'
// --------------------------------------------------------------------------
class DefaultMap extends Map {
get(key) {
return super.has(key)
@spiralx
spiralx / copy-to-clipboard.js
Created November 15, 2016 15:11
Copy text to the clipboard
(function() {
'use strict'
// --------------------------------------------------------------------------
window.copyToClipboard = function copyToClipboard (value) {
if (!value) return // Can't copy zero characters!
const $input = Object.assign(document.createElement('input'), {
type: 'text',
@spiralx
spiralx / github.com.css
Created November 9, 2016 18:20
UserStyles
@-moz-document domain("github.com") {
@import url(https://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic);
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
word-spacing: normal !important;
letter-spacing: normal !important;
@spiralx
spiralx / globals.snippets.js
Created August 12, 2016 10:30 — forked from pocotan001/globals.snippets.js
Finding improper JavaScript globals.
// globals.js
// https://gist.github.com/pocotan001/6305714
// Finding improper JavaScript globals
(function() {
var prop, cleanWindow,
globals = new function globals() {},
body = document.body,
iframe = document.createElement('iframe'),
ignore = {
@spiralx
spiralx / mocha-guide-to-testing.js
Last active August 11, 2016 13:43 — forked from samwize/mocha-guide-to-testing.js
Explain Mocha's testing framework - describe/it/before/beforeEach etc.
/* -----------------------------------------------------------------------------
### Mocha Guide to Testing ###
Objective is to explain `describe()`, `it()`, and `before()`/etc hooks.
1. `describe()` is merely for grouping, which you can nest as deep
as is required.
2. `it()` is a test case.
@spiralx
spiralx / console.inject.js
Created July 29, 2016 09:13
Find and inject libraries from cdnjs by name
/* jshint asi: true, esnext: true */
(() => {
'use strict'
const BOLD = 'font-weight: bold;',
LINK = 'text-decoration: underline; color: #03d',
RESET = 'font-weight: normal; text-decoration: none; color: black; background-color: white; display: inline'
// ----------------------------------------------------------
@spiralx
spiralx / promise.finally.polyfill.js
Created July 29, 2016 07:34
Polyfill to add a finally() method to the Promise object
Promise.prototype.finally = function (callback) {
return this.then(
value => this.constructor.resolve(callback()).then(() => value),
reason => this.constructor.resolve(callback()).then(() => { throw reason })
)
}
@spiralx
spiralx / console.message.js
Created May 28, 2016 09:58
console.message library
(function () {
var cssNumbers = {
columnCount: true,
fillOpacity: true,
flexGrow: true,
flexShrink: true,
fontWeight: true,
lineHeight: true,
opacity: true,
order: true,
@spiralx
spiralx / copy-on-click.js
Created May 20, 2016 11:11
An ES6 class for auto-copying text content to the clipboard when particular elements are clicked
/* jshint asi: true, esnext: true */
; (function() {
'use strict'
/*
Iterator for a selection's range objects e.g.
const r = [...ranges()]
*/