Skip to content

Instantly share code, notes, and snippets.

View hirohitokato's full-sized avatar

Hirohito Kato hirohitokato

View GitHub Profile
@hirohitokato
hirohitokato / DLFonts.swift
Created June 23, 2017 07:47
ダウンロードフォントの管理クラス
//
// DLFonts.swift
//
// Created by Hirohito Kato on 2017/04/21.
// Copyright © 2017 Hirohito Kato. All rights reserved.
//
//
// FontDownloader.swift
// FontDownloader
@hirohitokato
hirohitokato / hubeny-distance.js
Created June 23, 2017 05:55
ヒュベニの距離計算式による2地点の距離(m)を計算するコード。測地系にはWGS84を使用
/**
* ヒュベニの距離計算式を使用して、2点({latitude1,longitude1}, {latitude2,longitude2})間の
* 距離を求める。測地系にはWGS84を使用。
*
* 参考:
* - ヒュベニの距離計算式の簡略式( http://www.kashmir3d.com/kash/manual/std_siki.htm )
* - 正式な公式は http://www.amano-tec.com/apps/paceruler.html を参照
*/
function calculateDistance(latitude1, longitude1, latitude2, longitude2) {
// 先に計算しておいた定数
@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