New codingmarks added in 2018 so far. Keywords - git, nodejs, design-patterns, mongodb etc.


Octocat **Promotion** - Efficiently manage your coding bookmarks, aka #codingmarks, on www.codingmarks.org and share your hidden gems with the world. They are published weekly on Github. You can help us build THE programming-resources location - Star


New codingmarks added this year so far. They were marked with the following keywords:

clean-code

Template method pattern - Wikipedia

What problems can the Template Method design pattern solve? [4]

  • The invariant parts of a behavior should be implemented only once so that subclasses can implement the variant parts.
  • Subclasses should redefine only certain parts of a behavior without changing the other parts.

Usually, subclasses control how the behavior of a parent class is redefined, and they aren’t restricted to redefine only certain parts of a behavior.


The Principles of OOD - Object Oriented Design

The first five principles are principles of class design. The first three package principles are about package cohesion, they tell us what to put inside packages. The last three principles are about the couplings between packages, and talk about metrics that evaluate the package structure of a system.


Single responsibility principle - Wikipedia

The single responsibility principle is a computer programming principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. Robert C. Martin expresses the principle as, “A class should have only one reason to change.”


Writing Your F.I.R.S.T Unit Tests - DZone Java

When writing unit tests in Java, stick to FIRST. Your tests should be fast, independent, repeatable, self-validating, and timely (unless you’re using TDD).


debugging

Debug Node.js Apps using VS Code

The Visual Studio Code editor includes Node.js debugging support. Set breakpoints, step-in, inspect variables and more.


Error: Permission denied (publickey) - User Documentation


design-patterns

Template method pattern - Wikipedia

What problems can the Template Method design pattern solve? [4]

  • The invariant parts of a behavior should be implemented only once so that subclasses can implement the variant parts.
  • Subclasses should redefine only certain parts of a behavior without changing the other parts.

Usually, subclasses control how the behavior of a parent class is redefined, and they aren’t restricted to redefine only certain parts of a behavior.


The Principles of OOD - Object Oriented Design

The first five principles are principles of class design. The first three package principles are about package cohesion, they tell us what to put inside packages. The last three principles are about the couplings between packages, and talk about metrics that evaluate the package structure of a system.


Single responsibility principle - Wikipedia

The single responsibility principle is a computer programming principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. Robert C. Martin expresses the principle as, “A class should have only one reason to change.”


expressjs

RESTful API In Node & Express With TypeScript & MongoDB - YouTube

This video covers writing a RESTful JSON API using Node, Express, MongoDB, Mongoose, and TypeScript. My other Node…


git

Setting your username in Git - User Documentation

$ git config --global user.name "Mona Lisa"
$ git config --global user.email mona.lisa@paris.com

Error: Permission denied (publickey) - User Documentation


Adding a new SSH key to your GitHub account - User Documentation

$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

http

Helmet

Helmet helps you secure your Express.js apps by setting various HTTP headers. It’s not a silver bullet, but it can help!


mongodb

javascript - Mongoose Model.save() hangs when called from node.js app - Stack Overflow

You haven’t created a connection for Mongoose to use by default. Replace this:

db = mongoose.createConnection('localhost','nextrak')

With this:

db = mongoose.connect('localhost', 'nextrak');

MongoDB Node.js Driver

The official MongoDB Node.js driver provides both callback-based and Promise-based interaction with MongoDB, allowing applications to take full advantage of the new features in ES6.


RESTful API In Node & Express With TypeScript & MongoDB - YouTube

This video covers writing a RESTful JSON API using Node, Express, MongoDB, Mongoose, and TypeScript. My other Node…


GitHub - szokodiakos/typegoose: Typegoose - Define Mongoose models using TypeScript classes.

typegoose - Typegoose - Define Mongoose models using TypeScript classes.


mongoose

javascript - Mongoose Model.save() hangs when called from node.js app - Stack Overflow

You haven’t created a connection for Mongoose to use by default. Replace this:

db = mongoose.createConnection('localhost','nextrak')

With this:

db = mongoose.connect('localhost', 'nextrak');

RESTful API In Node & Express With TypeScript & MongoDB - YouTube

This video covers writing a RESTful JSON API using Node, Express, MongoDB, Mongoose, and TypeScript. My other Node…


@types/mongoose-promise does not override mongoose’s default promise lib · Issue #10743 · DefinitelyTyped/DefinitelyTyped · GitHub

Apparently Typescript 2 doesn’t allow assigning properties on an imported module. So this:

