Skip to content

Instantly share code, notes, and snippets.

View torifat's full-sized avatar
🤒
Why do we even have this here?

Rifat Nabi torifat

🤒
Why do we even have this here?
View GitHub Profile
export function after(
$pos: ResolvedPos,
predicate: (node: Node, pos: number) => boolean
): { $pos: ResolvedPos; node: Node; parent: Node } | null {
let result: { $pos: ResolvedPos; node: Node; parent: Node } | null = null;
$pos.doc.nodesBetween($pos.pos, $pos.doc.content.size, (node, pos, parent) => {
if (pos < $pos.pos) {
// Don't recurse into nodes that are completely before the position we're
// interested in.
if (pos + node.nodeSize < $pos.pos) {

A Redux Story

Developer: "Doo Doo Doo... Working on the new Redux rewrite. Gotta write some fetch actions..."

FETCH_USERS -> function fetchUsersAction() {...}
FETCH_PAGES -> function fetchPagesAction() {...}
FETCH_FRIENDS -> function fetchFriendsAction() {...}
FETCH_GROUPS -> function fetchGroupsAction() {...}
FETCH_EVENTS -> function fetchEventsAction() {...}
@bvaughn
bvaughn / index.md
Last active April 3, 2024 07:41
Interaction tracing with React

This API was removed in React 17


Interaction tracing with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.

@samhatoum
samhatoum / chrome-driver-troubleshooting.sh
Last active November 8, 2019 10:05
Troubleshoot / Debug Chromedriver Issues
# First start chromedriver from the console like this
chromedriver --url-base=wd/hub --verbose
# Then in another tab / window: issue a command to start a new chrome session via the JSON protocol
curl -XPOST http://localhost:9515/wd/hub/session -d '{"desiredCapabilities":{"browserName":"chrome"}}'
# If you can see a chrome window pop up, you're all set. If not, check the chromedriver output and fix your issue
@bmeurer
bmeurer / destructuring-performance-test.js
Last active November 17, 2016 06:09
Destructuring performace (V8 ToT 2016/11/16)
/////////////////////////////////////////////////////////////////////////////
// Test framework:
// Warmup
for (var i = 0; i < 1000; ++i) test(data);
function time(test, a) {
let startTime = Date.now();
// Using F.p.apply here to prevent inlining, so we can really
// just measure the performance of test stand-alone.

Input

function example(obj: { prop: string | number }): string {
  if (typeof obj.prop === 'string') {
    mutatesProp(obj);
    return obj.prop;
  } else {
    return "default";
 }
@MoOx
MoOx / package.json.js
Last active June 26, 2022 22:18
Boost your Webpack performance with DLLPlugin (will bundle as dll all your "dependencies", see comment in package.json)
{
"private": true,
// ...
"#dependencies": "dependencies are the one shipped to the client",
"dependencies": {
"babel-polyfill": "^6.7.4",
"react": "^15.0.0",
// ...
"whatwg-fetch": "^0.11.1"
},
@Rich-Harris
Rich-Harris / service-workers.md
Last active April 21, 2024 16:24
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@mirague
mirague / CustomComponent-test.js
Last active November 9, 2021 09:32
Testing React-Intl components with Enzyme's mount() and shallow() methods. This is a helper function which wraps the `intl` context around your component tests in an easy and efficient way.
import { mountWithIntl } from 'helpers/intl-enzyme-test-helper.js';
const wrapper = mountWithIntl(
<CustomComponent />
);
expect(wrapper.state('foo')).to.equal('bar'); // OK
expect(wrapper.text()).to.equal('Hello World!'); // OK
@sibelius
sibelius / Codemod RN24 to RN25.md
Last active November 9, 2016 13:09
Codemod React Native 24 imports to RN25 imports

README

Why this transform is necessary?

Until React Native 24, you import React from 'react-native' package, but this will change on RN 25, you will need to import React from 'react'. You probably have many files that does this, so I've created a codemod to save you a bunch of time

How to use this

  • Install jscodeshif