Skip to content

Instantly share code, notes, and snippets.

View benbahrenburg's full-sized avatar

Ben Bahrenburg benbahrenburg

View GitHub Profile
malhal / CLLocationManager+Combine.swift
Last active April 12, 2023 22:02
A Combine location publisher for CLLocationManager.
View CLLocationManager+Combine.swift
// Requirements: a NSLocationWhenInUseUsageDescription entry in Info.plist
// Usage: @State var locator = CLLocationManager.publishLocation()
// and
// .onReceive(locator) { location in
// Improvements needed: Move requestWhenInUseAuthorization into its own publisher and perhaps have a combineLatest pipeline for both authorized and valid location.
// A configuration param to init(), e.g. so each manager can have the same distanceFilter.
import Foundation
import Combine
import CoreLocation
View OIDExternalUserAgentASWebAuthenticationSession.swift.swift
import UIKit
import SafariServices
import AuthenticationServices
import AppAuth
import Reachability
class OIDExternalUserAgentASWebAuthenticationSession: NSObject, OIDExternalUserAgent {
private let presentingViewController: UIViewController
private var externalUserAgentFlowInProgress: Bool = false
private var authenticationViewController: ASWebAuthenticationSession?
perlmunger / SecCertificateWrapper.swift
Last active September 22, 2023 14:05
A wrapper around SecCertificate to simplify accessing iOS app certificate properties found in the embedded.mobileprovision file inside the bundle payload. The WrapperImplementation file shows how to extract both the provisioning profile and the details of each certificate. Works on iOS 12, iOS 13, and newer
View SecCertificateWrapper.swift
struct SecCertificateWrapper : Comparable {
var data:Data
var cert:SecCertificate
// Initialize with a data object from the "DeveloperCertificates"
// array (see WrapperImplementation.swift)
init(data:Data) {
self.cert = SecCertificateCreateWithData(nil, data as CFData)!
// Use this later for parsing the date details from the cert
icerge /
Last active November 17, 2021 16:58
Security: ACLs, Query Business Rules

Number of rows removed due to security constraint

User gets this message in a list of records whenever there is a record user doesn't have rights to view. I.e. there is an ACL restricting access to a record or there in NO ACL granting the access. Let's ignore security mode setting here.

It's a default system beharior.

Would you like to get rid of it? System to count with records user has access to?

Solution 1

Replicate row level read access ACLs to query business rules. Naturally, every query will get controlled.

osteslag / Metadata.swift
Created August 14, 2018 16:55
Swift Playground for updating an image file’s metadata without re-processing the image.
View Metadata.swift
// Adapted from Apple's Tech Note, [Modifying Image Metadata Without Recompressing Image](
import Cocoa
import ImageIO
let url = URL(fileURLWithPath: "/path/to/file.tiff")
guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil) else { fatalError("Cannot create URL") }
guard var properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? Dictionary<CFString, Any> else { fatalError("Cannot get image properties") }
properties[kCGImageDestinationDateTime] = Date()
View Writer.swift
import UIKit
import CoreServices
import ImageIO
class Writer {
let output = NSTemporaryDirectory().appending("output.heic")
lazy var outputUrl: CFURL = {
return URL(fileURLWithPath: output) as CFURL
davidrleonard / add-team-to-repos.js
Last active September 24, 2023 03:35
Add a new team to all Github repos in an organization
View add-team-to-repos.js
* Adds a team to all the repos in a Github organization. This is a tedious
* process in the UI. You'll need a newer version of node to run this (e.g 9+)
* because it uses async/await.
* Instructions:
* 1. Copy this file somewhere on your computer, e.g. ~/addteamrepos.js
* 2. Fill in the uppercase variables below with the right values
* 3. Run this file: `$ node ~/addteamrepos.js`
nyg / EXIFUserComment.swift
Last active August 17, 2022 17:03
Get and set an EXIF UserComment to a JPEG image using the ImageIO framework.
View EXIFUserComment.swift
// Note: to add a JPEG COM marker go here:
import Foundation
import ImageIO
#if os(iOS)
import MobileCoreServices
hollance / eliza.swift
Last active February 17, 2023 15:50
The classic ELIZA chat bot in Swift.
View eliza.swift
Joseph Weizenbaum's classic ELIZA chat bot in Swift.
Based on the IBM PC BASIC program from CREATIVE COMPUTING by Patricia
Danielson and Paul Hashfield, and the Java adaptation by Jesper Juul.
Run this script from Terminal:
$ swift eliza.swift
Press Ctrl-C or Ctrl-D to quit. (Or type "shut up".)
View CGImageMetadata.swift
import UIKit
import MobileCoreServices
import ImageIO
let sourceOptions: [String: AnyObject] = [kCGImageSourceTypeIdentifierHint as String: kUTTypeJPEG]
let cfSourceOptions = sourceOptions as CFDictionary
let image = UIImage(named: "input.jpg")!
let data = UIImageJPEGRepresentation(image, 1.0)