Skip to content

Instantly share code, notes, and snippets.

View sindresorhus's full-sized avatar

Sindre Sorhus sindresorhus

View GitHub Profile
@sindresorhus
sindresorhus / NSControl+Extension.swift
Created August 25, 2017 03:11
[Alternative] NSControl extension for closure version of `.action`
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 / issuehunt-bounties.md
Last active July 5, 2019 08:51
IssueHunt bounties
@sindresorhus
sindresorhus / jquery.touchhover.js
Created October 11, 2011 12:58
jQuery plugin - Adds a .hover class on click on touch devices. Which will make it easier to use :hover and still support touch devices.
$.fn.touchHover = function() {
return 'ontouchstart' in document.documentElement ? this.click(function() {
$(this).toggleClass('hover');
}) : this;
};
/*
Example: $('.button').touchHover();
You also need to add .hover to your :hover CSS rules:
.button:hover -> .button:hover, .button.hover
*/
@sindresorhus
sindresorhus / github-email.sh
Created January 11, 2013 17:46
Magically retrieves a GitHub users email even though it's not publicly shown
#!/bin/bash
# Created by Sindre Sorhus
# Magically retrieves a GitHub users email even though it's not publicly shown
[ "$1" = "" ] && echo "usage: $0 <GitHub username> [<repo>]" && exit 1
[ "$2" = "" ] && repo=`curl "https://api.github.com/users/$1/repos?type=owner&sort=updated" -s | sed -En 's|"name": "(.+)",|\1|p' | tr -d ' ' | head -n 1` || repo=$2
curl "https://api.github.com/repos/$1/$repo/commits" -s | sed -En 's|"(email\|name)": "(.+)",?|\2|p' | tr -s ' ' | paste - - | sort -u -k 1,1
@sindresorhus
sindresorhus / EmptyInitializable.swift
Created January 7, 2020 09:40
A type that can be initialized without any parameters.
/// Types that can be initialized without any parameters.
/// Useful if you need to accept an array of metatypes and then initialize them.
protocol EmptyInitializable {
init()
}
extension Int: EmptyInitializable {}
extension Int8: EmptyInitializable {}
extension Int16: EmptyInitializable {}
extension Int32: EmptyInitializable {}
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 / package.json
Last active March 23, 2020 19:54
my package.json template. put it into Dash.app. enjoy ;)
{
"name": "__name__",
"version": "0.0.0",
"description": "",
"license": "MIT",
"repository": "sindresorhus/__name__",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com"
@sindresorhus
sindresorhus / NSControl+Extension.swift
Last active June 13, 2020 06:50
NSControl extension for closure version of `.action`
enum AssociationPolicy {
case assign
case retainNonatomic
case copyNonatomic
case retain
case copy
var rawValue: objc_AssociationPolicy {
switch self {
case .assign:
@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 / MenuBarApp.swift
Last active July 18, 2020 14:52
Dream API for macOS menu bar apps
@main
struct MyApp: App {
var body: some Scene {
StatusBar {
StatusItem(id: "foo", systemImage: "gear") {
Menu {
Button("Toggle") {}
Divider()
Button("Quit") {}
}