This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- { key: N, mods: Command, command: { program: "open", args: ["-nb", "io.alacritty"] } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bookshelf = require('bookshelf') | |
class Users extends bookshelf.Collection { | |
get model () { | |
return User | |
} | |
} | |
class User extends bookshelf.Model { | |
static collection (...args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# completely remove atom on mac os x | |
rm -r ~/.atom | |
rm -r /usr/local/bin/atom | |
rm -r /usr/local/bin/apm | |
rm -r /Applications/Atom.app | |
rm -r ~/Library/Preferences/com.github.atom.plist | |
rm -r ~/Library/Application\ Support/com.github.atom.ShipIt | |
rm -r ~/Library/Application\ Support/Atom | |
rm -r ~/Library/Saved\ Application\ State/com.github.atom.savedState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
touch ~/.bash_profile | |
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash |
NewerOlder