Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Bahrenburg benbahrenburg

View GitHub Profile
@benbahrenburg
benbahrenburg / gist:1129364
Created Aug 6, 2011
Tell git to globally ignore .DS_Store
View gist:1129364
git config --global core.excludesfile ~/.gitignore
echo .DS_Store >> ~/.gitignore
@benbahrenburg
benbahrenburg / CLLocationManager+Combine.swift
Created Jun 11, 2021 — forked from malhal/CLLocationManager+Combine.swift
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
@benbahrenburg
benbahrenburg / UIImageToDataIO.swift
Created Mar 5, 2017
Using ImageIO and Swift to convert a UIImage to Data
View UIImageToDataIO.swift
func UIImageToDataIO(image: UIImage, compressionRatio: CGFloat, orientation: Int = 1) -> Data? {
return autoreleasepool(invoking: { () -> Data in
let data = NSMutableData()
let options: NSDictionary = [
kCGImagePropertyOrientation: orientation,
kCGImagePropertyHasAlpha: true,
kCGImageDestinationLossyCompressionQuality: compressionRatio
]
let imageDestinationRef = CGImageDestinationCreateWithData(data as CFMutableData, kUTTypeJPEG, 1, nil)!
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?
@benbahrenburg
benbahrenburg / escape-json.js
Created Dec 25, 2020 — forked from matthewmueller/escape-json.js
Escape JSON strings before trying to run JSON.parse
View escape-json.js
/*
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 / UIImageToDataTests.swift
Last active Aug 30, 2020
Swift Playground for testing memory associated with converting UIImage to Data
View UIImageToDataTests.swift
import UIKit
import ImageIO
import MobileCoreServices
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
func report_memory() -> UInt64 {
var taskInfo = mach_task_basic_info()
var count = mach_msg_type_number_t(MemoryLayout<mach_task_basic_info>.size)/4
@benbahrenburg
benbahrenburg / number_of_rows_removed.md
Created Jul 26, 2020 — forked from icerge/number_of_rows_removed.md
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.

@benbahrenburg
benbahrenburg / PasscodeUtils.swift
Last active Jul 8, 2020
Use Swift to determine if device has passcode set
View PasscodeUtils.swift
//
// PasscodeUtils.swift
//
// Created by Ben Bahrenburg on 12/31/16.
// Copyright © 2016 bencoding.com. All rights reserved.
//
import Foundation
import LocalAuthentication
@benbahrenburg
benbahrenburg / PDFHelpers.swift
Last active Jun 2, 2020
Removing PDF password using Swift
View PDFHelpers.swift
//
// PDF.swift
//
// Created by Ben Bahrenburg on 1/1/17.
// Copyright © 2017 bencoding.. All rights reserved.
//
import UIKit
open class PDFHelpers {
@benbahrenburg
benbahrenburg / appt.tss
Last active May 11, 2020
Titanium Android Portrait Orientation
View appt.tss
//In your app/styles directory you will find an app.tss file
//If this file doesn't exist, simply add it to your project.
//The app.tss is used to apply styles across your project.
//For more on how this works, please visit http://docs.appcelerator.com/platform/latest/#!/guide/Alloy_Styles_and_Themes-section-35621526_AlloyStylesandThemes-GlobalStyles
//In your app.tss add the below Window style. This will set the orientation
//for all windows in your app
"Window" : {
orientationModes :[
Ti.UI.PORTRAIT