Skip to content

Instantly share code, notes, and snippets.

View insidegui's full-sized avatar

Guilherme Rambo insidegui

View GitHub Profile
@insidegui
insidegui / mergegenstrings.py
Created October 4, 2016 23:14 — forked from yoichitgy/mergegenstrings.py
A script to generate .strings file for .swift, .m, .storyboard and .xib files by genstrings and ibtool commands, and merge them with existing translations.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Localize.py - Incremental localization on XCode projects
# João Moreno 2009
# http://joaomoreno.com/
# Modified by Steve Streeting 2010 http://www.stevestreeting.com
# Changes
# - Use .strings files encoded as UTF-8
CKContainer.default().requestApplicationPermission(.userDiscoverability) { status, error in
guard status == .granted, error == nil else {
// error handling voodoo
return
}
CKContainer.default().discoverUserIdentity(withUserRecordID: recordID) { identity, error in
guard let components = identity?.nameComponents, error == nil else {
// more error handling magic
return
@insidegui
insidegui / iBridge2_1_devtree.txt
Created March 10, 2018 15:38
iBridge 2,1 device tree
dtre
Device Tree with 19 properties and 10 children
Properties:
device-tree:
| +--name 12 bytes: device-tree
| +--target-type 5 bytes: J137
| +--mlb-serial-number 29 bytes: syscfg/MLB#/0x20,zeroes/0x20
| +--compatible 27 bytes: J137AP
| +--secure-root-prefix 3 bytes: md
| +--AAPL,phandle 4 bytes: 1
@insidegui
insidegui / fix-homekit-entitlement.sh
Created August 12, 2022 21:20
Fixes missing HomeKit entitlement when building for Mac Catalyst on Xcode 14
if [ "$EFFECTIVE_PLATFORM_NAME" = "-maccatalyst" ]; then
echo "Adding com.apple.developer.homekit entitlement"
/usr/libexec/PlistBuddy -c "Add :com.apple.developer.homekit bool true" "$TARGET_TEMP_DIR/$FULL_PRODUCT_NAME.xcent"
fi
@insidegui
insidegui / atoi.swift
Last active August 10, 2022 12:30
Implementation of the "atoi" function in Swift (just an exercise, not for use in production)
/**
Implementation of the "atoi" function in Swift.
This implementation is an exercise and should not be used in production,
Swift has built-in types and functions that can do this sort of conversion.
*/
/// Parses the input string as a 32-bit integer.
/// Returns `nil` if the input contains non-ASCII characters, or is not a valid number.
func myAtoi(_ input: String) -> Int32? {
/// The base ASCII code, where the numbers begin.
@insidegui
insidegui / reloadplugins.sh
Created January 29, 2022 23:00
Make your Mac app's extensions immediately available on macOS with a run script build phase
# Add this to a "Run Script" build phase in your app's main target, as the last step.
# It will use the pluginkit command-line tool to force the plugin system on macOS to add your extensions to its database, making them available.
# I made this specifically for widgets, but it should work for pretty much any extension type (appex bundle).
find $CODESIGNING_FOLDER_PATH -name '*.appex' -exec pluginkit -a {} \;
@insidegui
insidegui / Animation+Slow.swift
Created July 6, 2022 20:00
Handy debugging extension on SwiftUI's Animation
import SwiftUI
/// On macOS, modifying an Animation with .currentSpeed(), or using the .current static property
/// allows for easy animation debugging by holding down the Shift key when triggering the animation.
/// When the animation is triggered while the Shift key is pressed, it will be played in slow motion.
/// Using this extension has no effect when targeting other OSes or when building for release.
extension Animation {
static var currentSpeed: Double {
#if DEBUG
@insidegui
insidegui / FixSwiftUIMaterialInPreviews.m
Created May 13, 2022 21:27
Fixes SwiftUI's Material not being rendered correctly in Xcode previews
#if DEBUG
/*
This fixes SwiftUI previews not rendering translucent materials correctly by
swizzling a couple of properties on NSWindow.
Just drop into your project and add to the target being previewed (or something it links against).
Notice the #if DEBUG, so this code won't end up in release builds. It also checks for the
XCODE_RUNNING_FOR_PREVIEWS environment variable so that it won't affect regular debug builds of the app.
@insidegui
insidegui / SemanticVersion.swift
Created January 30, 2022 13:56
Simple Swift type for representing Major.Minor.Patch versions, useful for things such as comparing app versions against values from a backend
/*
Example:
let v1 = SemanticVersion(string: "1.0.0")
let v2 = SemanticVersion(string: "2.0.0")
print(v1 > v2) // false
print(v2 > v1) // true
@insidegui
insidegui / statusbarfix.sh
Created March 16, 2021 23:04
Alias called "statusbarfix" which will update the status bar on any iOS Simulator that's currently running to look better for marketing images
alias statusbarfix='xcrun simctl status_bar booted override --time 9:41 --cellularMode active --cellularBars 4 --batteryState charging --operatorName ""'