Skip to content

Instantly share code, notes, and snippets.

@shirish87
shirish87 / worker.module.ts
Created February 15, 2020 20:46
Propagate NATS connection error to microservice init
import { Module, INestMicroservice, Logger } from '@nestjs/common';
import { WorkerService } from './worker.service';
import { WorkerController } from './worker.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { NestFactory } from '@nestjs/core';
import { Transport } from '@nestjs/common/enums/transport.enum';
@Module({
imports: [TypeOrmModule.forRoot()],
providers: [WorkerService],
import { Test, TestingModule } from '@nestjs/testing';
import { OrganisationTariffService } from './organisation-tariff.service';
import { getRepositoryToken } from '@nestjs/typeorm';
import { OrganisationTariff } from './organisation-tariff.entity';
import { Repository } from 'typeorm';
// @ts-ignore
export const repositoryMockFactory: () => MockType<Repository<OrganisationTariff>> = jest.fn(() => ({
manager: { connection: { close: () => Promise.resolve() } },
findOneOrFail: jest.fn(entity => entity),
#!/bin/bash
# https://stackoverflow.com/questions/28226229/bash-looping-through-dates
startdate=$(date -I -d "$1") || exit -1
enddate=$(date -I -d "$2") || $(date -I)
d="$startdate"
while [ "$(date -d "$d" +%Y%m%d)" -le "$(date -d "$enddate" +%Y%m%d)" ]; do
echo "$d"
@shirish87
shirish87 / main.ts
Created July 9, 2019 08:58
AWS Systems Manager: Parameter Store
import * as AWS from 'aws-sdk';
async function getParameterStoreValues(names: string[], region: string) {
const ssm = new AWS.SSM({ region });
const { Parameters = [], InvalidParameters = [] } = await ssm.getParameters({ Names: names }).promise();
if (InvalidParameters.length) {
throw new Error(`Invalid parameter names: ${InvalidParameters.join(', ')}`);
}
@shirish87
shirish87 / Makefile
Last active May 16, 2019 08:45
Manage docker-compose containers with make. With the directory structure in place, run `make deploy` to launch production mode locally.
# root/
# |_ app/
# | |_ Dockerfile
# | |_ secrets.env
# | |_ secrets.dev.env
# |_ web/
# | |_ Dockerfile
# | |_ secrets.env
# | |_ secrets.dev.env
@shirish87
shirish87 / restrict_plex_dlna
Last active January 23, 2018 10:51
iptables-based blocking of Plex's DLNA ports
# =====================================================
# USAGE
# $> ips="192.168.0.10 192.168.0.11 192.168.0.12"
# $> restrict_plex_dlna block "$ips"
# $> restrict_plex_dlna unblock "$ips"
# =====================================================
restrict_plex_dlna() {
filters="tcp,32469 udp,1900"
@shirish87
shirish87 / JSONView Dark Theme.css
Created June 20, 2017 17:52 — forked from timnew/JSONView Dark Theme.css
This is a dark theme for JSONView chrome extension
body {
white-space: pre;
font-family: monaco, Consolas, Menlo, monospace;
color: white;
background: #282a36;
font-size: 12px;
line-height: 1.5m;
}
.property {
@shirish87
shirish87 / index.js
Created February 5, 2017 08:36
Authentication using external token microservice. file: src/services/authentication/index.js
'use strict';
const auth = require('feathers-authentication');
const request = require('request');
module.exports = function() {
const app = this;
const config = app.get('auth');
const authHost = config.local.authHost;
@shirish87
shirish87 / patch-boto-sqs.sh
Created January 22, 2017 06:31
Patches the boto library (v2) with the correct hostnames for Amazon SQS.
#!/usr/bin/env python
"""
Patches the boto library (v2) with the correct hostnames for Amazon SQS.
Work around for Celery issue:
https://github.com/celery/celery/issues/3221
which is waiting on PR in boto:
https://github.com/boto/boto/pull/3633
"""
from __future__ import print_function
@shirish87
shirish87 / bringit.go
Last active November 2, 2016 02:41
Util for ARM devices to download partial files using Range header. 'cuz curl'ing be buggy and wget 1.17.x doesn't support Range header when response is piped (http://savannah.gnu.org/bugs/?func=detailitem&item_id=20416).
package main
import (
"fmt"
"io"
"gopkg.in/cheggaaa/pb.v1"
"os"
"net/http"
"strconv"
"strings"