Skip to content

Instantly share code, notes, and snippets.

Avatar

Ujjwal Ojha ojhaujjwal

View GitHub Profile
View reduce-map.test.ts
import { reduceMap } from './reduce-map';
describe('reduceMap', () => {
const sumValueAndSubtractKey = (result: number, value: number, key: number) => result + value - key;
it('should return initial value for empty map', () => {
expect(
reduceMap(
new Map(),
sumValueAndSubtractKey,
View typescript-decorators-composition-gist5.ts
import { Controller, ControllerOptions } from '@nestjs/common';
import { join } from 'path';
import { AuthenticationGuard, AccessControlGuard } from 'app/guards';
expose function AdminController(options: ControllerOptions) {
return function (target: Function) {
Controller(join('/admin', options.path))(target);
AuthenticationGuard()(target);
AccessControlGuard({ role: 'admin' })(target);
};
View typescript-decorators-composition-gist4
@AdminController(options) {
@Controller({ path: '/admin' + options.path })
@AuthenticationGuard()
@AccessControlGuard({ role: 'admin' })
}
View typescript-decorators-composition-gist3.ts
import { Controller, Get } from '@nestjs/common';
import { AdminController, AccessControlGuard } from 'app/decorators';
@AdminController({ path: '/dashboard' })
export class AdminDashboardController {
@Get()
index(): string {
return 'dashboard data for admin';
}
}
View typescript-decorators-composition-gist2.ts
import { Controller, Get } from '@nestjs/common';
import { AuthenticationGuard, AccessControlGuard } from 'app/decorators';
@Controller({ path: '/admin/dashboard' })
@AuthenticationGuard()
@AccessControlGuard({ role: 'admin' })
export class AdminDashboardController {
@Get()
index(): string {
return 'dashboard data for admin';
View typescript-decorators-composition-gist1.ts
import { Controller, Get } from '@nestjs/common';
@Controller('/cats')
export class CatsController {
@Get()
findAll(): string {
return 'This action returns all cats';
}
}
View deploy-node-app-on-terraform-gist5.tf
resource "google_cloud_run_service_iam_binding" "binding" {
location = google_cloud_run_service.nodejs_app.location
service = google_cloud_run_service.nodejs_app.name
role = "roles/run.invoker"
members = [
"allUsers",
]
}
View deploy-node-app-on-terraform-gist4.tf
variable "app_name" {
type=string
}
variable "image_tag" { type=string }
resource "google_cloud_run_service" "nodejs_app" {
name = var.app_name
location = "us-central1"
View deploy-node-app-on-terraform-gist3.tf
variable "gcp_region" {
type=string
default="us-west3"
}
provider "template" {
version = "~> 2.0"
}
provider "google" {
View deploy-node-app-on-terraform-gist3.sh
#!/usr/bin/env sh
set -eu
export GCP_PROJECT=my-gcp-project
export APP_NAME=cloudrun-node-app-demo
# Logging in to GCR using service account credentials placed on ./gcp-credentials.json
cat ./gcp-credentials.json | docker login -u _json_key --password-stdin https://gcr.io
You can’t perform that action at this time.