Skip to content

Instantly share code, notes, and snippets.

🎉
50% hackin', 50% slackin'

Martin Iwanowski fl0w

🎉
50% hackin', 50% slackin'
Block or report user

Report or block fl0w

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fl0w
fl0w / bodyparser.js
Last active Oct 7, 2019
Simple for-await JSON body parser for Koa (node.js)
View bodyparser.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 / modifiers.js
Last active Oct 29, 2018
Test modifiers
View modifiers.js
'use strict'
const Knex = require('knex')
const objection = require('objection')
const knex = new Knex({
client: 'pg',
connection: { database: 'fl0w', user: 'fl0w' }
})
objection.Model.knex(knex)
@fl0w
fl0w / alacritty.yml
Created Oct 28, 2018
New Window shortcut for Alacritty on macOS
View alacritty.yml
- { key: N, mods: Command, command: { program: "open", args: ["-nb", "io.alacritty"] } }
@fl0w
fl0w / koa-router-expand.js
Created Aug 24, 2018
Adds Router.expand which accepts and expands Router instances for Router.use.
View koa-router-expand.js
'use strict'
const { flatten } = require('lodash')
const Router = require('koa-router')
/**
* Adds Router.expand which accepts and expands Router instances for Router.use.
* @returns this
*/
Router.prototype.expand = function (...args) {
@fl0w
fl0w / bookshelf.collection.cascade.destroy.js
Created May 24, 2018
naive collection cascade destroy
View bookshelf.collection.cascade.destroy.js
async destroy (options = {}) {
const destroyed = this.clone().reset()
destroyed._events = this._events // Copy referens to events
if (!this.length) return destroyed
await destroyed.triggerThen('destroying', this, options)
for (const model of this) {
await model.destroy(options)
destroyed.add(model)
@fl0w
fl0w / bookshelf-registry-collection.js
Created May 6, 2018
The correct way to define custom bookshelf Collections with registry plugin
View bookshelf-registry-collection.js
const bookshelf = require('bookshelf')
class Users extends bookshelf.Collection {
get model () {
return User
}
}
class User extends bookshelf.Model {
static collection (...args) {
View objection-qb-distinctOn.js
class BaseQueryBuilder extends objection.QueryBuilder {
distinctOn (columns, tableStar = `${this.modelClass().tableName}.*`) {
columns = asArray(columns)
const identifiers = columns.map(() => '??').join(', ')
columns = columns.map(column => {
return column.split('.').length === 1
? `${this.modelClass().tableName}.${column}`
: column
View install-nvm.sh
touch ~/.bash_profile
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
@fl0w
fl0w / README.md
Created May 28, 2017 — forked from subfuzion/README.md
vim/neovim configuration
View README.md

I recently switched over to neovim (see my screenshots at the bottom). Below is my updated config file.

It's currently synchronized with my .vimrc config except for a block of neovim-specific terminal key mappings.

This is still a work in progress (everyone's own config is always a labor of love), but I'm already extremely pleased with how well this is working for me with neovim. While terminal mode isn't enough to make me stop using tmux, it is quite good and I like having it since it simplifies my documentation workflow for yanking terminal output to paste in a markdown buffer.

These days I primarily develop in Go. I'm super thrilled and grateful for fatih/vim-go,

View gist:da347390d6135eb89bf74b0a186e176f
'use strict'
// const v8 = require('v8-natives')
const Benchmark = require('benchmark')
const suite = new Benchmark.Suite()
const MixinOne = (base) => class extends base {}
const MixinTwo = (base) => class extends base {}
const MixinThree = (base) => class extends base {}
const MixinFour = (base) => class extends base {}
You can’t perform that action at this time.