Skip to content

Instantly share code, notes, and snippets.

View matsuda's full-sized avatar

Kosuke Matsuda matsuda

  • Tokyo, Japan
View GitHub Profile
@matsuda
matsuda / memoryAddress.swift
Last active February 20, 2025 08:01
Get memory address in Swift
///
/// https://stackoverflow.com/a/29741007
///
let s = Struct() // Struct
withUnsafePointer(to: s) {
print(String(format: "%p", $0)
}
///
/// http://stackoverflow.com/a/36539213/226791
@matsuda
matsuda / 1_sample.sql
Last active January 25, 2025 15:14
SQLite snippets
/*
CREATE文における各種データ型の設定
擬似的にBOOLEAN型を設定
*/
CREATE TABLE IF NOT EXISTS tests (id INTEGER PRIMARY KEY AUTOINCREMENT,
memo TEXT,
image BLOB,
type INTEGER,
favorite BOOLEAN NOT NULL DEFAULT 0 CONSTRAINT testsFavorite CHECK (favorite IN (0, 1) OR favorite IS NULL),
createdAt DATETIME
@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 / NSData+AES.h
Created February 25, 2014 07:14
Objective-C code for encrypt and decrypt by AES-128 encryption.
/**
http://mythosil.hatenablog.com/entry/20111017/1318873155
http://blog.dealforest.net/2012/03/ios-android-per-aes-crypt-connection/
*/
@interface NSData (AES)
- (NSData *)AES128EncryptedDataWithKey:(NSString *)key;
- (NSData *)AES128DecryptedDataWithKey:(NSString *)key;
- (NSData *)AES128EncryptedDataWithKey:(NSString *)key iv:(NSString *)iv;
@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 / 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 / gist:1280514
Created October 12, 2011 07:12
install readline by Homebrew
$ brew install readline
==> Downloading http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file vi_mode.c
patching file callback.c
==> ./configure --prefix=/usr/local/Cellar/readline/6.2.1 --mandir=/usr/local/Cellar/readline/6.2.1/share/man --infodir=/usr/local/Cellar/readline/6.2.1/share/info --enable-multibyte
==> make install
@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|
@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 / lldb_tips.txt
Last active August 23, 2021 00:58
LLDB tips
Simulator起動時に `Lost connection to the debugger` と表示されてディタッチされてしまう&Simulator上でアプリが起動しない
# https://developer.apple.com/forums/thread/681037
```
settings set plugin.process.gdb-remote.packet-timeout 300
```