Skip to content

Instantly share code, notes, and snippets.

View bennycode's full-sized avatar

Benny Neugebauer bennycode

View GitHub Profile
@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 / list-all-files-in-directoy.js
Created May 22, 2021 10:52
List all files in a directory (Node.js)
const fs = require('fs');
const testFolder = './test/';
fs.readdirSync(testFolder).forEach(file => {
console.log(file);
});
@bennycode
bennycode / autoexec.cfg
Last active April 18, 2021 08:28
CS:GO Duck Jump Binding
# Find the location where CS:GO is installed:
# 1. Open your Steam Library
# 2. Right-click on "Counter-Strike: Global Offensive" in your list of games
# 3. Select "Properties..."
# 4. Select "Local Files"
# 5. Click on "Browse..."
# 6. Open the following location:
# ...\Counter-Strike Global Offensive\csgo\cfg\autoexec.cfg
# 7. Save the entries below to your "autoexec.cfg":
@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>
@bennycode
bennycode / show-lines-of-code.js
Created April 1, 2020 13:48
Traverse directories and show lines of code
const fs = require('fs');
const path = require('path');
function walkDir(dir, callback) {
fs.readdirSync(dir).forEach(file => {
const dirPath = path.join(dir, file);
const isDirectory = fs.statSync(dirPath).isDirectory();
isDirectory ?
walkDir(dirPath, callback) : callback(path.join(dir, file));
});
@bennycode
bennycode / simple-server.ts
Created March 7, 2020 12:55
Simple Server
import {createServer} from 'http';
createServer((request, response) => {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello World!');
response.end();
}).listen(8080);
@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 / 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 / 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 / 50-shades-types.ts
Created October 17, 2019 10:32
50 Shades of Types
const a: object = { name: 'Benny' };
const b: Object = { name: 'Benny' };
const c: {} = { name: 'Benny' };
const d: Record<string, string> = { name: 'Benny' };
const e: any = { name: 'Benny' };
const f: {[index: string]: string} = { name: 'Benny' };