Skip to content

Instantly share code, notes, and snippets.

@Ridwy
Ridwy / MTAudioProcessingTapSample.swift
Created July 30, 2021 11:21
How to use MTAudioProcessingTap in Swift 5
//
// Created by Chiharu Nameki @Ridwy on 2021/07/30.
//
import UIKit
import AVFoundation
/*
Using MTAudioProcessingTap, you can touch raw audio samples playing with AVPlayer.
This sample code shows how to use MTAudioProcessingTap in Swift 5.
@Ridwy
Ridwy / UIViewControllerScreenshot.swift
Created August 8, 2017 04:15
take screenshots of each UIViewController
import UIKit
import AVFoundation
// call this in application(_:didFinishLaunchingWithOptions:)
func setupDebugScreenshot() {
let from = class_getInstanceMethod(UIViewController.self, #selector(UIViewController.viewDidAppear))
let to = class_getInstanceMethod(UIViewController.self, #selector(UIViewController.viewDidAppearWithScreenshot))
method_exchangeImplementations(from, to)
}
extension String {
var md5: String? {
guard let str = cString(using: .utf8) else { return nil }
let strLen = CC_LONG(lengthOfBytes(using: .utf8))
let digestLen = Int(CC_MD5_DIGEST_LENGTH)
let result = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLen)
CC_MD5(str, strLen, result)
let hash = (0 ..< digestLen).map({String(format:"%02x", result[$0])}).joined()
@Ridwy
Ridwy / URLRouter.swift
Last active February 12, 2016 13:05
Swift URL Router
class URLRouter {
let placeholders: [String: String]
init(placeholders: [String: String] = [:]) {
self.placeholders = placeholders
}
typealias ActionHandler = ((NSURL)->())
func register(path: String, handler: ActionHandler) -> Self {
let pathWithoutRoot = path.hasPrefix("/") ? path.substringFromIndex(path.startIndex.advancedBy(1)) : path
var node = root
import Foundation
import SwiftyJSON
extension JSON {
func update(keyPath: String, value: JSON?) -> JSON {
let keys = keyPath.componentsSeparatedByString(".")
guard let targetKey = keys.first else {
return self
}
//
// CNImageView.swift
// ImageView
//
// Created by Chiharu Nameki on 2015/08/02.
// Copyright (c) 2015 Chiharu Nameki. All rights reserved.
//
import UIKit
//
// ScrollPageController.swift
// ScrollPageController
//
// Created by Chiharu Nameki on 2015/06/21.
// Copyright (c) 2015 Chiharu Nameki. All rights reserved.
//
import UIKit
@Ridwy
Ridwy / CNLiningUpView.swift
Last active August 29, 2015 14:17
User icon lining up view like FourSquare
//
// CNLiningUpView.swift
// CNLiningUpView
//
// Created by Chiharu Nameki on 2015/03/29.
// Copyright (c) 2015 Chiharu Nameki. All rights reserved.
//
import UIKit
@Ridwy
Ridwy / iOS 7 OSD Log
Created April 28, 2014 04:49
デバッガみたいに自動でスクロールアップするUITextView
@interface SomeViewController ()
@property (weak) UITextView *logView;
@end
@implementation SomeViewController
- (void)writeOSDLog:(NSString *)log
{
if (self.logView == nil) {
NSTextStorage *textStorage = [NSTextStorage new];
NSLayoutManager *layoutManager = [NSLayoutManager new];
@Ridwy
Ridwy / gist:6290416
Last active December 21, 2015 10:09
UITextFieldがキーボードで隠れないようにスクロールアップする方法。 ViewControllerに以下のコードを実装してUITextFieldのdelegateにする
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide)
name:UIKeyboardWillHideNotification
object:nil];
}