Skip to content

Instantly share code, notes, and snippets.

View alemar11's full-sized avatar

Alessandro alemar11

View GitHub Profile
@alemar11
alemar11 / PasteboardWatcher.swift
Created January 22, 2022 16:26 — forked from Daemon-Devarshi/PasteboardWatcher.swift
A class which performs polling to determine the newly copied url of desired kind in an external app
//
// PasteboardWatcher.swift
// PasteboardWatcher
//
// Created by Devarshi Kulshreshtha on 6/19/15.PasteboardWatcher
// Copyright © 2015 Devarshi Kulshreshtha. All rights reserved.
//
import Cocoa
@alemar11
alemar11 / gist:b5dad930b133980874eaf6ec320226ff
Created January 20, 2022 13:48 — 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 |
import Foundation
// Swift translation of https://pspdfkit.com/blog/2016/running-ui-tests-with-ludicrous-speed/
class ConditionTester {
typealias TestCondition = () -> (Bool)
private let condition: TestCondition
private var fulfilled: Bool { return condition() }
private var currentRunLoop: CFRunLoop {
return RunLoop.current.getCFRunLoop()
@alemar11
alemar11 / libdispatch-efficiency-tips.md
Created October 7, 2021 10:11 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

// Bigger iPhones = any Max, any Plus, iPhone XR, iPhone 11
switch (UITraitCollection.current.horizontalSizeClass, UITraitCollection.current.verticalSizeClass) {
case (.compact, .compact):
// Smaller iPhones in landscape
case (.compact, .regular):
// Bigger iPhones in portrait
// iPads in portrait during any split screen,
@alemar11
alemar11 / openssl-build.h
Created July 15, 2021 14:02 — forked from steipete/openssl-build.h
Updated script that builds OpenSSL with Bitcode enabled (tested with Xcode 7.0b3)
#!/bin/bash
# This script downlaods and builds the iOS and Mac openSSL libraries with Bitcode enabled
# Credits:
# https://github.com/st3fan/ios-openssl
# https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh
# Peter Steinberger, PSPDFKit GmbH, @steipete.
set -e
// a.swift
public dynamic func f() {
print("original")
}
// b.swift
import a
@_dynamicReplacement(for: f())
public func f_b() {
@alemar11
alemar11 / gist:2a28acd1b166dd452f81e7abfd8521fc
Created April 27, 2021 08:33 — forked from horseshoe7/gist:e85bbb90278f626bea2f827ee5228703
Incremental MHWMigrationManager extended for optional finalDestinationURL
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class MHWMigrationManager;
@protocol MHWMigrationManagerDelegate <NSObject>
NS_ASSUME_NONNULL_BEGIN
@optional
- (void)migrationManager:(MHWMigrationManager *)migrationManager migrationProgress:(float)migrationProgress;
@import CoreData;
/**
A subclass of NSMigrationManager that is more memory efficient than
NSMigrationManager itself.
This class maintains its own source and destination instance association
tables, which store only the URI representation of the instances's object IDs,
rather than the objects themselves. This means that objects do not accumulate
@alemar11
alemar11 / multiple-deploy-keys-multiple-private-repos-github-ssh-config.md
Created February 22, 2021 11:06 — forked from gubatron/multiple-deploy-keys-multiple-private-repos-github-ssh-config.md
How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent

How to configure multiple deploy keys for different private github repositories on the same computer without using ssh-agent

Let's say alice is a github.com user, with 2 or more private repositories repoN. For this example we'll work with just two repositories named repo1 and repo2

https://github.com/alice/repo1

https://github.com/alice/repo2

You need to be to pull from these repositories without entering a passwords probably on a server, or on multiple servers.