Skip to content

Instantly share code, notes, and snippets.

View motokiee's full-sized avatar
🎯
Focusing

motokiee motokiee

🎯
Focusing
  • Mercari, Inc.
  • Tokyo
  • 06:05 (UTC +09:00)
  • X @motokiee
View GitHub Profile
@motokiee
motokiee / CodePiece.go
Created January 26, 2016 13:38
golang #CodePiece
package main
import "fmt"
type Person struct {
name string
age int
}
func (p Person) greet() {
package main
import (
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
extension IntegerType {
var isZorome: Bool {
let characters = "\(self)".characters
guard characters.count < 2 else {
return false
}
@motokiee
motokiee / CodePiece.swift
Last active January 15, 2016 05:49
けさ書いたゾロ目判定処理。もうちょっとうまく書けたりするかな #CodePiece
func isZorome(number:Int) -> Bool {
let numString = String(number)
guard numString.characters.count > 1, let first = numString.characters.first else {
return false
}
let bools = numString.characters.map { $0 == first }.reduce(true) { (a, b) -> Bool in
a&&b
@motokiee
motokiee / CodePiece.swift
Created December 26, 2015 00:39
なるほどな〜 #CodePiece
public mutating func next() -> Element? {
guard let b = base.next() else { return nil }
defer { count += 1 }
return (index: count, element: b)
}
typealias PaymentType = (Bool, Bool, Bool)
func getPayAmountEasySwitch(payment: PaymentType) -> Double {
switch (payment.0, payment.1, payment.2) {
case (true, _, _):
return 0.0
case (_, true, _):
return 1.0
case (_, _, true):
@motokiee
motokiee / DebugLog.swift
Last active April 14, 2016 02:35
Original debug log in Swift
func DebugLog(@autoclosure condition: () -> Bool = true, _ message: String = "", function: StaticString = __FUNCTION__, file: StaticString = __FILE__, line: UInt = __LINE__) {
#if DEBUG
if let fileName = NSURL(string: String(file))?.lastPathComponent {
print("time: \(NSDate()), message: \(message), function: \(function), file: \(fileName), line: \(line)")
} else {
print("time: \(NSDate()), message: \(message), function: \(function), file: \(file), line: \(line)")
}
assert(condition, message, file: file, line: line)
@motokiee
motokiee / CodePiece.swift
Created November 14, 2015 08:29
Associated Typeでパターンマッチ #CodePiece
enum Option {
case Regular(MoreOption)
case Irregular(MoreOption)
}
enum MoreOption {
case One, Two, Three
}
let os1 = Option.Regular(.One)
let os2 = Option.Regular(.Two)
@motokiee
motokiee / CodePiece.swift
Created November 14, 2015 06:31
勉強会の休憩中に部分適用とかいじった #CodePiece
typealias Closure = (Int,Int) -> Int
let addClosure = { (a:Int, b:Int) -> Int in
return a+b
}
let multipleClosure = { (a:Int, b:Int) -> Int in
return a*b
}
@motokiee
motokiee / CodePiece.swift
Created November 14, 2015 05:49
extensionで新しく定義の追加できるの知らなかった。protocolに定義したもののデフォルト値を設定するだけじゃなかったのか。 #cswift #CodePiece
protocol Foo {
func hoge() -> Void
}
extension Foo {
func hoge() -> Void {
print("hoge")
}
func hoge2() -> Void {