Skip to content

Instantly share code, notes, and snippets.

View iamshadmirza's full-sized avatar
👨‍💻
Tap Tap Tap

Shad Mirza iamshadmirza

👨‍💻
Tap Tap Tap
View GitHub Profile
(function ( ) {
// keyof: This created a literal type where new type will be equal to keyof type
interface Resume {
name: string,
education: string,
skills: Array<string>
}
@iamshadmirza
iamshadmirza / TNBW-contributors.md
Last active June 15, 2021 06:00
Drop your hashnode username to join "The Next Big Writer" mentorship program.

Hey everyone,

I see you have chosen to level up your technical writing skills. Drop a comment here with your Hashnode username or create an account here if you haven't already.

We will add you as contributors on the "The Next Big Writer" publication and you will be able to see it in dropdown while submitting your draft.
See you on the other side 👋🏼

This gist is associated with the https://thenextbigwriter.tech/ mentorship program.

@iamshadmirza
iamshadmirza / binaryQueue.js
Created December 17, 2019 08:48
binaryQueue solution from Cassidy's newsletter
// This week's question:
// Given a positive number N, generate binary numbers between 1 to N
// using a queue-type structure in linear time.
// Example:
// > binaryQueue(10)
// > 1 10 11 100 101 110 111 1000 1001 1010
function binaryQueue(n) {
const queue = [];
@iamshadmirza
iamshadmirza / recurseUnderscore.js
Created December 6, 2019 02:38
Iterate through object and flatten it.
//Iterate through user object and flatter in one object.
//append _ on every level
var user = {
name: "Shad",
address: {
personal: {
city: "Varanasi",
area: "Chauhatta",
},
office: {
@iamshadmirza
iamshadmirza / memoizedCutRod.js
Created December 4, 2019 02:29
Optimized recursive solution for cut rod problem
function cutRod(n, prices){
if(n === 0){ return 0; }
let maxRevenue = -1;
for( let i = 0; i < n; i++){
maxRevenue = Math.max(maxRevenue, prices[n- i - 1] + memoizedCutRod(i, prices));
}
return maxRevenue;
}
function memoize(fn){
@iamshadmirza
iamshadmirza / memoizedStair.js
Created December 4, 2019 01:41
Cache recursive calls to optimize runtime
function stair(n){
if(n === 1){ return 1; }
if(n === 2){ return 2; }
return memoizedStair(n-1) + memoizedStair(n-2);
}
function memoize(fn){
const cache = {};
return function(...args){
if(cache[args]){
@iamshadmirza
iamshadmirza / dayOffset.js
Created December 3, 2019 11:09
Solution of weekly problem from Cassidy Williams's Newsletter
// Interview question of the week by Cassidy Williams's Newsletter
// This week's question courtesy of Louis:
// Write a function that takes the name of a day (e.g "Monday", "Tuesday")
// and an integer offset, and returns the name of the day which would be the original + offset.
// Extra credit: do it in 1 line!
// Example:
// > dayOffset("Wednesday", 4)
// > "Sunday"
(function(){
let food = [
{type: 'beverage', name: 'tea'},
{type: 'veg', name: 'aloo paratha'},
{type: 'non-veg', name: 'biryani'},
{type: 'non-veg', name: 'butter chicken'}
];
const filterFunction = (string) => (item) => item.type === string;
@iamshadmirza
iamshadmirza / listclipper.py
Created February 21, 2018 09:39
output first and last element of list
def inserlist(givenlist):
first, *middle, last = givenlist
newlist = [first, last]
return newlist
list = [12,45,78,45,96,67,81,39]
print("List to be clipped is",list)
print("First and the last element of clip are",inserlist(list))
@iamshadmirza
iamshadmirza / checkprime.py
Created February 21, 2018 08:33
prime, non prime and composite
userinput = int(input("Enter the number to check prime\n"))
a = []
if userinput == 1:
print("One is not a prime nor a composite")
else:
if userinput == 2 or userinput%2 != 0:
for x in range(1,userinput):
if userinput%x==0 :
a.append(x)
if len(a)==1: