Skip to content

Instantly share code, notes, and snippets.

@chosa91
chosa91 / KeyboardScrollView.swift
Created December 2, 2019 05:56 — forked from douglashill/KeyboardScrollView.swift
A UIScrollView subclass that allows scrolling using a hardware keyboard like NSScrollView. Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end.
// Douglas Hill, November 2019
import UIKit
/// A scroll view that allows scrolling using a hardware keyboard like `NSScrollView`.
/// Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end.
/// Limitations:
/// - Paging scroll views (isPagingEnabled = true) are not supported yet.
/// - The scroll view must become its own delegate so setting the delegate is not supported yet.
/// - Does not consider zooming. This has not been tested at all.
@chosa91
chosa91 / GivenWhenThen.swift
Created January 13, 2020 17:29 — forked from IanKeen/GivenWhenThen.swift
FunctionBuilder mvp for a given/when/then test setup
import XCTest
@_functionBuilder
struct Test<T> {
var data: T
var given: given<T>
var when: when<T>
var then: then<T>
func execute() {
@chosa91
chosa91 / machine.js
Created January 13, 2020 19:29
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine({
id: 'some-id',
initial: 'compact',
states: {
compact: {
on: {
PULL_UP: 'expanded',
PULL_DOWN: 'closed'
}
},
@chosa91
chosa91 / HW2020Q1 - Sentiment Analysis.md
Last active November 14, 2022 21:27
Hackweek 2020 Q1 - Sentiment analysis

👋 Hackweek 2020 Q1 - Sentiment analysis 👀

Goal

Plan

Tone analysis on text like Grammarly.

Tone detector teaser

@chosa91
chosa91 / AutoLayout.md
Created February 8, 2020 09:53 — forked from oliverkrakora/AutoLayout.md
The best damn AutoLayout guide I've ever seen

ℹ️ This article is also available on his blog.


Fundamentals

Layout and Drawing are two different things:

  • Layout defines only the positions and sizes of all views on screen.
  • Drawing specifies how each view is rendered (how it looks).
@chosa91
chosa91 / libdispatch-efficiency-tips.md
Created February 22, 2020 14:55 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are:

struct StateMachine<State, Action> {
private(set) var state: State
private let transition: (State, Action) -> State?
init(startState: State, transition: @escaping (State, Action) -> State?) {
self.state = startState
self.transition = transition
}
mutating func apply(action: Action) -> Bool {
@discardableResult
public func with<T>(_ value: T, _ builder: (T) -> Void) -> T {
builder(value)
return value
}
@discardableResult
public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T {
try builder(value)
return value
@chosa91
chosa91 / updateSafeAreaForKeyboardFromNotification.swift
Created March 20, 2020 14:21 — forked from douglashill/updateSafeAreaForKeyboardFromNotification.swift
Avoid the keyboard by leveraging additionalSafeAreaInsets.
// Avoids the keyboard in a UIKit app by leveraging additionalSafeAreaInsets.
// You can put this in the root view controller so the whole app will avoid the keyboard.
// Only tested on iOS 13.3.
// Made for https://douglashill.co/reading-app/
@objc func updateSafeAreaForKeyboardFromNotification(_ notification: Notification) {
guard let endFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else {
return
}
// Please consider whether the force unwrap here is safe for your own use case.
@chosa91
chosa91 / FileManagerExtensions.swift
Created April 17, 2020 12:27 — forked from AvdLee/FileManagerExtensions.swift
Easily print out useful locations for usage during debugging on the Simulator.
extension FileManager {
/*
Prints out the locations of the simulator and the shared group folder.
This is useful for debugging file issues.
Example usage: FileManager.default.printFileLocations()
*/
func printFileLocations() {
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let simulatorFolder = paths.last!