Skip to content

Instantly share code, notes, and snippets.

@shu223
shu223 / CustomActivity.swift
Last active November 4, 2020 17:59
Custom UIActivity in Swift 3
import UIKit
class CustomActivity: UIActivity {
override class var activityCategory: UIActivityCategory {
return .action
}
override var activityType: UIActivityType? {
guard let bundleId = Bundle.main.bundleIdentifier else {return nil}
@shu223
shu223 / duration_timestamp.md
Last active September 11, 2018 09:50
CADisplayLinkのメモ

##duration と timestamp

普通に初期化して、

CADisplayLink *displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onTimer:)];
displayLink.frameInterval = 30;
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
self.displayLink = displayLink;
[self onTimer:self.displayLink];
#!/usr/bin/env python
import argparse
import datetime
import os
import yaml
def main(args):
@shu223
shu223 / normalize.md
Last active February 12, 2018 18:25
Normalize

Normalize 1

UInt16 processGain(AudioBuffer buffer,
                   float gain)
{
    SInt16 *input = (SInt16 *)buffer.mData;
    UInt64 avg = 0;
    for(int i = 0; i < buffer.mDataByteSize; i++){
        avg += abs(input[i]);        // 音量増幅前の累計
@shu223
shu223 / beacon.md
Last active February 12, 2018 18:23
ビーコンを Core Bluetooth で検出するメリット

高速レンジング

ビーコン領域監視のレンジングは1秒間隔。それ以上速くできない。

実際これが結構遅い。 3mぐらいしか離れてないオブジェクト同士を移動する場合、didEnterとか待ってられないし、1秒待ってたら「遅い!」ってな感覚がある

Core Bluetooth を使えばアドバタイズのインターバルまで速くできる。100msecとか。

Core Location によるビーコン領域監視のメリットはバックグラウンドでの挙動なので、レンジングを高速に行いたい場合、フォアグラウンドでは Core Bluetooth を使うのがベストプラクティスなのでは?

@shu223
shu223 / beacon.md
Last active February 12, 2018 18:22
屋外でビーコン領域監視を使うメリット

屋外なら位置情報ベースの領域監視が使える。 (ビーコンではなく)位置情報ベースの領域監視を使えば、

  • 電池切れの心配がない
  • 設置の手間がかからない
  • 盗まれる心配もない
  • 人体によって電波が吸収されたりしない

というように、ビーコンの物理特性による欠点が、位置情報を使う場合には問題にならなくなる。

@shu223
shu223 / get_properties.md
Last active February 12, 2018 18:12
オブジェクトが持つプロパティの型と名前のリストを取得する ref: http://qiita.com/items/2823
#import "objc/runtime.h"
static const char * getPropertyType(objc_property_t property) {
    const char *attributes = property_getAttributes(property);
    char buffer[1 + strlen(attributes)];
    strcpy(buffer, attributes);
    char *state = buffer, *attribute;
@shu223
shu223 / TensorFlow_TIPS.md
Last active February 12, 2018 18:01
TensorFlow TIPS
@shu223
shu223 / オープンソースAPI関連Tips.md
Last active December 12, 2017 06:32
オープンソースAPI関連Tips

メソッドの使用を禁止する

- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

メソッド・プロパティをdeprecated/unavailableにする

// Modified from: https://github.com/katleta3000/CancelBlocks/blob/master/CancelBlocks.swift
typealias dispatch_cancelable_block_t = (cancel: Bool) -> (Void)
private func dispatch_after_delay(delay: Double, queue: dispatch_queue_t, block: dispatch_block_t?) -> dispatch_cancelable_block_t? {
guard let block = block else { return nil }
var originalBlock: dispatch_block_t? = block
var cancelableBlock: dispatch_cancelable_block_t? = nil
let delayBlock: dispatch_cancelable_block_t = {(cancel: Bool) -> Void in
if let originalBlock = originalBlock where !cancel {