Skip to content

Instantly share code, notes, and snippets.

@ahallora
ahallora / s1ep1.md
Created Jul 28, 2020
Math and JavaScript live problem solving with Anders - episode 1
View s1ep1.md

Math and JavaScript live problem solving - episode 1

Welcome to this mini series of me trying to solve a simple math problem with Javascript. I apologize in advance to everyone more capable in both math and javascript.

Today's objective

  • Divide a number by 100 and limit the result's amount of decimals to 5 tops.
  • Expected outcome: 49.95 becomes 0.4995 and 9.95 becomes 0.0995.

That's easy, you might think.

@ahallora
ahallora / index.html
Created Jun 19, 2020
XSS onerror image example
View index.html
<img src=x onerror="&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041">
@ahallora
ahallora / README.md
Last active May 13, 2020
Webflow API rate limiter workaround (ES6 / Nodejs)
View README.md

Webflow API rate limit workaround

This is a naive work-around to the glitchy rate limiter of the current Webflow API. Any suggestions to optimizations is much appreciated.

How to use

It's a wrapper to your existing webflow-api functions, where you define two parameters:

  1. a collection ID and
  2. the function you want to call

If you have reached the rate limit this wrapper will handle the error and try to reset the rate

@ahallora
ahallora / CsvToJson.js
Created Apr 8, 2020
Javascript function to convert a CSV list into list of JSON objects
View CsvToJson.js
const mapCsvToJson = (csv, delimiter) => {
const lines = csv.split("\n");
let dataArray = [];
let keys = [];
for (i = 0; i < lines.length; i++) {
const line = lines[i];
const data = line.split(delimiter);
if (i === 0) {
@ahallora
ahallora / LambdaCacheController.js
Last active Mar 29, 2020
Simple AWS Lambda Container In-Memory Cache Controller for Node.js / ES6
View LambdaCacheController.js
export class LambdaCacheController {
constructor() {
this.value = null;
this.timestamp = null;
this.ttl = 3000000; // default 5 minutes
}
async getValue() {
return new Promise((resolve, reject) => {
try {
@ahallora
ahallora / timestampToExcelDate.js
Last active Apr 5, 2020
Epoch / Unix timestamp to Excel Date converter in JavaScript / ES6 / Node
View timestampToExcelDate.js
const timestampToExcelDate = timestamp => {
const start = new Date("1899-12-30 00:00:00");
return (timestamp - start) / (1000 * 60 * 60 * 24).toFixed(12);
};
@ahallora
ahallora / PwnedPasswords.js
Created Feb 6, 2019
A simple ES6 implementation of PwnedPasswords API
View PwnedPasswords.js
// 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 / tracker.js
Last active Oct 25, 2017
Tracker Object to track time - including pause and resume functionality
View tracker.js
/*
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 / hextorgb.js
Created Jul 27, 2017
Convert hex value to RGB value
View hextorgb.js
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 / promises.js
Last active Feb 15, 2020
How to properly nest functions returning Promises (ECMA6) in node.js (Nested Promises example)
View promises.js
/*
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
You can’t perform that action at this time.