Skip to content

Instantly share code, notes, and snippets.

Lawrence Cherone lcherone

Block or report user

Report or block lcherone

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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
View age_range.js
const ageRange = birthYear => {
// get age
let age = new Date().getFullYear() - birthYear
// range of ages
const range = [
0,
4,
9,
14,
View index.js
/**
* A handy module pattern
*/
const Module = (function () {
/*
** Private variables
*/
let private = {
i: 0
@lcherone
lcherone / gist:5e2283e5659a2ebba1de09013ce223ba
Last active May 23, 2019
Express SPA history API express.static fallback
View gist:5e2283e5659a2ebba1de09013ce223ba

Mostly taken from: https://gitlab.com/sebdeckers/express-history-api-fallback, without all the repo/package fluff.

let staticPath = '/path/to/dist'

app.use(express.static(staticPath))

app.use('/', ((...args) => (req, res, next) => {
  if ((req.method === 'GET' || req.method === 'HEAD') && req.accepts('html')) {
    (res.sendFile || res.sendfile).call(res, ...args, err => err && next())
@lcherone
lcherone / index.md
Created May 19, 2019
Template variable replacement, js and php
View index.md

In PHP

<?php
$vars = [
  'name' => 'Loz'
];

$template = 'Hello {{ name }}!';
@lcherone
lcherone / asyncDirListNaturalSort.js
Last active May 3, 2019 — forked from oliverswitzer/nonModuleDirList.js
Async load list of files from directory, with optional extensions filtering and natural sort in nodejs
View asyncDirListNaturalSort.js
// asyncDirListNaturalSort.js
const path = require('path')
const fs = require('fs')
/**
* Asynchronous load list of files from directory,
* - with optional extensions filtering and natural sort
*
* @param {string} dirPath directory path to folder
@lcherone
lcherone / lxd 1000000.md
Last active Apr 29, 2019
Broken LXD 1000000 mapping, since some update
View lxd 1000000.md

Make sure got volatile keys in config:

lxc config edit my-borked-container

Lookout for these, if they are missing adding them and restarting the container should fix it.

  volatile.idmap.base: "0"
@lcherone
lcherone / encryption.js
Last active Apr 22, 2019
AES CBC Encryption helper nodejs
View encryption.js
const crypto = require("crypto");
/**
* AES CBC Encryption helper
*
* Usage:
* ``` javascript
//
const encryption = require('@lib/encryption');
You can’t perform that action at this time.