Skip to content

Instantly share code, notes, and snippets.

View sindresorhus's full-sized avatar

Sindre Sorhus sindresorhus

View GitHub Profile
//<editor-fold desc="Node Requires, gulp, etc">
var gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
clean = require('gulp-clean'),
concat = require('gulp-concat'),
csso = require('gulp-csso'),
debug = require('gulp-debug'),
footer = require('gulp-footer'),
gutil = require('gulp-util'),
gzip = require('gulp-gzip'),

Strict Mode: The Summary!

Identifiers (variables, functions) cannot be named any of these: "implements", "interface", "let", "package", "private", "protected", "public", "static", and "yield"

OctalLiterals are not allowed.

@sindresorhus
sindresorhus / average.swift
Last active October 17, 2017 10:56 — forked from fcanas/average.swift
Abstracted average function in 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 / dividable.swift
Created October 17, 2017 11:07 — forked from moiseev/dividable.swift
If you really really miss the `/` from `Numeric`...
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 / libdispatch-efficiency-tips.md
Created February 1, 2019 02:46 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

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.
import Combine
import SwiftUI
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
@propertyWrapper
public struct Model<Value>: DynamicProperty {
private final class _Box: ObservableObject {
let objectWillChange = ObservableObjectPublisher()
var value: Value {
@sindresorhus
sindresorhus / more-mute-regex.md
Created October 18, 2012 08:14 — forked from jimmynotjim/more-mute-regex.md
Tweetbot can use regular expressions to mute tweets in your timeline and mentions.

##Simply annoying Tweets

Annoyingly extended words (4+ of the same letter in a phrase): OOOOHHHHMMMMYYYYGGGGOOOODDDD

([a-z])/1{4}

Tweet w/ just a single hashtag: #omgthissucks

^ *#[^ ]+$
@sindresorhus
sindresorhus / LICENSE.txt
Created March 7, 2012 13:34 — forked from 140bytes/LICENSE.txt
stripScripts - Strip script tags from an HTML string (140byt.es)
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2012 Sindre Sorhus <http://sindresorhus.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@sindresorhus
sindresorhus / Rakefile
Created July 2, 2017 00:18 — forked from soffes/Rakefile
Programmatically build and sign a Developer ID macOS app
APP_NAME = 'My App'
TEAM_ID = 'XXXXXXXXXX'
desc 'Create a beta build'
task :build do
# Start with a clean state
build_dir = 'build'
system %(rm -rf #{build_dir})
# Build
@sindresorhus
sindresorhus / gist:23c3e88c7685d77b95a8c380d08cbd45
Created March 4, 2017 17:35 — forked from vilhalmer/gist:3052f7e9e7f34b92a40f
NSVisualEffectView undocumentation
NSVisualEffectMaterial constants, and the undocumented materials they coorespond to in various modes:
+----------------------+-------+----------+------+---------+
| MATERIAL # | LIGHT | LIGHT EM | DARK | DARK EM |
+----------------------+-------+----------+------+---------+
| | | | | |
| 0 - Appearance Based | 3 | 3 | 5 | 5 |
| | | | | |
| 1 - Light | 3 | 3 | 3 | 3 |
| | | | | |
| 2 - Dark | 4 | 4 | 4 | 4 |