Skip to content

Instantly share code, notes, and snippets.


Kosuke Ohmura KosukeOhmura

View GitHub Profile
KosukeOhmura /
Last active Feb 9, 2019

Privacy Policy

Effective date: February 1, 2019

Your privacy is important to us. It is Kosuke Ohmura's policy to respect your privacy regarding any information we may collect from you across our website,, and other sites we own and operate.

  • What data we store, we’ll protect within commercially acceptable means to prevent loss and theft, as well as unauthorised access, disclosure, copying, use or modification. We don’t share any personally identifying information publicly or with third-parties, except when required to by law.
  • We may use third-party Service Providers to monitor and analyze the use of our Service.
  • Our application may link to external sites that are not operated by us. Please be aware that we have no control over the content and practices of these sites, and cannot accept responsibility or liability for their respective privacy policies.
  • Your continued use of our application will be regarded as acceptance of our practices around privacy and personal infor
KosukeOhmura / file1.txt
Last active May 2, 2019
Rails アプリを eager_load! してみることでプロダクション環境での出落ちを未然に防ぐ ref:
View file1.txt
bundle exec rails runner Rails.application.eager_load!
KosukeOhmura / AppDelegate.swift
Last active Dec 1, 2018
UIWindow を使用して安全にグローバルなモーダル画面を表示する ref:
View AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow()
self.window = window // 参照を保持しておく
return true
KosukeOhmura / ListViewController.swift
Created Dec 14, 2017
【UITableView】ページング処理のため残りの cell の数を取得する ref:
View ListViewController.swift
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if tableView.belowCellsCount(cellIndexPath: indexPath) < 6 {
// 残りのセル数が6を下回った
// 追加のコンテンツ取得処理
KosukeOhmura / URL+.swift
Last active Sep 29, 2017
Swift で URL のクエリストリングを簡単に追加したい ref:
View URL+.swift
extension URL {
// クエリを一つ追加した新しいURLを返す
func queryItemAdded(name: String, value: String?) -> URL? {
return self.queryItemsAdded([URLQueryItem(name: name, value: value)])
// クエリを複数追加した新しいURLを返す
func queryItemsAdded(_ queryItems: [URLQueryItem]) -> URL? {
guard var components = URLComponents(url: self, resolvingAgainstBaseURL: nil != self.baseURL) else {
KosukeOhmura / ImageManager.swift
Last active Jan 12, 2019
iOS で RxSwift を使ってカメラかフォトライブラリから画像を一枚取得する ref:
View ImageManager.swift
final class ImageManager {
// 権限確認 -> 選択された画像のストリーム
func pick(on viewController: UIViewController, sourceType: UIImagePickerControllerSourceType) -> Observable<Result<UIImage, InternalError>> {
return self.authorizedSourceType(sourceType)
// 画像選択画面作成
.map { sourceType -> (picker: UIImagePickerController, delegate: ImagePickerControllerDelegate) in
// UIImagePickerControllerとそれにわたすdelegateを生成
let picker = UIImagePickerController()
let delegate = ImagePickerControllerDelegate()
KosukeOhmura / WebViewController.swift
Created Jul 29, 2017
モーダルで表示したUIWebView上のアラートが閉じたときにUIWebViewも道連れにされた話 ref:
View WebViewController.swift
final class WebViewController: UIViewController {
// 閉じるボタンが押されたフラグ
private var closeBtnFlag: Bool = false
@IBOutlet private weak var webView: UIWebView!
View BadKbn.swift
class Constants {
enum Kbn: String {
// 性別
case genderKbnMan = "00101"
case genderKbnWoman = "00102"
// 都道府県
case prefectureKbnHokkaido = "00201"
// ...
var logicalName: String {
KosukeOhmura / file0.txt
Created Jan 25, 2017
プロジェクトを開いたり、アプリをrunすると "Xcodeが予期しない理由で終了しました。" となる ref:
View file0.txt
rm -r ~/Library/Developer/Xcode/DerivedData/
You can’t perform that action at this time.