Skip to content

Instantly share code, notes, and snippets.

@ewliang
ewliang / px-rem-cheat-sheet.css
Created September 3, 2018 06:17 — forked from glueckpress/px-rem-cheat-sheet.css
Cheat sheet for rem-calculations based upon 14px and 16px.
/*! = $rembase: 14px
--------------------------------------------------------------
* hmtl { font-size: 87.5%; }
* body { font-size: 14px; font-size: 1rem; line-height: 1; }
* 4px 0.28571429rem
* 8px 0.571428571rem
* 12px 0.857142857rem
* 13px 0.928571429rem
* 14px 1rem
* 16px 1.142857143rem
@ewliang
ewliang / CopyToClipboard.js
Created September 25, 2018 16:14
Vanilla JavaScript for creating a button that allows users to copy a hardcoded element's text content.
/* HTML
<p id="text_element">I am the text that the button will allow you to copy.</p>
<button onclick="copyToClipboard('text_element')">
Copy
</button>
*/
function copyToClipboard(elementId) {
// Create an auxiliary hidden input.
// Reason: The hidden aux input will act as a temporary container for our code to select via highlighting and copying since it's easier to do it on an input element.
@ewliang
ewliang / RegEx Expressions.txt
Last active October 19, 2018 18:13
A list of RegEx expressions I made which are tested and works.
Created by Eric Liang
https://www.eric-liang.com
Root Domain Matcher
/(https:\/\/|http:\/\/)?((www.)?([a-z\-]+.))?(([a-z\-]+)(?:\.\w+)+)/i
- Supports with or without http, https, or www. in the front of a domain name.
- Supports long segmented subdomains.
- Supports long suffix domain extensions (e.g. .co.uk).
- Supports any domain roots (e.g. .com, .net, .io, .club, etc.)
@ewliang
ewliang / Useful NPM Commands
Last active June 29, 2020 17:18
Useful npm commands to know for convenience.
// List All Globally Installed NPM Packages on Operating System
npm list -g
npm list -g --depth 0
> By adding "--depth 0", you avoid printing out the globally installed packages' dependencies.
// Update NPM on Windows
npm install -g npm
@ewliang
ewliang / jwtDecoder.js
Created February 28, 2020 17:11
Function for Decoding JWT Tokens to Access JWT Payload via JavaScript (No Library)
// Decodes a JWT with JavaScript
function jwtDecoder(token) {
// 1. Split and Target the Payload Portion of the JWT Token String
// 2. atob() to Decode the JWT's Base64 Encoded String into Readable JSON String
// 3. Convert JSON String to parsable JSON Object
return JSON.parse(atob(token.split('.')[1]));
}