Skip to content

Instantly share code, notes, and snippets.

@wwilsman
wwilsman / absolute-to-relative.js
Created January 31, 2020 16:43
Convert absolute URLs to be root relative where possible
export function absoluteToRelative() {
const origin = window.location.origin;
const $internalElements = window.document.querySelectorAll(`[href^="${origin}"],[src^="${origin}"]`);
for (let $el of $internalElements) {
const attr = $el.hasAttribute('href') ? 'href' : 'src';
const value = $el.getAttribute(attr);
$el.setAttribute(attr, value.replace(origin, ''));
}
}
@wwilsman
wwilsman / cypress-inject-css.js
Created August 22, 2019 17:08
Cypress - Inject Percy-specific CSS
// access the cypress document
cy.document().then(doc => {
// create a new style tag
let $style = doc.createElement("style");
// add percy-specific css
$style.innerHTML = "@media only percy { iframe { display: none !important; } };";
// inject styles into the document
doc.body.head.appendChild($style);
});
@wwilsman
wwilsman / modeline.el
Created April 19, 2018 15:05
Wil's Emacs modeline config
;; mode line modes
(line-number-mode t)
(column-number-mode t)
(size-indication-mode t)
;; diff-hl reducer used ro replace the git-gutter reducer
(defun ww/diff-hl-reducer (acc it)
"A reducer to count added, removed, and modified lines for diff-hl."
(cl-destructuring-bind (added removed modified) acc
(let ((lines (nth 1 it))
@wwilsman
wwilsman / convergent-it.js
Last active August 4, 2017 20:58
Convergent it + helpers
it.immediately = window.it;
it.skip = it.immediately.skip;
it.only = itOnly;
it.still = itStill;
export default it;
function it(name, assertion) {
return !assertion ? it.immediately(name) :
it.immediately(name, _convergeOn(assertion));
}
@wwilsman
wwilsman / dired.el
Last active July 21, 2017 16:08
Frontmacs Initializers
(unless (package-installed-p 'dired+)
(package-install 'dired+))
(require 'dired+)
(setq diredp-hide-details-initially-flag nil
diredp-hide-details-propagate-flag nil)
(diredp-toggle-find-file-reuse-dir 1)