This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2022 Confusion Studios LLC | |
// by Dan Rosenstark | |
import Foundation | |
/// Extension on DispatchQueue? for Testing | |
/// If you don't have a DispatchQueue, run immediately (on current queue) | |
extension Optional where Wrapped : DispatchQueue { | |
public func asyncIfNotNil(execute block: @escaping ()->()) { | |
if let self = self { | |
self.async(execute: block) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSArray+Filter.h" | |
@implementation NSArray (Filter) | |
- (NSArray *) filteredArrayUsingBlock:(BOOL (^)(id obj))block { | |
NSIndexSet *const filteredIndexes = [self indexesOfObjectsPassingTest:^BOOL (id _Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) { | |
return block(obj); | |
}]; | |
return [self objectsAtIndexes:filteredIndexes]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
func permute(_ s: String) -> [String] { | |
var arr = Array(s) | |
var permutations = [[Character]]() | |
permute(&arr, 0, &permutations) | |
return permutations.map { String($0) } | |
} | |
func permute<T>(_ arr: inout [T], _ k: Int, _ result: inout [[T]]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# swiftWatchAndRun | |
if [ $# -ne 1 ]; then | |
echo "Use like this:" | |
echo " $0 filename-to-watch" | |
exit 1 | |
fi | |
if which fswatch >/dev/null; then | |
echo "Watching swift file $1" | |
while true; do fswatch --one-event $1 >/dev/null && echo "----------------"; echo `date +"%m-%d-%y %I:%M%p"`; echo "----------------" && swift $1; sleep 0.1; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pbpaste > /tmp/shellpaste.sh | |
echo "Execute this?" | |
cat /tmp/shellpaste.sh | |
echo | |
read -p "Press enter to run it..." | |
bash /tmp/shellpaste.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Run with: | |
/// swift -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks xctest-in-repl.swift | |
import Foundation | |
import XCTest | |
class ATest : XCTestCase { | |
func testIt() { | |
print("Oh yeah, it's on") | |
XCTAssertTrue(false, "That needed to be true!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc public protocol Equalable: class { | |
@objc func isEqual(_ object: Any?) -> Bool | |
} | |
/// Store AnyObject subclasses weakly | |
/// * Note: if you wish to use a protocol, it must: | |
/// - be marked with `@objc` | |
/// - have all methods marked with `@objc` | |
/// - refine Equalable | |
public struct WeakArray<Element: Equalable> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def convert_mermaid_md_to_jpg | |
Dir["mermaid-*.md"].each do |f| | |
slug = f["mermaid-".length...f.length-".md".length] | |
command = "~/node_modules/.bin/mmdc -i mermaid-#{slug}.md -o mermaid-#{slug}.png -b '#FFFFFF'" | |
puts "Converting mermaid-#{slug}.md to mermaid-#{slug}.png" | |
`#{command}` | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
`xcrun simctl shutdown all` | |
device_lines = `xcrun simctl list`.split("\n") | |
device_lines.each do |line| | |
line.strip! | |
matches = /[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/.match(line) | |
if matches | |
`xcrun simctl delete #{matches}` | |
puts "Deleting sim with ID #{matches}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
git checkout -b $1 && git push --set-upstream origin $1 |