Skip to content

Instantly share code, notes, and snippets.

@iammerrick
iammerrick / LazilyLoad.js
Last active August 7, 2019 14:15
Lazily Load Code Declaratively in React + Webpack
import React from 'react';
const toPromise = (load) => (new Promise((resolve) => (
load(resolve)
)));
class LazilyLoad extends React.Component {
constructor() {
super(...arguments);
@iammerrick
iammerrick / PinchZoomPan.js
Last active February 27, 2024 07:33
React Pinch + Zoom + Pan
import React from 'react';
const MIN_SCALE = 1;
const MAX_SCALE = 4;
const SETTLE_RANGE = 0.001;
const ADDITIONAL_LIMIT = 0.2;
const DOUBLE_TAP_THRESHOLD = 300;
const ANIMATION_SPEED = 0.04;
const RESET_ANIMATION_SPEED = 0.08;
const INITIAL_X = 0;
@redgeoff
redgeoff / index.html
Last active March 30, 2022 06:15
Pinch Zoom And Pan With HammerJS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
<title>Pinch Zoom</title>
</head>
<body>
@paulirish
paulirish / what-forces-layout.md
Last active April 16, 2024 17:32
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
@tegansnyder
tegansnyder / disable mcafee endpoint protection.md
Last active December 26, 2023 03:18
Disable McAffee Endpoint Protection OSX

method 1

sudo /usr/local/McAfee/AntiMalware/VSControl stopoas

alternatively

sudo defaults write /Library/Preferences/com.mcafee.ssm.antimalware.plist OAS_Enable -bool False
sudo /usr/local/McAfee/AntiMalware/VSControl stop
sudo /usr/local/McAfee/AntiMalware/VSControl reload
@gaearon
gaearon / ReduxMicroBoilerplate.js
Last active March 26, 2020 00:35
Super minimal React + Redux app
import React, { Component } from 'react';
import { createStore, combineReducers, applyMiddleware, bindActionCreators } from 'redux';
import { provide, connect } from 'react-redux';
import thunk from 'redux-thunk';
const AVAILABLE_SUBREDDITS = ['apple', 'pics'];
// ------------
// reducers
// ------------
@dgraham
dgraham / fetch.js
Last active March 24, 2023 15:44
Simple window.fetch wrapper.
(function() {
function status(response) {
if (response.ok) {
return response
} else {
var error = new Error(response.statusText || response.status)
error.response = response
throw error
}
}
@wycats
wycats / app.js
Last active February 11, 2016 16:08
App.Router.map(function() {
this.resource('post', { path: '/posts/:post_id' });
});
App.PostRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('post', params.post_id);
}
});
@wycats
wycats / HTMLBars Plan.md
Last active December 18, 2015 15:59
HTMLBars Binding

HTMLBars serves as a polyfill for a native implement of node.bind.

Instead of letting the browser parse the HTML and generate nodes, which leaves us at the mercy of the limitations of the parser, HTMLBars implements an HTML parser and generates the nodes itself.

As HTMLBars generates the nodes, it calls into node.bind if it detects mustache syntax.

Open questions:

  • MDV "syntaxes"
@cobyism
cobyism / gh-pages-deploy.md
Last active April 18, 2024 13:44
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).