Skip to content

Instantly share code, notes, and snippets.

View trevorhreed's full-sized avatar

Trevor trevorhreed

  • Utah
  • 17:40 (UTC -06:00)
View GitHub Profile
@robertpainsi
robertpainsi / commit-message-guidelines.md
Last active July 15, 2024 08:33
Commit message guidelines

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
@trevorhreed
trevorhreed / full-text-search-algorithm.js
Last active October 20, 2021 22:17
A simple full-text-search algorithm
// Draft 2
ngm.service('searchArray', function(){
let THRESHHOLD = 0;
let FULL_EXACTMATCH_MODIFIER = 1.0;
let FULL_STARTSWITH_MODIFIER = 0.9;
let FULL_CONTAINS_MODIFIER = 0.3;
let FULL_PARTIAL_MODIFIER = 0.3;
let PRECISION = 2;
let re = /[\s\b]+/g;
let search = (term, arr, key) => {
@trevorhreed
trevorhreed / short-uuid.js
Created October 25, 2017 20:13
Shorter UUIDs
const bigInt = require("big-integer")
const symbols = `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`;
const v2r = (n, b) => {
if(!bigInt.isInstance(n)) n = bigInt(n);
let digits = '';
while(n > 0){
let r = n.divmod(b);
digits = symbols[r.remainder] + digits;
n = r.quotient;
@trevorhreed
trevorhreed / get-fn-params.js
Last active January 14, 2022 21:15
getFnParams: takes a function and returns the names of that function's parameters as an array
const fnParamsRe = /^(?:async)?\s*(?:(?:function\s+[a-zA-Z_][a-zA-Z0-9_]*|function|[a-zA-Z_][a-zA-Z0-9_]*)\s*(?:\(([^)]*)\))|(?:\(([^)]*)\)|([a-zA-Z_][a-zA-Z0-9_]*))\s*=>\s*{)/
const sepRe = /\s*,\s*/g
const getFnParams = fn => {
const source = fn.toString()
const match = fnParamsRe.exec(source) || []
const paramStr = match[1] || match[2] || match[3] || ''
return paramStr.split(sepRe).filter(Boolean)
}
console.clear()
const Pid = (function(){
// UUID generator
!function(n){"use strict";function e(){var e=n.crypto||n.msCrypto;if(!f&&e&&e.getRandomValues)try{var r=new Uint8Array(16);s=f=function(){return e.getRandomValues(r),r},f()}catch(n){}if(!f){var o=new Array(16);i=f=function(){for(var n,e=0;e<16;e++)0===(3&e)&&(n=4294967296*Math.random()),o[e]=n>>>((3&e)<<3)&255;return o},"undefined"!=typeof console&&console.warn&&console.warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()")}}function r(){if("function"==typeof require)try{var n=require("crypto").randomBytes;c=f=n&&function(){return n(16)},f()}catch(n){}}function o(n,e,r){var o=e&&r||0,t=0;for(e=e||[],n.toLowerCase().replace(/[0-9a-f]{2}/g,function(n){t<16&&(e[o+t++]=y[n])});t<16;)e[o+t++]=0;return e}function t(n,e){var r=e||0,o=v;return o[n[r++]]+o[n[r++]]+o[n[r++]]+o[n[r++]]+"-"+o[n[r++]]+o[n[r++]]+"-"+o[n[r++]]+o[n[r++]]+"-"+o[n[r++]]+o[n[r++]]+"-"+o[n[r++]]+o[n[r++]]+o[n[r++]]+o[n[r++]]+o[n[r++]]+o[n[r++]]}functi
@trevorhreed
trevorhreed / command-line-args.js
Last active January 20, 2022 23:34
Turns `process.argv` into an array-like object with fixed position arguments indexed by number and named arguments indexed by key.
/**
* Simple command line argument parser
*
* An instance of Args is an array-like
* object that contains a list of fixed
* and named arguments
*
* Given command line args of:
*
* node args.js command -a --param=value