Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Bahrenburg benbahrenburg

View GitHub Profile
@malhal
malhal / CLLocationManager+Combine.swift
Last active Jun 11, 2021
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?
@icerge
icerge / number_of_rows_removed.md
Last active Sep 25, 2020
Security: ACLs, Query Business Rules
View number_of_rows_removed.md

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.

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
}()
@hollance
hollance / eliza.swift
Last active Jul 5, 2020
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".)
@seckincengiz
seckincengiz / ExampleUsage.swift
Last active Jul 10, 2018 — forked from s-aska/Keychain.swift
Swift Keychain class ( supported Xcode 8.1 Beta and IOS 10.1 ) [swift3]
View ExampleUsage.swift
import UIKit
let scoresStringArray : [String] = ["Mike","Tom","Bily"]
let scoresDataArray = NSKeyedArchiver.archivedData(withRootObject: scoresStringArray)
//Save data
_ = Keychain.save(key: "scoresKey", data: scores)
//Load data
if Keychain.load(key: "scoresKey") != nil{
anonymous
anonymous / debounce.swift
Created Jul 9, 2016
debounce in Swift 3
View debounce.swift
func debounce(delay: Int, queue: DispatchQueue, action: (()->()) ) -> ()->() {
var lastFireTime = DispatchTime.now()
let dispatchDelay = DispatchTimeInterval.seconds(delay)
return {
lastFireTime = DispatchTime.now()
let dispatchTime: DispatchTime = lastFireTime + dispatchDelay
queue.after(when: dispatchTime) {
let when: DispatchTime = lastFireTime + dispatchDelay
let now = DispatchTime.now()
View UIBarButtonItem+Badge.swift
//
// UIBarButtonItem+Badge.swift
// PiGuardMobile
//
// Created by Stefano Vettor on 12/04/16.
// Copyright © 2016 Stefano Vettor. All rights reserved.
//
import UIKit
@Danielku15
Danielku15 / Example.html
Created Feb 25, 2016
A MediaTypeFormatter for WebApi for multipart/form-data including file uploads
View Example.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>File Upload example</title>
<link href="/Content/bootstrap.css" rel="stylesheet" />
</head>
<body>
<form action="api/Upload" method="post">
<div class="form-group">
View UBNTDiscardableThumbnail.m
// public interface
@interface UBNTDiscardableThumbnail : NSObject<NSDiscardableContent>
+ (instancetype)discardableThumbnailWithImage:(UIImage *)image;
- (instancetype)initWithImage:(UIImage *)thumbnail;
@property (nonatomic, readonly) UIImage *thumbnail;
@end