Skip to content

Instantly share code, notes, and snippets.

View mitsuse's full-sized avatar
💭
🐈🐈

mitsuse mitsuse

💭
🐈🐈
View GitHub Profile
@mitsuse
mitsuse / A.swift
Last active September 14, 2017 01:58
A.swift (A.framework を生成) を B.swift (B.framework を生成) から参照. A.Namespace が class ではないかつ private/fileprivte なフィールドがあると A.Namespace.T1 を継承できなくなっている (Swift 3.1 まではコンパイルできた).
// public class Namespace { // OK
// public final class Namespace { // NG
// public struct Namespace { // NG
public enum Namespace { // NG
open class T1 {
private func test1() {}
fileprivate func test2() {}
}
}
@mitsuse
mitsuse / interporation.swift
Created September 5, 2017 02:35
Swift の string interpolation (文字列補間) は型の変更を検出できないので事故しやすい話.
struct Cat {
let name: String
let age: Int
}
let cat1 = "jiji"
let cat2 = Cat(name: "jiji", age: 13)
print("name: \(cat1)") // name: jiji
print("name: \(cat2)") // name: Cat(name: "jiji", age: 13)
@mitsuse
mitsuse / lazy_size.swift
Last active August 6, 2017 06:40
Embed a value into type with lazy-evaluation in Swift.
import Foundation
protocol Size { static var value: Int { get } }
enum N: Size { static let value = Int(ProcessInfo.processInfo.environment["ARRAY_SIZE_N"]!)! }
import UIKit
extension UIViewController {
public func present(
_ viewController: UIViewController,
with transitioningDelegate: UIViewControllerTransitioningDelegate,
completion: (() -> Void)? = nil
) {
viewController.transitioningDelegate = transitioningDelegate
viewController.modalPresentationStyle = .custom
@mitsuse
mitsuse / switch_im.vim
Created January 2, 2017 08:53
Switch the current input source to "ABC - Extended" on `InsertLeave` in Vim.
if executable('swim')
autocmd InsertLeave * :call system('swim use com.apple.keyboardlayout.all')
endif
@mitsuse
mitsuse / jenkins.py
Last active November 7, 2016 08:14
A command-line tool to run a job on Jenkins remotely.
#!/usr/bin/env python3
# coding: utf-8
from collections import namedtuple
Crumb = namedtuple('Crumb', ('key', 'value'))
def run(args):
@mitsuse
mitsuse / format_swift.py
Created October 30, 2016 15:52
Recursively format source files written in Swiftm.
#!/usr/bin/env python
# coding: utf-8
def main(args):
for p in walk(args.path, pattern='.*\.swift$'):
format(p, args.indent_width)
def format(path, indent_width):
@mitsuse
mitsuse / AppDelegate.swift
Created October 25, 2016 06:37
A minimal implementation of `AppDelegate` for Swift 2.x.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(
application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?
) -> Bool {
@mitsuse
mitsuse / uint.py
Last active October 1, 2016 07:48
Failure in type checking for `__new__` with mypy.
#!/usr/bin/env python
# coding: utf-8
from typing import Optional
class Uint(object):
def __new__(c, value: int) -> 'Optional[Uint]':
if value < 0:
return None
else:
@mitsuse
mitsuse / forward_ref.py
Last active September 29, 2016 14:52
An example of forward reference in mypy.
#!/usr/bin/env python
# coding: utf-8
from typing import Generic
from typing import Optional
from typing import TypeVar
T = TypeVar('T')
class Box(Generic[T]):