Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sindresorhus's full-sized avatar
🌴
On vacation

Sindre Sorhus sindresorhus

🌴
On vacation
View GitHub Profile
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 {
'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 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.
@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 / 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 / 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 |
@sindresorhus
sindresorhus / TrueColour.md
Created January 17, 2017 11:46 — forked from XVilka/TrueColour.md
True Colour (16 million colours) support in various terminal applications and terminals

Colours in terminal

It's a common confusion about terminal colours... Actually we have this:

  • plain ascii
  • ansi escape codes (16 colour codes with bold/italic and background)
  • 256 colour palette (216 colours + 16 ansi + 24 gray) (colors are 24bit)
  • 24bit true colour ("888" colours (aka 16 milion))
printf "\x1b[${bg};2;${red};${green};${blue}m\n"
@sindresorhus
sindresorhus / .profile
Created April 6, 2016 11:10 — forked from bmhatfield/.profile
Automatic Git commit signing with GPG on OSX
# In order for gpg to find gpg-agent, gpg-agent must be running, and there must be an env
# variable pointing GPG to the gpg-agent socket. This little script, which must be sourced
# in your shell's init script (ie, .bash_profile, .zshrc, whatever), will either start
# gpg-agent or set up the GPG_AGENT_INFO variable if it's already running.
# Add the following to your shell init to set up gpg-agent automatically for every shell
if [ -f ~/.gnupg/.gpg-agent-info ] && [ -n "$(pgrep gpg-agent)" ]; then
source ~/.gnupg/.gpg-agent-info
export GPG_AGENT_INFO
else
//<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'),