Skip to content

Instantly share code, notes, and snippets.

View DamianMullins's full-sized avatar
💭
👽

Damian Mullins DamianMullins

💭
👽
View GitHub Profile
@DamianMullins
DamianMullins / esnextbin.md
Last active September 20, 2016 20:11
esnextbin sketch
@DamianMullins
DamianMullins / helpers.js
Last active June 22, 2016 10:50
Testing with Tape and jsdom global.
import tape from 'tape';
import jsdom from 'jsdom-global';
export function test (description, fn, { html } = {}) {
tape(description, t => {
const cleanup = jsdom(html);
fn(t);
cleanup();
});
}
@DamianMullins
DamianMullins / mocha-chai-jsdom-global.js
Last active June 22, 2016 10:50
Testing with Mocha, Chai, and jsdom global.
import { expect } from 'chai';
describe('dom', () => {
before(function () {
this.jsdom = require('jsdom-global')()
})
after(function () {
this.jsdom()
// Copyright © John Leitch 2010 [email protected]
var destination = null;
var useClone = false;
var cloneSource = null;
var cloneDelay = 1000;
function hookInputs() {
var frame = document.getElementById('overlayFrame');
var keyPressScript =
@DamianMullins
DamianMullins / substring.js
Created January 12, 2016 21:21
Check that one string contains another substring
~'foo'.indexOf('oo');
@DamianMullins
DamianMullins / getDataAttributeValue-es2015.js
Last active January 13, 2016 14:51
Return data attribute value from a given element. Falls back to `getAttribute()` in older browsers.
/**
* Return data attribute value from a given element. Falls back to `getAttribute()` in older browsers.
* @example
* let value = getDataAttributeValue(element, 'component-name');
* @example
* let value = getDataAttributeValue(element, 'componentName');
*/
export default function getDataAttributeValue(element, dataName, defaultDataValue = '') {
const datasetSupported = element.dataset !== undefined;
@DamianMullins
DamianMullins / getElementsByDataAttribute.js
Last active October 30, 2015 13:48
Returns an array of elements with a matching data attribute name.
/**
* Returns an array of elements with a matching data attribute name.
* @example
* let value = getElementsByDataAttribute('component-name');
*/
export default function getElementsByDataAttribute(name) {
var elements = document.querySelectorAll(`[data-${name}]`);
return Array.prototype.slice.call(elements);
};
@DamianMullins
DamianMullins / Uninstall-NpmPackagesInDirectory.ps1
Last active August 29, 2015 14:24
Uninstall npm packages by scanning directories inside node_modules
Function Uninstall-NpmPackagesInDirectory {
Param (
# Optional path to node_modules directory
[String]$pathToNodeModules = (Get-Item -Path ".\node_modules").FullName
)
# Loop over each folder in the directory
ForEach ($dep in Get-ChildItem -Path $pathToNodeModules | ? { $_.FullName -notmatch ".bin" }) {
# Uninstall the package
iex "npm uninstall $dep"
@DamianMullins
DamianMullins / Uninstall-NpmPackages.ps1
Last active August 29, 2015 14:24
Uninstall npm packages by scanning packages.json file.
Function Uninstall-NpmPackages {
Param (
# Optional path to package.json
[String]$pathToPackage = $(Resolve-Path "package.json")
)
# Read the json content
$json = (Get-Content $pathToPackage) -join "`n" | ConvertFrom-Json
# Loop over each package in devDependencies
Execute a function by specifying its name as a string.
-----
A [Pen](http://codepen.io/anon/pen/AgCDt) by [Anonasaurus Rex](http://codepen.io/anon) on [CodePen](http://codepen.io/).
[License](http://codepen.io/anon/pen/AgCDt/license).