Skip to content

Instantly share code, notes, and snippets.

View AllThingsSmitty's full-sized avatar

Matt Smith AllThingsSmitty

View GitHub Profile
@AllThingsSmitty
AllThingsSmitty / disable-right-click.js
Created July 28, 2016 23:18
Disable right-click menu
// credit: Louis Lazaris
window.addEventListener('contextmenu', function (e) {
console.log('context menu disabled');
e.preventDefault();
}, false);
document.addEventListener('mouseup', function (e) {
if (e.button === 2) {
console.log('right-click enabled');
}
@AllThingsSmitty
AllThingsSmitty / index.htm
Created April 10, 2015 20:06
Simple responsive table in CSS (no JS)
<table>
<thead>
<tr>
<th>Payment</th>
<th>Issue Date</th>
<th>Amount</th>
<th>Period</th>
</tr>
</thead>
<tbody>
@AllThingsSmitty
AllThingsSmitty / width.css
Created April 6, 2015 13:35
Calculating grid column widths
/*
First: determine the number of columns, ex.: 12
Second: determine the width of a single (1/12) column using the following formula:
scw = (100 – (m * (mc – 1))) / mc
Where:
scw = single column width
m = margin (1.6%)
mc = maximum columns (12)
Ex.: scw = 6.86666666667%
Lastly: use the scw to calculate the rest of the column widths using the following formula:
@AllThingsSmitty
AllThingsSmitty / rainbow.css
Created January 17, 2016 15:21
Animated background color shift
/* based on dbox.us */
body {
background: linear-gradient(238deg, #fd8800, #fd008f, #9700fd, #003dfd, #05c7e6, #4bd58d);
background-size: 1200% 1200%;
-webkit-animation: rainbow 30s ease infinite;
animation: rainbow 30s ease infinite;
}
@-webkit-keyframes rainbow {
0% { background-position: 0% 50% }
50% { background-position: 100% 50% }
@AllThingsSmitty
AllThingsSmitty / js-terms.md
Last active April 21, 2023 04:21
10 terms to help you better understand JavaScript

10 JavaScript Terms You Should Know

From currying to closures there are quite a number of special words used in JavaScript. These will not only help you increase your vocabulary but also better understand JavaScript. Special terms are normally found in documentation and technical articles. But some of them like closures are pretty standard things to know about. Knowing what the word itself means can help you know the concept it's named for better.

  1. Arity
  2. Anonymous
  3. Closure
  4. Currying
  5. Hoisting
  6. Mutation
@AllThingsSmitty
AllThingsSmitty / css-reset.css
Created October 18, 2017 19:54
Snippet for CSS reset
*,
*:before,
*:after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
@AllThingsSmitty
AllThingsSmitty / querySelector.js
Last active August 20, 2022 13:32
Use querySelector with .bind() as a shortcut to familiar function names
// returns first element selected - $('input[name="food"]')
var $ = document.querySelector.bind(document);
// return array of selected elements - $$('img.dog')
var $$ = document.querySelectorAll.bind(document);
// Credit: https://twitter.com/wesbos/status/608341616173182977
@AllThingsSmitty
AllThingsSmitty / apple-mq.css
Last active June 23, 2022 19:56
iPhone 6/6 Plus and Apple Watch CSS media queries
/* iPhone 6 landscape */
@media only screen and (min-device-width: 375px)
and (max-device-width: 667px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2)
{ }
/* iPhone 6 portrait */
@media only screen
and (min-device-width: 375px)
@AllThingsSmitty
AllThingsSmitty / font-awesome-loaded.js
Created April 24, 2016 13:38
Dynamically check if Font Awesome CDN loaded
function css(element, property) {
return window.getComputedStyle(element, null).getPropertyValue(property);
}
window.onload = function () {
var span = document.createElement('span');
span.className = 'fa';
span.style.display = 'none';
document.body.insertBefore(span, document.body.firstChild);