Skip to content

Instantly share code, notes, and snippets.

View hvsw's full-sized avatar
🏠
Working from home

Henrique Valcanaia hvsw

🏠
Working from home
View GitHub Profile
@hvsw
hvsw / bash_profile.sh
Created December 15, 2020 14:24
macOS developer free space
function freespace() {
# rm -rf ~/Library/Containers/com.apple.mail/Data/Library/Mail\ Downloads/
# https://stackoverflow.com/a/53199763/3724306
echo "1. Boot all the sims that I want to use"
echo "2. remove all the simulators that I don't have booted"
echo "Run: xcrun simctl list | grep -w \"Shutdown\" | grep -o \"([-A-Z0-9]*)\" | sed \'s/[\(\)]//g\\' | xargs -I uuid xcrun simctl delete uuid"
echo "Cleaning ~/Library/Caches/com.apple.dt.Xcode..."
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*
@hvsw
hvsw / DynamicTypeResponsive.swift
Created October 15, 2018 19:09 — forked from stevethomp/DynamicTypeResponsive.swift
Adds a simple way to register a view for automatic dynamic type updating by setting respondsToDynamicTypeChanges = true. Really only useful on iOS < 10
import Foundation
import ObjectiveC
// MARK: - DynamicTypeResponsive
protocol DynamicTypeResponsive {
var respondsToDynamicTypeChanges: Bool { get set }
}
extension UILabel: DynamicTypeResponsive {
var respondsToDynamicTypeChanges: Bool {
// TO BE CONTINUED...
extension Notification.Name {
func post(to notificationCenter: NotificationCenter = .default, withObject object: Any? = nil) {
notificationCenter.post(name: self, object: object)
}
}
extension Notification {
struct MyApp {
@hvsw
hvsw / Data+HexString.swift
Last active August 3, 2017 00:26
Hex string representing Data
import Foundation
extension Data {
var hexString: String {
let hexString = map { String(format: "%02.2hhx", $0) }.joined()
return hexString
}
}
let photo = try! loadImage("./Resources/John Appleseed.jpg")
let x = try! divide(2, 2)
// Using optional try
let x = try? divide(0, 2) // (Yes you can use an if let/guard/whatever to unwrap it safely)
// Using do-catch
let y: Float?
do {
y = try divide(0, 2)
} catch { // exhaustive just for testing
y = nil
}
func calculate() {
do {
let x = 2
let y = 2
let result = try divide(x, y)
resultLabel.text = String(result)
} catch DivisionErrorEnum.DividendIsZero(let code) {
print("Your message when the DIVIDEND is zero. \nDetails: Execution failed with code \(code).")
} catch DivisionErrorEnum.DivisorIsZero(let code) {
print("Your custom message when the DIVISOR is zero. \nDetails: Execution failed with code \(code).")
enum DivisionErrorEnum: ErrorType {
case DividendIsZero(code: Int)
case DivisorIsZero(code: Int)
}
func calculate() {
do {
let x:Float = 2.0
let y:Float = 2.0
let result = try divide(x, y)
resultLabel.text = String(result)
} catch DivisionErrorEnum.DividendIsZero(let msg) {
print(msg)
} catch DivisionErrorEnum.DivisorIsZero(let msg) {
print(msg)