Skip to content

Instantly share code, notes, and snippets.

View bhumit070's full-sized avatar

Bhoomit Ganatra bhumit070

View GitHub Profile
@bhumit070
bhumit070 / replace_space_with_dots.sh
Created April 26, 2024 11:53
Replace space with dots
for file in *; do
# Check if the file name contains spaces
if [[ "$file" == *" "* ]]; then
# Replace spaces with dots and rename the file
new_name=$(echo "$file" | tr ' ' '.')
mv "$file" "$new_name"
echo "Renamed '$file' to '$new_name'"
fi
done
@bhumit070
bhumit070 / launch.json
Created July 24, 2023 16:11
VsCode Launch.json for VsCode Debugger ( JavaScript )
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node",
"port": 9229,
"request": "attach",
@bhumit070
bhumit070 / express_zod_validator.ts
Created May 12, 2023 15:58
Way to parse body, params, and query in Nodejs using Zod
import express, { Request, Response } from 'express';
import z, { AnyZodObject, ZodError } from 'zod';
import { generateError } from 'zod-error';
const app = express();
const mySchema = z.object({
body: z.object({
name: z.string(),
}),
@bhumit070
bhumit070 / macos_screen_shot_script.sh
Last active May 14, 2023 13:10
macos_screen_shot_script.sh
#!/bin/bash
randomScreenShotName="$RANDOM.png"
screenShotPath="/tmp/$randomScreenShotName"
screencapture $screenShotPath
screenShotDir="$HOME/screenshots/$(date +"%Y-%m-%d")"
if ! [ -d $screenShotDir ]; then
mkdir -p $screenShotDir
@bhumit070
bhumit070 / stop_on_debug.html
Created May 3, 2023 04:09
STOP_BROWSER_ON_DEBUGGER_IF_DEVTOOLS_IS_OPENED
-- HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
@bhumit070
bhumit070 / typesafe_localstorage.ts
Created April 22, 2023 17:21
Typesafe Localstorage With Typescript And Zod
import * as z from 'zod';
const LocalStorageSchema = z.object({
name: z.string(),
age: z.number(),
isEmployed: z.boolean(),
});
type LocalStorageData = z.infer<typeof LocalStorageSchema>;
@bhumit070
bhumit070 / image.html
Last active April 22, 2023 05:37
Google image 403 error
<img
referrerpolicy="no-referrer"
src="link-to-image"
/>
@bhumit070
bhumit070 / nodejs_debug_vscode.json
Created April 21, 2023 17:43
Vscode NodejS Debugger
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Node",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"envFile": "${workspaceFolder}/.env",
"type": "node"
#!/bin/bash
function ss() {
local screenName="$1"
if [ -z "$screenName" ]; then
echo "No service name provided."
exit 1
fi
local isScreenRunning=$(screen -ls | grep -ciw "$screenName")
@bhumit070
bhumit070 / event_emitter.ts
Created April 15, 2023 05:10
Type safe event emitter
type Listener<Args extends Array<any>> = (...args: Args) => void;
class MyEmitter<EventMap extends Record<string, Array<any>>> {
private eventListeners: {
[K in keyof EventMap]?: Set<Listener<EventMap[K]>>;
} = {};
constructor() {}
on<K extends keyof EventMap>(