Skip to content

Instantly share code, notes, and snippets.

@shavit
shavit / CoreImageFilters.swift
Created May 12, 2018 18:13
CIFilter opacity
/*
Change the opacity of a CIFilter.
*/
func changeOpacity(to opacity: CGFloat, on filter: CIFilter, original image: UIImage) -> CIImage? {
guard let backgroundImage: CIImage = CIImage(image: image) else { fatalError() }
// The CIColorMatrix filter, will contain the requested filter and control its opacity
guard let overlayFilter: CIFilter = CIFilter(name: "CIColorMatrix") else { fatalError() }
let overlayRgba: [CGFloat] = [0, 0, 0, opacity]
let alphaVector: CIVector = CIVector(values: overlayRgba, count: 4)
######################
# Options
######################
REVEAL_ARCHIVE_IN_FINDER=false
@vakhidbetrakhmadov
vakhidbetrakhmadov / AVAsset+util.swift
Last active April 28, 2025 08:57
Cropping video track to a specified crop rectangle.
import Foundation
import AVFoundation
extension AVAsset {
func cropVideoTrack(at index: Int, cropRect: CGRect, outputURL: URL, completion: @escaping (Result<Void, Swift.Error>) -> Void) {
enum Orientation {
case up, down, right, left
@darrarski
darrarski / FormattedTextField.swift
Last active September 26, 2024 06:33
SwiftUI FormattedTextField - TextField with custom display/edit formatters
import SwiftUI
public struct FormattedTextField<Formatter: TextFieldFormatter>: View {
public init(_ title: String,
value: Binding<Formatter.Value>,
formatter: Formatter) {
self.title = title
self.value = value
self.formatter = formatter
}
@mattt
mattt / UIViewControllerPreview.swift
Last active December 3, 2024 07:42
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@chriseidhof
chriseidhof / viewmirror.swift
Last active April 3, 2025 08:40
View Mirror
import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
Text("Hello")
.padding()
.background(.blue)
.overlay {
Color.yellow
@alladinian
alladinian / SwiftUICocoaApp.swift
Last active April 21, 2022 18:21
A super simple Cocoa App boilerplate for SwiftUI prototyping _without_ Xcode
import Cocoa
import SwiftUI
func startApp(content: NSView) {
let app = NSApplication.shared
let menubar = NSMenu()
let appMenuItem = NSMenuItem()
let appMenu = NSMenu()
let appName = ProcessInfo.processInfo.processName
let quitTitle = "Quit \(appName)"
//
// Diagrams.swift
// DiagramsSample
//
// Created by Chris Eidhof on 16.12.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import SwiftUI
@chriseidhof
chriseidhof / boilerplate.swift
Last active April 17, 2025 11:08
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@Sauerstoffdioxid
Sauerstoffdioxid / googleurlparams.md
Last active May 19, 2025 19:27
Google/Blogger Image URL Parameters

Google/Blogger Image URL Parameters

This is an effort to document what is known about Google's (Blogger's/Blogspot's) image URL parameters. Some of these options were taken from existing first or third party documentation (see the links at the end of this document), but the majority is based off my own investigations.

Where to use them?

  • On Blogger's image URL's: 2.bp.blogspot.com/-OF7u67HQE1M/VHc8S8qJTDI/AAAAAAAACxI/UD-11c63diQ/s1600/005.png
  • On just about any googleusercontent image URL: https://lh3.googleusercontent.com/Jvmz11cLrvNIHG_LWjVO9B-UV2IN4Cfk1pycbhWZl6IriMgCAGCOFuBRtoHaiZ6xeVGqCugZcCql=w176-h176-n-o

Replace the bolded parts with the parameters.