Skip to content

Instantly share code, notes, and snippets.

View lcherone's full-sized avatar
:octocat:

Lawrence Cherone lcherone

:octocat:
View GitHub Profile
@lcherone
lcherone / script.js
Last active June 27, 2020 00:15
JavaScript, merge 2 arrays of objects, remove dupes, irrelevant of length, keys or reference
/*
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 June 9, 2020 23:43
FNV hash function, 32/64
/**
* 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 13:30
Browser crypto.subtle (SubtleCrypto) simple encrypt/decrypt
// 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 February 29, 2020 21:10
Basic reverse proxy configs.
<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 November 9, 2019 16:11
parceljs - jQuery is undefined jquery-ui

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';
https://freegeoip2.azurewebsites.net/Home/Resolve
https://freegeoip2.azurewebsites.net/Home/Resolve/123-123-123-123
@lcherone
lcherone / objectEnum.js
Last active September 21, 2019 22:11
traverse recursive enumerate javascript object safe from [Circular] reference
/**
* 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 August 24, 2019 06:34
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.
/**
* 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
const ageRange = birthYear => {
// get age
let age = new Date().getFullYear() - birthYear
// range of ages
const range = [
0,
4,
9,
14,
@lcherone
lcherone / index.js
Last active May 26, 2019 08:19
handy
/**
* A handy module pattern
*/
const Module = (function () {
/*
** Private variables
*/
let private = {
i: 0