Skip to content

Instantly share code, notes, and snippets.

View fromkk's full-sized avatar

Kazuya Ueoka fromkk

View GitHub Profile
@fromkk
fromkk / CodePiece.swift
Created August 29, 2016 11:09
最近はこうする事が多いかな #love_swift #CodePiece #akiba_swift
import UIKit
public protocol ReusableTableViewCell: class {
static var cellIdentifier: String { get }
static func reusableTableView<T>(tableView: UITableView, forIndexPath indexPath: NSIndexPath) -> T
}
extension ReusableTableViewCell {
public static func reusableTableView<T>(tableView: UITableView, forIndexPath indexPath: NSIndexPath) -> T {
guard let cell: T = tableView.dequeueReusableCellWithIdentifier(self.cellIdentifier, forIndexPath: indexPath) as? T else {
@fromkk
fromkk / CodePiece.swift
Last active August 31, 2016 00:52
.@codelynx1 さんの発表を参考にif文とwhile文を日本語で作ってみた。これは闇が深そうだ。。 #iOSDCRC #CodePiece
import Foundation
//Swift 2.2
public func もし(val: Bool, @noescape _ closure: () -> Void) -> Void {
if val {
closure()
}
}
public func 間(@autoclosure check: (Void) -> Bool, @noescape _ closure: () -> Void) -> Void {
# Mac側
docker run --privileged -d -p 9080:9080 --name centos_realm centos:6.8 /sbin/init
docker exec -it centos_realm /bin/bash
# Docker内
yum update -y && \
yum install -y wget curl && \
yum -y groupinstall base "Development tools" && \
iptables -A INPUT -p tcp -m tcp --dport 9080 -j ACCEPT && \
service iptables save && \
// Instantitable
import UIKit
public protocol Instantitable: class {}
public protocol StoryboardInstantitable: Instantitable {
static var viewControllerIdentifier: String? { get }
}
// MARK: - Regular Expression
private extension String {
func regexp(_ pattern: String) -> NSRegularExpression {
do {
let regexp: NSRegularExpression = try NSRegularExpression(pattern: pattern, options: [NSRegularExpression.Options.caseInsensitive])
return regexp
} catch {
fatalError("regular expression pattern is invalid.")
}
}
[alias]
unstage=reset HEAD
pushcurrent=!git push origin `git rev-parse --abbrev-ref HEAD`
pullcurrent=!git pull origin `git rev-parse --abbrev-ref HEAD`
removemergedbranch=!git branch --merged | grep -vE '^\\*|master$|develop$' | xargs -I % git branch -d %
protocol AnyGetableAndSavable {
associatedtype T
func get() -> T
func save()
}
class GetAndSaver<U>: AnyGetableAndSavable {
typealias T = U
var value: T
required init(value: T) {
self.value = value
sips icon.png -Z 20 --out icon_20.png
sips icon.png -Z 40 --out icon_20@2x.png
sips icon.png -Z 60 --out icon_20@3x.png
sips icon.png -Z 29 --out icon_29.png
sips icon.png -Z 58 --out icon_29@2x.png
sips icon.png -Z 87 --out icon_29@3x.png
sips icon.png -Z 40 --out icon_40.png
sips icon.png -Z 80 --out icon_40@2x.png
@fromkk
fromkk / DIContainer.swift
Last active July 9, 2019 22:49
Simplest DI container in Swift
public class DIContainer {
public typealias Resolver = ([Any]) -> Any?
static var resolvers: [ObjectIdentifier: Resolver] = [:]
public static func register<T>(_ type: T.Type, resolver: @escaping Resolver) {
resolvers[ObjectIdentifier(type)] = resolver
}
public static func resolve<T>(_ type: T.Type, args: Any...) -> T? {
guard let resolver = resolvers[ObjectIdentifier(type)] else { return nil }
return resolver(args) as? T
@fromkk
fromkk / Bindable.swift
Last active May 13, 2018 00:26
Bind feature with Swift from scratch
import UIKit
public class Variable<T: Equatable> {
public var value: T {
didSet {
obserbers.forEach {
$0(value)
}
}