Instantly share code, notes, and snippets.

View settings.json
{
"workbench.colorTheme": "Plastic - deprioritised punctuation",
"workbench.statusBar.visible": false,
"editor.fontFamily": "operator mono",
"editor.fontWeight": "300",
"typescript.tsserver.log": "verbose",
"editor.matchBrackets": false,
"editor.renderLineHighlight": "gutter",
"workbench.iconTheme": null,
"editor.lineHeight": 30,
View settings.json
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "storage.type.class.jsdoc, punctuation.definition.block.tag.jsdoc, punctuation.definition.bracket.curly.begin.jsdoc, punctuation.definition.bracket.curly.end.jsdoc,variable.other.jsdoc",
"settings": {
"foreground": "#65737eff",
}
}
]
}
View hooks.js
const { hooks } = require('@adonisjs/ignitor')
hooks.after.httpServer(function () {
const Server = use('Server')
const httpInstance = Server.getInstance()
// do whatever you like
})
View setup.js
const { registrar, ioc } = require('@adonisjs/fold')
const _ = require('lodash')
/**
* Very bare bones implementation of the config provider.
* If you run into issues, then make sure to check the
* implementation in adonis-framework repo
*/
class Config {
constructor (config) {
View .zshrc
function rext () {
if [ $# -lt 3 ]; then
echo 1>&2 "$0 needs 3 arguments as DIR SOURCE_EXT DEST_EXT"
else
for file in "$1"/*.$2; do
mv "$file" "${file%.$2}.$3"
done
fi
}
View get-cat.js
// Import category model
const Category = use('App/Models/Category')
// Get all categories
const categories = await Category.all()
View models.js
const Model = use('Model')
class User extends Model {
posts () {
return this.hasMany('App/Models/Post')
}
}
class Post extends Model {
author () {
View models.js
const Model = use('Model')
class User extends Model {
}
class Post extends Model {
}
class Category extends Model {
}
View routes.js
// Display categories in the blog header
const categories = await Database.table('categories').select('*')
// Fetch posts for a category where category_id = 1
const posts = await Database
.table('posts')
.innerJoin('category_posts', 'posts.id', 'category_posts.post_id')
.where('category_posts.category_id', categoryId)
// Select author for a given post
View routes.js
await Database
.table('users')
.insert({ username: 'virk', role: 'admin', password: 'secret' })
// Bulk inserts
await Database
.table('users')
.insert([
{ username: 'virk', role: 'admin', password: 'secret' },
{ username: 'nikk', role: 'guest', password: 'secret' }