Skip to content

Instantly share code, notes, and snippets.

View iampeterbanjo's full-sized avatar
💭
Error24: not enough hours in the day

Peter Banjo iampeterbanjo

💭
Error24: not enough hours in the day
View GitHub Profile
@iampeterbanjo
iampeterbanjo / branch-fu.md
Created April 22, 2022 10:40 — forked from unbracketed/branch-fu.md
Moving commits between branches

Example: Moving up to a few commits to another branch

Branch A has commits (X,Y) that also need to be in Branch B. The cherry-pick operations should be done in the same chronological order that the commits appear in Branch A.

cherry-pick does support a range of commits, but if you have merge commits in that range, it gets really complicated

git checkout branch-B
git cherry-pick X
git cherry-pick Y
@iampeterbanjo
iampeterbanjo / fastify-request-declaration-merge.ts
Last active May 14, 2020 08:12
fastify declaration merging for requests
// https://github.com/fastify/help/issues/122
import fastify from 'fastify'
declare module 'fastify' {
interface FastifyRequest<
HttpRequest,
Query = fastify.DefaultQuery,
Params = fastify.DefaultParams,
Headers = fastify.DefaultHeaders,
Body = any
@iampeterbanjo
iampeterbanjo / custom-error.ts
Created February 20, 2020 15:14
Custom error in Typescript that has stack information
// based on https://gunargessner.com/subclassing-exception
// example usage
try {
throw new DataError('Boom')
} catch(error) {
error.name === 'DataError' // true
}
class DataError {
@iampeterbanjo
iampeterbanjo / tsconfig.json
Created October 21, 2019 14:38
tsconfig that supports src/@types folder
{
"compilerOptions": {
"outDir": "build",
"rootDir": "src",
/* Basic Options */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["es2015"] /* Specify library files to be included in the compilation. */,
"allowJs": false /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
@iampeterbanjo
iampeterbanjo / vscode-settings-font.json
Created September 30, 2019 11:24
Vscode settings font
{
"editor.fontFamily": "Cascadia Code, Droid Sans Mono Dotted for Powerline"
}
// plugin.ts
import bell from '@hapi/bell';
import cookie from '@hapi/cookie';
import doorkeeper from 'hapi-doorkeeper';
import utils from '../utils';
const {
vars: {
SESSION_SECRET_KEY,
AUTH0_DOMAIN,
@iampeterbanjo
iampeterbanjo / ts-models.ts
Last active September 12, 2019 15:24
How to model types in Typescript and Mongoose
/*
Lets have type models in Typescript and keep it simple
- borrows from https://brianflove.com/2016/10/04/typescript-declaring-mongoose-schema-model/
- validation is useful when parsing data from external APIs
- avoids typegoose, class-validator, class-transform in favour of stable features
*/
import * as mongoose from 'mongoose';
import { Document, Model, Schema, model } from "mongoose";
import jointz, { ExtractResultType } from "jointz";
@iampeterbanjo
iampeterbanjo / nestjs-notes.md
Created September 2, 2019 08:12
NestJS notes

NestJS notes

In a larger application, it makes sense to organize your application into multiple modules that split up your code into features and related capabilities.

To define a module, you have to register all of the

  • Services that will be instantiated by the Nest.js injector as Providers
  • Controllers that will require the Providers as Controllers
  • Controllers exported by another module as imports

Providers can be injected into:

Note: for Jest to detect a memory leak and throw an error both arguments are required i.e. detectLeaks and logHeapUsage.

10:45 nestjs-cats (master) ✗ yarn test --detectLeaks --logHeapUsage
yarn run v1.17.3
$ jest --detectLeaks --logHeapUsage
 PASS  src/auth/auth.controller.spec.ts (61 MB heap size)
 PASS  src/cats/cats.service.spec.ts (61 MB heap size)
 PASS  src/app.controller.spec.ts (61 MB heap size)
 FAIL  src/cats/cats.controller.spec.ts
let character = {};
updateCharacter = (path, value) => {
character[path] = value;
}
const Character = function() {
this.moves = [];
this.firstName = ''
this.lastName = ''