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 / 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);
}
@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}
}
;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 / 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 / Batch colors (HEX)
Last active August 29, 2015 14:12
Use this in combination with .bat and the command `COLOR ##`
0 = Black
8 = Gray
1 = Blue
9 = Light Blue
2 = Green
A = Light Green
3 = Aqua
B = Light Aqua
4 = Red
C = Light Red
@A1rPun
A1rPun / Customizable Promise
Last active August 29, 2015 14:16
Customizable Promise
function Promise(o, fnNames){
fnNames = fnNames || ['done', 'fail', 'always'];
var done = fnNames[0],
fail = fnNames[1],
always = fnNames[2];
o.states = { none: 0 };
o.states[done] = 1;
o.states[fail] = 2;
@A1rPun
A1rPun / convertStringToInput
Created April 10, 2015 11:35
Convert a string to keys on your keyboard
function convertStringToInput(str){
var result = [];
for (var i = 0, l = str.length; i < l; i++) {
var charCode = str.charCodeAt(i);
result.push(charCode > 255 ? '+' + charCode.toString(16) : charCode);
}
return result.join(' ');
}
@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
@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;