stopBefore(document, 'getElementById')
stopBefore('document.getElementById') // the same as the previous
stopBefore(Element.prototype, 'removeChild')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES7, async/await | |
function sleep(ms = 0) { | |
return new Promise(r => setTimeout(r, ms)); | |
} | |
(async () => { | |
console.log('a'); | |
await sleep(1000); | |
console.log('b'); | |
})() |
The fun part of user scripting is deciding what happens. The boring part is scavenging the DOM for bits of templated data, or elements you want to mod.
Have on.js
do it for you!
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
Compress 1K bytes with Zippy ............. 3,000 ns = 3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs
SSD random read ........................ 150,000 ns = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# adds 'brew refresh' as an external command, which essentially does | |
# 'brew update' followed by 'brew outdated' | |
# | |
require 'update' | |
def outdated | |
outdated_brews.each do |keg, name, version| | |
if $stdout.tty? and not ARGV.flag? '--quiet' | |
versions = keg.cd{ Dir['*'] }.join(', ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Small utility which uses the homepage and nokogori to get a description from the formula's homepage. | |
# | |
# As written in the homebrew wiki: | |
# > Homebrew doesn’t have a description field because the homepage is always up to date, | |
# > and Homebrew is not. Thus it’s less maintenance for us. To satisfy the description | |
# > we’re going to invent a new packaging microformat and persuade everyone to publish | |
# > it on their homepage. | |
# | |
# Too bad no packaging microformat has yet been invented, but brew-more just first looks for a | |
# `<meta name="description">` tag, then for an `a#project_summary_link` tag (which is used in |