Skip to content

Instantly share code, notes, and snippets.

View AstroMash's full-sized avatar
🛸

Matt Shultz AstroMash

🛸
  • Pedago, LLC
  • Clinton, MS
View GitHub Profile
@AstroMash
AstroMash / regularize.css
Created January 1, 2024 23:37
CSS Reset & Normalize
@charset "UTF-8";
/* Reset box-model and set borders */
/* ============================================ */
*,
::before,
::after {
box-sizing: border-box;
border-style: solid;
border-width: 0;
}
@AstroMash
AstroMash / pSBC.js
Last active April 10, 2023 14:18
Programmatically lighten or darken colors
// Version 4.0
// StackOverflow question that spawned pSBC
// ↳ https://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color-or-rgb-and-blend-colors
// Full writeup by author
// ↳ https://github.com/PimpTrizkit/PJs/wiki/12.-Shade,-Blend-and-Convert-a-Web-Color-(pSBC.js)
const pSBC=(p,c0,c1,l)=>{
let r,g,b,P,f,t,h,i=parseInt,m=Math.round,a=typeof(c1)=="string";
if(typeof(p)!="number"||p<-1||p>1||typeof(c0)!="string"||(c0[0]!='r'&&c0[0]!='#')||(c1&&!a))return null;
if(!this.pSBCr)this.pSBCr=(d)=>{
@AstroMash
AstroMash / style.css
Created April 10, 2021 00:21
Minimal CSS Reset
* {
margin: 0;
padding: 0;
}
*,
*::after,
*::before {
box-sizing: inherit;
}
@AstroMash
AstroMash / styles.css
Last active April 6, 2023 01:46
System font stack
body {
font-family: -apple-system, /* (San Francisco) iOS Safari, macOS Safari, macOS Firefox. (San Francisco) iOS Safari, macOS Safari, macOS Firefox */
BlinkMacSystemFont, /* (San Francisco) macOS Chrome */
"Segoe UI", /* Windows */
Roboto, /* Android, Chrome OS */
Helvetica, /* Any */
Arial, /* Any */
sans-serif, /* Any */
"Apple Color Emoji", /* Emojis */
"Segoe UI Emoji", /* Emojis */
@AstroMash
AstroMash / rgbToHex.js
Last active August 25, 2020 00:29
Convert RGB to Hex
function rgb(r, g, b){
return toHex(r) + toHex(g) + toHex(b);
}
function toHex(numb) {
if (numb <= 0) return '00';
if (numb > 255) return 'FF';
return numb.toString(16).toUpperCase();
}
@AstroMash
AstroMash / fullYear.js
Last active August 25, 2020 00:30
Shortest way to print year in JS
document.write(new Date().getFullYear())
function Tree(size, leaves) {
this.size = (typeof size === "undefined")? 10 : size;
const defaultLeaves = {spring: 'green', summer: 'green', fall: 'orange', winter: null};
this.leaves = (typeof leaves === "undefined")? defaultLeaves : leaves;
this.leafColor;
}
Tree.prototype.changeSeason = function(season) {
this.leafColor = this.leaves[season];
if (season === 'spring') {
@AstroMash
AstroMash / gist:9350d302bc21ed5c4057d09a77236a4e
Created May 25, 2018 02:33
Convert NodeLists to Arrays
// Helper function to convert NodeLists to Arrays
function slice(nodes) {
return Array.prototype.slice.call(nodes);
}
// Example usage
this.buttons = slice(this.el.querySelectorAll('.radio'));
// Shuffle function from http://stackoverflow.com/a/2450976
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;