Skip to content

Instantly share code, notes, and snippets.

@henrahmagix
henrahmagix / all-top-level-class-selectors.js
Last active February 8, 2017 12:18
Find all top-level selectors, at least with a class included. Useful for finding style files to remove after removing HTML.
'use strict';
var fs = require('fs');
var path = require('path');
// npm install these.
var glob = require('glob');
var gonzales = require('gonzales-pe');
var infile = 'sass/**/*.sass';
@henrahmagix
henrahmagix / all-css-selectors.js
Created February 7, 2017 14:17
Find all selectors in a CSS file. Requires https://github.com/tonyganch/gonzales-pe
var fs = require('fs');
var infile = 'mycssfile.css;'
var input = fs.readFileSync(infile).toString();
var parseTree = require('gonzales-pe').parse(input);
var output = [];
parseTree.traverseByType('selector', node => output.push(node.toString()));
@henrahmagix
henrahmagix / find-angular-no-inline-deps.md
Last active January 4, 2017 16:09
Find non-annotated Angular v1 things that will break when minified. Can be used with ngmin/ng-annotate.

Find Angular v1 things without annotated dependencies

Annoyed by this error?

Error: [$injector:unpr] Unknown provider: cProvider <- c

This will help find non-annotated Angular things that will break when minified. Can also be used with ngmin/ng-annotate and ng-strict-di to find instances where they didn't apply a fix or throw an informative error.

To do this, we must edit angular.js.

@henrahmagix
henrahmagix / protractor-element-screenshot.js
Last active October 30, 2017 17:38
Take a screenshot of an element in all browsers by cropping a page screenshot
// Altered from http://stackoverflow.com/a/38311061/3150057
const fs = require('fs');
const sharp = require('sharp');
const takeElementScreenshot = function (element, name) {
return protractor.promise
.all([
element.getLocation(),
element.getSize(),
browser.takeScreenshot()
])
function invert(initial) {
return Object.keys(initial)
.reduce((obj, key) => {
obj[initial[key]] = key;
return obj;
}, {});
}
const SELECTOR_FIRST_CHARS = {
ID: '#',
@henrahmagix
henrahmagix / protractor-backbone-plugin.js
Created September 24, 2016 15:47
Copy of protractor-testability-plugin to allow use of browser.setLocation()
exports.onPageLoad = function () {
// Copied from protractor-testability-plugin.
return browser.executeScript(function () {
if (!window.angular) {
// TODO: This is very very very (very^n) dirty...
// but the only way right now to make protractor work without setting ignoreSynchronization.
window.angular = {
resumeBootstrap: function () { },
module: function () {
return {
@henrahmagix
henrahmagix / 1-undo-redo-with-prototype.js
Last active August 6, 2016 15:06
An undo/redo example using only the prototype, no history array saving, whilst still allowing garbage collection.
class ValueAction {
constructor(value = 0) {
this.actions = 0;
this.redos = 0;
this.limit = -1;
this.data = {
value: value
};
this.latest = this.data;
}
@henrahmagix
henrahmagix / git-demo-merge-conflicts.sh
Created July 20, 2016 18:58
Git Presentation Demo: merge conflicts
touch foo
git add foo
git commit --message 'Create foo'
git checkout --branch one
echo one > foo
git commit --message 'Add one to foo'
git checkout --branch two master --no-track
echo two > foo
git commit --message 'Add two to foo'
git checkout master
@henrahmagix
henrahmagix / git-demo-branches.sh
Created July 20, 2016 16:02
Git Presentation Demo: branches
git init
echo 'start' > start.txt
git add start.txt
git commit --message 'Initial commit'
git log
# Make a new branch
git branch new
git branch
git log new
git log master