Skip to content

Instantly share code, notes, and snippets.

View mike3k's full-sized avatar

Mike Cohen mike3k

View GitHub Profile
@josevazquez
josevazquez / testDecodableExtensions.swift
Created June 16, 2023 17:44
Add parse() from a json string to any Decodable
import XCTest
extension Decodable {
init(_ json: String) throws {
self = try JSONDecoder().decode(Self.self, from: json.data(using: .utf8)!)
}
}
final class DecodableExtensions: XCTestCase {
@kastiglione
kastiglione / helpers.swift
Last active June 2, 2022 02:02
Swift helpers, and the lldb setup to use them. Presented @ SLUG https://speakerdeck.com/kastiglione/advanced-debugging-and-swift
extension UIView {
/// Example: call someView.nudge(0, 30)
func nudge(_ dx: CGFloat, _ dy: CGFloat) {
self.frame = self.frame.offsetBy(dx: dx, dy: dy)
CATransaction.flush()
}
}
extension UIView {
/// Example: po UIView.root
@cellularmitosis
cellularmitosis / EmojiPointersDemo.swift
Created August 15, 2018 18:11
Representing pointer values as emoji can be useful for "visually" debugging certain issues, like cell reuse, etc.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
@kastiglione
kastiglione / aliases.lldb
Last active May 29, 2019 04:09
Mnemonic lldb commands
# Calling functions
expression CATransaction.flush()
call CATransaction.flush()
# Assigning variables
expression didLoad = true
command alias assign expression --
assign didLoad = true
# Symbolic breakpoints
// Swift: Syntax Cheat Codes
// ↑ ↑ ↓ ↓ ← → ← → B A
//
// Author: Andyy Hope
// Twitter: @andyyhope
// Medium: medium.com/@andyyhope
import UIKit
import UIKit
import Darwin
@IBDesignable
class DTWheelChart: UIView {
@IBInspectable var days: Int = 28
var shapeLayers : [CAShapeLayer]!
@shinypb
shinypb / git-pr
Created December 5, 2014 17:25
Create GitHub pull request from the command line
#!/usr/bin/env ruby
remote_url = `git config --get remote.origin.url`.strip
matches = remote_url.match(/github\.com:(.+)\/(.+)\.git/)
if matches
branch_name = `git rev-parse --abbrev-ref HEAD`.strip
exec "open https://github.com/#{matches[1]}/#{matches[2]}/compare/#{branch_name}?expand=1"
end
# Save this file as ~/bin/git-pr and then `chmod +x ~/bin/git-pr`.
@chockenberry
chockenberry / gist:11235824
Last active October 22, 2020 19:23
Pipe standard output to a running Cocoa app
1) Create a script named '~/bin/xscope':
#!/bin/sh
parameter=""
if [ -z "$1" ]; then
parameter=`cat /dev/stdin`
else
parameter="$1"
fi
@nonamelive
nonamelive / DMNavigationController.m
Last active April 21, 2023 06:56
Prevent UINavigationController from pushing two view controllers at the same time in case of stack inconsistency and crashes
@interface UINavigationController (DMNavigationController)
- (void)didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
@end
@interface DMNavigationController ()
@property (nonatomic, assign) BOOL shouldIgnorePushingViewControllers;
@chrismiles
chrismiles / reveal.py
Last active September 2, 2021 00:26
Lazy script to wrap Reveal lib load/start commands in one LLDB command.
""" File: reveal.py
Add to ~/.lldbinit:
command script import ~/.lldb-scripts/reveal.py
Q: Want to automatically load the Reveal lib on launch while debugging from Xcode?
A: In Xcode:
Add a Symbolic Breakpoint
Symbol: "UIApplicationMain"
Action: Debugger Command with value "reveal"