Skip to content

Instantly share code, notes, and snippets.

View piyushgarg-dev's full-sized avatar
🎯
Coding

Piyush Garg piyushgarg-dev

🎯
Coding
View GitHub Profile
@piyushgarg-dev
piyushgarg-dev / custom-promise.ts
Created November 12, 2024 05:36
Custom Promise in Typescript / Javascript
type TPromiseResolve<T> = (value: T) => void;
type TPromiseReject<T> = (reason: T) => void;
type TPromiseExecutor<T, K> = (
resolve: TPromiseResolve<T>,
reject: TPromiseReject<K>
) => void;
type TPromiseThenCallback<T> = (value: T | undefined) => void;
type TPromiseCatchCallback<T> = (reason: T | undefined) => void;
@piyushgarg-dev
piyushgarg-dev / CLICKHOUSE_DB_CREATE.sql
Last active September 5, 2024 04:43
Vercel Clone 2.0 Commands
CREATE TABLE log_events (
event_id UUID,
timestamp DateTime MATERIALIZED now(),
deployment_id Nullable(String),
log String,
metadata Nullable(String)
)
ENGINE=MergeTree PARTITION BY toYYYYMM(timestamp)
ORDER BY (timestamp);
@piyushgarg-dev
piyushgarg-dev / Dockerfile
Created October 21, 2023 10:00
Docker In One Shot
FROM ubuntu
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get upgrade -y
RUN apt-get install -y nodejs
COPY package.json package.json
COPY package-lock.json package-lock.json
@piyushgarg-dev
piyushgarg-dev / README.md
Last active November 14, 2024 06:49
Kafka Crash Course

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Create Free AWS Account

Create free AWS Account at https://aws.amazon.com/

2. Create and Lauch an EC2 instance and SSH into machine

I would be creating a t2.medium ubuntu machine for this demo.

@piyushgarg-dev
piyushgarg-dev / install_nginx.md
Last active October 20, 2024 04:04
Nginx Installation
buyButton.addEventListener('click', async (event) => {
const response = await fetch('/order', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ amount: 500 }) // Rs.500
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Razorpay</title>
</head>
<body>
<div>
const { request, response } = require('express');
const express = require('express');
const Razorpay = require('razorpay');
const app = express();
const PORT = 8000;
app.use(express.static('./public'));
app.use(express.json());
const express = require('express');
const app = express();
const PORT = 8000;
app.use(express.static('./public'));
app.use(express.json());