Skip to content

Instantly share code, notes, and snippets.

View sairajchouhan's full-sized avatar

Sairaj sairajchouhan

View GitHub Profile
# DSA Question Bank
## Arrays, Hashing, Prefix/Suffix
1. Find the second largest element in one pass without extra space.
2. Find the k largest distinct elements without fully sorting the array.
3. Find the two numbers that appear once when every other number appears twice.
4. Find the majority element that appears more than n / 2 times.
5. Find all elements that appear more than n / 3 times.
6. Count inversions in an array.
// ==UserScript==
// @name TUF Vim Mode
// @namespace http://tampermonkey.net/
// @version 12.0
// @description Vim support for takeUforward code editor
// @author You
// @match https://*.takeuforward.org/*
// @connect unpkg.com
// @connect cdn.jsdelivr.net
// @grant GM_xmlhttpRequest

Multiple GitHub accounts (Work vs Personal)

This setup uses some tricks to ensure that the right email/name/ssh-key is used for the right repos without having to think about it ever again.

  • First generate two SSH keys, ~/.ssh/id_ed25519 and ~/.ssh/id_ed25519_work
  • Add one key to your personal account and the other to your work account

.ssh/config

@sairajchouhan
sairajchouhan / script.js
Created August 17, 2023 08:43
script to pin some repos in the sidebar of home page of Github
const repo_list = [
"contentstack/UI-React",
"contentstack/visual-editor",
"contentstack/schema-form",
"contentstack/UI-E2E",
"contentstack/venus-components",
];
document.addEventListener("DOMContentLoaded", () => {
setTimeout(() => {
@sairajchouhan
sairajchouhan / cbugger.lua
Last active September 22, 2023 09:52
lua script to insert logs in javascript for neovim
M = {}
local num = 0;
M.setup = function()
vim.api.nvim_set_keymap('n', '<leader>cl', ':Cbugger<CR>', { noremap = true, silent = true })
vim.api.nvim_create_user_command("Cbugger", function()
local cursor = vim.api.nvim_win_get_cursor(0);
local final_str = "console.log(`" .. num .. ": ";
version: '3.9'
services:
db:
image: postgres:latest
container_name: minibyte_postgres_dev
restart: always
ports:
- 5432:5432
environment:
- POSTGRES_USER=minibyte
import { useState } from "react"
const useModal = (initial = false, duration = 300) => {
const [isOpen, setIsOpen] = useState(initial)
const closeModal = () => {
return new Promise((res) => {
setIsOpen(false)
setTimeout(() => {
res(true)
@sairajchouhan
sairajchouhan / useTwWindowSize.ts
Created February 6, 2022 13:12
I use this buddy in every tailwind project so thought to put it here so that I don't have to bang my head writing the same hook again and again
import { useEffect, useState } from 'react'
export type ScreenSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '_'
export const getScreenSize = (width: number) => {
let screenSize: ScreenSize = '_'
if (width < 768 && width >= 640) {
screenSize = 'sm'
}
@sairajchouhan
sairajchouhan / useImageUpload.tsx
Created October 18, 2021 15:38
React hook for image file upload
import { useEffect, useState } from 'react'
// fill the array with the image type you want to allow
const allowedImageTypes = ['image/jpeg', 'image/png']
export const useFileUpload = () => {
const [selectedFile, setSelectedFile] = useState<Blob | null>(null)
const [previewUrl, setPreviewUrl] = useState<string | null>(null)
const [error, setError] = useState<string | null>(null)
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": [
"dom",
"es6",
"es2017",
"esnext.asynciterable"
],