Skip to content

Instantly share code, notes, and snippets.

View matijs's full-sized avatar
:dependabot:
Scouting turtles

matijs matijs

:dependabot:
Scouting turtles
View GitHub Profile
@matijs
matijs / insert-script.js
Created March 9, 2016 18:37
Sure fire DOM Element insertion
function insertScript(url, onload, onerror) {
var ref = document.getElementsByTagName('script')[0];
var script = document.createElement('script');
script.src = url;
if (typeof onload === 'function') {
script.onload = onload;
}
if (typeof onerror === 'function') {
script.onerror = onerror;
}
@matijs
matijs / qsaHelper.js
Created June 23, 2016 05:36
Helper function to return querySelectorAll results as an array
function $_( selectors, baseElement ) {
var elements = (baseElement || document).querySelectorAll( selectors );
return Array.prototype.slice.call( elements );
}
function isInteractiveElement( element ) {
if ( [ 'A', 'BUTTON', 'DETAILS', 'EMBED', 'IFRAME', 'KEYGEN', 'LABEL', 'SELECT', 'TEXTAREA' ].indexOf( element.nodeName ) !== -1 ) {
return true;
}
if ( element.nodeName === 'INPUT' && element.type !== 'hidden' ) {
return true;
}
if ( ['AUDIO', 'VIDEO'].indexOf( element.nodeName ) > -1 && element.hasAttribute('controls') ) {
return true;
}
@matijs
matijs / .scss-lint.yml
Last active August 4, 2016 10:36
All SCSS Linter options, quite restrictive, see https://github.com/brigade/scss-lint/blob/master/lib/scss_lint/linter/README.md for an explanation of the options.
---
linters:
BangFormat:
space_before_bang: true
space_after_bang: false
BemDepth:
enabled: false
BorderZero:
enabled: true
convention: none
@matijs
matijs / camelCase.js
Last active November 3, 2016 14:18
Convert foo-bar-baz into a camelCased version
const camelCase = str => str.split( /[_,-]+/ ).map( ( item, index ) => index === 0 ? item : item.charAt(0).toUpperCase() + item.slice(1).toLowerCase()
).join('');
@matijs
matijs / switcher.js
Created December 8, 2016 15:25
Stylesheet Switcher
(function() {
const links = Array.from( document.querySelectorAll( 'link[title]' ) );
const styles = Array.from( new Set( links.map( link => link.title ) ) );
let title = localStorage.getItem( 'title' );
function selectStyle( title ) {
links.forEach( link => {
link.disabled = true;
link.disabled = link.title !== title;
});
@matijs
matijs / switcher-es5.js
Last active December 8, 2016 22:47
Stylesheet switcher sans ES6 features
(function() {
window.addEventListener( 'load', function() {
var links = Array.prototype.slice.call( document.querySelectorAll( 'link[title]') );
var uniqueTitles = links.reduce( function( titles, link ) {
if ( titles.indexOf( link.title ) === -1 ) {
titles.push( link.title );
}
return titles;
}, []);
var title = window.sessionStorage && window.sessionStorage.getItem( 'title' ) || '';
@matijs
matijs / sitemap.xml
Created July 11, 2014 15:14
Jekyll sitemap
---
layout: none
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for post in site.posts %}{% unless post.unpublished == false %}<url>
<loc>{{ site.url }}{{ post.url }}</loc>
<lastmod>{% if post.sitemap.lastmod %}{{ post.sitemap.lastmod | date: "%Y-%m-%d" }}{% else %}{{ post.date | date_to_xmlschema }}{% endif %}</lastmod>{% if post.sitemap.changefreq %}
<changefreq>{{ post.sitemap.changefreq }}</changefreq>{% endif %}{% if post.sitemap.priority %}
<priority>{{ post.sitemap.priority }}</priority>{% endif %}
(function(doc, body) {
const main = doc.querySelector('main').parentNode.removeChild(doc.querySelector('main'));
while (body.firstChild) body.removeChild(body.firstChild);
body.appendChild(main)
}(document, document.body));
@matijs
matijs / settings.json
Created November 20, 2017 10:33
Visual Studio Code User Settings
// Place your settings in this file to overwrite the default settings
{
"editor.fontFamily": "Source Code Pro",
"editor.fontSize": 14,
"editor.renderWhitespace": "all",
"editor.renderIndentGuides": false,
"editor.selectionHighlight": false,
"files.insertFinalNewline": true,
"workbench.colorTheme": "Solarized Dark",
"workbench.iconTheme": "vs-minimal",