Skip to content

Instantly share code, notes, and snippets.

View ffmpeg-ios.txt
# Convert from H264 to H265
ffmpeg -i in.mov -c:v libx265 -an -x265-params crf=20 output.mp4
# Tag as HVC instead of HEV1 so iOS can play it
ffmpeg -i output.mp4 -vcodec copy -acodec copy -tag:v hvc1 output2.mp4
# Bonus: it can take a second to play (no more than H264) so here's how to generate
# a thumbnail of the first frame to embed in your view as a placeholder.
ffmpeg -i output2.mp4 -vf "select=eq(n\,34)" -vframes 1 thumbnail.png
View test.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
:root {
color-scheme: light dark;
--sat: env(safe-area-inset-top);
--sar: env(safe-area-inset-right);
@christianselig
christianselig / Locale+SFSymbol.swift
Created Sep 3, 2021
Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc.
View Locale+SFSymbol.swift
extension Locale {
/// Returns an SF Symbol currency image that match's the device's current locale, for instance dollar in North America, Indian rupee in India, etc.
func currencySFSymbol(filled: Bool, withConfiguration configuration: UIImage.Configuration? = nil) -> UIImage {
// Default currency symbol will be the Animal Crossing Leaf coin 􁂬 to remain impartial to any specific country
let defaultSymbol = UIImage(systemName: "leaf.circle\(filled ? ".fill" : "")")!
guard let currencySymbolName = currencySymbolNameForSFSymbols() else { return defaultSymbol }
let systemName = "\(currencySymbolName).circle\(filled ? ".fill" : "")"
return UIImage(systemName: systemName, withConfiguration: configuration) ?? defaultSymbol
@christianselig
christianselig / UIAlertController+Conversion.swift
Created Sep 3, 2021
Adding an image to a UIAlertController
View UIAlertController+Conversion.swift
extension UIAlertController {
/// Creates a view controller for notifying the user that a conversion is occurring. Accepts a block that is executed upon conversion completion.
static func createConvertingAlertController(onConversionCompletion: @escaping () -> Void) -> UIAlertController {
// The title font corresponds to Dynamic Type style "Headline"
let titleFont = UIFont.preferredFont(forTextStyle: .headline)
let calculatorImageView = UIImageView(image: UIImage(named: "calculator.fill", in: nil, with: UIImage.SymbolConfiguration(font: UIFont.systemFont(ofSize: titleFont.pointSize * 2.0, weight: .semibold))))
let measuringAttributedStringHeight = NSAttributedString(string: "Penguin", attributes: [.font: titleFont]).boundingRect(with: .zero, options: [.usesFontLeading, .usesLineFragmentOrigin], context: nil).height
let desiredOffset = 15.0 + calculatorImageView.bounds.height
let totalNewlinePrefixes = Int((desiredOffset / measuringAttributedStringHeight).
View image-decode.swift
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://external-preview.redd.it/nL7zG2Q2FkHwyJ15KgT4A7jk2R4cMddQpKb_Kx9YR8U.jpg?width=1080&crop=smart&auto=webp&s=91ee8327fdb33b3bb94cb0eab7e26221763e33f4")!
URLSession.shared.dataTask(with: url) { data, response, error in
print("Downloaded! Waiting…")
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(8)) {
// Immediately spikes approximately 7 MB upon execution
View avplayer.swift
import UIKit
import AVKit
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let videoURL = URL(string: "https://v.redd.it/dneaulg46lt61/HLSPlaylist.m3u8?a=1624119730%2CZjViMWYxNmQ3MjM2MWNhNjE1NTIyNGNiNDA5NDQ2Njk2ZjNhNmRmNmJiYmEwNzZkMTdmYjJkNmNkNzE2MTE0Yg%3D%3D&v=1&f=sd")!
let player = AVPlayer(url: videoURL)
let playerViewController = AVPlayerViewController()
View swift-settings.swift
//
// ContentView.swift
// TestSwiftSettings3
//
// Created by Christian Selig on 2021-05-13.
//
import SwiftUI
import Combine
View swiftui-settings.swift
struct Setting {
enum SettingIcon {
case system(name: String)
case custom(name: String)
}
enum SettingType: Equatable {
case toggle
case menu(settings: [MenuSetting])
case viewController(creationBlock: (() -> UIViewController))
View swiftui-settings.swift
import SwiftUI
struct Setting {
enum SettingIcon {
case system(name: String)
case custom(name: String)
}
enum SettingType: Equatable {
case toggle
@christianselig
christianselig / context-menu.swift
Created May 6, 2021
Attempt at organizing my context menu code better
View context-menu.swift
import UIKit
class ViewController: UIViewController {
var contextMenuDataSource = CommentsContextMenuHandler()
override func viewDidLoad() {
super.viewDidLoad()
let interaction = UIContextMenuInteraction(delegate: contextMenuDataSource)
view.addInteraction(interaction)