Skip to content

Instantly share code, notes, and snippets.

@matsuda
matsuda / MockResponse.swift
Created September 15, 2020 09:50
Custom URLProtocol in Swift
import Foundation
open class MockResponse {
static let errorDomain = "API Mock Error"
enum ErrorCode: Int {
case fileNotFound = -10001
case disableReadFile = -10002
var description: String {
switch self {
@matsuda
matsuda / UINavigationController+extensions.swift
Last active July 2, 2024 03:36
Completion handler for UINavigationController push or pop
/// https://stackoverflow.com/a/33767837
/// https://iganin.hatenablog.com/entry/2019/07/27/172911
extension UINavigationController {
public func pushViewController(
_ viewController: UIViewController,
animated: Bool,
completion: @escaping () -> Void) {
pushViewController(viewController, animated: animated)
guard animated, let coordinator = transitionCoordinator else {
DispatchQueue.main.async { completion() }
@matsuda
matsuda / String+AES.swift
Created November 18, 2019 10:45
AES encryption in Swift
import CommonCrypto
// MARK: AES128 暗号、復号化
public extension String {
func aesEncrypt(key: String, iv: String) -> String? {
guard
let data = self.data(using: .utf8),
let key = key.data(using: .utf8),
let iv = iv.data(using: .utf8),
@matsuda
matsuda / git-commit-count.sh
Last active August 31, 2022 13:46
git tips
#!/bin/sh
# ファイルの1年間のコミット数
git ls-files |
while read file ; do
commits=`git log --since=1.year --no-merges --oneline -- $file | wc -l`;
echo "$commits - $file";
done | sort -n
@matsuda
matsuda / Fastfile
Created May 8, 2019 10:37
指定されたブランチを取得するlane
###############################
# get latest release git branch
###############################
desc "get latest release git branch"
private_lane :git_latest_release_branch do
pattern = "release\/(.+)"
branches = git_find_branches(pattern: pattern)
reg = Regexp.new(pattern)
branches = branches.sort { |a, b|
internal extension KeyedDecodingContainer {
/// 不正なurlだとdecodeエラーになるので、nilにしてスルーする
/// @see https://github.com/apple/swift/blob/master/stdlib/public/Darwin/Foundation/URL.swift
/// @see https://github.com/apple/swift/blob/master/stdlib/public/core/Codable.swift.gyb
/// @see https://github.com/apple/swift/blob/master/stdlib/public/Darwin/Foundation/JSONEncoder.swift
func decodeIfPresent(_ type: URL.Type, forKey key: K) throws -> URL? {
guard try contains(key) && !decodeNil(forKey: key)
else { return nil }
do {
@matsuda
matsuda / decode_unicode.rb
Created March 15, 2019 09:59
Ruby文字列のUnicodeエスケープシーケンスをデコードする
#
# https://techracho.bpsinc.jp/baba/2013_05_31/8837
#
dir = '~/Downloads/Dev/JSON/'
dir = File.expand_path(dir)
def decode(file)
puts file
@matsuda
matsuda / UIImageExtension.swift
Created March 8, 2019 11:33
Utility for UIImage
public extension UIImage {
/// 画像を指定したサイズでリサイズする
/// @see https://qiita.com/ruwatana/items/473c1fb6fc889215fca3
func resized(to size: CGSize) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
draw(in: CGRect(origin: .zero, size: size))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
@matsuda
matsuda / Fastfile
Last active March 15, 2019 10:53
Carthageのoutdatedを実行し、最新のバージョンがリリースされてるかチェックしてSlackへ通知するFastlane action
desc "check carthage outdated"
lane :check_carthage_outdated do
carthage_outdated(
slack_url: "https://hooks.slack.com/services/xxxx",
slack_username: "MyBot"
)
end
desc "check cocoapods outdated"
lane :check_cocoapods_outdated do |options|
@matsuda
matsuda / Fastfile
Last active December 11, 2018 01:20
A Fastlane's action for xcprofiler customized to display total time. https://github.com/giginet/xcprofiler
# -Xfrontend -debug-time-function-bodies -Xfrontend -warn-long-function-bodies=100
lane :profile_build_time do |options|
gym(
...
)
options.merge!(product_name: 'Sample', display_limit: 30)
xcprofiler(options)
output_path = Actions.lane_context[SharedValues::XCPROFILER_OUTPUT_PATH]