Skip to content

Instantly share code, notes, and snippets.

Lawrence Cherone lcherone

View GitHub Profile
@lcherone
lcherone / script.js
Created Jun 27, 2020
asynchronous IIAFE in a for loop, with step timing
View script.js
console.log('asynchronous IIAFE in a for loop, with step timing')
for (let i = 0; i <= 10; i++)
setTimeout(
async () =>
(async function (index) {
console.log(index)
})(i),
i * 250
)
@lcherone
lcherone / script.js
Last active Jun 26, 2020
Javascript merge multiple arrays, de-duped by property name, O(N1) using reduce
View script.js
const array1 = [
{ name: 'a', creationDate: new Date() },
{ name: 'b', creationDate: new Date() },
]
const array2 = [
{ name: 'a', creationDate: new Date() },
{ name: 'c', creationDate: new Date() },
]
const mergeBy = (...arrays) => {
@lcherone
lcherone / script.js
Last active Jun 27, 2020
JavaScript, merge 2 arrays of objects, remove dupes, irrelevant of length, keys or reference
View script.js
/*
You saw it here first, out of the 8k dupes on stackoverflow, none address diff length b array, diff keys or reference.
Leave a comment if you know a better way
*/
const a = [{ a: 'a' }, { b: 'b' }];
const b = [{ a: 'a' }, { c: 'c' }, { x: 'x' }, {}];
const merge = (a, b) => [
...new Set([
@lcherone
lcherone / fnv.js
Last active Jun 9, 2020
FNV hash function, 32/64
View fnv.js
/**
* FNV hash
* - 32 bit FNV-1a hash
* - 64 bit FNV-1a hash
* @link http://isthe.com/chongo/tech/comp/fnv/
*
* Usage:
* fnv.hash('Hello World', 32) // 3012568359
* fnv.hash('Hello World', 64) // 3599595964
*/
@lcherone
lcherone / gist:9450312764a0fb3055165e3825631976
Created May 30, 2020
Browser crypto.subtle (SubtleCrypto) simple encrypt/decrypt
View gist:9450312764a0fb3055165e3825631976
// derive string key
async function deriveKey(password) {
const algo = {
name: 'PBKDF2',
hash: 'SHA-256',
salt: new TextEncoder().encode('a-unique-salt'),
iterations: 1000
}
return crypto.subtle.deriveKey(
algo,
@lcherone
lcherone / Reverse Proxy (Apache)
Last active Feb 29, 2020
Basic reverse proxy configs.
View Reverse Proxy (Apache)
<VirtualHost *:80>
ServerName example.com
ErrorLog /var/log/httpd/example.com-error.log
CustomLog /var/log/httpd/example.com-access.log combined
ProxyRequests Off
ProxyVia Block
ProxyPreserveHost On
<Proxy *>
@lcherone
lcherone / index.md
Last active Nov 9, 2019
parceljs - jQuery is undefined jquery-ui
View index.md

parceljs - jQuery is undefined jquery-ui

//
import jQuery from "jquery";
window.$ = window.jQuery = jQuery;
import "jquery-ui-bundle";

// or something like, as suggested thoughout the internets
import $ from 'jquery';
View gist:04c6a4fece30edb3ae689caec8506149
https://freegeoip2.azurewebsites.net/Home/Resolve
https://freegeoip2.azurewebsites.net/Home/Resolve/123-123-123-123
@lcherone
lcherone / objectEnum.js
Last active Sep 21, 2019
traverse recursive enumerate javascript object safe from [Circular] reference
View objectEnum.js
/**
* Traverse over an object, safe from [Circular]
*
* - if value is string or number, returns value
* - if value is function, returns array of function arguments
* - if value is anything else, returns empty string
*
``` javascript
let test = {
@lcherone
lcherone / strictMerge.js
Last active Aug 24, 2019
Javascript recursive merge two arrays or objects where the first is the constraint. If item/value in B is not in A or is not the same type then A is used.
View strictMerge.js
/**
* Strict merge
*
* Recursive merge two arrays or objects where the first is the
* constraint, so if item/value in B is not in A or is not the
* same type as A then A is used.
*
* @param itemA An object or an array, which defines the merge
* @param itemB A matching object or array which will be merging in
* @returns object|array
You can’t perform that action at this time.