Skip to content

Instantly share code, notes, and snippets.

View ricealexander's full-sized avatar

Alex Rice ricealexander

View GitHub Profile
@ricealexander
ricealexander / css_colors.js
Last active April 10, 2023 10:20 — forked from bobspace/css_colors.js
an array that associates CSS color names with their hex values
// CSS Color Names
// Compiled by @bobspace
// Updates by @ricealexander
// added Rebecca Purple
// associates color names with their hex values
// random color and locating a color in the array by its name
const colorValues = [
{hex: "#F0F8FF", name: "AliceBlue"},
@ricealexander
ricealexander / playing_with_grids.js
Last active November 26, 2018 18:05
These snippets build a grid with HTML and associate the cells in a 2-dimensional array
// Inspired by @kokokonotsu
/// https://github.com/kokokonotsu/Cells-and-Grids
const
gridContainer = 'body', // selector for our HTML grid
columnCount = 26, // number of columns
rowCount = 20; // number of rows
// Generate the grid
@ricealexander
ricealexander / system_fonts.css
Last active March 31, 2021 01:56
system fonts across platforms
:root {
--system-sans-serif:
system-ui, /* detect system font automatically */
-apple-system, /* Safari (Mac OS X and iOS) and Older Mac OS X */
BlinkMacSystemFont, /* Chrome<56 (Mac OS X) */
"Segoe UI", /* Windows and Windows Phone */
"Roboto", /* Android and Chrome OS */
"Oxygen", /* KDE - Linux environment */
"Ubuntu", /* Ubuntu - Linux distribution */
"Cantarell", /* GNOME - Linux environment */
@ricealexander
ricealexander / countdown.css
Last active January 8, 2019 21:23
A countdown module
.countdown-container {
font-size: 1rem;
text-align: center;
}
.countdown-group {
display: inline-block;
margin: 0 1em;
}
.countdown-tile {
border-bottom: 2px solid;
const arr1 = ["a","b","c"];
const arr2 = ["d","e","f"];
const arr3 = ["g","h","i"];
// Array.prototype.concat()
const arrayConcat = arr1.concat(arr2).concat(arr3);
// Array.prototype.push() + spread operator
const arrayPush = [];
@ricealexander
ricealexander / click_disk.js
Last active March 11, 2019 19:52
Indicates where a user clicked with a circle that flashes out
// Stylesheet dependency builds custom stylesheets
function Stylesheet(id) {
this.sheet = id;
document.head.insertAdjacentHTML("beforeend", '<style id="'+ this.sheet +'"></style>');
this.add = function(rules) {
document.getElementById(this.sheet).insertAdjacentText("beforeend", rules);
}
};
@ricealexander
ricealexander / generate-1-to-100.js
Last active September 12, 2020 08:09
One liners that generate an array of values from 1 to 100
// As a thought experiment, what is he shortest bit of code that
// can generate an array of numbers from 1 to 100?
// Object.keys
/// when applied to a string, Object.keys returns an array of
/// 0 to the string's length - 1
Object.keys(' '.repeat(100)).map(v => Number(v) + 1)
Object.keys(' '.repeat(100)).map(v => +v + 1)
// Array.from
@ricealexander
ricealexander / tidy-deep-clone.js
Created July 26, 2019 20:32
Creates a deepClone of an object without null, undefined, or empty indexes
// deepCopy from
// https://stackoverflow.com/questions/38416020/deep-copy-in-es6-using-the-spread-syntax#answer-53771927
function tidyCopy(obj) {
if(typeof obj !== 'object' || obj === null) {
return obj;
}
if(obj instanceof Date) {
@ricealexander
ricealexander / regex-plan.md
Last active November 22, 2019 17:58
RegEx lesson plan

I'm going to go over a quick overview of Regular Expressions. I'll try to make the syntax fast, because using them is the fun stuff.

We'll be working with https://regex101.com

What Are RegEx?

RegEx stands for Regular Expression. A Regular Expression is a pattern-matching scheme. We use it to determine whether a string follows certain patterns. We'll often see these used to validate form input, and Single Page Applications may use them to compare the URL with patterns tell it what pages to serve.

@ricealexander
ricealexander / array-quiz.md
Last active November 29, 2019 18:20
Arrays Quiz

(1.) Which of the following are valid arrays (Answer all that apply)

const A = ["Harder", "Better", "Faster", "Stronger"];
const B = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
const C = [
  "Urban Chestnut",
  2009,
  "4Hands",
 2011,