Skip to content

Instantly share code, notes, and snippets.

🦄
I currently have a lot of PRs to review. I promise I'll get to yours eventually.

Sindre Sorhus sindresorhus

  • ʵ̎̐ˡ̐̎ʵ̎̐ˌ̐̎̐ ˌ̐̎ˌ̎̐̎ˌ̐̎̐̎ˌ̎̐̎ˌ̐̎ˌ̎ ˌ̎̐̎ˌ̐̎̐̎ˌ̎̐̎̐ˌ̐̎̐̎̐ˌ̎̐̎̐̎̐ˌ̐̎̐̎̐ˌ̎̐̎̐ˌ̐̎̐̎ˌ̎̐̎ ʵ̎̐ˌ̎̎̎̐ʵ̎̐ʵ̐̎̐ˡʵ̎̐ˡ̐̎ʵ̎̐ˌ̎̎̎̐ʵ̎̐ʵ̐̎̐ˡˈ̎̐̎ʵ̎̐ˡ̐̎ʵ̎̐ˌ̐̎̐ ˌ̐̎ˌ̎̐̎ˌ̐̎̐̎ˌ̎̐̎ˌ̐̎ˌ̎ ˌ̎̐̎ˌ̐̎̐̎ˌ̎̐̎̐ˌ̐̎̐̎̐ˌ̎̐̎̐̎̐ˌ̐̎̐̎̐ˌ̎̐̎̐ˌ̐̎̐̎ˌ̎̐̎ ʵ̎̐ˌ̎̎̎̐ʵ̎̐ʵ̐̎̐ˡʵ̎̐ˡ̐̎ʵ̎̐ˌ̎̎̎̐ʵ̎̐ʵ̐̎̐ˡˈ̎̐̎
  • ⎹⎹⎸⎸⎸⎹⎸⎹⎸⎹⎸⎹⎸⎹⎹⎸⎸⎹⎹⎸⎸⎹⎹⎸⎸⎸⎹⎸⎹⎸⎸⎸⎸⎹⎸⎹⎸⎹⎸⎹⎸⎹⎹⎸⎸⎹⎹⎸⎹⎸⎹⎸⎹⎹⎸⎸⎹⎸⎸⎸⎹⎸⎹⎸⎹⎸⎹⎸⎸⎸⎹⎸⎸⎹⎸⎹⎸⎹⎸⎹⎸⎸⎸⎹⎹⎸⎹⎸⎹⎸⎹⎸⎹⎸⎹⎹⎸⎸⎹⎹⎸⎸⎹⎹⎸⎸⎹⎹⎸⎹⎸⎸⎸⎹⎹⎸⎸⎸⎹⎸⎹⎸⎹⎹⎸⎸⎸⎹⎹⎸⎹⎸⎸⎸⎸⎸⎹⎹⎸⎸
  • Sign in to view email
View GitHub Profile
View puppeteer-with-adblock.js
'use strict';
const puppeteer = require('puppeteer');
(async () => {
/* PRECONDITION:
0. download ublock, I used https://github.com/gorhill/uBlock/releases/download/1.14.19b5/uBlock0.chromium.zip
1. run $PATH_TO_CHROME --user-data-dir=/some/empty/directory --load-extension=/location/of/ublock
2. enable block lists you want to use
*/
@sindresorhus
sindresorhus / libdispatch-efficiency-tips.md
Created Feb 1, 2019 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)
View libdispatch-efficiency-tips.md

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are:

  • You should have very few queues that target the global pool. If all these queues are active at once, you will get as many threads running. These queues should be seen as execution contexts in the program (gui, storage, background work, ...) that benefit from executing in parallel.
View keybase.md

Keybase proof

I hereby claim:

  • I am sindresorhus on github.
  • I am sindresorhus (https://keybase.io/sindresorhus) on keybase.
  • I have a public key whose fingerprint is 9167 E91F 3DA4 65D0 020A 48B3 5A35 FFDB 8B07 983A

To claim this, I am signing this object:

View EmptyInitializable.swift
/// Types that can be initialized without any parameters
protocol EmptyInitializable {
init()
}
extension Int: EmptyInitializable {}
extension Int8: EmptyInitializable {}
extension Int16: EmptyInitializable {}
extension Int32: EmptyInitializable {}
extension Int64: EmptyInitializable {}
@sindresorhus
sindresorhus / dividable.swift
Created Oct 17, 2017 — forked from moiseev/dividable.swift
If you really really miss the `/` from `Numeric`...
View dividable.swift
public protocol Dividable {
static func / (lhs: Self, rhs: Self) -> Self
}
extension Int : Dividable {}
extension Double : Dividable {}
extension Sequence where Element : Numeric & Dividable {
func average() -> Element {
var i: Element = 0
@sindresorhus
sindresorhus / average.swift
Last active Oct 17, 2017 — forked from fcanas/average.swift
Abstracted average function in Swift
View average.swift
extension Sequence where Element: ExpressibleByIntegerLiteral {
private func abstractAverage<T>(sum: (T, T) -> T, div: (T, T) -> T) -> T where Element == T {
var i: T = 0
var total: T = 0
for value in self {
total = sum(total, value)
i = sum(i, 1)
}
@sindresorhus
sindresorhus / NSControl+Extension.swift
Created Aug 25, 2017
[Alternative] NSControl extension for closure version of `.action`
View NSControl+Extension.swift
class SelectorWrapper<T> {
let selector: Selector
let closure: (T) -> Void
init(withClosure closure: @escaping (T) -> Void) {
self.selector = #selector(callClosure)
self.closure = closure
}
@objc
@sindresorhus
sindresorhus / NSControl+Extension.swift
Created Aug 24, 2017
NSControl extension for closure version of `.action`
View NSControl+Extension.swift
extension NSControl {
typealias ActionClosure = ((NSControl) -> Void)
private struct AssociatedKeys {
static let onActionClosure = AssociatedObject<ActionClosure>()
}
@objc
private func callClosure(_ sender: NSControl) {
onAction?(sender)
You can’t perform that action at this time.