- Side Effects are lies, promises one thing and does other hidden things unexpected changes to variable of its own class
- Avoid using output arguments
- Function should either do something or ans something, but not both
FROM node:fermium-alpine AS builder | |
WORKDIR /app/builder | |
COPY . . | |
# https://github.com/nodejs/docker-node/issues/384#issuecomment-305208112 | |
RUN apk --no-cache add --virtual native-deps \ | |
git g++ gcc libgcc libstdc++ linux-headers make python && \ | |
yarn global add --silent node-gyp &&\ | |
yarn --silent && \ | |
apk del native-deps |
If you've got 15 minutes to spare and have docker installed, this Gist will get you started with a working debuggable Nestjs application using Docker with additional settings for vscode
. Clearly you'll want to dig deeper, but this is a start...
Nestjs is a popular nodejs
for typescript
framework for building microservices. It enjoys a large active community, has many extensions and is easily extended. Documentation can be found here
Create the basic file structure from the Github Gist
const otpGenerator = require("otp-generator"); | |
const crypto = require("crypto"); | |
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret | |
function createNewOTP(phone){ | |
// Generate a 6 digit numeric OTP | |
const otp = otpGenerator.generate(6, {alphabets: false, upperCase: false, specialChars: false}); | |
const ttl = 5 * 60 * 1000; //5 Minutes in miliseconds | |
const expires = Date.now() + ttl; //timestamp to 5 minutes in the future | |
const data = `${phone}.${otp}.${expires}`; // phone.otp.expiry_timestamp |
const fs = require('fs'); | |
const cols = 8; | |
function randomChar () { | |
return String.fromCharCode(Math.floor(Math.random() * (122-65) + 65)); | |
} | |
function randomString (length) { | |
let string = ''; |
import * as mongoose from 'mongoose'; | |
export let Schema = mongoose.Schema; | |
export let ObjectId = mongoose.Schema.Types.ObjectId; | |
export let Mixed = mongoose.Schema.Types.Mixed; | |
export interface IHeroModel extends mongoose.Document { | |
name: string; | |
power: string; |
Using cron to perform incremental Map-Reduce in MongoDB |
// | |
// JAZMusician.h | |
// JazzyApp | |
// | |
#import <Foundation/Foundation.h> | |
/** | |
JAZMusician models, you guessed it... Jazz Musicians! | |
From Ellington to Marsalis, this class has you covered. |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.