Skip to content

Instantly share code, notes, and snippets.

View sahara-ooga's full-sized avatar

Yuu Ogasawara sahara-ooga

View GitHub Profile
@sahara-ooga
sahara-ooga / search-active-keyboard-api.sh
Last active March 6, 2024 07:49
scripts for Privacy Manifest files
grep -Rn \
--exclude='*.sh' \
-e 'activeInputModes'
@sahara-ooga
sahara-ooga / sample-swift-concurrency.swift
Created October 17, 2022 11:06
swiftplaygroundでSwift Concurrencyを試す
// https://online.swiftplayground.run/ でSwift Concurrencyを試す用のサンプル
struct Example {
@available(macOS 10.15.0, *)
static func factors(for number: Int) async -> [Int] {
var result = [Int]()
for check in 1...number {
if number.isMultiple(of: check) {
result.append(check)
@sahara-ooga
sahara-ooga / assert.rb
Created October 3, 2022 14:54
simple assert function for Ruby
def assert(actual, expected)
# p "actual: #{actual}"
if actual == expected
return
else
puts "#{actual} is not equal to #{expected}!"
exit(false)
end
end

Definition

        func customPrint(line: Int = #line, file: String = #file, _ target: Any) {
            Pretty.splatPrint(
                    label: nil,
                    targets: ["file", file],
                    separator: " : ",
                    option: Pretty.Option(colored: true)
 )
@sahara-ooga
sahara-ooga / UIContentSizeCategory+String.swift
Last active March 22, 2022 07:24
Readable UIContentSizeCategory string
/*
The rawValue of UIContentSizeCategory is not as clear as `UICTContentSizeCategoryL`(see example below) .
```swift
UIContentSizeCategory.large.rawValue//"UICTContentSizeCategoryL"
UIContentSizeCategory.accessibilityExtraExtraExtraLarge.rawValue//"UICTContentSizeCategoryAccessibilityXXXL"
```
To solve this problem, I defined mapping.
@sahara-ooga
sahara-ooga / convert_mkv_mp4.sh
Last active July 19, 2022 01:51
Convert movies via ffmpeg
ffmpeg -i foo.mkv -vcodec copy -acodec copy foo.mp4
@sahara-ooga
sahara-ooga / drop-start-quantity.swift
Created August 25, 2021 05:34
Cut out the middle of an array in Swift
extension Sequence {
func drop(start at: Int, quantity: Int) -> [Element] {
return Array(self.dropFirst(at).prefix(quantity))
}
}
let array = [0, 1, 2, 3, 4, 5]
let actual = array.drop(start: 2, quantity: 3)
print(actual == [2, 3, 4])
@sahara-ooga
sahara-ooga / swift-format-configuration.md
Created August 17, 2021 14:18
Swift format configuration

In root directory of project:

% swift-format -m dump-configuration > .swift-format.json 
% code .swift-format.json

configure indentation in .swift-format.json:

@sahara-ooga
sahara-ooga / convert-aiff-to-mp3.sh
Last active August 15, 2021 07:19
Convert `.aiff` files to `.mp3`
# precondition
# install ffmpeg
for f in *.aiff;
do
ffmpeg -i "$f" -f mp3 -acodec libmp3lame -ab 320000 -ar 44100 "output/${f%.aiff}.mp3";
done
@sahara-ooga
sahara-ooga / SwiftUIViewInUIKit.swift
Created August 8, 2021 14:26
SwiftUI's View in UIKit
import UIKit
import SwiftUI
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
configure(BindingView())
}
}