Skip to content

Instantly share code, notes, and snippets.

View alvarhansen's full-sized avatar

Alvar Hansen alvarhansen

View GitHub Profile
OTHER_SWIFT_FLAGS_ENABLE_PREVIEWS_YES = "-DENABLE_PREVIEWS"
OTHER_SWIFT_FLAGS_ENABLE_PREVIEWS_NO = ""
OTHER_SWIFT_FLAGS_ENABLE_PREVIEWS = $(OTHER_SWIFT_FLAGS_ENABLE_PREVIEWS_$(ENABLE_PREVIEWS))

Cool. But not usable as Xcode editor does set ENABLE_PREVIEWS build flag, so all errors are missing in editor, which makes it hard to use.

In theory, could be useful when you want to exclude something during debug build that is not in active preview.

@alvarhansen
alvarhansen / libdispatch-efficiency-tips.md
Created July 26, 2021 19:40 — 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

import Foundation
print(URL(string: "http:\\adsdasipaguneriougneri.uifwiuhfweiuhwefiu"))
print(URL(string: "http://adsdasipaguneriougneri.uifwiuhfweiuhwefiu"))
import CryptoSwift
import Foundation
// Combined from https://github.com/lachlanbell/SwiftOTP/blob/master/SwiftOTP/Generator.swift and https://raw.githubusercontent.com/vapor/open-crypto/3.3.3/Sources/Crypto/MAC/OTP.swift
// MARK: TOTP
/// Generates Time-based One-time Passwords using HMAC.
///
@alvarhansen
alvarhansen / Withable.swift
Created February 5, 2019 08:06 — forked from nicklockwood/Withable.swift
Withable.swift
/// Withable is a simple protocol to make constructing
/// and modifying objects with multiple properties
/// more pleasant (functional, chainable, point-free)
public protocol Withable {
init()
}
public extension Withable {
/// Construct a new instance, setting an arbitrary subset of properties
init(with config: (inout Self) -> Void) {
@alvarhansen
alvarhansen / CALayer_CAMeshTransform_CALight.h
Created June 22, 2018 05:32 — forked from Ciechan/CALayer_CAMeshTransform_CALight.h
Cleaned up headers for CAMeshTransform, CALight, and mesh&lights properties of CALayer
#ifndef CALayer_CAMeshTransform_CALight_h
#define CALayer_CAMeshTransform_CALight_h
typedef struct CAMeshFace {
unsigned int indices[4];
float w[4];
} CAMeshFace;