Skip to content

Instantly share code, notes, and snippets.

@paulirish
paulirish / what-forces-layout.md
Last active June 11, 2024 07:58
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
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@johnnyclem
johnnyclem / gist:11015360
Created April 17, 2014 22:35
CMSamplebufferRef to CIImage
CVImageBufferRef cvImage = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:cvImage];
@fent
fent / youtube_next.applescript
Last active May 13, 2022 00:49
Scripts for controlling youtube videos. Now maintained at https://github.com/fent/dotfiles/tree/master/scripts
# If in a playlist, play the next video.
tell application "Google Chrome"
repeat with t in tabs of windows
tell t
if URL starts with "http://www.youtube.com/watch" or URL starts with "https://www.youtube.com/watch" then
execute javascript "
var player =
document.getElementById('movie_player') ||
document.getElementsByTagName('embed')[0];
var next = document.getElementsByClassName('yt-uix-button-icon-playlist-bar-next')[0];
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active June 10, 2024 09:43
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@dannycroft
dannycroft / exclude-node-modules
Last active February 27, 2019 18:25
Exclude node_modules out of Sublime Text 2 searches
// Add the following to your preferences file
"folder_exclude_patterns":[".git","node_modules"]
@jadeatucker
jadeatucker / HOWTODMG.md
Last active May 29, 2024 21:16
How to create a "DMG Installer" for Mac OS X

Creating a "DMG installer" for OS X

A DMG Installer is convenient way to provide end-users a simple way to install an application bundle. They are basically a folder with a shortcut to the Applications directory but they can be customized with icons, backgrounds, and layout properties. A DMG file (.dmg) is a Mac OS X Disk Image file and it is used to package files or folders providing compression, encryption, and read-only to the package.

##Creating the DMG file #Disk Utility

@potch
potch / README.md
Last active June 6, 2022 10:54
Path data generation helper for SVG <path> elements

SVG path data generator

This is excerpted from my work on emilio.js, a d3 plotting library, but useful enough to stand on its own.

  • Generators are constructed with new Path().
  • Takes two optional arguments, xScale and yScale.
    • Methods for coordinate space translation.
    • Works great with d3.scale() objects!
    • xScale and yScale affect the x and y coordinate spaces, respectively.
  • If only xScale is supplied, y values will be in the xScale space.
@rnapier
rnapier / fix-xcode
Last active March 18, 2022 01:17
Links Xcode SDKs from the /SDKs directory (which you maintain yourself)
#!/usr/bin/python
# fix-xcode
# Rob Napier <robnapier@gmail.com>
# Script to link in all your old SDKs every time you upgrade Xcode
# Create a directory called /SDKs (or modify source_path).
# Under it, put all the platform directories:
# MacOSX.platform iPhoneOS.platform iPhoneSimulator.platform
# Under those, store the SDKs:
@jboner
jboner / latency.txt
Last active June 11, 2024 07:09
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD