Skip to content

Instantly share code, notes, and snippets.

View joncardasis's full-sized avatar
🔬
📱 Probing iOS internals...

Jon Cardasis joncardasis

🔬
📱 Probing iOS internals...
View GitHub Profile
@joncardasis
joncardasis / UIViewController+StatusBar.swift
Created July 10, 2018 19:12
A swizzling method which introduces a `statusBarStyle` to control the display of the status bar on a view controller.
//
// UIViewController+StatusBar.swift
// StatusBarTesApp
//
// Created by Jonathan Cardasis (C) on 7/10/18.
// Copyright © 2018 Jonathan Cardasis. All rights reserved.
//
import UIKit
@joncardasis
joncardasis / ColladaAnimationForXcode.py
Last active August 10, 2021 09:31
Convert Collada (.DAE) animation files for Xcode Scenekit Animation use by removing unnecessary data.
#!/usr/local/bin/python
# Jonathan Cardasis, 2018
#
# Cleans up a collada `dae` file removing all unnessasary data
# only leaving animations and bone structures behind.
# Combines multiple animation sequences into a single animation
# sequence for Xcode to use.
import sys
import os
import re
@joncardasis
joncardasis / UIFont+BestFit.swift
Last active May 11, 2023 03:20
Swift Dynamic Font Size for Bounds
extension UIFont {
/**
Will return the best font conforming to the descriptor which will fit in the provided bounds.
*/
static func bestFittingFontSize(for text: String, in bounds: CGRect, fontDescriptor: UIFontDescriptor, additionalAttributes: [NSAttributedStringKey: Any]? = nil) -> CGFloat {
let constrainingDimension = min(bounds.width, bounds.height)
let properBounds = CGRect(origin: .zero, size: bounds.size)
var attributes = additionalAttributes ?? [:]
@joncardasis
joncardasis / FVPasswordManager.py
Created May 3, 2018 20:17
A python script to check if a FileVault password has ever been used on macOS before.
import os, sys
import re
import base64
import hashlib
import plistlib
from binascii import unhexlify
class FVPasswordManager(object):
PL_SALTED_HASH_ARRAY_KEY = 'SALTED-SHA512-PBKDF2'
@joncardasis
joncardasis / ssltest.swift
Created March 21, 2018 16:54
Example of direct OpenSSL usage in Swift
//
// ssltest.swift
//
// Created by Cardasis, Jon C. (CAC) on 1/22/18.
// Copyright © 2018 Jon Cardasis. All rights reserved.
//
import OpenSSL
import Security
@joncardasis
joncardasis / build_openssl.sh
Created January 26, 2018 15:11
Shell Script to Build i386 and x86 flavors of OpenSSL for macOS. Will create a standalone "OpenSSL" folder with binaries, headers, and license.
#!/bin/bash
# Jonathan Cardasis - 2018
# Builds OpenSSL libssl and libcrypto for macOS
# binary distribution (i386 and x86).
VERSION="1.1.0g"
VERSION_SHA256_CHECKSUM="de4d501267da39310905cb6dc8c6121f7a2cad45a7707f76df828fe1b85073af"
####################################
curl -O https://www.openssl.org/source/openssl-$VERSION.tar.gz
@joncardasis
joncardasis / MenuBarOptionKeyListener.swift
Created January 5, 2018 17:35
Showing/Hiding Menu Bar Items If OPTION is held down (Swift macOS AppKit)
class AppDeleatate: NSObject, NSApplicationDelegate {
fileprivate var optionalMenuItems = [NSMenuItem]()
//...
func applicationDidFinishLaunching(_ aNotification: Notification) {
//...
let specialItem = NSMenuItem(title: MenuBarItemLabelText.specialItem, action: #selector(doNeatAction), keyEquivalent: "")
specialItem.isHidden = true
optionalMenuItems.append(specialItem)
@joncardasis
joncardasis / DebugLogger.swift
Last active March 30, 2018 14:49
Reroute print and NSLogs to BOTH Xcode console and a file url [Swift + ObjC Solutions]
//
// DebugLogger.swift
//
// Created by Jonathan Cardasis. on 1/1/18.
// Copyright ©2018 Jonathan Cardasis. All rights reserved.
//
#if DEBUG
import Foundation
@joncardasis
joncardasis / ConsoleUser.swift
Created December 5, 2017 16:26
Retrieve the console username of the user running a Swift program
import SystemConfiguration
/**
Retrieve the console username of the user running the program.
Will be the same result as a `whoami` command.
*/
public func systemConsoleUsername() -> String? {
var uid: uid_t = 0
var gid: gid_t = 0
@joncardasis
joncardasis / UIFont+BestFit_DEPRECATED.swift
Last active January 31, 2020 22:19
[DEPRECATED] Swift Dynamic Font Size for Bounds
import UIKit
extension UIFont {
/**
Will return the best approximated font size which will fit in the bounds.
If no font with name `fontName` could be found, nil is returned.
*/
static func bestFitFontSize(for text: String, in bounds: CGRect, fontName: String) -> CGFloat? {
var maxFontSize: CGFloat = 32.0 // UIKit best renders with factors of 2