Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
ben-bradley / remote-debugging-nodejs.md
Created July 19, 2021 14:08
Remote Debugging Node.js

How to Remotely Debug a Node.js Process

  • Open the Brave/Chrome dev tools - brave://inspect/#devices
  • Click on Open dedicated DevTools for Node
  • Log in to the remote host:
ssh USER@REMOTE_IP
  • Figure out how to add --inspect-brk to the startup for your app
  • Bounce the app with whatever process manager you use
@ben-bradley
ben-bradley / .eslintrc.json
Created November 5, 2020 14:42
Lint defs
{
"env": {
"es6": true,
"node": true,
"jest": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2017
},
'use strict';
const iteratePromise = (promise, list) =>
list.reduce((promiseChain, item) =>
promiseChain.then((results) =>
promise(item).then((result) =>
results.concat(result)))
, Promise.resolve([]));
const list = [ `a`, `b`, `c` ];
@ben-bradley
ben-bradley / template.js
Created March 26, 2018 15:40
How to use variables as ES6 templates
'use strict';
const xml = '<foo>${data.bar}</foo>';
const template = (data, string) =>
eval('((data) => `'+string+'`)('+JSON.stringify(data)+')');
const obj = {
bar: `baz`
};
@ben-bradley
ben-bradley / validateCreditCardNumber.js
Created September 15, 2017 19:40
credit card validator
'use strict';
// https://stackoverflow.com/questions/72768/how-do-you-detect-credit-card-type-based-on-number/72801
const validate = (num) => (num
.replace(/\D/g, ``) // strip all non-digit chars
.split(``) // make an array where each digit is an element
.map((n) => Number(n)) // make them all numbers
.reverse() // reverse the order
.reduce((checksum, n, i) =>
(i % 2) ? checksum + n : checksum + (n * 2), 0) % 10) === 0;
@ben-bradley
ben-bradley / index.js
Last active November 22, 2016 16:18
Create-React-App with MUI
// src/index.js
import React from 'react';
import ReactDOM from 'react-dom';
import injectTapEventPlugin from 'react-tap-event-plugin';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import App from './App';
import './index.css';
injectTapEventPlugin();
@ben-bradley
ben-bradley / keep.js
Created August 29, 2016 22:18
A way to dynamically assign property names during an object declaration
'use strict';
/**
* With a Promise that receives a context object, but returns a different value that you want to
* have assigned to the context, you can assign dynamic property names like this:
*/
const keep = (ctx, prop) => (value) => Object.assign(ctx, { [ prop ]: value });
const session = {};
@ben-bradley
ben-bradley / flatten.js
Created August 11, 2016 19:48
javascript array flattener
'use strict';
// es6
const flatten = (a) => (!Array.isArray(a)) ? [ a ] : a.reduce((f, i) => f.concat(flatten(i)), []);
// es5
/*
function flatten(ary) {
if (!Array.isArray(ary))
return [ ary ];
#!/bin/bash
TARGET=$1
ping -c 1 -a $TARGET &> /dev/null
while [ $? -ne 0 ]; do
sleep 2
ping -c 1 -a $TARGET &> /dev/null
done
@ben-bradley
ben-bradley / styles.less
Created April 15, 2016 19:30
control atom theme colors in tree-view (dirs & files)
@dark-text: #777;
@light-text: lightgray;
.tree-view {
.status-ignored {
.header {
&::before {
color: @light-text !important;
}