Skip to content

Instantly share code, notes, and snippets.

View A1rPun's full-sized avatar
🌊
Fractalicious

Thom Bakker A1rPun

🌊
Fractalicious
  • The Netherlands
View GitHub Profile
@A1rPun
A1rPun / Keyboard
Created November 19, 2014 11:22
Browser keyboard/mouse/touch
var keys;
document.addEventListener('keydown', function (e) {
e = e ? e : window.event;
keys[e.keyCode] = true;
});
document.addEventListener('keyup', function (e) {
e = e ? e : window.event;
keys[e.keyCode] = false;
});
@A1rPun
A1rPun / EncodeDecode
Last active November 16, 2015 23:03
Encode/Decode XML meta characters
function htmlDecode(s) {
var el = document.createElement("div");
el.innerHTML = s;
return el.textContent;
}
function htmlEncode(s) {
var el = document.createElement("div");
el.textContent = s;
return el.innerHTML;
@A1rPun
A1rPun / animation
Last active November 16, 2015 23:02
Minimal css animation setup
#me {
-webkit-animation: rotation 2s infinite linear;
-moz-animation: rotation 2s infinite linear;
-o-animation: rotation 2s infinite linear;
animation: rotation 2s infinite linear;
}
@-webkit-keyframes rotation {
from {-webkit-transform: rotatex(0deg);}
to {-webkit-transform: rotatex(359deg);}
@A1rPun
A1rPun / scrollspy.js
Last active November 16, 2015 23:02 — forked from pascaldevink/scrollspy.js
/*
Copyright (C) 2021 Pascal de Vink (Tweakers.net)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
;var _ = (function () {
function lo() { }
lo.prototype = {
//XMLHttpRequest wrapper
ajax: function() {
var a = arguments,
requestData,
opts = { method: 'GET', data: null, url: '', async: true, done: null, fail: null, always: null };
@A1rPun
A1rPun / Enum
Last active August 29, 2015 14:05
function mune(){
var a=Array.isArray(arguments[0]) ? arguments[0] : arguments;
for(var i=0,l=a.length,l=l>31?31:l;i<l;i++){this[a[i]] = 1 << i}
}
@A1rPun
A1rPun / Async
Last active August 29, 2015 14:05
var async = {
waterfall: function (listOfRequests, callback) {
var callbacks = 0;
function handleCallback() {
callbacks++;
if (callbacks === listOfRequests.length) {
callback();
} else {
listOfRequests[callbacks](handleCallback);
}