Skip to content

Instantly share code, notes, and snippets.

@isabellachen
isabellachen / async.js
Created August 17, 2017 09:08 — forked from arol/async.js
Asynchronicity exercise
const randomNumber = () => {
return Math.random();
}
// 1. Make it wait for 1 sec. with `setTimeout`
const timeoutRandomNumber = () => {
}
// 2. Now wrap the timeout version to work with promises
@isabellachen
isabellachen / sqlite-db.js
Last active October 10, 2017 13:42
Creating SQlite3 DB with Sequelize
const Sequelize = require('sequelize');
const sequelize = require('../utils/db');
const Console = console;
const Event = sequelize.define('event', {
info: {
type: Sequelize.STRING
},
date: {
type: Sequelize.DATE
@isabellachen
isabellachen / search-mongo-db.md
Last active October 10, 2017 13:52
Listing documents in collection in Mongo DB
$ mongo
$ show dbs
$ use myDatabase
$ show collections
$ db.myDatabase.find()
@isabellachen
isabellachen / async-error-handling-chai.js
Last active October 10, 2017 13:41
Using chai-as-promised library and proxyrequire to test async functions
const chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
chai.should();
const mockStoryModel = {};
const proxyquire = require('proxyquire');
//creates mock model functions to replace original model functions in controller
const StoriesController = proxyquire('../controller/controller',
@isabellachen
isabellachen / basic-koa-server-index.js
Last active October 10, 2017 13:41
Bootstrap Koa Server index.js
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const cors = require('kcors');
const Console = console;
const app = new Koa();
const router = require('./router');
const db = require('./db');
app
@isabellachen
isabellachen / stash-and-checkout-prev-commit.md
Last active October 10, 2017 13:40
Checkout out a previous commit and returning to uncommitted changes from HEAD
$ git stash //stash uncommited changes
$ git log //look at your changes and choose the commit you want
$ git checkout <e2g> //where e2g is the commit no.
$ git checkout HEAD //go back to the latest commit
$ git stash pop //pop your uncommited changes 
@isabellachen
isabellachen / git-committing-after-refactor.md
Created October 10, 2017 13:56
Making a commit after refactoring and renaming files and adding new files
$ git add -p 
$ git ls-files --others --exclude-standard //list untracked files
$ git ls-files
$ git add <untracked01.js> <untracked02.js>
$ git commit -m 'commit message'
@isabellachen
isabellachen / search-names-regexp.js
Created October 11, 2017 08:02
Querying MongoDB with Mongoose for RegExp string matching names
//if query is 'stephen' it will match 'stephen' and 'stephen hawking' but not 'stephen foobar'
//cases ignored
Editor.searchEditors = async (query) => {
const editors = await Editor.find({'name' : new RegExp(query, "gi")});
if (editors) {
return editors;
}
};
@isabellachen
isabellachen / eslintrc-backend.json
Last active April 8, 2018 18:22
.eslintrc build for backend
{
"env": {
"browser": true,
"es6": true,
"jquery": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
@isabellachen
isabellachen / eslintrc-frontend-react.json
Last active April 8, 2018 18:22
eslintrc for react front end custom builds
{
"env": {
"browser": true,
"es6": true,
"jquery": true,
"node": true,
"mocha": true
},
"parser": "babel-eslint",
"extends": "eslint:recommended",