Skip to content

Instantly share code, notes, and snippets.

View eashish93's full-sized avatar

Ashish Rawat eashish93

View GitHub Profile
@eashish93
eashish93 / frontend.ts
Created August 3, 2024 11:51
Parallel upload on R2 using S3 sdk with multipart (for large files)
// Define the type for upload parts
type UploadParts = {
ETag: string;
PartNumber: number;
};
// Function to create multipart upload
async function createMultipartUpload(file: File): Promise<{ uploadId: string; key: string }> {
const fileKey = `${crypto.randomUUID()}-${file.name}`;
This file has been truncated, but you can view the full file.
{"nodes":[{"id":1,"callFrame":{"functionName":"(root)","scriptId":"0","url":"","lineNumber":-1,"columnNumber":-1},"hitCount":0,"children":[2,43,380,381,388,666,678,682,691,2493,2496,2505,2507,2509,2513,2514,2552,2554,2568,2711,2720,2722,2799,2805,2881,2899,2918,2919,2923,2925,2946,2948,2976,2996,4836,4908,5999,6387,6418,6423,6437,6468,6490,6794,6849,6854,6855,6888,6898,6900,6901,7321,7416,7420,7426,7444,7455]},{"id":2,"callFrame":{"functionName":"processTicksAndRejections","scriptId":"39","url":"node:internal/process/task_queues","lineNumber":66,"columnNumber":34},"hitCount":6,"children":[3,408,415,2797,2894,2898,2908,2979,2982,3004,3005,4830,6672,6723,7360,8083],"positionTicks":[{"line":69,"ticks":1},{"line":98,"ticks":1},{"line":81,"ticks":1},{"line":82,"ticks":2},{"line":77,"ticks":1}]},{"id":3,"callFrame":{"functionName":"emit","scriptId":"455","url":"node:internal/child_process","lineNumber":934,"columnNumber":15},"hitCount":1,"children":[4,393],"positionTicks":[{"line":936,"ticks":1}]},{"id":4,"callFram
@eashish93
eashish93 / countries.ts
Last active February 3, 2023 07:43
Get countries with their flag.
// From : http://country.io/names.json, http://country.io/prefix.json
// Make sure to update it once in a while
const countries = [
{ name: 'Afghanistan', code: 'AF', prefix: '93' },
{ name: 'Aland Islands', code: 'AX', prefix: '35818' },
{ name: 'Albania', code: 'AL', prefix: '355' },
{ name: 'Algeria', code: 'DZ', prefix: '213' },
{ name: 'American Samoa', code: 'AS', prefix: '1684' },
{ name: 'Andorra', code: 'AD', prefix: '376' },
{ name: 'Angola', code: 'AO', prefix: '244' },
@eashish93
eashish93 / lang.js
Created February 3, 2018 18:27
Language codes
const langCodes = [
{name: 'Africans', code: 'afr'},
{name: 'Arabians', code: 'abr'},
{name: 'Chinese', code: 'chi_sim'},
{name: 'Danish', code: 'dan'},
{name: 'Dutch', code: 'nld'},
{name: 'English', code: 'eng'},
{name: 'Finish', code: 'fin'},
{name: 'French', code: 'fra'},
{name: 'Greek', code: 'ell'},
@eashish93
eashish93 / treeview.js
Created January 25, 2018 07:01
Simplest tree view rendering in react
import React from 'react';
function shortId() {
// Taken from stackoverflow. I Forget the reference.
// I generate the UID from two parts here
// to ensure the random number provide enough bits.
var firstPart = (Math.random() * 46656) | 0;
var secondPart = (Math.random() * 46656) | 0;
firstPart = ("000" + firstPart.toString(36)).slice(-3);
secondPart = ("000" + secondPart.toString(36)).slice(-3);
@eashish93
eashish93 / deploy-node.sh
Last active November 17, 2017 21:02
Deploy Script for My Node.JS app for zero-downtime (single server - no revert - only latest commit)
#!/bin/bash
## SEE: http://pm2.keymetrics.io/docs/tutorials/capistrano-like-deployments
# 0. Folder Structure
# -> /var/www/project_root
# -> source
# -> current -> symlink to latest release
# -> versions
# -> sha-of-commit
# -> logs
@eashish93
eashish93 / material_colors.js
Created September 29, 2017 13:54
Material Colors in JS (For Use in JS based CSS)
// This version is specially built for used in css-in-js solution.
// You can specifically import single colors to take advantage of webpack. For eg: import {red_50} from 'material_colors'
// This one consist of flat naming instead of this json based : https://gist.github.com/kawanet/a880c83f06d6baf742e45ac9ac52af96
module.exports = {
// red
'red_50': '#ffebee',
'red_100': '#ffcdd2',
'red_200': '#ef9a9a',
'red_300': '#e57373',
@eashish93
eashish93 / bash scripting cheatsheet.md
Created August 23, 2017 14:09
Bash Scripting Cheatsheet
@eashish93
eashish93 / express-seed.js
Created April 5, 2017 22:20
Quick Express Seed
const
express = require('express'),
logger = require('morgan'),
path = require('path'),
bodyParser = require('body-parser'),
serveStatic = express.static,
MongoClient = require('mongodb').MongoClient,
io = require('socket.io'),
http = require('http');