Skip to content

Instantly share code, notes, and snippets.

View bennycode's full-sized avatar
🏡
Working from home

Benny Neugebauer bennycode

🏡
Working from home
View GitHub Profile
@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 / 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}
           ...
@bennycode
bennycode / stateful-copies.js
Created December 2, 2019 13:45
Stateful copies
const test = {
tree: {
branch1: 10,
branch2: 20,
}
};
const copies = {};
for (let i = 0; i < 10; i++) {
@bennycode
bennycode / absence-io-example.js
Created January 14, 2020 16:01
Hacky absence.io API example
const Hawk = require('@hapi/hawk');
const request = require('request');
const API_KEY = 'KEY';
const API_KEY_ID = 'ID';
const credentials = {
id: API_KEY_ID,
key: API_KEY,
algorithm: 'sha256'
@bennycode
bennycode / bluebird-promise-cancellation.js
Last active May 6, 2024 11:30
Bluebird Promise Cancellation
// Compliant Promise/A+ implementation: https://www.promisejs.org/implementing/
// Alternative implementation: https://dexie.org/docs/Promise/Promise
// Checkout the Node.js Event Loop: https://www.youtube.com/watch?v=PNa9OMajw9w
// Bluebird breaking change: http://bluebirdjs.com/docs/new-in-bluebird-3.html#cancellation-overhaul
const Promise = require('bluebird');
Promise.config({
cancellation: true,
});
@bennycode
bennycode / index.html
Last active May 6, 2024 11:30
Header, Main, Footer with Flexbox
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css"
>
<style>
Playlist: https://www.youtube.com/playlist?list=PLCbdBdyNHZXLX9p_F8WCPwXHn67QlstZ9
Video in Playlist: https://www.youtube.com/watch?v=qZN0Lo-f3iE&list=PLCbdBdyNHZXLX9p_F8WCPwXHn67QlstZ9
Video: https://www.youtube.com/watch?v=qZN0Lo-f3iE
@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));
@bennycode
bennycode / await-default-import.ts
Created May 27, 2021 12:49
Await default import
const ClassImpl = await import(packageName);
return new ClassImpl.default();
@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)