Skip to content

Instantly share code, notes, and snippets.

View jdalton's full-sized avatar

John-David Dalton jdalton

View GitHub Profile
@malte-wessel
malte-wessel / browserify-replace-underscore-with-lodash-globally.md
Last active December 29, 2016 17:22
Replace underscore with lodash globally

If you are using backbone (and backbone.marionette) in a browserify managed project, you will likely run into issues with underscore (at least if you manage your dependencies with npm). Each package, that has underscore as a dependency, will require its own version of underscore (making your bundle file contain multiple versions of underscore). Back in the days, you could shim backbone and underscore like:

browserify({
	shim: {
		'underscore': {
			path: './node_modules/underscore/underscore.js',
			exports: '_'
 },
@kosamari
kosamari / _.R.js
Last active December 7, 2018 11:12
Underscore mixin to enable core R functions
_.mixin({
sum : function(data){
return _.reduce(data, function(memo, num){ return memo + num; }, 0);
},
mean : function(data){
return this.sum(data)/data.length
},
median : function(data){
return this.percentile(data,50);
},
@pilwon
pilwon / test-es6-imports.js
Created March 29, 2015 06:57
Tests if regex matches all valid ES6 import syntaxes. https://github.com/facebook/react-native/pull/386
//
// Tests if regular expression matches all valid ES6 import syntaxes.
//
// ES6 Language Specification Reference:
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-imports
//
const ES6_IMPORT_REGEX = /\bimport\s+(?:.+\s+from\s+)?[\'"]([^"\']+)["\']/g;
const VALID_ES6_IMPORT_SYNTAXES = [
@paulirish
paulirish / gist:43b68a2b6a38ceaaf345
Last active August 4, 2016 11:29
jQuery 3.0 Ideas

Just some early draft thoughts

Increased modularity is a long-standing request of jQuery. 3.0 should deliver on that. Many authors will use jQuery 3.0 in ES6 codebases, and often alongside frameworks that have overlap in functionality.

That said, a majority of developers will use a monolithic build. jQuery 3.0 must aggressively remove API surface area and functionality from this core build to protect developers from performance footguns. The jQuery team has reasonably voiced concern that removing modules means it's less likely for people to upgrade. While some users do attempt jQuery version upgrades, many freeze their version and never revisit it. I'd like to get more data on this phenomenon as I think we're optimizing API deprecation policy for a small audience.

Lastly, it's 2015 and the gap between JavaScript developers and jQuery developers has never been bigger. Let's bridge that gap. We should encourage the developer to use modern DOM APIs (that don't suck) and polyfill as neccessary.

Rem

@paulirish
paulirish / what-forces-layout.md
Last active May 9, 2024 07:00
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
@fcalderan
fcalderan / Jekyll-base64.md
Last active June 24, 2023 19:39
A Base64 image encoder plugin for JekyllRB

#Jekyll Base64 Encoder A Liquid tag for base64 encoding

Note: this plugin requires Colorize:

gem install colorize
#!/usr/bin/env bash
cat $1 | R -rR --slurp \
'unlines' \
'to-lower' \
'match /\w+/g' \
'lodash.uniq' \
'sort-by length' \
'reverse' \
'take 10'
(function () {
var textarea;
function createTextArea() {
if (textarea) {
return textarea;
}
textarea = document.createElement('textarea');
textarea.style.position = 'absolute';
textarea.style.left = '-9999px';
textarea.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
@deathbearbrown
deathbearbrown / accessibility.md
Last active April 27, 2017 20:33
Please be accessible, my dudes.

If you have images and you are showing them on the web using an <img> tag, you must ALWAYS include alt text.

If you are writing markdown, you have no excuse not to add alt text.

![Alt text right here buddy](src)

Doing this is lazy. You're better than that.

![](src)
@bcoe
bcoe / npm-top.md
Last active March 23, 2024 20:02
npm-top.md

npm Users By Downloads (git.io/npm-top)


npm users sorted by the monthly downloads of their modules, for the range May 6, 2018 until Jun 6, 2018.

Metrics are calculated using top-npm-users.

# User Downloads