Skip to content

Instantly share code, notes, and snippets.

View keitaito's full-sized avatar

Keita Ito keitaito

View GitHub Profile
@inamiy
inamiy / typed-error-poem.md
Last active November 8, 2018 13:58
Swift Poem: Why I prefer typed error (for https://github.com/apple/swift-evolution/pull/757)

Typed error can be useful in certain cases, especially when accompanied with NoError type.

For example, in reactive programming, https://github.com/ReactiveCocoa/ReactiveSwift (typed error) allows us to create UI bindings only if Error is NoError, i.e.:

static func <~ <Source: BindingSource> (provider: Self, source: Source) -> Disposable? 
    where Source.Value == Value, Source.Error == NoError { ... }
    
// example
let alphaSignal: Signal = ...
@shunirr
shunirr / criminal_jc.md
Last active December 25, 2024 04:13
女子中学生チケット詐欺事件

criminal_jc

@0xmachos
0xmachos / Keychain.md
Last active March 2, 2025 15:18
Useful resources for working with iOS/ macOS Keychain API

Keychain API

kSecAttrAccessible Mapping

Protection Domain (pdmn) Keychain Accessibility Values
ck kSecAttrAccessibleAfterFirstUnlock
cku kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
dk kSecAttrAccessibleAlways
akpu kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly
@tayvano
tayvano / gist:6e2d456a9897f55025e25035478a3a50
Created February 19, 2017 05:29
complete list of ffmpeg flags / commands
Originall From: Posted 2015-05-29 http://ubwg.net/b/full-list-of-ffmpeg-flags-and-options
This is the complete list that’s outputted by ffmpeg when running ffmpeg -h full.
usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…
Getting help:
-h — print basic options
-h long — print more options
-h full — print all options (including all format and codec specific options, very long)
let str = "acxz"
func isFunny(_ s: AnySequence<UInt8>) -> Bool {
let n1: [Int] = zip(s.dropFirst(), s).map { Int($0)-Int($1) }
let n2: [Int] = zip(s.reversed().dropFirst(), s.reversed()).map { Int($1)-Int($0) }
return n1 == n2
}
isFunny(AnySequence(str.utf8))
@yaakov-h
yaakov-h / ReadingListReader.swift
Last active January 10, 2021 08:17
Read your Safari Reading List and dump to plain text
import Foundation
func fatalerror(_ text : String) {
fputs(text, __stderrp)
exit(-1)
}
struct ReadingListItem {
init(title: String?, previewText: String?, url: URL, dateAdded: Date) {
self.title = title
@brennanMKE
brennanMKE / HTTPStatusCodes.swift
Last active June 5, 2023 15:19
Swift Enums for HTTP Status Codes
enum HTTPStatusCodes: Int {
// 100 Informational
case Continue = 100
case SwitchingProtocols
case Processing
// 200 Success
case OK = 200
case Created
case Accepted
case NonAuthoritativeInformation
@mrh-is
mrh-is / SantaArrivalCalculator.swift
Created December 23, 2016 10:41
When will Santa be at my house?
extension Location {
func closestLocationOnPath(start: Location, end: Location) -> (location: Location, t: Double, distance: Double) {
let pathVector = (latitude: end.latitude - start.latitude, longitude: end.longitude - start.longitude)
var t = (self.latitude * pathVector.latitude - start.latitude * pathVector.latitude + self.longitude * pathVector.longitude - start.longitude * pathVector.longitude) / (pow(pathVector.latitude,2) + pow(pathVector.longitude,2))
t = min(max(t, 0), 1)
let closestLocation = Location(latitude: start.latitude + t * pathVector.latitude, longitude: start.longitude + t * pathVector.longitude)
return (location: closestLocation, t: t, distance: distance(to: closestLocation))
}
func distance(to other: Location) -> Double {
@nazywamsiepawel
nazywamsiepawel / UICollectionView + NSFetchedResultsController.swift
Created October 17, 2016 13:18
UICollectionView + NSFetchedResultsController Swift 3 / iOS 10
var blockOperations: [BlockOperation] = []
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
if type == NSFetchedResultsChangeType.insert {
print("Insert Object: \(newIndexPath)")
blockOperations.append(
BlockOperation(block: { [weak self] in
@ashfurrow
ashfurrow / Fresh macOS Setup.md
Last active October 14, 2024 10:28
All the stuff I do on a fresh macOS Installation

Apps to install from macOS App Store:

  • Pastebot
  • GIF Brewery
  • Slack
  • Keynote/Pages/Numbers
  • 1Password
  • OmniFocus 3
  • Airmail 3
  • iA Writer