Skip to content

Instantly share code, notes, and snippets.

View hirohitokato's full-sized avatar

Hirohito Kato hirohitokato

View GitHub Profile
@hirohitokato
hirohitokato / Wrapper.swift
Last active November 16, 2016 01:52
Extract inner value like a C pointer
import Foundation
prefix operator *
infix operator <-
class Wrapper<T> {
var value: T
init(_ v: T) { value = v }
}
@hirohitokato
hirohitokato / XCSourceEditorCommand.h
Created October 10, 2016 16:11
Header files in XcodeKit.framework (Xcode 8.0 (8A218a))
//
// XCSourceEditorCommand.h
// Xcode
//
// Copyright © 2016 Apple Inc. All rights reserved.
//
#import <XcodeKit/XcodeKitDefines.h>
@hirohitokato
hirohitokato / ServiceCollector.swift
Last active October 5, 2016 14:04
macOS上で調べた、BluetoothでのWell KnownなサービスとそのUUID一覧
// @ref: https://www.bluetooth.com/specifications/gatt/services?sc_lang=en
for i in 0..<0xFFFF {
let uuid = CBUUID(string: String(format: "0x%.04X", i))
if !"\(uuid)".contains("Unknown") {
print("\(String(format: "0x%.04X", i)) : \(uuid)")
}
}
/* Result
0x1800 : Generic Access Profile
0x1801 : Generic Attribute Profile
@hirohitokato
hirohitokato / UITextField+autoShrinkText.swift
Last active July 28, 2016 09:18
UITextFieldに長いテキストを入れても、きちんとフォントサイズをシュリンクしてくれる autoShrinkText プロパティを作ってみた
// -see: http://stackoverflow.com/a/16356147
extension UITextField {
private struct AssociatedKeys {
static var origFontSize:NSObject?
}
var autoShrinkText: String? {
get { return text }
set {
guard let font = font else { text = newValue; return }
@hirohitokato
hirohitokato / commit-msg
Last active July 8, 2016 09:48
コミットメッセージに含まれる絵文字のショートネーム(`: bug :`)を絵文字そのもの ( 🐛) に変換してからコミットするフックスクリプト。.git/hooks/下に置いて使う
#!/usr/bin/env python
# coding: utf-8
import sys, os, time
import re
EMOJI = {
":bug:" :"🐛", # バグ修正
":+1:" :"👍", # 機能改善
":sparkles:" :"✨", # 部分的な機能追加
@hirohitokato
hirohitokato / Collection+movingavg.swift
Last active May 16, 2016 05:29
A moving average of the specified array by Swift. It is merged from https://gist.github.com/norio-nomura/fdbf22dacefcfcf87705cf2cd8fb846f
// merged from https://gist.github.com/norio-nomura/fdbf22dacefcfcf87705cf2cd8fb846f
import Foundation
public protocol ArithmeticType: IntegerLiteralConvertible {
func +(lhs: Self, rhs: Self) -> Self
func -(lhs: Self, rhs: Self) -> Self
func *(lhs: Self, rhs: Self) -> Self
func /(lhs: Self, rhs: Self) -> Self
}
// Playground - noun: a place where people can play
import Foundation
typealias Byte = UInt8
protocol GenericIntegerType: IntegerType {
init(_ v: Int)
init(_ v: UInt)
init(_ v: Int8)
@hirohitokato
hirohitokato / build_boost.sh
Last active August 29, 2015 14:16
Build boost libraries(1.57) for iOS/OS X.
# Shell script for building Boost C++ for iOS (armv7, armv7s, arm64), the iOS Simulator
# (i386, x86_64), and Mac OSX (i386, x86_64).
#
# Creates a set of universal libraries and a pseudo-framework to facilitate using
# Boost C++ in Xcode.
#
# To configure the script, define:
#
# BOOST_VERSION Boost C++ version (e.g. 1.57.0)
# BOOST_LIBS: which Boost C++ libraries to build
@hirohitokato
hirohitokato / HKLCGImageUtils.swift
Created December 26, 2014 02:57
Create a thumbnail from NSData with required size. It doesn't consume much memory.
//
// HKLCGImageUtils.swift
//
// Created by Hirohito Kato on 2014/12/26.
//
// @see https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/ImageIOGuide/imageio_source/ikpg_source.html#//apple_ref/doc/uid/TP40005462-CH218-DontLinkElementID_6
import Foundation
import ImageIO
@hirohitokato
hirohitokato / HKLCMTimeUtils.swift
Last active December 1, 2023 14:05
Convenience Methods/Variables/Operators for CMTime
//
// HKLCMTimeUtils.swift
//
// Created by Hirohito Kato on 2015/01/07.
// Copyright © 2020 Kato Hirohito. Licensed under Unlicense(https://unlicense.org). Feel free to use it!
import CoreMedia
// MARK: Initialization
public extension CMTime {