Skip to content

Instantly share code, notes, and snippets.

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

codecracker2020

🏠
Working from home
View GitHub Profile
//Colorify your Console statements
//Follow us @JSTipsNTricks
const bright = "\x1b[1m";
const black = "\x1b[30m";
const red = "\x1b[31m";
const green = "\x1b[32m";
const BGred = "\x1b[41m";
const BGgreen = "\x1b[42m";
const BGyellow = "\x1b[43m";
function checkCapsLock(){
let isCapsLockOn = false;
document.addEventListener( 'keydown', (_)=> {
var state = _.getModifierState && _.getModifierState('CapsLock');
if(isCapsLockOn !== state){
isCapsLockOn = state;
console.log(`Caps Lock Status: ${isCapsLockOn}`)
}
});
}
@codecracker2020
codecracker2020 / batterystatus.js
Created June 5, 2021 11:02
Get Battery Status in Javascript
/*
Web API 2 - Get Battery Status
Follow us @jstipsntricks
*/
const batteryPromise = navigator.getBattery();
batteryPromise.then((e)=>{
printBatteryStatus(e);
});
@codecracker2020
codecracker2020 / digitsinanum.js
Last active May 22, 2021 13:41
Use _ for visual separation of digits in a number and using exponential representation
/*
JS: Use _ for visual separation of digits in a number
Follow us @jstipsntricks
*/
const num1 = 1000000;
const num2 = 1_000_000;
console.log(num1 === num2); //true
//Using exponential representation
@codecracker2020
codecracker2020 / openurl.py
Created May 21, 2021 10:25
A python code to open an url using Selenium WebDriver
import time
# import webdriver from selenium
from selenium import webdriver
# Choose browser of your wish
# In the case of Firefox, use webdriver.Firefox()
driver = webdriver.Chrome(executable_path = 'C:/Users/user1/Downloads/chromedriver_win32/chromedriver.exe')
# provide an URL
@codecracker2020
codecracker2020 / compress-file.js
Last active May 7, 2021 01:48
Compress a file using zlib node module in Node.js
/*
Node JS: Compress a file using zlib
Follow us @jstipsntricks
*/
const zlib = require('zlib');
const fs = require('fs');
const zip = zlib.createGzip();