Skip to content

Instantly share code, notes, and snippets.

:octocat:
Turtle hunting

Matijs Brinkhuis matijs

:octocat:
Turtle hunting
Block or report user

Report or block matijs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@matijs
matijs / qsaHelper.js
Created Jun 23, 2016
Helper function to return querySelectorAll results as an array
View qsaHelper.js
function $_( selectors, baseElement ) {
var elements = (baseElement || document).querySelectorAll( selectors );
return Array.prototype.slice.call( elements );
}
@matijs
matijs / insert-script.js
Created Mar 9, 2016
Sure fire DOM Element insertion
View insert-script.js
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 / makefile
Last active Nov 6, 2017
Minimalist makefile using PostCSS
View makefile
# some variables
POSTCSS = ./node_modules/.bin/postcss
POSTCSS_FLAGS = --use autoprefixer autoprefixer.browsers "> 2%"
# wildcard expansion is performed only in targets and in prerequisites so here we need $(wildcard)
SOURCES = $(wildcard src/css/*.css)
# use $(SOURCES) to determine what we actually need using a bit of pattern substitution
TARGETS = $(patsubst src%, build%, $(SOURCES))
# our default target (see below)
all: $(TARGETS)
@matijs
matijs / .editorconfig
Last active Feb 9, 2016
Sensible EditorConfig defaults
View .editorconfig
# For more information about the properties used in
# this file, please see the EditorConfig documentation:
# http://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
@matijs
matijs / textarea-keyboard-save.js
Created Jan 26, 2016
Trigger a click on a 'save' button by pressing cmd/ctrl-s in a textarea (adapt as needed)
View textarea-keyboard-save.js
(function() {
'use strict';
document.addEventListener('keydown', function(event) {
var S = 83,
activeElement = document.activeElement,
saveButtonId,
saveButton;
if ((event.key === S || event.keyCode === S) && (event.metaKey || event.ctrlKey) && activeElement.nodeName === 'TEXTAREA') {
View index.html
<p>
<a href="#" class="button">Foo Bar</a>
<button type="button" class="button">Baz Quux</button>
</p>
@matijs
matijs / slow_server.py
Created Feb 25, 2015
Enhanced Python SimpleHTTPServer to slowly serve a specific mimetypes
View slow_server.py
"""Simple HTTP Server.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
__version__ = "0.6"
@matijs
matijs / loadCSS.js
Created Feb 23, 2015
load CSS using JS
View loadCSS.js
function loadCSS(href, options){
'use strict';
options = options || {};
var styleSheet = document.createElement('link');
var ref = options.before || document.getElementsByTagName('script')[0];
styleSheet.media = 'not all';
styleSheet.rel = 'stylesheet';
styleSheet.href = href;
styleSheet.onload = function () {
styleSheet.onload = null; // only run once
View vanilla-click-handler.js
;(function(handlers) {
if (!handlers) {
throw new Error('Nothing to handle');
}
document.documentElement.addEventListener('click', function(event) {
var handler = event.originalTarget.getAttribute('data-handler');
if (!handler) {
// nothing to do
return;
@matijs
matijs / enhancer.js
Created Nov 18, 2014
jQuery-based enhancing of components / elements declared with a data-attribute
View enhancer.js
$(function() {
'use strict';
// kick off js enhancements
$('[data-enhancer]').each(function() {
var enhancer = this.getAttribute('data-enhancer');
if (enhancers && typeof enhancers[enhancer] === 'function') {
enhancers[enhancer].call(this);
}
else {
if (window.console && typeof console.log === 'function') {
You can’t perform that action at this time.