This file contains hidden or 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
// create asyncMap func with array and callback as args | |
// create empty results list | |
// create counter set to 0 | |
// for func in array of functions | |
// invoke func with anonymous function as arg which takes item | |
// asign item to results sub index | |
// increment counter by 1 | |
// if last func in array | |
// invoke callback with results as arg |
This file contains hidden or 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
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 |
This file contains hidden or 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
/** | |
* | |
* You should be receiving all the tweets that contain Minecraft | |
* | |
* */ | |
{ | |
"meta": { | |
"total": 1, | |
"count": 1, |
This file contains hidden or 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
// 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')); |
This file contains hidden or 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
// 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 |
This file contains hidden or 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
// 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 | |
}); |
This file contains hidden or 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
# Easier navigation: .., ..., ...., ....., ~ and - | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias .....="cd ../../../.." | |
alias ~="cd ~" # `cd` is probably faster to type though | |
alias -- -="cd -" | |
# Shortcuts |
This file contains hidden or 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
/* | |
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++}}} |
This file contains hidden or 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 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'); | |
}); |
This file contains hidden or 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
// 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") | |
} | |
} | |
/* |
NewerOlder