This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CNImageView.swift | |
// ImageView | |
// | |
// Created by Chiharu Nameki on 2015/08/02. | |
// Copyright (c) 2015 Chiharu Nameki. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ScrollPageController.swift | |
// ScrollPageController | |
// | |
// Created by Chiharu Nameki on 2015/06/21. | |
// Copyright (c) 2015 Chiharu Nameki. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CNLiningUpView.swift | |
// CNLiningUpView | |
// | |
// Created by Chiharu Nameki on 2015/03/29. | |
// Copyright (c) 2015 Chiharu Nameki. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
// register for keyboard notifications | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(keyboardWillHide) | |
name:UIKeyboardWillHideNotification | |
object:nil]; | |
} |
NewerOlder