import * as mongoose from 'mongoose';
mongoose.Promise = Promise;

leads to error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. To get your code to compile you will need to choose from one of the options below:

  • (<any>mongoose).Promise = Promise
  • require('mongoose').Promise = Promise
  • import mongoose = require('mongoose'); ... mongoose.Promise = Promise

GitHub - szokodiakos/typegoose: Typegoose - Define Mongoose models using TypeScript classes.

typegoose - Typegoose - Define Mongoose models using TypeScript classes.


nodejs

javascript - Mongoose Model.save() hangs when called from node.js app - Stack Overflow

You haven’t created a connection for Mongoose to use by default. Replace this:

db = mongoose.createConnection('localhost','nextrak')

With this:

db = mongoose.connect('localhost', 'nextrak');

MongoDB Node.js Driver

The official MongoDB Node.js driver provides both callback-based and Promise-based interaction with MongoDB, allowing applications to take full advantage of the new features in ES6.


RESTful API In Node & Express With TypeScript & MongoDB - YouTube

This video covers writing a RESTful JSON API using Node, Express, MongoDB, Mongoose, and TypeScript. My other Node…


Helmet

Helmet helps you secure your Express.js apps by setting various HTTP headers. It’s not a silver bullet, but it can help!


Debug Node.js Apps using VS Code

The Visual Studio Code editor includes Node.js debugging support. Set breakpoints, step-in, inspect variables and more.


GitHub - szokodiakos/typegoose: Typegoose - Define Mongoose models using TypeScript classes.

typegoose - Typegoose - Define Mongoose models using TypeScript classes.


npm install gets stuck at sill install loadIdealTree · Issue #17228 · npm/npm · GitHub

nodejs hangs when installing some packages

Moste voted solution:

Try to remove ‘package-lock.json’ file from directory where ‘package.json’ locate.


npm

npm install gets stuck at sill install loadIdealTree · Issue #17228 · npm/npm · GitHub

nodejs hangs when installing some packages

Moste voted solution:

Try to remove ‘package-lock.json’ file from directory where ‘package.json’ locate.


rxjs

forkJoin · learn-rxjs

This operator is best used when you have a group of observables and only care about the final emitted value of each. One common use case for this is if you wish to issue multiple requests on page load (or some other event) and only want to take action when a response has been receieved for all. In this way it is similar to how you might use Promise.all.


ssh

Adding a new SSH key to your GitHub account - User Documentation

$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

testing

Writing Your F.I.R.S.T Unit Tests - DZone Java

When writing unit tests in Java, stick to FIRST. Your tests should be fast, independent, repeatable, self-validating, and timely (unless you’re using TDD).


typescript

RESTful API In Node & Express With TypeScript & MongoDB - YouTube

This video covers writing a RESTful JSON API using Node, Express, MongoDB, Mongoose, and TypeScript. My other Node…


@types/mongoose-promise does not override mongoose’s default promise lib · Issue #10743 · DefinitelyTyped/DefinitelyTyped · GitHub

Apparently Typescript 2 doesn’t allow assigning properties on an imported module. So this:

import * as mongoose from 'mongoose';
mongoose.Promise = Promise;

leads to error TS2450: Left-hand side of assignment expression cannot be a constant or a read-only property. To get your code to compile you will need to choose from one of the options below:

  • (<any>mongoose).Promise = Promise
  • require('mongoose').Promise = Promise
  • import mongoose = require('mongoose'); ... mongoose.Promise = Promise

Coding guidelines · Microsoft/TypeScript Wiki · GitHub

These guidelines are mainly meant for contributors to the TypeScript project. Feel free to adopt them for your own team.


unit-testing

Writing Your F.I.R.S.T Unit Tests - DZone Java

When writing unit tests in Java, stick to FIRST. Your tests should be fast, independent, repeatable, self-validating, and timely (unless you’re using TDD).


utils

Adding a new SSH key to your GitHub account - User Documentation

$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

vscode

Debug Node.js Apps using VS Code

The Visual Studio Code editor includes Node.js debugging support. Set breakpoints, step-in, inspect variables and more.


Adrian Matei

Adrian Matei
Life force expressing itself as a coding capable human being

New codingmarks published in week 39 of 2018

New codingmarks published in week 39 of 2018. Keywords: angular, async, async-await, asynchronous, caching, charts, cron, crontab, data-science, ejb, java, javaee, javascript, jpa, keycloak, nodejs, python, reactive, reactive-programming, ruby, ruby-on-rails, rxjava, scheduler, scheduling and tools Continue reading