Skip to content

Instantly share code, notes, and snippets.

@adamyanalunas
adamyanalunas / ios_split_device_testing.rb
Created April 28, 2021 15:47
A script to evenly split the number of tests run between n iOS devices. Useful for splitting UI tests in device farms like Test Lab.
#!/usr/bin/env ruby
require 'xcodeproj'
require 'open3'
require 'ostruct'
require 'timeout'
require 'benchmark'
class Device
ACTION = build
AD_HOC_CODE_SIGNING_ALLOWED = NO
ALTERNATE_GROUP = staff
ALTERNATE_MODE = u+w,go-w,a+rX
ALTERNATE_OWNER = grantdavis
ALWAYS_SEARCH_USER_PATHS = NO
ALWAYS_USE_SEPARATE_HEADERMAPS = YES
APPLE_INTERNAL_DEVELOPER_DIR = /AppleInternal/Developer
APPLE_INTERNAL_DIR = /AppleInternal
APPLE_INTERNAL_DOCUMENTATION_DIR = /AppleInternal/Documentation
def app_store_license(bundle_id: nil, license: "", countries: nil)
# Make sure your Spacehip::Tunes.client is already logged in
app = Spaceship::Tunes::Application.find(bundle_id)
raise "Could not find an app with the bundle ID `#{bundle_id}`" unless app
app_id = app.apple_id
details = app.details
url = "https://appstoreconnect.apple.com/WebObjects/iTunesConnect.woa/ra/apps/#{app_id}/details"
@adamyanalunas
adamyanalunas / fastlane_connect_api_data_protection.rb
Created November 14, 2019 02:05
A template for creating a request to set an App ID’s data protection capability
def set_data_protection(bundle_id: nil, level: nil)
puts "Setting data protection level to `#{level}` for `#{bundle_id}`"
token = Spaceship::ConnectAPI::Token.create()
client = Spaceship::ConnectAPI::Provisioning::Client.new(token: token)
# Bundle IDs have, themselves, a unique ID. We’ll have to look that up first before firing off this request.
bundle_info = Spaceship::ConnectAPI::BundleId.all(filter: {identifier: bundle_id}).first
bundle_id_id = bundle_info.id
now = DateTime.now.to_time
# You can test different times, like testing 300 days in the future with: now = (DateTime.now + 300).to_time
provisioning_profile = "~/Library/MobileDevice/Provisioning Profiles/11BBCC...AF21BD2.mobileprovision"
expiration_string = `/usr/libexec/PlistBuddy -c 'Print :ExpirationDate' /dev/stdin <<< $(security cms -D -i #{provisioning_profile})`.chomp
expiration_date = DateTime.strptime(expiration_string, '%a %b %d %H:%M:%S PST %Y').to_time
remaining_days = (expiration_date.to_i - now.to_i) / (3600 * 24)
if remaining_days < 1
# Delete ".red" if you aren’t using the Colorize gem
#!/usr/bin/env ruby
#coding:utf-8
require "open-uri"
require "fileutils"
destination_path = ENV['RSS_DOWNLOAD_DESTINATION'] || File.expand_path('.')
feed_url = ENV['RSS_FEED']
feed_file = URI.parse(feed_url).open
feed_file.close
@adamyanalunas
adamyanalunas / private_nsobject_initializer.swift
Created February 14, 2019 18:40
Generic Swift initializer of NSObjects with private init
fileprivate extension NSObject {
/**
Initializes private init() subclasses of NSObject. Pure Swift classes
(and especially structs) will not work here.
```
// Given a class “PrivateInitClass” where `init()` is private
let somePrivateInitClassInstance = (PrivateInitClass.forcedInit() as PrivateInitClass)
```
@adamyanalunas
adamyanalunas / KeyboardTableView.swift
Created January 11, 2019 17:34 — forked from douglashill/KeyboardTableView.swift
A UITableView that allows navigation and selection using a hardware keyboard.
// Douglas Hill, December 2018
// Made for https://douglashill.co/reading-app/
import UIKit
/// A table view that allows navigation and selection using a hardware keyboard.
/// Only supports a single section.
class KeyboardTableView: UITableView {
// These properties may be set or overridden to provide discoverability titles for key commands.
var selectAboveDiscoverabilityTitle: String?
@adamyanalunas
adamyanalunas / strings.swift
Created September 28, 2017 22:01
Swift 4 array of string iteration differences
// Normal array of strings
let array = ["This", "is", "string", "array"]
let characters = array.flatMap {
$0.characters
}
// This prints ["T", "h", "i", "s", "i", "s", "s", "t", "r", "i", "n", "g", "a", "r", "r", "a", "y"]
print(characters)
let words = array.flatMap {
@adamyanalunas
adamyanalunas / levenshtein.swift
Created May 9, 2016 16:00
Siwft 3 compatible Levenshtein distance
// Light syntax cleanup from https://gist.github.com/daehn/f17e8cdcf8d91b046f3c
private extension String {
subscript(index: Int) -> Character {
return self[startIndex.advancedBy(index)]
}
subscript(range: Range<Int>) -> String {
let start = startIndex.advancedBy(range.startIndex)