Skip to content

Instantly share code, notes, and snippets.

@yoichitgy
yoichitgy / Playground-MercariTechConf2017-DIContainer.swift
Last active October 1, 2017 02:07
Mercari Tech Conf 2017 - Demo implementing a simple dependency injection container
protocol Animal {
func sound() -> String
}
class Cat: Animal {
func sound() -> String { return "😺Meow" }
}
class Dog: Animal {
func sound() -> String { return "🐶Bow wow" }
}
@yoichitgy
yoichitgy / ViewController.swift
Created September 16, 2017 06:29
iOSDC JAPAN 2017 Demo - ViewController.swift
import UIKit
class ViewController: UIViewController {
private var count = 0
override func viewDidLoad() {
super.viewDidLoad()
Log.info(message: "viewDidLoad")
Log.info(message: "API: GET /some/values")
Log.info(message: "User did something.")
@yoichitgy
yoichitgy / AppDelegate.swift
Created September 16, 2017 06:29
iOSDC JAPAN 2017 Demo - AppDelegate.swift
import UIKit
import Fabric
import Crashlytics
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Fabric.with([Crashlytics.self])
@yoichitgy
yoichitgy / Log.swift
Created September 16, 2017 06:28
iOSDC JAPAN 2017 Demo - Log.swift
import Foundation
import os.log
import Crashlytics
final class Log {
private init() {}
static func debug(message: String) {
writeLog(message: message, level: .debug)
}
@yoichitgy
yoichitgy / CakePatternExample.swift
Created April 4, 2017 03:02
Cake Pattern Example in Swift (Demo at iOSCon 2017 in London)
// Demo at iOSCon 2017 in London
// https://speakerdeck.com/yoichitgy/dependency-injection-in-practice-ioscon
//
// How to Use: Paste this program to a Playground.
// Tested with: Xcode 8.2.1
// Interface (protocol)
protocol Logger {
func log(_ message: String)
}
@yoichitgy
yoichitgy / SwinjectExample.swift
Created April 4, 2017 02:54
Swinject Example (Demo at iOSCon 2017 in London)
// Demo at iOSCon 2017 in London
// https://speakerdeck.com/yoichitgy/dependency-injection-in-practice-ioscon
//
// Tested with: Xcode 8.2.1
//
// How to Use:
// 1. Clone Swinject: git clone --recursive [email protected]:Swinject/Swinject.git
// 2. Checkout 2.0.0 branch: cd Swinject; git checkout 2.0.0
// 3. Build the Swinject project for a simulator target
// 4. Open the playground in the project
@yoichitgy
yoichitgy / SimpleDIContainer.swift
Last active July 11, 2019 19:08
Simple DI Container in Swift (Demo at iOSCon 2017 in London)
// Demo at iOSCon 2017 in London
// https://speakerdeck.com/yoichitgy/dependency-injection-in-practice-ioscon
//
// How to Use: Paste this program to a Playground.
// Tested with: Xcode 8.2.1
protocol Animal: class { }
class Cat: Animal { }
class Dog: Animal { }
@yoichitgy
yoichitgy / hugodeploy
Last active July 1, 2022 18:19
A bash script to deploy GitHub Pages with Hugo.
#!/bin/bash
while getopts p option
do
case $option in
p) opt_p=TRUE ;;
esac
done
if [ ! -d "public" ]
@yoichitgy
yoichitgy / genassetimages.sh
Created March 17, 2015 05:27
A script to generates iOS asset PNG images from a PSD file for @1x, @2x and @3x scales.
#!/bin/sh
#
# genassetimages.sh
# Generates iOS asset PNG images from a PSD file for @1x, @2x and @3x scales.
# ImageMagick is used to resize the images.
#
# settings ==========
outputDir="image_assets"
assetSuffixes=(".png" "@2x.png" "@3x.png")
@yoichitgy
yoichitgy / mergegenstrings.py
Last active July 9, 2022 23:59
A script to generate .strings file for .swift, .m, .storyboard and .xib files by genstrings and ibtool commands, and merge them with existing translations.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Localize.py - Incremental localization on XCode projects
# João Moreno 2009
# http://joaomoreno.com/
# Modified by Steve Streeting 2010 http://www.stevestreeting.com
# Changes
# - Use .strings files encoded as UTF-8