Skip to content

Instantly share code, notes, and snippets.

View sethdavis512's full-sized avatar
🤖

Seth Davis sethdavis512

🤖
View GitHub Profile
var ageInput = document.getElementById("age")
ageInput.addEventListener("keydown", function(e) {
// prevent: "e", "=", ",", "-", "."
if ([69, 187, 188, 189, 190].includes(e.keyCode)) {
e.preventDefault();
}
})
function getSafe(fn) {
try {
return fn();
} catch (e) {
return undefined;
}
}
getSafe(() => obj.a.lot.of.properties);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>React Template</title>
<style>
body {
font-family: sans-serif;
font-weight: 100;
}
@sethdavis512
sethdavis512 / Popper.js
Created January 24, 2018 19:25 — forked from ebakan/Popper.js
React Component for Popper.js that takes the reference as its first child and the popper as its second child (a la react-tether)
import React, { Component, PropTypes } from 'react';
import popperJS from 'popper.js';
export default class Popper extends Component {
constructor(props) {
super(props);
this.state = {};
this.update = this.update.bind(this);
}
@sethdavis512
sethdavis512 / visually-hidden.css
Last active March 22, 2018 19:41
Visually hidden to sighted users. Still able to be read by screen readers.
/*
* Hide only visually, but have it available for screen readers:
* https://snook.ca/archives/html_and_css/hiding-content-for-accessibility
*
* 1. For long content, line feeds are not interpreted as spaces and small width
* causes content to wrap 1 word per line:
* https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe
*/
.visuallyhidden {
# Safety First
git branch | grep ‘your_string_here’
# Delete'em
git branch | grep 'your_string_here' | xargs git branch -D
# Delete Remote too
git branch | grep ‘your_string_here’ | xargs git push origin — delete
@sethdavis512
sethdavis512 / replace-char.js
Last active August 4, 2022 06:33 — forked from alisterlf/gist:3490957
Remove Accents
function RemoveAccents(strAccents) {
var strAccents = strAccents.split('');
var strAccentsOut = new Array();
var strAccentsLen = strAccents.length;
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
for (var y = 0; y < strAccentsLen; y++) {
if (accents.indexOf(strAccents[y]) != -1) {
strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1);
} else
const scream = str => str.toUpperCase()
const exclaim = str => `${str}!`
const repeat = str => `${str} ${str}`
const string = 'Egghead.io is awesome'
// Nested
const result2 = repeat(exclaim(scream(string)))
// EGGHEAD.IO IS AWESOME! EGGHEAD.IO IS AWESOME!
// Building-blocks to use for composition
const double = x => x + x;
const triple = x => 3 * x;
const quadruple = x => 4 * x;
// Function composition enabling pipe functionality
const pipe = (...fns) => input => [...fns].reduce((acc, fn) => fn(acc), input);
// Composed functions for multiplication of specific values
const multiply6 = pipe(double, triple);
// Avoid "Cannot read property of undefined"
// https://silvantroxler.ch/2017/avoid-cannot-read-property-of-undefined/
export function getSafe(fn) {
try {
return fn();
} catch (e) {
return undefined;
}
}