Skip to content

Instantly share code, notes, and snippets.

View phatblat's full-sized avatar

Ben Chatelain phatblat

View GitHub Profile
@phatblat
phatblat / simulating-joins.swift
Created June 22, 2023 21:10 — forked from mbalex99/simulating-joins.swift
How to Do SQL-like JOINs in Ditto
class DittoManager {
let ditto: Ditto
static let shared = DittoManager()
init() {
ditto = Ditto(identity: .onlinePlayground(appID: "e23ffe6b-70d1-4246-83a8-94cbd7a79a8d", token: "f058ac2a-4576-4af1-96f2-c4788d848cf8"))
try! ditto.startSync()
}
@phatblat
phatblat / MakeAutomaticVariables.md
Last active August 1, 2022 16:13
Make Automatic Variables Cheatsheet

Make Automatic Variables Cheatsheet

I can never remember all of the automatic variables that can be used in a Makefile so here is a table of them.

Variable Description
$@ File name of the target of the rule
$% Target member name, when the target is an archive member
$< Name of the first prerequisite
@phatblat
phatblat / high-sierra-virtualbox-install.md
Last active July 2, 2018 01:58 — forked from arobb/sierra-virtualbox-install.md
Install macOS High Sierra in VirtualBox on macOS host

Step 1 - Create a bootable macOS High Sierra ISO

hdiutil attach Downloads/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
hdiutil create -o Downloads/HighSierra.cdr -size 7316m -layout SPUD -fs HFS+J
hdiutil attach Downloads/HighSierra.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/install_build
asr restore -source Downloads/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/BaseSystem.dmg -target /Volumes/install_build -noprompt -noverify -erase
rm /Volumes/OS\ X\ Base\ System/System/Installation/Packages
cp -rp /Volumes/install_app/Packages /Volumes/OS\ X\ Base\ System/System/Installation/
cp -rp Downloads/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/BaseSystem.chunklist /Volumes/OS\ X\ Base\ System/BaseSystem.chunklist
@phatblat
phatblat / rename.fish
Created March 15, 2018 21:38
Renames a set of groovy files to kotlin, preserving folder hierarchy
for file in **/*.groovy
mv $file (dirname $file)/(basename $file groovy)kt
end
@phatblat
phatblat / homebrew.mxcl.artifactory.plist
Created January 9, 2018 16:52
Custom Artifactory launchctl plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.jfrog.artifactory</string>
<key>WorkingDirectory</key>
<string>/usr/local/opt/artifactory/libexec</string>
@phatblat
phatblat / SchwartzianTransform.swift
Last active May 8, 2016 06:13
An example of the Schwartzian Transform in Swift
// Schwartzian Transform
let list = ["a", "aa", "aaaa"]
// Create tuples with the attribute to sort on in the 2nd position
let sorted = list.map { ($0, Int($0.characters.count)) }
.sort { $0.1 > $1.1 }
.map { $0.0 }
print(sorted)
@phatblat
phatblat / AppDelegateTests.m
Created May 6, 2016 19:26
This is cheating
- (void)testAppDelegate {
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate applicationWillEnterForeground:[UIApplication sharedApplication]];
[appDelegate applicationDidBecomeActive:[UIApplication sharedApplication]];
[appDelegate applicationWillTerminate:[UIApplication sharedApplication]];
[appDelegate applicationDidEnterBackground:[UIApplication sharedApplication]];
[appDelegate applicationWillResignActive:[UIApplication sharedApplication]];
BOOL output = [appDelegate application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:[NSDictionary new]];
XCTAssertTrue(output,@"is not true");
}
@phatblat
phatblat / AppDelegate.swift
Last active January 12, 2024 07:18
Example of creating HKObserverQuery and enabling background delivery for multiple HKObjectType
@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {
let healthKitManager = HealthKitManager()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if onboardingComplete {
healthKitManager.requestAccessWithCompletion() { success, error in
if success { print("HealthKit access granted") }
else { print("Error requesting access to HealthKit: \(error)") }
}
@phatblat
phatblat / create_branch.rb
Created May 4, 2016 17:42
Script for creating a matching topic branch in each of repos in the current directory
#!/usr/bin/env ruby
# create_branch.rb
base_branch="development"
ARGV.each do|a|
puts "Argument: #{a}"
end
@phatblat
phatblat / SpecFunctions.swift
Last active May 29, 2016 14:46
Swift 2.2 curried functions for asserting IB outlets and actions are wired up correctly.
//
// SpecFunctions.swift
//
// Created by Ben Chatelain on 6/6/15.
// Copyright (c) 2015-2016 Ben Chatelain.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell