Skip to content

Instantly share code, notes, and snippets.

View dermotos's full-sized avatar

Dermot dermotos

  • Sydney, Australia
View GitHub Profile
@dermotos
dermotos / DebugFrame.swift
Last active March 25, 2024 21:33
View modifier to help debug framing issues in SwiftUI. Draws a box with measurements around the view this is added to.
#if DEBUG
import Foundation
import SwiftUI
// MARK: - Public Interface
public extension View {
// swiftlint:disable identifier_name
/// Draw a frame around the view and print its size on screen.
@dermotos
dermotos / Utility.swift
Last active March 5, 2018 03:46
Swift computed variable that lets you know if a debugger is currently attached to the process
class Utlity {
internal var isDebuggerAttached: Bool {
var info = kinfo_proc()
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
var size = MemoryLayout<kinfo_proc>.stride
let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
assert(junk == 0, "sysctl failed")
return (info.kp_proc.p_flag & P_TRACED) != 0
}
@dermotos
dermotos / MyView.swift
Created February 1, 2018 05:29
UIView extension to quickly add and fit or center a subview inside a superview, using constraints
class MyView : UIView {
func buildMyView() {
var indicatorView :UIActivityIndicatorView!
let indicatorSize : CGFloat = 120
loadingIndicator = UIView(frame: CGRect(origin: CGPoint.zero, size: CGSize(width: indicatorSize, height: indicatorSize)))
loadingIndicator.backgroundColor = UIColor.darkGray.withAlphaComponent(0.7)
loadingIndicator.layer.cornerRadius = 10.0
indicatorView = UIActivityIndicatorView(activityIndicatorStyle: .white)
indicatorView.hidesWhenStopped = false
@dermotos
dermotos / Listable.swift
Created February 1, 2018 05:25
Protocol pattern for allowing an Enum to list all its cases
protocol ListableEnumeration {
associatedtype T
static var allItems :[T] { get }
}
# Download the file manually from here https://launchpad.net/gcc-arm-embedded
# Note: `curl` command doesn't work
# I downloaded this one: "gcc-arm-none-eabi-4_7-2013q3-20130916-mac.tar.bz2"
# double click it to unzip it
# Make a place to install it to
mkdir /usr/local/gcc_arm
# Move the unzipped stuff there.
-(void)doCodeSnippetWithCompletion:(void(^)())block{
//dispatching to background queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSString *code = @"Code", *test = @"Test";
BOOL iterationPrinted = NO;
for (int x = 1; x<=100; x++) {
iterationPrinted = NO;
if(x % 3 == 0 && x % 5 == 0)
NSLog(@"%@%@",code,test);
else if(x % 5 == 0)