Skip to content

Instantly share code, notes, and snippets.

View ajayvarghese's full-sized avatar
🖖

Ajay Varghese ajayvarghese

🖖
View GitHub Profile
// Random Color Generator
const getRandomHexColor = () => '#'+ Math.random().toString(16).substr(-6);
var url = new URL('https://sl.se')
var params = {lat:35.696233, long:139.570431} // or:
var params = [['lat', '35.696233'], ['long', '139.570431']]
url.search = new URLSearchParams(params)
fetch(url)
// NodeJS
export async function uploadFile(url, body, uploadActions) {
const formData = new FormData();
formData.append('dataset', body[0]);
const {
onUploadStart, onUploadProgress, onUploadSuccess,
onUploadError, onUploadAbort, onUploadEnd,
} = uploadActions;
let promise,
@ajayvarghese
ajayvarghese / loadStylesheet.js
Created July 6, 2018 09:33
Load CSS file after page load, which is not required for the initial view of the page.
const loadStyleSheet = src => {
if(document.createStylesheet) {
document.createStylesheet(src);
} else {
const stylesheet = document.createElement('link');
stylesheet.href = src;
stylesheet.rel = 'text/css';
document.querySelector('head').appendChild(stylesheet);
}
}
@ajayvarghese
ajayvarghese / ScrollToTop.js
Created May 23, 2018 07:11
Scroll to top of website on Click of button
document.getElementsByClassName('Overview__up-arrow___Y5yuq')[0].addEventListener('click', () => {
console.log('Clicked');
yPos = window.scrollY;
k = setInterval( () => {
if(yPos >= 0){
yPos = yPos - 100;
window.scrollTo(0, yPos);
} else {
clearInterval(k);
window.addEventListener('visibilitychange', () => {
switch(document.visibilityState) {
case 'prerender':
console.log('Tab is pre-rendering');
break;
case 'hidden':
console.log('Tab is hidden');
break;
case 'visible':
console.log('Tab is focused');