Skip to content

Instantly share code, notes, and snippets.

View jwrigh26's full-sized avatar

Justin Wright jwrigh26

View GitHub Profile
@jwrigh26
jwrigh26 / VS Code JS Snippets
Created February 16, 2023 23:12
My JS Snippets
{
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Log value to console": {
"prefix": "lg-var",
"body": ["console.log($1);", "$2"],
"description": "Log value and string output to console"
@jwrigh26
jwrigh26 / VSCode User settings
Created February 16, 2023 23:11
My horrible VSCode user settings
{
"workbench.iconTheme": "material-icon-theme",
// "workbench.editor.showTabs": false,
"[javascript]": {
"editor.formatOnSave": false,
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.detectIndentation": false,
},
"[json]": {
// Matches
// values: be90d703-4671-4024-9a20-bf4c42d5 from
// URL: .../accruals.html#/accruals-wizard/be90d703-4671-4024-9a20-bf4c42d5/create
const foo = {
fooIdFromPathname: pathname => {
const regex = new RegExp(
`^(?:.*)(?:(?:herp-dirp\/)|(?:foo\/))([a-zA-z0-9-]*)(?:\/)(?:(?:.*))?`
);
const results = regex.exec(pathname) ?? [];
@jwrigh26
jwrigh26 / node_nginx_ssl.md
Created October 15, 2021 03:19 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

@jwrigh26
jwrigh26 / Regex Example
Created July 30, 2021 16:52
An example of using regex in React/node.js
useEffect(() => {
const pathname = location?.pathname;
const pathNameChanged = hasValue(pathname) && pathname !== prevPathname;
const managedPaths = {
// regex looks for the id and value of foo
create: () => {
const regex = new RegExp(`^(?:.*)(${id})(?:(?:.*)(${foo}))?`);
const results = regex.exec(pathname) ?? [];
@jwrigh26
jwrigh26 / removeItem.js
Last active June 3, 2021 22:06
Remove Object Properties with Destructing
// Helper method to delete without mutating
// Why not use delete? It's a mutable operation (side-effects).
// By using object destructuring, we have a one-liner approach.
// Inspired by: https://ultimatecourses.com/blog/remove-object-properties-destructuring
const removeItem = (key, { [key]: _, ...obj }) => obj;
// How does this work?
// We pass in the name of the key we wish to remove from the object.
// For the second param, we pass in the object
@jwrigh26
jwrigh26 / gist:82b71da5b5994112f816a3b4e86babc5
Created March 21, 2020 00:36
Local & Session Storage Helper
export default function storage(isSession = false) {
const manager = isSession ? sessionStorage : localStorage;
const hasManager = isSession ? window.sessionStorage : window.localStorage;
function getItem(id, json = true) {
if (hasManager) {
return json ? JSON.parse(manager.getItem(id)) : manager.getItem(id);
}
return undefined;
}
{
"breadcrumbs.enabled": true,
"editor.tabSize": 2,
"eslint.packageManager": "yarn",
"files.autoSave": "onFocusChange",
"javascript.format.enable": false,
// "editor.lineNumbers": "relative",
"editor.formatOnSave": false,
"eslint.autoFixOnSave": true,
// Set the default
{
"Print to console": {
"prefix": "lgvar",
"body": [
"console.log('$1', $1);$0"
],
"description": "Log output to console"
},
"Print String to console": {
"prefix": "lg",
@jwrigh26
jwrigh26 / getScrollbarWidth
Created September 25, 2019 16:16
Get Scrollbar width
function getScrollbarWidth() {
// Creating invisible container
const outer = document.createElement('div');
outer.style.visibility = 'hidden';
outer.style.overflow = 'scroll'; // forcing scrollbar to appear
outer.style.msOverflowStyle = 'scrollbar'; // needed for WinJS apps
document.body.appendChild(outer);
// Creating inner element and placing it in the container
const inner = document.createElement('div');