Skip to content

Instantly share code, notes, and snippets.

View ryanve's full-sized avatar
📶
stay free

deepskyblue ryanve

📶
stay free
View GitHub Profile
@paullewis
paullewis / requestIdleCallback.js
Last active February 21, 2024 16:56
Shims rIC in case a browser doesn't support it.
/*!
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@nathansmith
nathansmith / [1] convertToMarkup.js
Last active November 16, 2023 12:43
Handy utilities for dealing with `<div contenteditable="true">` areas.
// Helpers.
import { convertToText } from './';
/*
You would call this when receiving a plain text
value back from an API, and before inserting the
text into the `contenteditable` area on a page.
*/
const convertToMarkup = (str = '') => {
return convertToText(str).replace(/\n/g, '<br>');
@paulirish
paulirish / what-forces-layout.md
Last active April 30, 2024 17:56
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
@DarrenN
DarrenN / get-npm-package-version
Last active April 17, 2024 16:57 — forked from yvele/get-npm-package-version.sh
Extract version from package.json (NPM) using bash / shell
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')
echo $PACKAGE_VERSION
@Phlow
Phlow / for-loop-sorted-collection
Last active April 30, 2024 13:30
This Liquid loop for Jekyll sorts a collection by date in reverse order
{% comment %}
*
* This loop loops through a collection called `collection_name`
* and sorts it by the front matter variable `date` and than filters
* the collection with `reverse` in reverse order
*
* To make it work you first have to assign the data to a new string
* called `sorted`.
*
{% endcomment %}
@cdaringe
cdaringe / grunt-npm-dedupe.js
Created June 29, 2015 01:25
grunt npm dedupe
var spawnSync = require('spawn-sync');
var NODE_ENV = process.env.NODE_ENV;
var production = (NODE_ENV === 'production');
/**
* `npm dedupe` in cwd
* @return {undefined}
*/
var dedupe = function() {
var result;
@STRML
STRML / gist:2117f574726bdf0b8d58
Created June 24, 2015 19:38
Relying on React as an external

The problem:

When writing a React component, you want to target all environments. It is easy to generate a build that will work on the server and browser with Webpack, and as a bonus you can use loaders (like babel-loader for ES6 code).

When you generate this bundle, you should rely on "react" as an external so it isn't included in the bundle. In all environments this is desired behavior so you don't duplicate "react" and break it. This is necessary both because it would make a much larger bundle than necessary, but also because React behaves badly when multiple copies are loaded.

If you do this, you'll end up with a UMD shim like:

(function webpackUniversalModuleDefinition(root, factory) {
@chantastic
chantastic / on-jsx.markdown
Last active March 20, 2024 01:03
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@ryanve
ryanve / .gitconfig
Last active May 11, 2022 09:17
git aliases
[alias]
co = checkout
ci = commit
ca = commit --amend
cia = commit -a
can = commit --amend --no-edit
com = checkout master
st = status
s = status --short
b = branch