Skip to content

Instantly share code, notes, and snippets.

@ahallora
ahallora / Horizontal scroller.html
Created November 15, 2016 11:02
Horizontal scrolling area (iOS inertia style) with just CSS
<!-- Source: https://benfrain.com/horizontal-scrolling-area-css-overflow-ios/ -->
<div class="outer">
<div class="wrapper">
<a href="" class="internal">item 1</a>
<a href="" class="internal">item 2</a>
<a href="" class="internal">item 3</a>
<a href="" class="internal">item 4</a>
<a href="" class="internal">item 5</a>
<a href="" class="internal">item 6</a>
@ahallora
ahallora / Rearranger.html
Last active November 16, 2016 07:06
Rearrange List with smooth-sliding animations
<h1>Rearrange List with smooth-sliding animations</h1>
<p>Click on the tiles to randomly make them move among each other with a smooth 3D-like effect. Transitions are hardware accelerated with CSS3 and accompanied with under the hood DOM-manipulation.</p>
<p>Author: Anders Holm-Jensen, allora.dk - License: MIT</p>
<ul id="list">
<li>Anders And</li>
<li>Andersine And</li>
<li>Joakim von And</li>
<li>Fætter Højben</li>
<li>Rip, rap og Rup</li>
</ul>
@ahallora
ahallora / badges.html
Created February 6, 2017 09:27
App Store Badges
<!-- found on https://jawbone.com/up -->
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="0">
<symbol id="microsoft-store-badge" viewBox="0 0 210 72"><title>Microsoft Store badge</title><rect width="210" height="72" rx="8" ry="8"></rect><rect x="16" y="14.93" width="20.29" height="20.29" style="fill:#f25022"></rect><rect x="38.41" y="14.93" width="20.29" height="20.29" style="fill:#7fba00"></rect><rect x="16" y="37.33" width="20.29" height="20.29" style="fill:#00a4ef"></rect><rect x="38.41" y="37.33" width="20.29" height="20.29" style="fill:#ffb900"></rect><path d="M97.84,37.8a2,2,0,0,1,.65-1.5,2.2,2.2,0,0,1,1.55-.61,2.17,2.17,0,0,1,1.59.62,2,2,0,0,1,.63,1.49,1.94,1.94,0,0,1-.64,1.48,2.22,2.22,0,0,1-1.57.6,2.19,2.19,0,0,1-1.56-.6,2,2,0,0,1-.64-1.47m4,19.83H98.21V42.24h3.62V57.63Z" style="fill:#fff"></path><path d="M112.82,55a5,5,0,0,0,1.78-.37,7.52,7.52,0,0,0,1.8-1V57a7.26,7.26,0,0,1-2,.75A10.7,10.7,0,0,1,112,58a7.32,7.32,0,0,1-7.65-7.63,8.78,8.78,0,0,1,2.17-6.11,7.86,7.86,0,0,1,6.15-2.4,8.42
@ahallora
ahallora / Utility Functions.js
Created February 20, 2017 19:31
Various functions to check the integrity of data.
function isString(x) {
return x !== null && x !== undefined && x.constructor === String
}
function isNumber(x) {
return x !== null && x !== undefined && x.constructor === Number
}
function isBoolean(x) {
return x !== null && x !== undefined && x.constructor === Boolean
@ahallora
ahallora / promises.js
Last active February 15, 2020 20:27
How to properly nest functions returning Promises (ECMA6) in node.js (Nested Promises example)
/*
How to properly nest functions returning Promises (ECMA6) in node.js (Nested Promises example)
generated output (with 1 second ticks) =>
p1 function
p2 function
p3 function
p3 done
p2 done
@ahallora
ahallora / hextorgb.js
Created July 27, 2017 18:13
Convert hex value to RGB value
function hexToRGBA (hex, opacity = 1) {
const components = hex
.replace('#', '')
.match(/.{1,2}/g)
.map(hextet => parseInt(hextet, 16))
.concat(opacity)
.join(', ');
return `rgba(${components})`
}
@ahallora
ahallora / tracker.js
Last active October 25, 2017 14:54
Tracker Object to track time - including pause and resume functionality
/*
LICENSE: MIT
Created by: Anders Holm-Jensen
Website: allora.dk
Date: 25-oct-2017
*/
const timestamp = () => ( Math.round( new Date() * 1 / 1000) );
let tracker = {
data: {
@ahallora
ahallora / PwnedPasswords.js
Created February 6, 2019 07:05
A simple ES6 implementation of PwnedPasswords API
// https://cdnjs.cloudflare.com/ajax/libs/js-sha1/0.6.0/sha1.min.js
/*
* [js-sha1]{@link https://github.com/emn178/js-sha1}
*
* @version 0.6.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
*/
!function(){"use strict";function t(t){t?(f[0]=f[16]=f[1]=f[2]=f[3]=f[4]=f[5]=f[6]=f[7]=f[8]=f[9]=f[10]=f[11]=f[12]=f[13]=f[14]=f[15]=0,this.blocks=f):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],this.h0=1732584193,this.h1=4023233417,this.h2=2562383102,this.h3=271733878,this.h4=3285377520,this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}var h="object"==typeof window?window:{},s=!h.JS_SHA1_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;s&&(h=global);var i=!h.JS_SHA1_NO_COMMON_JS&&"object"==typeof module&&module.exports,e="function"==typeof define&&define.amd,r="0123456789abcdef".split(""),o=[-2147483648,8388608,32768,128],n=[24,16,8,0],a=["hex","array","digest","arrayBuffer"],f=[],u=functio
@ahallora
ahallora / timestampToExcelDate.js
Last active April 5, 2020 19:01
Epoch / Unix timestamp to Excel Date converter in JavaScript / ES6 / Node
const timestampToExcelDate = timestamp => {
const start = new Date("1899-12-30 00:00:00");
return (timestamp - start) / (1000 * 60 * 60 * 24).toFixed(12);
};
@ahallora
ahallora / LambdaCacheController.js
Last active March 29, 2020 19:50
Simple AWS Lambda Container In-Memory Cache Controller for Node.js / ES6
export class LambdaCacheController {
constructor() {
this.value = null;
this.timestamp = null;
this.ttl = 3000000; // default 5 minutes
}
async getValue() {
return new Promise((resolve, reject) => {
try {