Skip to content

Instantly share code, notes, and snippets.

@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 / TTMArithmetic.m
Created April 7, 2015 06:01
Accelerate.frameworkを用いた平均値計算
//
// TTMArithmetic.m
//
// Copyright (c) 2015 Shuichi Tsutsumi. All rights reserved.
//
#import "TTMArithmetic.h"
@import Accelerate;
/*
* libMobileGestalt header.
* Mobile gestalt functions as a QA system. You ask it a question, and it gives you the answer! :)
*
* Copyright (c) 2013-2014 Cykey (David Murray)
* All rights reserved.
*/
#ifndef LIBMOBILEGESTALT_H_
#define LIBMOBILEGESTALT_H_
//
// Async.swift
//
// Created by Tobias DM on 15/07/14.
//
// OS X 10.10+ and iOS 8.0+
// Only use with ARC
//
// The MIT License (MIT)
// Copyright (c) 2014 Tobias Due Munk
@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:22
屋外でビーコン領域監視を使うメリット

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

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

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

@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 / 0_reuse_code.js
Created November 20, 2015 03:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@shu223
shu223 / ClassList.m
Created January 13, 2016 13:48
サブクラスのリストを取得する
#import <objc/runtime.h>
@implementation ClassList
+ (NSArray*)subclassesOfClass:(Class)parentClass
{
int numClasses = objc_getClassList(NULL, 0);
Class *classes = (Class*)malloc(sizeof(Class) * numClasses);
numClasses = objc_getClassList(classes, numClasses);
@shu223
shu223 / TextField.swift
Created January 20, 2016 08:25
Make the margins of UITextField editable in IB
@IBDesignable
class TextField: UITextField {
@IBInspectable var insetX: CGFloat = 0
@IBInspectable var insetY: CGFloat = 0
// placeholder position
override func textRectForBounds(bounds: CGRect) -> CGRect {
return CGRectInset(bounds , insetX , insetY)
}