Skip to content

Instantly share code, notes, and snippets.

View madan712's full-sized avatar

Madan Chaudhary madan712

View GitHub Profile
@madan712
madan712 / deploy.sh
Created March 18, 2024 21:18
Shell script to manage docker process using pm2
#!/usr/bin/env bash
set -euo pipefail
# Variables
IMAGE_NAME="my_image_name"
CONTAINER_NAME="my_container_name"
TAG="latest"
# Build Docker image
@madan712
madan712 / .js
Created December 31, 2023 15:26
Node lambda function using AWS SDK javascript v3 to fetch quicksight embed url
const {STSClient, AssumeRoleCommand} = require("@aws-sdk/client-sts");
const {QuickSightClient, GetDashboardEmbedUrlCommand, RegisterUserCommand} = require("@aws-sdk/client-quicksight");
const AWS_REGION = "us-east-1";
const AWS_ACCOUNT_ID = "123456789012";
const QUICKSIGHT_ROLE_ARN = `arn:aws:iam::${AWS_ACCOUNT_ID}:role/QuicksightDashboardViewer`;
const stsClient = new STSClient({
region: AWS_REGION
});
@madan712
madan712 / .js
Created December 31, 2023 15:22
AWS SDK javascript v3 to get quicksight embed url
const getEmbedUrl = async (qsClient, dashboardId) => {
console.log(`Fetching embed url`);
const param = {
AwsAccountId: AWS_ACCOUNT_ID,
DashboardId: dashboardId,
IdentityType: "IAM",
UndoRedoDisabled: true,
ResetDisabled: true
};
@madan712
madan712 / .js
Created December 31, 2023 15:18
AWS SDK javascript v3 register new quicksight user
const registerUser = async (qsClient, email) => {
console.log(`Registering user`);
const param = {
IdentityType: "IAM",
Email: email,
UserRole: "READER",
IamArn: QUICKSIGHT_ROLE_ARN,
SessionName: email,
AwsAccountId: AWS_ACCOUNT_ID,
Namespace: "default"
@madan712
madan712 / .js
Created December 31, 2023 15:14
AWS SDK javascript v3 assume role
const assumeRole = async (email) => {
console.log(`Assuming role`);
const param = {
RoleArn: QUICKSIGHT_ROLE_ARN,
RoleSessionName: email, // An unique identifier like email/username etc
DurationSeconds: 900,
};
const command = new AssumeRoleCommand(param);
const response = await stsClient.send(command);
@madan712
madan712 / .json
Last active December 31, 2023 15:16
AWS IAM Role to fetch QuickSight embed URL
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "quicksight:RegisterUser",
"Resource": "*",
"Effect": "Allow"
},
{
"Action": "quicksight:GetDashboardEmbedUrl",
@madan712
madan712 / AutoSuggest.tsx
Created April 23, 2023 13:44
React auto suggest input, Auto complete input box, React input suggestion, Simple auto suggest input, User input auto suggest, Dynamic input suggestion, React search input, Instant search suggestion, Efficient auto complete input, React auto fill input
import React, { useState } from 'react';
import AutoSuggestInput from 'autosuggest-input-box';
import { Box, Control, Label, Row } from './AutoSuggestInputStyle';
const countries = [
'China',
'India',
'United States',
'Indonesia',
'Pakistan',
@madan712
madan712 / App.js
Last active January 6, 2024 07:17
React simple rich text editor using draft-js
import React, { useState } from 'react';
import { Editor, EditorState, RichUtils } from 'draft-js';
import {
FaBold,
FaCode,
FaHeading,
FaItalic,
FaListOl,
FaListUl,
@madan712
madan712 / Main.java
Created February 3, 2023 00:42
Java thread synchronization
class ZapOne {
synchronized void print(int n) {
for (int i = 1; i <= 5; i++) {
System.out.println(n * i);
}
}
}
//Synchronized Function
class coding extends Thread {
@madan712
madan712 / showProgressBar.java
Last active July 9, 2022 13:21
Java - Progress bar in console
public static void showProgressBar(int length, int interval, String message) {
char incomplete = '░';
char complete = '█';
StringBuilder progress = new StringBuilder();
// Initialize
Stream.generate(() -> incomplete).limit(length).forEach(progress::append);
StringBuilder percent = new StringBuilder("0");
String format = "\r[%s] %s%%";