Skip to content

Instantly share code, notes, and snippets.

View AdithyaBhat17's full-sized avatar
🏠
Working from home

Adithya NR AdithyaBhat17

🏠
Working from home
View GitHub Profile
@AdithyaBhat17
AdithyaBhat17 / expenses.js
Last active August 31, 2022 14:31
Get the total amount of expenses from expensify UI
const elements = document.querySelectorAll('.amount.isEditable');
const arr = [];
elements.forEach((element) => {
arr.push(element.innerText)
});
arr.reduce((total, current) => {
current = Number(current.replace('₹', '').replace(',',''));
total += Number(current)
return total;
}, 0)
@AdithyaBhat17
AdithyaBhat17 / useDraggable.js
Created July 27, 2021 05:38
Drag and sort react hook
import { useCallback, useState } from 'react';
export const initialState = {
draggedFrom: null,
draggedTo: null,
isDragging: false,
defaultOrder: [],
updatedOrder: []
};
file = open('coupons_seeds.txt', 'r')
queries = list()
def writeQuery ():
for line in file:
line = line.split(' ')
if(line[0] == '\n'): continue
query = 'insert into coupons (code, discount) values (\'{0}\', {1});'.format(line[0], line[1].replace('\n', '').replace('$', ''))
print(query)
import { useState, useEffect } from 'react'
export const useFetch = (url) => {
const [data, setData] = useState(undefined)
const [loading, setLoading] = useState(false)
useEffect(() => {
// loading set to true for spinner to show up
setLoading(true)
// make the api call
.hero-h1{
margin:30vh auto 25px;
font-weight: bold;
padding-bottom: 5px;
position: relative;
opacity: 0;
animation: 1s fade-in 1s forwards;
}
.hero-h1:before{
content: "";
@AdithyaBhat17
AdithyaBhat17 / answer.js
Created September 26, 2018 08:35
Udacity React quiz 2:
// Question 1: The output for the below code snippet
for(var i=0;i<10;i++){
setTimeout(function(){
console.log(i);
},0);
}
// is the number '10' printed 10 times . The reason for this is that each function executed within the
// loop will be executed after the entire loop has completed and all will therefore reference the last value stored
// in i, which was 10.
.start-btn
{
background : -moz-linear-gradient(0% 50% 0deg,rgba(79, 34, 128, 1) 0%,rgba(212, 20, 90, 1) 100%);
background : -webkit-linear-gradient(0deg, rgba(79, 34, 128, 1) 0%, rgba(212, 20, 90, 1) 100%);
background : -webkit-gradient(linear,0% 50% ,100% 50% ,color-stop(0,rgba(79, 34, 128, 1) ),color-stop(1,rgba(212, 20, 90, 1) ));
background : -o-linear-gradient(0deg, rgba(79, 34, 128, 1) 0%, rgba(212, 20, 90, 1) 100%);
background : -ms-linear-gradient(0deg, rgba(79, 34, 128, 1) 0%, rgba(212, 20, 90, 1) 100%);
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#4F2280', endColorstr='#D4145A' ,GradientType=0)";
background : linear-gradient(90deg, rgba(79, 34, 128, 1) 0%, rgba(212, 20, 90, 1) 100%);
border-radius : 26px;
@AdithyaBhat17
AdithyaBhat17 / appReducer.js
Last active August 1, 2018 14:40
Create A Reducer
/* Create A Reducer
*
* You need to create a reducer called "appReducer" that accepts two arguments:
* - First, an array containing information about ice cream
* - Second, an object with a 'DELETE_FLAVOR' `type` key
* (i.e., the object contains information to delete the flavor from the state)
*
* The action your reducer will receive will look like this:
* { type: 'DELETE_FLAVOR', flavor: 'Vanilla' }
*