Skip to content

Instantly share code, notes, and snippets.

View leviathan's full-sized avatar

Jörg Polakowski leviathan

View GitHub Profile
@leviathan
leviathan / FlowingSyntaxSugar.md
Last active July 20, 2021 13:03
2021-07-26 - Bosch eBike CoP

Combine syntactic sugar

Defining a Publisher pipeline, that Never fails:

Before
let diamonds: AnyPublisher<Diamond, Never>
@leviathan
leviathan / youtube-dl.md
Last active March 29, 2023 21:10
youtube-dl command line

youtube-dl command line

Use master version directly via:

python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
yt-dlp xx
@leviathan
leviathan / ffmpeg.sh
Created March 9, 2021 11:09 — forked from filipwodnicki/ffmpeg.sh
ffmpeg cheat sheet
# install ffmpeg
brew install ffmpeg
# convert .mov file to .mp4
ffmpeg -i demo.mov -vcodec h264 demo.mp4
@leviathan
leviathan / ObservableViewController.swift
Created January 7, 2021 16:46
ObservableViewController - functional reactive View Lifecycle handling with Combine
import Combine
import UIKit
/// View controller, that publishes events for it's `view`'s lifecycle,
/// and allows type safe access to it's main `UIView`.
class ObservableViewController<V: UIView>: UIViewController {
typealias LifecycleEvent = (view: V, animated: Bool)
/// Broadcasts event after the controller's view is loaded, e.g. `viewDidLoad()`.
@leviathan
leviathan / ScopedPublisher.swift
Last active November 10, 2020 08:17
A Combine publisher "wrapper", that receives on a specific Scheduler.
import Foundation
import UIKit
import Combine
import PlaygroundSupport
/// The `ScopedReceivePublisher` modifies any returned `Publisher` property of `V` to receive
/// published elements on the specified `Scheduler`.
///
/// Usage:
/// ```

Swift code snippets

Make every view scollable

You can constrain the content, the UIStackView, to the contentLayoutGuide top, bottom, leading, and trailing to define the scrollable area. You can then constrain the UIStackView’s width to the frameLayoutGuide so that it only scrolls vertically. That’s it—your content can now scroll as it shrinks or grows!

UIView update constraints

final class SomeView: UIView {
@leviathan
leviathan / markdown-snippets.md
Last active February 21, 2020 15:22
markdown snippets

Table

Before After
before after

raw

| Before | After |
@leviathan
leviathan / homebrew.md
Last active March 22, 2022 10:52
Cheat sheet: homebrew

Show Terminal config variables

$ env
TERM_PROGRAM=Apple_Terminal
SHELL=/usr/local/bin/zsh
TERM=xterm-256color
TMPDIR=/var/folders/l4/kb9wf5dn5g31y8ctr6fj_f9c0000gn/T/
...
@leviathan
leviathan / UIImage+FileDump.swift
Last active January 22, 2020 07:35
UIImage quick file dump
/// Quickly dump a UIImage from memory into a tmp file.
var image: UIImage?
// ...
let imageFilePath = NSTemporaryDirectory() + "\(Date().timeIntervalSince1970).png"
try? image.pngData()!.write(to: URL(fileURLWithPath: imageFilePath))
print("Saved turn-by-turn advice image to: \(imageFilePath)")
@leviathan
leviathan / xcode-utils.md
Last active March 5, 2024 04:40
xcrun cheat sheet

Environment Info

xcode-select --print-path
xcodebuild -version
swift --version
swift build --version
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version   // Check Xcode Command-Line-Tools Version