Skip to content

Instantly share code, notes, and snippets.

View WorldDownTown's full-sized avatar
🍺
working with beers

Keisuke Shoji WorldDownTown

🍺
working with beers
  • Tokyo, Japan
View GitHub Profile
@WorldDownTown
WorldDownTown / runtime.h
Created February 12, 2013 03:11
objc_setAssociatedObject
void objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
// id object: プロパティを持たせたいオブジェクト
// void *key: プロパティのアドレス (static で宣言した不変なローカルな静的変数を指定する)
// id value: 保持させるのオブジェクト
// objc_AssociationPolicy policy: 関連付けの方法 (後述)
@WorldDownTown
WorldDownTown / file0.swift
Last active August 29, 2015 14:14
Swiftで受付システムを作った話とCADisplayLink ref: http://qiita.com/WorldDownTown/items/f66d283052f9809d21df
let displayLink = CADisplayLink(target: self, selector: Selector("update:"))
displayLink.addToRunLoop(NSRunLoop.currentRunLoop(), forMode: NSRunLoopCommonModes)
-- 1. リストを引数に取って、length に π (=3.1415)を返す関数
pieTime x = fromIntegral (length x) + (pi :: Float)
-- 2. 2つの文字列を引数にとって、数値として足し算する関数
addString x y = (read x::Int) + (read y::Int)
-- 3. 文字列を逆する関数
reverse' x = [x !! z | z <- [((length x) - 1), ((length x) - 2)..0]]
-- 4. 文字列が回文かどうかを判定する関数 isPalindrome
#coding:utf-8
#Xcode上の不要なファイルを抽出するスクリプト
puts "- start class file #{Time.now.strftime("%Y/%m/%d %H:%M:%S")}"
class_waste_count = 0
#クラスファイルの一覧を取得
result = `find ~/SampleProject -type f -name "*.h" -exec basename {} \\; | sort`
class_filenames = result.split("\n")
@WorldDownTown
WorldDownTown / map_filter_reduce.swift
Created January 24, 2016 06:29 — forked from Nirma/map_filter_reduce.swift
Map and filter implemented with a version of reduce taking list as its reduce argument.
func reduce<T,R>(list: [T], block: (([R],T) -> R?)) -> [R]? {
var acc = [R]()
for x in list {
if let val = block(acc, x) {
acc += [val]
}
}
return acc
}
@WorldDownTown
WorldDownTown / Decorators.go
Created March 24, 2016 02:18 — forked from Nirma/Decorators.go
Using Decorators in Golang to profile performance
package main
import (
"fmt"
"math/rand"
"sort"
"time"
)
@WorldDownTown
WorldDownTown / ExtensionCompatibleSample.swift
Last active June 21, 2018 10:46
An example of Extension based on Kingfisher in Swift.
public final class Extension<Base> {
public let base: Base
public init(_ base: Base) {
self.base = base
}
}
public struct StaticExtension<Base> { }
public protocol ExtensionCompatible {
@WorldDownTown
WorldDownTown / ExtensionCompatibleSample.swift
Last active March 5, 2022 03:10
An example of Extension based on RxSwift in Swift.
public struct Extension<Base> {
public let base: Base
public init(_ base: Base) {
self.base = base
}
}
public protocol ExtensionCompatible {
associatedtype Compatible
var ex: Extension<Compatible> { get set }
@WorldDownTown
WorldDownTown / InsertRowsWithoutScrollingViewController.swift
Last active September 27, 2023 06:26
Insert rows in the top of UITableView without scrolling.
import UIKit
final class ViewController: UITableViewController {
private var names: [String] = (50...99).map { String($0) }
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
@WorldDownTown
WorldDownTown / UnitBezier.swift
Last active February 25, 2020 23:34
Solver for cubic bezier curve with implicit control points at (0, 0) and (1, 1)
import PlaygroundSupport
import UIKit
/// Solver for cubic bezier curve with implicit control points at (0, 0) and (1, 1)
/// Based on https://github.com/adobe/webkit/blob/master/Source/WebCore/platform/graphics/UnitBezier.h
struct UnitBezier {
private let a: CGPoint
private let b: CGPoint
private let c: CGPoint
private let epsilon: CGFloat = 0.000001