Skip to content

Instantly share code, notes, and snippets.

View shettayyy's full-sized avatar

Rahul Shetty shettayyy

View GitHub Profile
@shettayyy
shettayyy / BinarySearchEasy1.js
Last active May 24, 2022 17:21
Write a function to search target in nums
// Binary Search Easy 1
// Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.
// You must write an algorithm with O(log n) runtime complexity.
// Example 1:
// Input: nums = [-1,0,3,5,9,12], target = 9
// Output: 4
@shettayyy
shettayyy / storage.ts
Created April 18, 2022 09:17
A utility to store data locally on the web
const storage = () => {
const hasStorage = () => {
try {
const test = 'test'
localStorage.setItem(test, test)
localStorage.removeItem(test)
return true
} catch (e) {
return false
}
@shettayyy
shettayyy / keyof.ts
Created February 13, 2022 08:25
Get key of interface
export enum FormFields {
USERNAME = 'username',
GENDER = 'gender',
HEIGHT = 'height',
SKILLS = 'skills',
DATE_OF_BIRTH = 'dob',
LANGUAGES = 'languages',
COMPLEXION = 'complexion',
BUILD = 'build',
COUNTRY = 'country',
@shettayyy
shettayyy / username_regex.js
Last active February 12, 2022 21:57
Username regex
// Your field can only contain
// alphabets and numbers separated by period (.), hyphen (-), and underscore (_) and should begin with an alphabet
const usernameRegex = /^[a-z](?:[_.-]?[a-z0-9])*$/;
@shettayyy
shettayyy / useTheme.ts
Created January 12, 2022 18:29
Hook to switch the color scheme
import { useCallback } from 'react';
import useLocalStorage from 'use-local-storage';
enum ColorScheme {
Dark = 'dark',
Light = 'light',
}
const useTheme = (): [`${ColorScheme}`, () => void] => {
const isUserDefaultThemeDark = window.matchMedia(
@shettayyy
shettayyy / .antigenrc
Created June 29, 2021 10:53
Antigen config
# Load oh-my-zsh library
antigen use oh-my-zsh
# Select theme
antigen theme spaceship-prompt/spaceship-prompt
# Load bundles from the default repo (oh-my-zsh)
antigen bundle git
antigen bundle command-not-found
antigen bundle yarn
@shettayyy
shettayyy / .zshrc
Created June 29, 2021 10:52
MacOS Zsh config
# NVM Config
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# NVM bundle
export NVM_LAZY_LOAD=true
# Load Antigen
source /usr/local/share/antigen/antigen.zsh
@shettayyy
shettayyy / index.html
Last active May 1, 2020 12:27
Given two strings, write a function to determine if the second string is an anagram of the first. An anagram is a word, phrase, or name formed by rearranging the letters of another. We solve it using the frequency counter algorithm to find the valid anagram
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@shettayyy
shettayyy / index.html
Last active May 1, 2020 11:29
Naive solution to find the value present in one array squared in another array https://jsbin.com/muxaxil
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@shettayyy
shettayyy / index.html
Last active April 30, 2020 22:57
Get the character count of the characters present in the string https://jsbin.com/nuraxun
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">