Skip to content

Instantly share code, notes, and snippets.

View genesisneo's full-sized avatar
👽

Neo Genesis genesisneo

👽
View GitHub Profile
@genesisneo
genesisneo / copyCurrentUrl.js
Created February 24, 2021 08:08
Copy current URL to clipboard with callback function.
/*
Examples:
copyCurrentUrl(() => {
Toastify({
text: "URL successfully copied.",
duration: 3000
}).showToast();
});
*/
@genesisneo
genesisneo / gradientGenerator.js
Created February 11, 2021 17:57
Randomly generate angle and 2 set of colors for gradient background.
/*
Examples:
gradientGenerator() = { angle: 128, colorOne: "#e29482", colorTwo: "#c98d47" }
*/
const gradientGenerator = () => {
const hexValues = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e'];
const generateGradient = (color) => {
for (let i = 0; i < 6; i++) {
@genesisneo
genesisneo / randomizer.js
Last active January 30, 2021 19:26
Generate unique array of numbers base of range and set.
/*
Examples:
randomizer({ range: 50, set: 5 }) = [8, 16, 32, 40, 48]
randomizer({ range: 15, set: 3 }) = [4, 11, 15]
randomizer() = [1, 2, 3, 4, 5]
*/
function randomizer (data) {
const dataRange = data && data.range ? data.range : 5;
const dataSet = data && data.set ? data.set : 5;
@genesisneo
genesisneo / scrollDirectionListener.js
Created December 22, 2020 06:35
HTML Scroll Direction Listener
// compatibility check
const supportPageOffset = window.pageXOffset !== undefined;
const isCSS1Compat = ((document.compatMode || '') === 'CSS1Compat');
// previous scroll value
let currentScrollTop = supportPageOffset
? window.pageYOffset
: isCSS1Compat
? document.documentElement.scrollTop
: document.body.scrollTop;
@genesisneo
genesisneo / settings.json
Created December 7, 2020 11:52
Windows Terminal Settings
// Notes:
// Git for Windows should be installed on your machine
// To generate new guid open PowerShell then '[guid]::NewGuid()''
// PowerShell as Administrator require `Set-ExecutionPolicy RemoteSigned`
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"copyOnSelect": false,
"copyFormatting": false,
@genesisneo
genesisneo / form.html
Last active December 22, 2020 06:37
Convert HTML Form to JSON
<form id="myForm">
<!-- text, email, password -->
<input type="text" name="name" placeholder="name" /><br />
<input type="email" name="email" placeholder="email" /><br />
<input type="password" name="password" placeholder="password" /><br />
<!-- checkbox -->
<input type="checkbox" name="cb_one" value="one" /><br />
<input type="checkbox" name="cb_two" value="two" /><br />
<input type="checkbox" name="cb_three" value="three" /><br />
<!-- radio -->
@genesisneo
genesisneo / certificate.sh
Created February 6, 2020 12:46
Secure your local development server with HTTPS (Next.JS)
# This will output two (2) files: localhost.key & localhost.crt
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
@genesisneo
genesisneo / arrayMethods.js
Created January 22, 2020 12:43
15 JavaScript array methods
// .some()
const myAwesomeArray = ["a", "b", "c", "d", "e"]
myAwesomeArray.some(test => test === "d") // true
// .reduce()
const myAwesomeArray = [1, 2, 3, 4, 5]
myAwesomeArray.reduce((total, value) => total * value) // 1*2*3*4*5 = 120
// .every()
const myAwesomeArray = ["a", "b", "c", "d", "e"]
@genesisneo
genesisneo / isVideoPlayerVisible.js
Last active February 24, 2021 11:06
Small javascript for playing/pausing the video when in/out of the viewport
var videos = document.getElementsByTagName("video");
function checkViewport () {
for (var i = 0; i < videos.length; i++) {
var video = videos[i];
var x = video.offsetLeft,
y = video.offsetTop,
w = video.offsetWidth,
h = video.offsetHeight,
r = x + w,
@genesisneo
genesisneo / express-server.js
Last active July 10, 2019 09:45
Express server with http to https redirection for production.
const fs = require('fs');
const path = require('path');
const spdy = require('spdy');
const helmet = require('helmet');
const express = require('express');
const compression = require('compression');
const server = express();
const { NODE_ENV } = process.env;
const isDev = NODE_ENV === 'development';