Skip to content

Instantly share code, notes, and snippets.

View vjefri's full-sized avatar

Jefri Vanegas vjefri

View GitHub Profile
/* ES6 the Lazy Way */
var nums = [1, 2, 3, 4, 5, 6]
// You don't have to use braces when it is a simple expression
// No need to say return, it just knows
// The fat arrow is creating the function
// If we have one arg, no need to add parens
var odds = nums.map(v => v + 1); // [ 2, 3, 4, 5, 6, 7 ]
// This does not loose scope with fat arrow
var bob = {
_name: "Bob",
_friends: ["Jon", "Daenerys", "Arya", "Tyrion"],
printFriends() {
this._friends.forEach(f => // this === bob
console.log(this._name + " knows " + f)); // this === bob ("I should be undefined but I am bob")
}
}
/*
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
/*
Pseudoclassical Instantiation Pattern
*/
var Planet = function(water, life) {
// this = Object.create(Planet.prototype)(NOTE: done behind the scenes in Pseudoclassical)
// the keyword this delegates failed lookups to its prototype
// its prototype has the method rotationSpeed
// console.log(this); // => { prototype: {rotationSpeed: function(){this.speed++}}}
# Easier navigation: .., ..., ...., ....., ~ and -
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"
# Shortcuts
// users_controller.js
index() {
User.query()
.where({tweets__body__icontains: 'Minecraft'}) // add me
.join('tweets', {body__icontains: 'Minecraft'}) // add me
.end((err, models) => {
this.respond(err || models, ['tweets']); // add me
});
// models/user.js
'use strict';
const Nodal = require('nodal');
const Tweet = Nodal.require('app/models/tweet.js'); // import me
User.setDatabase(Nodal.require('db/main.js'));
User.setSchema(Nodal.my.Schema.models.User);
User.joinedBy(Tweet); // add me
// models/tweet.js
'use strict';
const Nodal = require('nodal');
const User = Nodal.require('app/models/user.js'); // import me
class Tweet extends Nodal.Model {}
Tweet.setDatabase(Nodal.require('db/main.js'));
/**
*
* You should be receiving all the tweets that contain Minecraft
*
* */
{
"meta": {
"total": 1,
"count": 1,
@vjefri
vjefri / 1. Command Line
Last active June 5, 2016 02:38 — forked from nsipplswezey/1. Command Line
Nodal TL:DR Seed Database
npm install -g nodal
nodal new todo-pgjson
cd todo-pgjson
nodal g:model Todo user_id:int tasks:json done:boolean
nodal g:controller --for Todos
nodal db:bootstrap
// add json data to seed.json
nodal db:seed