Skip to content

Instantly share code, notes, and snippets.

View benbahrenburg's full-sized avatar

Ben Bahrenburg benbahrenburg

View GitHub Profile
@malhal
malhal / CLLocationManager+Combine.swift
Last active February 12, 2024 23:19
A Combine location publisher for CLLocationManager.
// 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
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
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
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
icerge / number_of_rows_removed.md
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
osteslag / Metadata.swift
Created August 14, 2018 16:55
Swift Playground for updating an image file’s metadata without re-processing the image.
// Adapted from Apple's Tech Note, [Modifying Image Metadata Without Recompressing Image](https://developer.apple.com/library/archive/qa/qa1895/_index.html).
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()
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
davidrleonard / add-team-to-repos.js
Last active April 9, 2024 18:49
Add a new team to all Github repos in an organization
/*
* 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
nyg / EXIFUserComment.swift
Last active January 22, 2024 13:41
Get and set an EXIF UserComment to a JPEG image using the ImageIO framework.
// Note: to add a JPEG COM marker go here:
// https://gist.github.com/nyg/bdeae8190a41b4b56bde8e13dd471ecc
import Foundation
import ImageIO
#if os(iOS)
import MobileCoreServices
#endif
@hollance
hollance / eliza.swift
Last active February 17, 2023 15:50
The classic ELIZA chat bot in 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".)
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)