Skip to content

Instantly share code, notes, and snippets.

@enomoto
enomoto / fizzBuzz.swift
Created September 21, 2015 05:08
FizzBuzz in Swift
func fizzBuzz(num: Int) -> String {
switch num {
case _ where num % 15 == 0:
return "FizzBuzz"
case _ where num % 3 == 0:
return "Fizz"
case _ where num % 5 == 0:
return "Buzz"
default:
return num.description
#import "UserDefaultsUtility.h"
@implementation UserDefaultsUtility
/**
ユーザデフォルトに設定したオブジェクトを取得する
*/
+ (id) objectForKey:(NSString*) key {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSData *encodedObject = [userDefaults objectForKey:key];
@enomoto
enomoto / FontName.swift
Created March 1, 2017 02:36
find font names for iOS
import UIKit
for fn in UIFont.familyNames {
for font in UIFont.fontNames(forFamilyName: fn) {
print("font: \(font)")
}
}
@enomoto
enomoto / 1.2.rkt
Last active April 20, 2018 04:10
SICP excercise 1.2
#lang racket
(/ (+ 5 4
(- 2
(- 3
(+ 6
(/ 4 5)))))
(* 3
(- 6 2)
(- 2 7)))
@enomoto
enomoto / file0.txt
Created April 27, 2018 07:52
iOSプロジェクトのテストバンドルに存在するファイルを取得する ref: https://qiita.com/enomotok_/items/27d132969b41bcd26187
let path = Bundle.main.path(forResource: "foo", ofType: "json")
let data: NSData? = try? NSData(contentsOfFile: path!, options: .uncached)
@enomoto
enomoto / 1.3.rkt
Created April 27, 2018 13:29
SICP excercise 1.3
#lang racket
(define (sum_of_square a b c)
(cond ((< a b) (< a c) (+ (* b b) (* c c)))
((< b c) (< b a) (+ (* a a) (* c c)))
(else (+ (* a a) (* b b)))
)
)
(sum_of_square 3 4 5) ;41
(sum_of_square 8 4 5) ;89
@enomoto
enomoto / PromiseKitExample.swift
Last active May 10, 2018 01:07
PromiseKit 6 example with Xcode 9.2 and Swift 4.1
import Foundation
import PromiseKit
struct YoRepository {
func fetchDataWithPromise() -> Promise<String> {
return Promise { seal in
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .milliseconds(500)) {
guard true else {
// failure
seal.reject(MyError.unknown)
@enomoto
enomoto / sqrt.rkt
Created May 11, 2018 04:05
SICP 1.1.7
#lang racket
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess)))
(define (sqrt-iter guess x)
(if (good-enough? guess x)
guess
@enomoto
enomoto / AppVersionComparison.swift
Created May 17, 2018 01:05
samples of NSComparisonResult
import Foundation
// https://developer.apple.com/documentation/foundation/nscomparisonresult
let currentVersion = "0.0.2"
let latestVersion1 = "0.0.3"
let latestVersion2 = "0.0.21"
let latestVersion3 = "0.1.0"
let latestVersion4 = "1.0.0"
let latestVersion5 = "0.0.2"
@enomoto
enomoto / swiftc_help.txt
Created June 18, 2018 20:37
$ swiftc -help
OVERVIEW: Swift compiler
USAGE: swiftc [options] <inputs>
MODES:
-dump-ast Parse and type-check input file(s) and dump AST(s)
-dump-parse Parse input file(s) and dump AST(s)
-dump-scope-maps <expanded-or-list-of-line:column>
Parse and type-check input file(s) and dump the scope map(s)
-dump-type-refinement-contexts