Skip to content

Instantly share code, notes, and snippets.

View a-voronov's full-sized avatar
👽
Curious

Oleksandr Voronov a-voronov

👽
Curious
View GitHub Profile
@xsleonard
xsleonard / UUID+Extensions.swift
Created August 26, 2020 06:51
Swift: Convert UUID to and from Data and Int64
extension UUID {
// UUID is 128-bit, we need two 64-bit values to represent it
var integers: (Int64, Int64) {
var a: UInt64 = 0
a |= UInt64(self.uuid.0)
a |= UInt64(self.uuid.1) << 8
a |= UInt64(self.uuid.2) << (8 * 2)
a |= UInt64(self.uuid.3) << (8 * 3)
a |= UInt64(self.uuid.4) << (8 * 4)
a |= UInt64(self.uuid.5) << (8 * 5)
@keith
keith / simctl-commands.txt
Last active December 7, 2022 23:27
All the subcommands of `xcrun simctl` (including ones that aren't listed in `simctl help`) LC_SOURCE_VERSION 776.1 (Xcode 13.0 beta 5)
addmedia
addphoto
addvideo
appinfo
boot
bootstatus
clone
create
darwinup
delete

Answer to http://disq.us/p/1za4u75.


Hi, your problem is actually quite hard to solve with composition, at least without a profunctor-based approach, which is really hard to do in Swift due to the lack of higher-kinded types.

There is a solution, though, but we must be clear about what we're searching for here. In your ViewState<T> there could be no Prism that points just to T, because the inject function wouldn't know what case to produce with a value of type T: it's probably going to be an Affine.

At the bottom of this answer you'll find all the code needed to implement it: it can be directly copy-pasted into a playground.

@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active April 26, 2024 10:15
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

let a: Double? = 1.0
let b: Double? = 2.0
let c: Double? = 3.0
let d: Double? = 4.0
let e: Double? = 5.0
let f: Double? = 6.0
let g: Double? = 7.0
extension Optional {
func `or`(_ value : Wrapped?) -> Optional {
@krodak
krodak / Realm+CascadeDeleting.swift
Last active April 27, 2023 19:16
Cascade deletion for RealmSwift
import RealmSwift
import Realm
protocol CascadeDeleting: class {
func delete<Entity>(_ list: List<Entity>, cascading: Bool)
func delete<Entity>(_ results: Results<Entity>, cascading: Bool)
func delete<Entity: Object>(_ entity: Entity, cascading: Bool)
}
@natecook1000
natecook1000 / operatorCharacters.swift
Last active January 3, 2024 21:33
Allowed characters for Swift operators
import Foundation
extension UnicodeScalar : ForwardIndexType {
public func successor() -> UnicodeScalar {
return UnicodeScalar(value + 1)
}
}
var operatorHeads: [UnicodeScalar] = Array("=-+!*%<>&|^~?".unicodeScalars)
operatorHeads += Array("\u{00A1}" ... "\u{00A7}")
@CodaFi
CodaFi / alltheflags.md
Last active October 26, 2022 20:09
Every Option and Flag /swift (1.2) Accepts Ever

#Every Single Option Under The Sun

  • optimization level options
  • automatic crashing options
  • debug info options
  • swift internal options
  • swift debug/development internal options
  • linker-specific options
  • mode options
@natecook1000
natecook1000 / dumpmodule.sh
Created October 8, 2014 21:05
Dump the Swift-synthesized headers for a module
#! /bin/sh
# usage: <shellscript> [--osx] typename
if [ "$1" = "--osx" ] ; then
echo ":print_module $2" | xcrun swift -deprecated-integrated-repl
else
sdk_path=$(echo `xcrun --show-sdk-path` | sed 's#MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk#iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk#')
echo ":print_module $1" | xcrun swift -deprecated-integrated-repl -sdk "$sdk_path"
fi
@staltz
staltz / introrx.md
Last active May 7, 2024 09:38
The introduction to Reactive Programming you've been missing