Skip to content

Instantly share code, notes, and snippets.

View influxdb.ts
import {
ClientOptions,
WritePrecision,
WriteOptions,
WritePrecisionType,
} from '@influxdata/influxdb-client/dist/options';
import TransportImpl from '@influxdata/influxdb-client/dist/impl/node/NodeHttpTransport';
import WriteApiImpl from '@influxdata/influxdb-client/dist/impl/WriteApiImpl';
import QueryApiImpl from '@influxdata/influxdb-client/dist/impl/QueryApiImpl';
import {
@shirish87
shirish87 / extract-product-list.sh
Created Apr 15, 2020
Scripts to extract product list (for organizing pooled orders to StarBazaar during COVID-19 lockdown)
View extract-product-list.sh
#!/bin/bash -e
# Usage: ./extract-product-list.sh foodgrains.json > foodgrains.txt
jq -j '.ProductList[] | .product[] | .Name, " (Price: ", .Price, ", Offer Price: ", .sale_price, ")\n"' $@
View influx-backup.sh
#!/bin/bash -e
dest="$(date '+%Y-%m-%d')-snapshot"
container="${1:-influxdb-1}"
db="${2:-comp_prices}"
destpath="/tmp/${dest}"
destfile="/tmp/${dest}.tgz"
docker exec -it $container influxd backup -portable -database $db "$destpath"
@shirish87
shirish87 / worker.module.ts
Created Feb 15, 2020
Propagate NATS connection error to microservice init
View worker.module.ts
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],
View organisation-tariff.service.spec.ts
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),
View dateloop.sh
#!/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 / check-inet.sh
Last active Sep 28, 2021
Script on the intranet raspberry pi to reconnect the PPPoE internet connection in the TP-Link gateway. Notifies other devices using push notifs via Gotify server.
View check-inet.sh
#!/bin/bash -e
######
# Installed under cron for root user
# sudo crontab -e
# * * * * * bash /home/marvin/cron-scripts/check-inet.sh >> /tmp/check-inet.log 2>&1
######
GATEWAY_IP=192.168.0.1
GATEWAY_AUTH="Basic <base64:userpass>"
@shirish87
shirish87 / main.ts
Created Jul 9, 2019
AWS Systems Manager: Parameter Store
View main.ts
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
Manage docker-compose containers with make. With the directory structure in place, run `make deploy` to launch production mode locally.
View Makefile
# root/
# |_ app/
# | |_ Dockerfile
# | |_ secrets.env
# | |_ secrets.dev.env
# |_ web/
# | |_ Dockerfile
# | |_ secrets.env
# | |_ secrets.dev.env
@shirish87
shirish87 / downloader.js
Created Nov 21, 2017
Apply response timeout when downloading large files from S3 using Axios.
View downloader.js
const axios = require('axios')
const fs = require('fs-extra')
const TimeoutStream = require('./timeoutStream')
const DEFAULT_TIMEOUT = 10000
module.exports.download = function download(downloadURL, destPath, timeout=DEFAULT_TIMEOUT) {
const tmpPath = `${destPath}.tmp`