Skip to content

Instantly share code, notes, and snippets.

View natmegs's full-sized avatar

Natalie Smith natmegs

View GitHub Profile
@natmegs
natmegs / schema.json
Created February 1, 2019 05:13
Job schema
{
"$schema": "http:\/\/json-schema.org\/schema#",
"definitions": {
"pathType": {
"type": "string",
"pattern": "^([a-z0-9]([a-z0-9-]*[a-z0-9]+)*)([.][a-z0-9]([a-z0-9-]*[a-z0-9]+)*)*$",
"minLength": 1
}
},
"type": "object",
@natmegs
natmegs / example.js
Created May 1, 2018 23:24
Querying database using Sequelize
const models = require('../models');
models.user.findOne({ where: {id: id} })
.then(user => {
// Do something with User instance
});
models.user.create(data)
.then((newUser) => {
// Do something with User instance
@natmegs
natmegs / www
Created May 1, 2018 23:19
Database synchronization in bin/www
const models = require('../models');
models.sequelize.sync().then(function() {
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
});
@natmegs
natmegs / index.js
Created May 1, 2018 23:17
Consolidate all models (in models folder)
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const config = require('../config/db');
let db = {};
let sequelize = new Sequelize(config.database, config.username, config.password, config.options);
fs
.readdirSync(__dirname)
@natmegs
natmegs / user.js
Created May 1, 2018 23:15
Define User model (in models folder)
module.exports = function(sequelize, Sequelize) {
const User = sequelize.define('user', {
id: {
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
firstname: {
type: Sequelize.STRING,
notEmpty: true
@natmegs
natmegs / app.js
Created May 1, 2018 23:14
Connect to SQL Server and Database
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'SQL.server.address.database.net',
dialect: 'mssql',
dialectOptions: {
encrypt: true;
}
});
sequelize
@natmegs
natmegs / app.component.ts
Created January 10, 2018 19:07
ViewChild vs ViewChildren
@ViewChild(HelloComponent) hello: HelloComponent;
@ViewChildren(HelloComponent) hellos: QueryList<HelloComponent>;
ngAfterViewInit() {
console.log(this.hello);
console.log(this.hellos);
}
@natmegs
natmegs / app.component.ts
Created January 10, 2018 19:06
Using @ViewChild in a component
@ViewChild(HelloComponent) hello: HelloComponent;
@ViewChild('template') template: TemplateRef<any>;
@ViewChild('element') element: ElementRef;
@ViewChild('container', { read: ViewContainerRef }) container: ViewContainerRef;
ngAfterViewInit() {
console.log(this.hello);
console.log(this.template);
console.log(this.element);
console.log(this.container);
@natmegs
natmegs / app.template.html
Created January 10, 2018 19:04
ViewChild examples
<hello name="Jelly Donut"></hello>
<hello name="Old Fashioned Glazed"></hello>
<ng-container #container>
This is a container
</ng-container>
<ng-template #template>
This is a template
@natmegs
natmegs / app.template.html
Created January 8, 2018 23:12
Using SomeComponent with projected content
<some-component>
<h3>I am the projected content!</h3>
</some-component>