Skip to content

Instantly share code, notes, and snippets.

View abcdeepakr's full-sized avatar
🏋️
kaam karo vyast raho

Deepak Rawat abcdeepakr

🏋️
kaam karo vyast raho
View GitHub Profile
@abcdeepakr
abcdeepakr / get-files.js
Last active October 21, 2023 09:53
File operations
import { readdir } from "fs/promises";
import { resolve } from 'path';
// provide the basepath you want to start your recursion from
export const getFiles = async (basePath) => {
const dirents = await readdir(basePath, { withFileTypes: true });
const files = await Promise.all(dirents.map((dirent) => {
const res = resolve(basePath, dirent.name);
return dirent.isDirectory() ? getFiles(res) : res;
}));
@abcdeepakr
abcdeepakr / base64PDF.js
Created April 6, 2023 10:10
download base64 pdf
const downloadLink = document.createElement("a");
downloadLink.href = invoiceResponse.b64[0];
downloadLink.download = "File_name";
downloadLink.click();
@abcdeepakr
abcdeepakr / index.html
Created March 24, 2023 16:41
validate max input length
<div class="form-options">
<input id="pincode" type="number"
onkeypress="validateNumberFields(event)" pattern="\d*"
oninput="this.value=this.value.replace(/[^0-9]/g,'');"
type="number"
maxlength="6" />
</div>
@abcdeepakr
abcdeepakr / AppReducer.js
Last active March 16, 2023 14:32
Use context hook in reactJS
// create a simple nextjs project
// Two initial states, you can have as many and import as required
export const counterState = 0;
export const sentenceState = "";
// reducer that takes the state and the action paylod that determines which state to update
export const reducer = (state, action) => { // expects a current state and action to be worked on
switch (action.type) {
if exists(SELECT * from [dbo].[tbl_name] where id='my_id')
begin
update [dbo].[tbl_name] set column_name='${value}' where id='my_id'
end
else
begin
insert into [dbo].[tbl_name] values('val_1','val_2','val_3,...')
end
const data = {
'axis': {'amount': 4000000, 'roi': 14},
'icici': {'amount': 7000000, 'roi': 13.2},
'ubi': {'amount': 4900000, 'roi': 10},
'idfc': {'amount': 3000000, 'roi': 13},
'sbi': {'amount': 4000000, 'roi': 10.3},
'bob': {'amount': 2000000, 'roi': 9},
'bajaj': {'amount': 9000000, 'roi': 19},
'avanse': {'amount': 4000000, 'roi': 12},
'gd': {'amount': 4000000, 'roi': 15},
@abcdeepakr
abcdeepakr / flexTable.html
Last active February 23, 2023 13:30
responsive flexbox table
<!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>FlexBox Table</title>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
@abcdeepakr
abcdeepakr / parseUnix.js
Last active November 8, 2023 09:42
to local from unix
export function parseUnixTimeStamp(unix_timestamp){
var date = new Date(unix_timestamp);
// var hours = date.getHours();
// var minutes = "0" + date.getMinutes();
let parsedDate = date.toLocaleString([], {year: 'numeric', month: 'numeric', day: 'numeric',hour: '2-digit', minute:'2-digit'})
// or
parsedDate = date.toLocaleString([], {year: 'numeric', month: 'short', day: 'short',hour: '2-digit', minute:'2-digit'})
// or
parsedDate = date.toLocaleString([], {year: 'numeric', month: 'long', day: 'long',hour: '2-digit', minute:'2-digit'})
@abcdeepakr
abcdeepakr / toc.md
Created January 7, 2023 10:32
Markdown Table of content
@abcdeepakr
abcdeepakr / eventDelegation
Created January 4, 2023 09:32
Event delegation jq
https://learn.jquery.com/events/event-delegation/
(parentStaticSelector).on(event, dynamicChildSelector, function(){})