Skip to content

Instantly share code, notes, and snippets.

View meirkl's full-sized avatar
🍺
Working

Meir Keller meirkl

🍺
Working
  • Israel
View GitHub Profile
function Base32(v) {
v = v?.toString();
if (!v || !v.length) {
throw new Error('Value must not be empty');
}
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
let bits = 0;
const getActualRequestDurationInSeconds = start => {
const NS_PER_SEC = 1e9; // convert to nanoseconds
const diff = process.hrtime(start);
console.log( diff );
return (diff[0] * NS_PER_SEC + diff[1]) / NS_PER_SEC;
};
const requestDurationMiddleware = (req, res, next) => {
const start = process.hrtime();
res.on('finish', () => {
@meirkl
meirkl / white-noise.js
Created August 30, 2021 08:51
white noise js
document.getElementById("app").innerHTML = `
<button id="white-demo">White Noise</button>
<button id="pink-demo">Pink Noise</button>
<button id="brown-demo">Brown Noise</button>
`;
(function (AudioContext) {
AudioContext.prototype.createWhiteNoise = function (bufferSize) {
bufferSize = bufferSize || 4096;
const node = this.createScriptProcessor(bufferSize, 1, 1);
@meirkl
meirkl / fail-ec-verify.js
Last active May 30, 2021 05:12
Node JS EC verify
const { generateKeyPairSync, createSign, createVerify } = require('crypto');
const ALGORITHM = 'ec';
const NAMED_CURVE = 'P-256';
const HASH_FUNCTION = 'sha256';
const ENCODING = 'base64';
const { privateKey, publicKey } = generateKeyPairSync(ALGORITHM, {
namedCurve: NAMED_CURVE,
});
@meirkl
meirkl / aes.ts
Created December 14, 2020 08:00
AES 256 GCM Typescript
import * as crypto from 'crypto';
const ALGORITHM = 'aes-256-gcm';
const IV_LENGTH = 16;
const SALT_LENGTH = 64;
const TAG_LENGTH = 16;
const TAG_POSITION = SALT_LENGTH + IV_LENGTH;
const ENCRYPTED_POSITION = TAG_POSITION + TAG_LENGTH;
export class AES {
@meirkl
meirkl / decodeHTML.ts
Created October 19, 2020 11:55
Decoding HTML entities with vanilla JavaScript
/**
*
* @param html encoded html
* example:
* &lt;p&gt;In this course, you&amp;rsquo;ll learn:&lt;/p&gt;
* wiill get decoded to:
* <p>In this course, you'll learn:</p>
*/
function decode(html: string) {
var txt = document.createElement('textarea');
@meirkl
meirkl / docker-help.md
Created March 2, 2019 21:05 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

@meirkl
meirkl / App.js
Last active December 5, 2018 20:48
reactstrap tooltip example for dynamic content
import React from 'react';
import ReactDOM from 'react-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import { Button, Tooltip } from 'reactstrap';
class App extends React.Component {
state = {};
toggle = targetName => {
if (!this.state[targetName]) {