Skip to content

Instantly share code, notes, and snippets.

View krnlde's full-sized avatar
🦆
blackbelt rubberduck

Kai Dorschner krnlde

🦆
blackbelt rubberduck
View GitHub Profile
@krnlde
krnlde / macros.doskey
Created November 11, 2021 21:36
/bat/macros.doskey
ls=dir /B $1
ip=ipconfig $*
y=yarn $*
yes=yarn start $*
yo=yarn outdated $*
yup=yarn upgrade-interactive --latest $*
yb=yarn build $*
gs=git fetch && git status $*
gps=git push $*
gpr=git pull --rebase --autostash $*
@krnlde
krnlde / useAbortableAsyncResult.ts
Last active October 7, 2021 09:25
react hook for abortable async results
export function useAbortableAsyncResult<T extends any = any>(
fn: (signal: AbortSignal, clearData: () => void) => Promise<T>,
dependencies: DependencyList = []
) {
const isMounted = React.useRef(false);
const abortController = React.useRef<AbortController>();
const [isInitialized, setIsInitialized] = React.useState(false);
const [data, setData] = React.useState<T>();
const [error, setError] = React.useState<Error>();
const [isLoading, setIsLoading] = React.useState(false);
@krnlde
krnlde / proxy.js
Last active December 14, 2020 15:53
const qrcode = require('qrcode-terminal');
const open = require('open');
// setup your httpServer as you like (express.js)
// ...
// The '0.0.0.0' binding is important here, otherwise the addresses will not work
httpsServer.listen(1337, '0.0.0.0', () => {
for (const [_, addresses] of Object.entries(os.networkInterfaces())) {
const relevantAddresses = addresses.filter((a) => !a.internal && a.family === 'IPv4').map((a) => a.address);
@krnlde
krnlde / index.scss
Created December 14, 2020 13:52
My setup for a light and configurable CSS project
@import './variables';
// @import "~bootstrap/scss/bootstrap";
@import '~bootstrap/scss/_functions';
@import '~bootstrap/scss/_variables';
@import '~bootstrap/scss/_mixins';
@import '~bootstrap/scss/_root';
@import '~bootstrap/scss/_reboot';
@import '~bootstrap/scss/_type';
alias yo=yarn outdated $*
alias yup=yarn upgrade-interactive --latest $*
alias yes=yarn start $*
alias yb=yarn build $*
alias y=yarn $*
alias gco=git checkout $*
alias gm=git merge $*
alias gcam=git commit -am $*
alias gs=git status $*
alias gps=git push $*
@krnlde
krnlde / bruteforce.js
Last active July 15, 2017 17:06
Clustered bruteforce password-cracking example
const cluster = require('cluster');
const numCPUs = require('os').cpus().length - 1;
const {promisify} = require('util');
const pbkdf2 = promisify(require('crypto').pbkdf2);
if (cluster.isMaster) {
const workers = [];
console.log(`Starting ${numCPUs} workers…`)
for (let i = 0; i < numCPUs; i += 1) {
workers.push(cluster.fork());
@krnlde
krnlde / promisify-http.js
Last active February 22, 2023 03:42
util.promisify.custom and http.get example
const http = require('http');
const {promisify} = require('util');
http.get[promisify.custom] = function getAsync(options) {
return new Promise((resolve, reject) => {
http.get(options, (response) => {
response.end = new Promise((resolve) => response.on('end', resolve));
resolve(response);
}).on('error', reject);
});
@krnlde
krnlde / makepdf.es6.js
Last active August 29, 2015 14:23
This script handles HTTP POST requests and returns a generated, streamed PDF filled with the contents of the POST. You need to install wkhtmltopdf globally on your system first. You can either provide form data key value pairs or JSON data. It'll both be parsed to JSON and put into handlebars. Install all the imports via npm.
"use strict";
import fs from 'fs';
import express from 'express';
import bodyParser from 'body-parser';
import Handlebars from 'handlebars';
import wkhtmltopdf from 'wkhtmltopdf';
const app = express();
app.use(bodyParser.json());