Skip to content

Instantly share code, notes, and snippets.

View hartzis's full-sized avatar

(Brian) Emil Hartz hartzis

View GitHub Profile
@davidtheclark
davidtheclark / isElementInViewport.js
Created May 4, 2013 02:00
JavaScript: Is element in viewport?
/*
No jQuery necessary.
Thanks to Dan's StackOverflow answer for this:
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
*/
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
@natelandau
natelandau / .bash_profile
Last active June 13, 2024 18:01
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@irrationalistic
irrationalistic / parseTweet.js
Created May 29, 2014 20:55
Parse Tweets - Simple
var parseTweet = function(tweetText) {
var reghash, reguri, regusername;
reguri = /(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*))/g;
regusername = /([@]+([A-Za-z0-9-_]+))/g;
reghash = /[#]+([A-Za-z0-9-_]+)/g;
tweetText = tweetText.replace(reguri, "<a href='$1' target='_blank'>$1</a>");
tweetText = tweetText.replace(regusername, "<a href='http://twitter.com/$2' target='_blank'>$1</a>");
tweetText = tweetText.replace(reghash, "<a href='http://twitter.com/search?q=%23$1' target='_blank'>#$1</a>");
return tweetText;
};
var parseTweet = function(tweetText) {
var reghash, reguri, regusername;
reguri = /(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*))/g;
regusername = /([@]+([A-Za-z0-9-_]+))/g;
reghash = /[#]+([A-Za-z0-9-_]+)/g;
tweetText = tweetText.replace(reguri, "<a href='$1' target='_blank'>$1</a>");
tweetText = tweetText.replace(regusername, "<a href='http://twitter.com/$2' target='_blank'>$1</a>");
tweetText = tweetText.replace(reghash, "<a href='http://twitter.com/search?q=%23$1' target='_blank'>#$1</a>");
return tweetText;
};
@hartzis
hartzis / jquery password validation
Created September 5, 2014 15:53
Beautiful password validation from stackexchange, 8 chars, 1 upper, 1 lower, 1 special
// Hold functions related to client side password validation
var password = function () {
var minPasswordLength = 8;
var _hasLowerCase = /[a-z]/;
var _hasUpperCase = /[A-Z]/;
var _hasDigit = /\d/;
var _hasNonWord = /(_|[^\w\d])/;
var password = [];
@paulirish
paulirish / what-forces-layout.md
Last active June 17, 2024 12:46
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@erikcox
erikcox / SimCityLoadingMessages.txt
Created November 11, 2015 21:23
A list of loading messages from the game SimCity, which I repurposed for Slack loading messages.
Adding Hidden Agendas
Adjusting Bell Curves
Aesthesizing Industrial Areas
Aligning Covariance Matrices
Applying Feng Shui Shaders
Applying Theatre Soda Layer
Asserting Packed Exemplars
Attempting to Lock Back-Buffer
Binding Sapling Root System
Breeding Fauna
@andrewtamura
andrewtamura / raven.js
Last active May 10, 2017 18:26
raven wrapper with monkey patch for local logging
var Raven = require('raven');
// Configure the Raven client from the Sentry DSN. For local development, keep this environment variable unset to prevent
// Raven from sending events to sentry
var ravenClient = new Raven.Client(configOptions);
var originalCaptureException = ravenClient.captureException;
// Monkey patch the captureException function for easier development flow.
ravenClient.captureException = function() {
@hartzis
hartzis / Image.jsx
Last active October 4, 2018 06:57
React Universal/Isomorphic Image onError Component
class Image extends Component {
componentDidMount() {
// if image hasn't completed loading, then let react handle error
if (!this._image.complete) return;
// if image has finished loading and has 'errored'(errored when naturalWidth === 0)
// then run the onError callback
if (this._image.naturalWidth === 0) {
this.props.onError();
}
}
@newyankeecodeshop
newyankeecodeshop / ServingES6.md
Last active June 19, 2021 07:36
Serving ES6 to modern browsers

Background

Recently I noticed that Safari 10 for Mac/iOS had achieved 100% support for ES6. With that in mind, I began to look at the browser landscape and see how thorough the support in the other browsers. Also, how does that compare to Babel and its core-js runtime. According to an ES6 compatability table, Chrome, Firefox, and IE Edge have all surpassed what the Babel transpiler can generate in conjunction with runtime polyfills. The Babel/core-js combination achieves 71% support for ES6, which is quite a bit lower than the latest browsers provide.

It made me ask the question, "Do we need to run the babel es2015 preset anymore?", at least if our target audience is using Chrome, Firefox, or Safari.

It's clear that, for now, we can't create a site or application that only serves ES6. That will exclude users of Internet Explorer and various older browsers running on older iOS and Android devices. For example, Safari on iOS 9 has pretty mediocre ES6 support.