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 SwiftUI | |
import Combine | |
final class KeyboardObserver: ObservableObject { | |
@Published var keyboardHeight: CGFloat = 0 | |
@Published var isVisible = false | |
var keyboardCancellable = Set<AnyCancellable>() | |
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
const localizationContext = useLocalizationContext() | |
const t = localizationContext.t | |
t('Language', {}) |
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 MainActivity : LifecycleActivity() { | |
// create a LifecycleCompositeDisposable which will be disposed at onPause() | |
val disposableBag by lazy { createOnPauseCompositeDisposable() } | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
// keep firing a number on each second, |
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 TTTAttributedLabel | |
import RxSwift | |
import RxCocoa | |
fileprivate class RxTTTAttributedLabelDelegateProxy: DelegateProxy, TTTAttributedLabelDelegate, DelegateProxyType { | |
//We need a way to read the current delegate | |
static func currentDelegateFor(_ object: AnyObject) -> AnyObject? { | |
let label: TTTAttributedLabel = object as! TTTAttributedLabel | |
return label.delegate | |
} |
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 | |
extension UICollectionView { | |
var cellOffsetForVisibleItems: [IndexPath: CGFloat] { | |
let result = self.indexPathsForVisibleItems | |
.map { indexPath in | |
[indexPath: UICollectionView.cellOffset(with: self, at: indexPath)] | |
} | |
.reduce([IndexPath: CGFloat]()) { result, map in | |
var newResult = result |
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 | |
// ref: http://stackoverflow.com/questions/3707427/how-to-read-data-from-nsfilehandle-line-by-line | |
class FileReader { | |
private let fileHanlde: NSFileHandle | |
private let lineDelimiter = "\n" | |
private let chunkSize: Int = 16 | |
private let totalFileLen: UInt64 | |
private var currentOffset: UInt64 = 0 |
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 FileReader { | |
// 1. | |
private let fileHanlde: NSFileHandle | |
private let lineDelimiter = "\n" | |
private let chunkSize: Int = 16 | |
private let totalFileLen: UInt64 | |
private var currentOffset: UInt64 = 0 | |
// 2. |
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 NSData { | |
func rangeOfData_dd(dataToFind: NSData) -> NSRange { | |
let bytes = self.bytes | |
let len = self.length | |
let searchBytes = dataToFind.bytes | |
let searchLen = dataToFind.length | |
var searchIndex = 0 | |
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 NSData (DDAdditions) | |
- (NSRange) rangeOfData_dd:(NSData *)dataToFind; | |
@end | |
@implementation NSData (DDAdditions) | |
- (NSRange) rangeOfData_dd:(NSData *)dataToFind { |
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
#!/bin/bash | |
# images (@3x) to | |
# drawable-xxhdpi(3x), | |
# drawable-xhdpi(2x), | |
# drawable-mdpi(1x) | |
# Usage | |
# ------- |