Skip to content

Instantly share code, notes, and snippets.

View alexrintt's full-sized avatar

Alex alexrintt

View GitHub Profile
@alexrintt
alexrintt / scrollTop.js
Last active March 24, 2020 17:19
Function to Scroll window || any node to top with behavior smooth
function scrollTo(top = 0, left = 0, node = window) {
node.scroll({ top, left, behavior: "smooth" });
}
//Usage
node.onclick = function(){
scrollTo();
}
//With custom top, left
@alexrintt
alexrintt / darkmode.js
Last active January 21, 2020 22:14
script that implements a window api to control the user's choice of theme with localstorage support and without the flash bug
//window.__theme: variable with the current theme: "dark" or "light"
//window.__setPreferredTheme: function that receives the new theme to be applied
//window.__onThemeChange: function that will be called every time the theme changes
(function() {
window.__onThemeChange = function() {};
function setTheme(newTheme) {
window.__theme = newTheme;
preferredTheme = newTheme;
document.body.className = newTheme;
animation: example 5s linear 2s infinite alternate;
export default function copyToClipboard(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
textArea.style.position = 'fixed'; //avoid scrolling to bottom
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
}
function generateRandomColor(userConfig = {}) {
const defaultConfig = {
r: [0, 255],
g: [0, 255],
b: [0, 255],
a: [1, 1],
}
const config = Object.assign({}, defaultConfig, userConfig);
function randomIntFromInterval(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function createUniqueId() {
let dt = new Date().getTime();
const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(
c
) {
let r = (dt + Math.random() * 16) % 16 | 0;
dt = Math.floor(dt / 16);
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
});
return "id-" + uuid;
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
@import url('https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap');
font-family: 'Josefin Sans', sans-serif;
@import url('https://fonts.googleapis.com/css?family=Courier+Prime&display=swap');
font-family: 'Courier Prime', monospace;
index.js
if (process.env.DEVELOPMENT) {
const ngrok = require("ngrok");
(async function() {
try {
const url = await ngrok.connect({
proto: "http",
addr: process.env.PORT
});
console.log("Tunnel Created -> ");