Skip to content

Instantly share code, notes, and snippets.

View fl0w's full-sized avatar
🎉
50% hackin', 50% slackin'

Martin Iwanowski fl0w

🎉
50% hackin', 50% slackin'
  • Sweden, Stockholm
View GitHub Profile
@fl0w
fl0w / bodyparser.js
Last active October 7, 2019 12:32
Simple for-await JSON body parser for Koa (node.js)
const { StringDecoder } = require('string_decoder')
const decoder = new StringDecoder() // default utf8
// Note that this is a naive example
// There's no safe-guarding and the process could be flooded easily b/c there's no limits.
// This is just to illustrate how to use for-await in Koa
async function bodyParser (ctx, next) {
let acc = ''
for await (const chunk of ctx.req) acc += decode.write(chunk)
ctx.state.body = JSON.parse(acc)
@fl0w
fl0w / alacritty.yml
Created October 28, 2018 18:41
New Window shortcut for Alacritty on macOS
- { key: N, mods: Command, command: { program: "open", args: ["-nb", "io.alacritty"] } }
# lazyload nvm
# all props goes to http://broken-by.me/lazy-load-nvm/
# grabbed from reddit @ https://www.reddit.com/r/node/comments/4tg5jg/lazy_load_nvm_for_faster_shell_start/
lazynvm() {
unset -f nvm node npm npx
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
if [ -f "$NVM_DIR/bash_completion" ]; then
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion