Skip to content

Instantly share code, notes, and snippets.

@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;
//
// 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 / 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)
}
@shu223
shu223 / SomeViewController.swift
Created February 28, 2016 07:09
Open one of Twitter apps with username
let username = organizer.twitter
let twitterURLs = [
"twitter://user?screen_name=\(username)", // Twitter
"tweetbot://user_profile/\(username)", // TweetBot
"echofon://user_timeline?\(username)", // Echofon
"twit://user?screen_name=\(username)", // Twittelator Pro
"x-seesmic://twitter_profile?twitter_screen_name=\(username)", // Seesmic
"x-birdfeed://user?screen_name=\(username)", // Birdfeed
"tweetings://user?screen_name=\(username)", // Tweetings
@shu223
shu223 / AsyncMinimal.swift
Created April 6, 2016 17:27
Async https://github.com/duemunk/Async の `background` と `main` をチェーン実行するために必要な最小限のコードを抜き出したもの
public struct Async {
// MARK: - Private properties and init
/**
Private property to hold internally on to a `dispatch_block_t`
*/
private let block: dispatch_block_t
/**
/*
* 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_
@shu223
shu223 / universal-framework.sh
Created April 27, 2017 23:27 — forked from cromandini/universal-framework.sh
This run script will build the iphoneos and iphonesimulator schemes and then combine them into a single framework using the lipo tool (including all the Swift module architectures).
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
// 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 {