Skip to content

Instantly share code, notes, and snippets.

View vjefri's full-sized avatar

Jefri Vanegas vjefri

View GitHub Profile
// 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
@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
/**
*
* You should be receiving all the tweets that contain Minecraft
*
* */
{
"meta": {
"total": 1,
"count": 1,
// 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'));
// 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
// 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
});
# Easier navigation: .., ..., ...., ....., ~ and -
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"
# Shortcuts
/*
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++}}}
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 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")
}
}
/*