Skip to content

Instantly share code, notes, and snippets.

Taiki Fukui yashigani

Block or report user

Report or block yashigani

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cake.swift
struct User {
let username: String
}
extension User: CustomStringConvertible {
var description: String { return "username: \(username)" }
}
// DAO
@yashigani
yashigani / natural-number.swift
Created Aug 27, 2015
My live coding in #関モバ
View natural-number.swift
enum N {
case Zero
indirect case Succ(N)
static func succ(n: N) -> N {
return .Succ(n)
}
}
let zero: N = .Zero
@yashigani
yashigani / a.swift
Created Jul 27, 2015
Lazy stored propertyとImplicitly Unwrapped Optionalを組み合わせた時のおもしろい挙動
View a.swift
final class Person {
var name: String
lazy var greeting: ImplicitlyUnwrappedOptional<String> = {
return "Hello, \(self.name)"
}()
init(_ name: String) {
self.name = name
}
}
var p = Person("Steve")
@yashigani
yashigani / natural-number.swift
Last active Aug 29, 2015
indirectが実装されたのでSwiftで自然数を作りました
View natural-number.swift
enum N {
case Zero
indirect case Succ(N)
init(_ n: UInt) {
switch n {
case 0: self = .Zero
default: self = .Succ(N(n - 1))
}
}
View gist:cbc88af9c0b0d463cebf
import Foundation
public class JSON: Printable {
private let object: JSONObject
init(_ object: AnyObject?) {
self.object = JSONObject.parse(object)
}
private init(_ object: JSONObject) {
self.object = object
}
View gist:a57a0cc55e986b43e213
// FizzBuzz by Enum
enum FizzBuzz {
case Fizz, Buzz, FizzBuzz, Other(Int)
var state: String {
switch self {
case .Fizz: return "Fizz"
case .Buzz: return "Buzz"
case .FizzBuzz: return "FizzBuzz"
case .Other(let i): return "\(i)"
View game.pl
use strict;
use warnings;
use 5.010;
my $debug = $ENV{DEBUG} // 1;
my $answer = int(1 + rand 100);
say "answer is $answer" if $debug;
GAME: {
View gist:a2a6f3edfecc3269766b
enum Debug {
case Log(Bool)
func log(message: String) {
switch self {
case Log(true):
println(message)
case Log(false):
return
default:
return
@yashigani
yashigani / gist:10426186
Last active Aug 29, 2015
Accessing instance variables in Objective-C
View gist:10426186

ivarpropertyの純情な関係

@yashigani

Objective-Cにおけるインスタンス変数

@interface Person {
  NSString *_firstname;
  NSString *_lastname;
}
@yashigani
yashigani / brainfuck.hs
Created Mar 18, 2014
Brainfuck on Haskell(only Hello, world...)
View brainfuck.hs
helloworld = "+++++++++[>++++++++>+++++++++++>+++++<<<-]>.>++.+++++++..+++.>-.------------.<++++++++.--------.+++.------.--------.>+."
type Code = (String, String)
type Pointer = ([Int], [Int], [Int])
parse :: Code -> Pointer -> Pointer
parse ([], _) p = p
parse ('>':xs, bs) p = parse (xs, '>':bs) $ incrementP p
parse ('<':xs, bs) p = parse (xs, '<':bs) $ decrementP p
parse ('+':xs, bs) p = parse (xs, '+':bs) $ increment p
You can’t perform that action at this time.