Skip to content

Instantly share code, notes, and snippets.

@twalling
twalling / paleo-granola.md
Last active January 29, 2019 19:09
Paleo Granola

Paleo Granola

Ingredients

  • 2 cups sliced almonds
  • 1 cup pecans, chopped
  • 1 cup walnuts, chopped
  • 1 cup shelled pumpkin seeds (pepitas)
  • 1 cup shelled sunflower seeds
  • 1/4 cup ground flax seed or flax seed meal
@paulirish
paulirish / what-forces-layout.md
Last active June 26, 2024 20:47
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
@bencochran
bencochran / gist:5647603
Last active March 5, 2023 21:55
Block, threads, ivars, ARC, yay!
// 1.
// “Safe” but retain cycle.
[self setCompletionBlock:^{
NSLog(@"1: %@", self->_foo);
}];
// 2.
// Unsafe. Could dereference nil.
__weak BCThing *weakSelf = self;
@tbranyen
tbranyen / mixin-events.js
Created September 6, 2012 04:59
Mixin-able events
// Portable & reusable Events object, not too different from what is found
// in Backbone.
//
// (Credits @visionmedia) & Modified from:
// https://raw.github.com/component/emitter/master/index.js
var Events = {
// Cache all callbacks.
callbacks: {},
// Listen on the given `event` with `fn`.
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@tbranyen
tbranyen / extend.js
Created January 18, 2012 22:08
Minimalist extend function
function extend(destination) {
var prop, source;
var index = 0;
var length = arguments.length;
while (++index < length) {
source = arguments[index];
for (prop in source) {
destination[prop] = source[prop];
var elemDisplays = {},
// Store the iframe outside the function to reuse it
iframe,
iframeDoc;
function defaultDisplay( nodeName ) {
if ( !elemDisplays[ nodeName ] ) {
// Try the classical method first, which is far faster
var elem = document.createElement( nodeName ),
display;