Skip to content

Instantly share code, notes, and snippets.

View nikeshashar's full-sized avatar

Nikesh Ashar nikeshashar

  • Cledara
  • London
View GitHub Profile
// bin/www
models.sequelize.sync().then(function() {
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
});
// models/user.js
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
username: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
User.hasMany(models.Listing);
}
// models/listing.js
module.exports = function(sequelize, DataTypes) {
var Listing = sequelize.define('Listing', {
title: DataTypes.STRING,
description: DataTypes.TEXT
}, {
classMethods: {
associate: function(models) {
Listing.belongsTo(models.User);
.
├── config
│ └── config.json
├── migrations
│ ├── 20161104204911-create-user.js
│ └── 20161104205207-create-listing.js
├── models
│ ├── index.js
│ ├── listing.js
│ └── user.js
$ node_modules/.bin/sequelize init
$ node_modules/.bin/sequelize model:create --name User --attributes username:string
$ node_modules/.bin/sequelize model:create --name Listing --attributes title:string,description:text
{
"dependencies": {
"sequelize": "^3.24.7",
"sequelize-cli": "^2.4.0"
}
}
{
"name": "my-app",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "^1.15.2",
"cookie-parser": "^1.4.3",
.
├── app.js
├── bin
│ └── www
├── package.json
├── public
│ ├── images
│ ├── javascripts
│ └── stylesheets
│ └── style.css
@nikeshashar
nikeshashar / ruby_method.rb
Created October 24, 2016 08:21
Template Method
def hello(name)
puts "Welcome to learning how to code #{name}"
end
Challenge setup
Specification:
Thermostat starts at 20 degrees
You can increase the temperature with the up button
You can decrease the temperature with the down button
The minimum temperature is 10 degrees
If power saving mode is on, the maximum temperature is 25 degrees
If power saving mode is off, the maximum temperature is 32 degrees