Skip to content

Instantly share code, notes, and snippets.

View tanmay27vats's full-sized avatar

Tanmay Vats tanmay27vats

View GitHub Profile
@tanmay27vats
tanmay27vats / .bashrc
Created March 12, 2022 11:54
Add git branch name to shell prompt in Ubuntu with custom text. Sudo nano ~/.bashrc
# Colors definition
BLUE='\e[94m'
L_BLUE='\e[96m'
YELLOW='\e[93m'
GREEN='\e[32m'
L_GREEN='\e[92m'
RED='\e[31m'
L_RED='\e[91m'
NC='\e[0m'
@tanmay27vats
tanmay27vats / open_projects_on_terminal.sh
Created February 25, 2022 13:02
Open projects on the terminal in multiple tabs at once.
#!/bin/bash
####################################
#
# Open all required porjects.
#
####################################
gnome-terminal --tab --command="bash -c 'cd /path/to/your/project/angular-project-1; npm start; $SHELL'" \
--tab --command="bash -c 'cd /path/to/your/project/angular-project-2; ng serve -p 4201; $SHELL'" \
--tab --command="bash -c 'cd /path/to/your/project/angular-project-3; ng serve -p 4202; $SHELL'"
@tanmay27vats
tanmay27vats / solution.py
Created February 1, 2022 08:13
[Python] Valid Parentheses - Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Example 1: Input: s = "()" Output: true Example 2: Input: …
class Solution:
def isValid(self, s: str) -> bool:
s = s.replace(' ','')
if len(s)%2 != 0:
return False
dict = {'(' : ')', '[' : ']', '{' : '}'}
ar = []
for i in s:
if i in dict:
ar.append(i)
@tanmay27vats
tanmay27vats / solution.py
Created February 1, 2022 07:10
[Python] Longest Common Prefix - Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string "". Example 1: Input: strs = ["flower","flow","flight"] Output: "fl" Example 2: Input: strs = ["dog","racecar","car"] Output: "" Explanation: There is no common prefix among …
class Solution:
def longestCommonPrefix(self, strs: List[str]) -> str:
if len(strs) == 0:
return ""
common_prefix = strs[0]
for i in range(1,len(strs)):
temp = ""
if len(common_prefix) == 0:
break
for j in range(len(strs[i])):
@tanmay27vats
tanmay27vats / solution.py
Last active February 1, 2022 07:24
[Python] Roman to Integer - Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.
class Solution:
def romanToInt(self, s: str) -> int:
roman_dict = { 'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000, 'IV':4, 'IX':9, 'XL':40, 'XC':90, 'CD':400, 'CM':900 }
i = 0
sum = 0
while i < len(s):
if s[i:i+2] in roman_dict and i+1<len(s):
sum+=roman_dict[s[i:i+2]]
i+=2
else:
@tanmay27vats
tanmay27vats / solution.rb
Created January 31, 2022 14:21
[Ruby] Rotate Array - Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: Input: nums…
# @param {Integer[]} nums
# @param {Integer} k
# @return {Void} Do not return anything, modify nums in-place instead.
def rotate(nums, k)
count = 0
start = 0
while (count < nums.size)
current = start
prev = nums[start]
loop do
@tanmay27vats
tanmay27vats / solution.php
Created January 31, 2022 14:04
[PHP] Rotate Array - Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: Input: nums …
class Solution {
/**
* @param Integer[] $nums
* @param Integer $k
* @return NULL
*/
function rotate(&$nums, $k) {
$count = 0;
$start = 0;
@tanmay27vats
tanmay27vats / solution.py
Created January 31, 2022 13:56
[Python] Rotate Array - Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2: Input: nu…
class Solution:
def rotate(self, nums: List[int], k: int) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
count = 0
start = 0
while (count < len(nums)):
current = start
prev = nums[start]
@tanmay27vats
tanmay27vats / kill-pid.sh
Last active June 14, 2019 12:21
Delete Process by Process ID (PID) Ubuntu Linux Command
# This will print you PID of process bound on that port.
fuser 3000/tcp
# And this will kill that process
fuser -k 3000/tcp
@tanmay27vats
tanmay27vats / script.js
Created June 14, 2019 09:24
How to check if all inputs are not empty with jQuery
$("input:empty").length == 0;
/* Above statement will bypass the empty spaces. */
/* If you want to search for all empty inputs including blank/empty spaces. Try below one */
$("input").filter(function () {
return $.trim($(this).val()).length == 0
}).length == 0;