Skip to content

Instantly share code, notes, and snippets.

View shivam-tripathi's full-sized avatar
💫
Call it magic, Call it code

Shivam Tripathi shivam-tripathi

💫
Call it magic, Call it code
  • Bangalore, India
View GitHub Profile
@shivam-tripathi
shivam-tripathi / stime.ts
Last active August 10, 2023 09:30
Command Line script to convert localtime to UTC. Defaults to IST.
import { parse } from "https://deno.land/std/flags/mod.ts";
const allowed = ['--dt: datetime', '--tz: timezone', '--d: date', '--t: time'];
const flags = parse(Deno.args);
if (Object.keys(flags).length === 1) {
console.log(`TimeZone Date Utility: Help Utility\n\t${allowed.join('\n\t')}`);
console.log('Defaulting to current time and IST TZ.\n');
}
const { dt, tz = '+05:30' } = flags;
@shivam-tripathi
shivam-tripathi / result.ts
Created February 23, 2022 12:18
Result passing in Typescript
import { Context } from '@src/helpers/context';
import QError from '@src/helpers/error';
import is from 'is_js';
/**
* Contains result which can be error or ok
*/
export default class Result<T> {
private readonly value?: T;
private readonly error?: Error;
@shivam-tripathi
shivam-tripathi / struct-of-env.go
Last active August 29, 2021 14:08
Creates a struct from dotenv file. Has ability to json parse as well in case field is struct and has a key string against it in the env map. Constructs key for a namespace - eg start with "DEV" or "PROD". Input is original type we want to construct, env to store map of key and value (as string) and current active key.
package main
import (
"encoding/json"
"fmt"
"reflect"
"strconv"
"strings"
)
@shivam-tripathi
shivam-tripathi / whitelist.sh
Last active June 4, 2021 05:31
Bash script to white list your ip for a particular security group in AWS
export desc="shivam";
export sg_id="SG_ID"; # update this
export AWS_PAGER="";
# Revoke earlier white listed ip (compares it via desc)
aws ec2 describe-security-groups --group-ids $sg_id --output text | grep $desc | awk '{ print $2 }' | xargs -I {} aws ec2 revoke-security-group-ingress --group-id $sg_id --protocol tcp --port 0-65535 --cidr {};
# Give permission to current public ip
wget -qO- ifconfig.me | xargs -I {} aws ec2 authorize-security-group-ingress --group-id $sg_id --ip-permissions IpProtocol=tcp,FromPort=0,ToPort=65535,IpRanges='[{CidrIp={}/32,Description="'$desc'"}]';
@shivam-tripathi
shivam-tripathi / availability.txt
Last active May 4, 2021 06:02
Availability percentage to time mapping
+----------------+-----------------------+---------------+
| Availability % | per day | per year |
+================+=======================+===============+
| 99% | 864s = (24*60*60)/100 | 5256 minutes |
+----------------+-----------------------+---------------+
| 99.9% | 86.4s | 525.6 minutes |
+----------------+-----------------------+---------------+
| 99.99% | 8.64s | 52.56 minutes |
+----------------+-----------------------+---------------+
| 99.999% | 0.864s = 864ms | 5.256 minutes |
+-------+---------------+------------+------------+
| Power | Approx Value | Full Name | Short Name |
+=======+===============+============+============+
| 10 | 1 Thousand | 1 KiloByte | 1 KB |
+-------+---------------+------------+------------+
| 20 | 1 Million | 1 MegaByte | 1 MB |
+-------+---------------+------------+------------+
| 30 | 1 Billion | 1 GigaByte | 1 GB |
+-------+---------------+------------+------------+
| 40 | 1 Trillion | 1 TeraByte | 1 TB |
@shivam-tripathi
shivam-tripathi / leetcode.js
Created January 28, 2021 04:13
Get all leetcode problems
const axios = require('axios');
async function main() {
const url = 'https://leetcode.com/api/problems/all/';
const { data } = await axios({ method: 'GET', url });
const getDifficulty = (level) => {
switch(level) {
case 1: return 'easy';
case 2: return 'medium';
case 3: return 'hard';
@shivam-tripathi
shivam-tripathi / installJavaGradle.sh
Created January 19, 2021 07:16
Install Java and Gradle
pushd ~
sudo apt install unzip zip
curl https://get.sdkman.io -o ~/sdkman.sh
bash ~/sdkman.sh
source "/home/ubuntu/.sdkman/bin/sdkman-init.sh"
sdk install java 11.0.9.open-adpt
wget -O gradle.zip https://services.gradle.org/distributions/gradle-6.6.1-bin.zip
@shivam-tripathi
shivam-tripathi / mongo-cloud-watch.go
Last active March 10, 2021 14:57
MongoDB cloud watch metrics
/* User must have privileges to run: 1. db.stats() 2. db.serverStatus() 3. collStats on every column in the db 4. listCollections on relevant DB */
package main
import (
"context"
"fmt"
"log"
"math"
"os"
"reflect"
@shivam-tripathi
shivam-tripathi / mongoStress.go
Created December 30, 2020 07:37
Stress test mongo with specified concurrency limit
package main
import (
"context"
"errors"
"log"
"math/rand"
"reflect"
"time"