Skip to content

Instantly share code, notes, and snippets.

Avatar
👾
Coding Like A Pro

Mohit Varikuti GitHubEmploy

👾
Coding Like A Pro
View GitHub Profile
View expert_10.js
const touchSupported = () => {
(‘ontouchstart’ in window || window.DocumentTouch && document instanceof window.DocumentTouch);
}
console.log(touchSupported()); // Result: If touch event is supported, it will return True, otherwise it will return False
View expert_9.js
const elementIsInFocus = (el) => (el === document.activeElement);
elementIsInFocus(anyElement) // Result: If it is in focus, it will return True, otherwise it will return False
View expert_8.js
const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
console.log(isDarkMode) // Result: True or False
View expert_6.js
const hex = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`;
console.log(hex());
View expert_5.js
const even = num => num % 2 === 0;
console.log(even(2)); // true
console.log(even(3)); // false
View expert_4.js
const isBrowserTabInView = () => document.hidden;
isBrowserTabInView();
View expert_3.js
const reverse = str => str.split('').reverse().join('');
console.log(reverse('cake is yummy'));
// Result: 'ymmuy si ekac'
View expert_2.js
const week = (date) => date.getDay()% 6 !== 0;
console.log(week(new Date(2021, 0, 11))); // Result: true (Monday)
console.log(week(new Date(2021, 0, 15))); // Result: false (Sunday)
View expert_1.js
const randomBoolean = () => Math.random() >= 0.5;
console.log(randomBoolean());
View time_trial.py
import time
start_time = time.time()
for loop in range(1, 100000000):
pass
print('FINISHED EXECUTION')
print("--- %s seconds ---" % round(time.time() - start_time, 4))