Skip to content

Instantly share code, notes, and snippets.

View r3b's full-sized avatar

ryan bridges r3b

  • Atlanta, Georgia
View GitHub Profile
@r3b
r3b / accessibleImages.js
Created December 14, 2021 15:09
Highlight images without ALT attributes
(function() {
const style = document.createElement("style");
style.setAttribute("media", "screen")
document.head.appendChild(style);
const sheet = style.sheet;
sheet.insertRule(`img[alt=""], img[alt="Alt Text"], img:not([alt]):not([role*="presentation"]){border:2px dashed red;}`)
sheet.insertRule(`img[role*="presentation"], img[role*="none"]{border:2px solid blue;}`)
})();
@r3b
r3b / test.js
Created December 11, 2020 17:36
easter egg
const expected = [
'ArrowUp',
'ArrowDown',
'ArrowUp',
'ArrowDown',
'ArrowLeft',
'ArrowRight',
'ArrowLeft',
'ArrowRight',
'a',
@r3b
r3b / tabmenu.html
Last active August 2, 2019 20:34
Tabbable menu #javascript #html
<html>
<head>
<style>
.menu-submenu, .menu-submenu-open{
position:relative;
list-style-type: none;
}
.menu-submenu:before{
content: '\21e8';
@r3b
r3b / ng.sh
Last active February 28, 2020 20:26
Create angular modules and components
ng generate module common -m app
ng generate service common/authentication
ng generate guard common/authentication
ng generate module QuantityAdjustments -m app --routing
ng generate component quantity-adjustments/QuantityAdjustmentsItem -m quantity-adjustments --force --prefix=rpm --flat
ng generate component quantity-adjustments/QuantityAdjustmentsList -m quantity-adjustments --force --prefix=rpm --flat
ng generate component quantity-adjustments/QuantityAdjustments -m quantity-adjustments --force --prefix=rpm --flat
@r3b
r3b / pullAll.sh
Created December 7, 2018 15:17
iterate over directories and perform git pull on each
for i in $(find . -type d -name '.git');
do dirname $i;
echo "$(
cd $(dirname $i);
git pull;
cd -
)";
done;
const flatten = object => {
return Object.assign( {}, ...function _flatten( objectBit, path = '' ) { //spread the result into our return object
return [].concat( //concat everything into one level
...Object.keys( objectBit ).map( //iterate over object
key => typeof objectBit[ key ] === 'object' ? //check if there is a nested object
_flatten( objectBit[ key ], `${ path }/${ key }` ) : //call itself if there is
( { [ `${ path }/${ key }` ]: objectBit[ key ] } ) //append object with it’s path as key
)
)
}( object ) );
@r3b
r3b / phone.js
Last active May 30, 2017 18:47
US phone number formatter
(function (app) {
"use strict";
function format_nanp(num) {
return num
.replace(/[^0-9]/g, '')
.replace(/^\+?1?(\d{1,3})(\d{0,3})(\d{0,4})(.*)/, function replacer(
match,
p1, p2, p3, p4, offset, string) {
return `(${p1}) ${p2}-${p3}` + ((p4) ? ' ext. ' + p4 : '');
@r3b
r3b / bitmask.js
Created May 25, 2017 20:14
ES5 Bitmask
function Bitmask(value) {
function parse(value){
return Number(parseInt(value)||0);
}
return Object.create({}, {
_value: {
value: parse(value),
enumerable: false,
configurable: false,
writable: true
@r3b
r3b / enum.js
Created May 25, 2017 19:21
ES5 ENUM implementation
function ENUM(){
return Object.create({}, {
add: {
value: function (name) {
name = name.replace(/\s/, '_').replace(/\W/, '').toUpperCase();
var ptr = this;
Object.defineProperty(ptr, name, {
enumerable: true,
configurable: false,
writable: false,
@r3b
r3b / colors.sh
Created May 22, 2015 20:59
Handy bash snippets
# Colorize your script output like it's 1985
clrd() [ $# -lt 3 ]&& echo "Usage: $0 COLOR BOLD message\n" || printf "\033[%d;%dm%s\033[0;0m" $2 $1 "${@:3}"}
# echo with feeling
bold() { local MSG=$@;echo -e $(clrd 33 1 ">") $(clrd 30 1 "$MSG"); }
# Make a repeating string of characters
make_str() { [[ -z $2 ]] && $2="*"; [[ -z "$1" || "$1" -lt 1 ]] && echo || { echo -n "$2"; make_str $(( $1-1 )) "$2"; }; }