Skip to content

Instantly share code, notes, and snippets.

View benbahrenburg's full-sized avatar

Ben Bahrenburg benbahrenburg

View GitHub Profile
@benbahrenburg
benbahrenburg / CLLocationManager+Combine.swift
Created June 11, 2021 19:28 — forked from malhal/CLLocationManager+Combine.swift
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?
@benbahrenburg
benbahrenburg / escape-json.js
Created December 25, 2020 03:39 — forked from matthewmueller/escape-json.js
Escape JSON strings before trying to run JSON.parse
/*
Escape JSON
*/
var escapeJSON = exports.escapeJSON = function(json) {
var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
var meta = { // table of character substitutions
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
@benbahrenburg
benbahrenburg / number_of_rows_removed.md
Created July 26, 2020 03:08 — forked from icerge/number_of_rows_removed.md
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.

@benbahrenburg
benbahrenburg / TimeZoneManager.swift
Created December 29, 2019 04:25
List all iOS timezones
class TimeZoneManager {
static let shared = TimeZoneManager()
private init() {}
private var continents = [String]()
private var timeZonesList = [String: [String]]()
var timeZones: [String: [String]] {
get {
for timeZone in TimeZone.knownTimeZoneIdentifiers {
@benbahrenburg
benbahrenburg / Writer.swift
Created October 28, 2019 13:26 — forked from steve228uk/Writer.swift
Write XMP
import UIKit
import CoreServices
import ImageIO
class Writer {
let output = NSTemporaryDirectory().appending("output.heic")
lazy var outputUrl: CFURL = {
return URL(fileURLWithPath: output) as CFURL
}()
@benbahrenburg
benbahrenburg / CryptoKitHelpers.swift
Last active July 13, 2022 11:37
CryptoKit ChaChaPoly Helper Functions
import UIKit
import CryptoKit
struct CryptoKitHelpers {
static func encrypt(secret: String, image: UIImage, compressionRatio: CGFloat = 0.9) throws -> Data? {
guard let encryptionKey = getKey(secret: secret) else { return nil }
guard let contentData = UIImageToDataJPEG2(image: image, compressionRatio: compressionRatio) else {
return nil
}
return try ChaChaPoly.seal(contentData, using: encryptionKey).combined
@benbahrenburg
benbahrenburg / String+NLP.swift
Last active February 3, 2019 20:01
Swift String Extension to Trim Trailing Punctuation
extension String {
func trimTrailingPunctuation() -> String {
return self.trimmingCharacters(in: .whitespacesAndNewlines)
.trimmingCharacters(in: .punctuationCharacters)
.trimmingCharacters(in: .whitespacesAndNewlines)
}
}
@benbahrenburg
benbahrenburg / MailKitExts.cs
Last active February 5, 2019 04:16
MailKit ToMailAddressCollection Extension
public static class MailKitExts
{
public static MailAddressCollection ToMailAddressCollection(this InternetAddressList addressList)
{
if(addressList == null)
{
return new MailAddressCollection();
}
return addressList.Mailboxes.Aggregate(new MailAddressCollection(), (c, r) => { c.Add(new MailAddress(r.Address, r.Name)); return c; });
}
@benbahrenburg
benbahrenburg / MailKitReadMessageEnvelop.cs
Last active February 3, 2019 18:57
MailKit InternetAddressList Example
foreach (var summary in inbox.Fetch(0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure))
{
var tos = summary.Envelope.To;
var replyToList = summary.Envelope.ReplyTo;
}