Skip to content

Instantly share code, notes, and snippets.

View AllThingsSmitty's full-sized avatar

Matt Smith AllThingsSmitty

View GitHub Profile
@AllThingsSmitty
AllThingsSmitty / readyState.js
Last active March 9, 2016 19:59
Using readyState to show document state
// credit: Louis Lazaris
document.onreadystatechange = function () {
switch (document.readyState) {
case 'loading':
console.log('loading...');
break;
case 'interactive':
console.log('DOM is ready...');
break;
case 'complete':
@AllThingsSmitty
AllThingsSmitty / preload.htm
Created February 12, 2016 15:21
Async CSS w/ link[rel=preload]
<link rel="preload" href="http://scottjehl.com/css-temp/slow.php" as="style" onload="this.rel='stylesheet'">
<!-- Ref: http://filamentgroup.github.io/loadCSS/test/preload.html -->
@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 / toggle-css-script-on-off.js
Created November 15, 2015 19:39
Disable/enable a stylesheet or script
// Use the Boolean `disabled` attribute
myCSS.disabled = true;
myJS.disabled = true;
// Create a stylesheet toggle button:
var stylesheet = document.getElementById('boot'),
btn = document.querySelector('.btn');
btn.addEventListener('click', function () {
stylesheet.disabled = (stylesheet.disabled === false) ? true : false;
@AllThingsSmitty
AllThingsSmitty / touch-icons.htm
Last active September 22, 2016 06:49
Which touch-icon sizes to use for mobile
<!-- https://mathiasbynens.be/notes/touch-icons#sizes -->
<!-- For the iPad mini and the first- and second-generation iPad (@1× display) on iOS ≤ 6: -->
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72-precomposed.png">
<!-- For the iPad mini and the first- and second-generation iPad (@1× display) on iOS ≥ 7: -->
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="apple-touch-icon-76x76-precomposed.png">
<!-- For iPhone with @2× display running iOS ≤ 6: -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114-precomposed.png">
<!-- For iPhone with @2× display running iOS ≥ 7: -->
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="apple-touch-icon-120x120-precomposed.png">
@AllThingsSmitty
AllThingsSmitty / live-code.css
Created August 27, 2015 13:08
Making an entire live-code-enabled presentation
<style contenteditable>
* {
display: block;
}
</style>
@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 / truncate.js
Last active November 29, 2015 14:29
Apply ellipsis to the end of content that has more than 300 characters
if (content.length > 300) {
// truncate to a shorter text length
return content.substring(0, 200) + '...';
}
@AllThingsSmitty
AllThingsSmitty / palindrome.js
Last active November 29, 2015 14:29
Determine if a given string is a palindrome
var input_str = 'madam';
function checkIfPalindrome(str) {
if (str == str.split('').reverse().join('')) {
alert('Yup, ' + str + 'is a palindrome');
} else {
alert('Nope, ' + str + ' isn\'t a palindrome');
}
}
@AllThingsSmitty
AllThingsSmitty / sub-array-sum.js
Last active November 15, 2015 14:36
Given an array of integers (positive or negative) find the sub-array with the largest sum
var list = [
2, -4,
6, -9, [8, 9, -6],
12, [45, 3, 7], -34, [7, -2]
];
sublists = [];
sublists_sum = [];
for (var i in list) {
if (Object.prototype.toString.call(list[i]) == '[object Array]') {