Skip to content

Instantly share code, notes, and snippets.

View bennycode's full-sized avatar

Benny Neugebauer bennycode

View GitHub Profile
@bennycode
bennycode / nodejs-clean-exit.ts
Created October 8, 2019 10:12
Node.js process.exit cleanup
function emitExit(signal: string) {
const exitCode = 0;
console.log(`Received "${signal}" signal. Will terminate with exit code "${exitCode}".`);
process.exit(exitCode);
}
// Catches Ctrl + C events
process.on('SIGINT', () => emitExit('SIGINT'));
// Catches "kill pid" events (for example: nodemon restarts)
@bennycode
bennycode / tsconfig.minimum.json
Created August 19, 2019 14:22
Minimum Viable TypeScript config
{
"compilerOptions": {
"lib": ["dom", "es2017"],
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"target": "es6"
}
}
@bennycode
bennycode / momentjs-cheatsheet.js
Created August 13, 2019 12:25
moment.js Cheatsheet
const moment = require('moment');
const date = moment('2019-07-23', 'YYYY-MM-DD');
const oneWeekLater = date.add(1, 'week');
console.log(oneWeekLater.format());
@bennycode
bennycode / material-ui-tricks.md
Last active May 6, 2024 11:31
Material UI Tricks

Add class

  render(): JSX.Element {
    const {classes, title} = this.props;
    return (
      <>
         <TextField
           className={classes.TextField}
           ...
interface MandatoryProps {
id: number;
}
type StoreRecord =
MandatoryProps &
Object;
type Store = {[index: number]: StoreRecord};
@bennycode
bennycode / jasmine-samples.ts
Last active September 1, 2019 22:45
Jasmine Samples
import Spy = jasmine.Spy;
spyOn(exchange['client'], 'candles').and.callFake(() => {
const candlesSpy = (exchange['client'].candles as Spy);
switch (candlesSpy.calls.count()) {
case 1:
return require('../test/fixtures/binance/candles/BTC-USDT-1m-500-1561500000000.json');
case 2:
return require('../test/fixtures/binance/candles/BTC-USDT-1m-500-1561530000000.json');
default:
@bennycode
bennycode / window-fetch-post.js
Created February 18, 2019 23:19
Send POST request in Google Chrome
// Using "var" here to easily change the parameters and resubmit the code in a JS dev console!
var url = 'http://127.0.0.1:3000/login';
var parameters = {
user: 'bennyn',
password: 'secret'
};
fetch(url, {
method: 'post',
@bennycode
bennycode / coinbase-transaction-buy.js
Created February 9, 2019 16:05
Log Coinbase buy transactions
require('dotenv').config();
const Client = require('coinbase').Client;
const {promisify} = require('util');
const {COINBASE_API_KEY, COINBASE_API_SECRET} = process.env;
const client = new Client({
apiKey: COINBASE_API_KEY,
apiSecret: COINBASE_API_SECRET
});
@bennycode
bennycode / Skeleton.tsx
Created January 13, 2019 20:10
Material UI example (TypeScript)
import {createStyles, Grid, Paper, Theme, WithStyles, withStyles,} from '@material-ui/core';
import * as React from 'react';
const styles = (theme: Theme) =>
createStyles({
root: {
flexGrow: 1,
},
paper: {
padding: theme.spacing.unit * 2,
@bennycode
bennycode / dump.js
Last active May 6, 2024 11:29
Dump text into JSON file (Node.js)
const payload = {name: 'text'};
(require('fs')).writeFileSync(`dump-${Date.now()}.json`, JSON.stringify(payload));