Skip to content

Instantly share code, notes, and snippets.

View ShMcK's full-sized avatar

Shawn McKay ShMcK

View GitHub Profile
@Rich-Harris
Rich-Harris / http-apis.md
Last active November 3, 2022 09:02
Next-gen Node HTTP APIs

I saw this poll on Twitter earlier and was surprised at the result, which at the time of writing overwhelmingly favours option 1:

Screen Shot 2020-09-10 at 10 19 22 AM

I've always been of the opinion that the (req, res, next) => {} API is the worst of all possible worlds, so one of two things is happening:

  • I'm an idiot with bad opinions (very possibly!)
  • People like familiarity
@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.

@ShMcK
ShMcK / Atom-Stylesheet.less
Last active June 14, 2016 21:04
Atom Stylesheet with background whitespace grid & styled html properties
// Atom Styles
// theme: one-dark
// syntax: apm install oceanic-next
atom-text-editor,
atom-workspace {
font-family: "Fira Code"; // https://github.com/tonsky/FiraCode
font-size: 14px;
line-height: 1.7;
}
@paulirish
paulirish / what-forces-layout.md
Last active July 17, 2024 00:51
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
@davideast
davideast / index.ts
Created April 15, 2015 17:25
Simple Angular 2 Forms with Firebase
import {bootstrap, Component, Decorator, View, If, For, EventEmitter} from 'angular2/angular2';
import {FormBuilder, Validators, FormDirectives, ControlGroup} from 'angular2/forms';
@Component({
selector: 'app',
injectables: [FormBuilder]
})
@View({
template: `
<div class="container" [control-group]="myForm">
@paulirish
paulirish / bling.js
Last active July 3, 2024 20:45
bling dot js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@james2doyle
james2doyle / parseTwitterDate.js
Created August 4, 2013 17:11
parse the twitter date(created_at) into a nice format.
function parseTwitterDate(tdate) {
var systemDate = new Date(Date.parse(tdate));
var userDate = new Date();
var diff = Math.floor((userDate - systemDate) / 1000);
if (diff <= 1) {return 'just now';}
if (diff < 20) {return diff + ' seconds ago';}
if (diff < 40) {return 'half a minute ago';}
if (diff < 60) {return 'less than a minute ago';}
if (diff <= 90) {return 'one minute ago';}
if (diff <= 3540) {return Math.round(diff / 60) + ' minutes ago';}