This file contains hidden or 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
| private func swizzle(_ bundle: Bundle.Type) { | |
| [(#selector(bundle.localizedString(forKey:value:table:)), | |
| #selector(bundle.rd_localizedString(forKey:value:table:)))] | |
| .forEach { original, swizzled in | |
| guard let originalMethod = class_getInstanceMethod(bundle, original), | |
| let swizzledMethod = class_getInstanceMethod(bundle, swizzled) else { return } | |
| let didAddMethod = class_addMethod( |
This file contains hidden or 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
| public class PhoneFormatter: Formatter, FormatterProtocol { | |
| override public func getObjectValue( | |
| _ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, | |
| for string: String, | |
| errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool { | |
| guard obj != nil else { return false } | |
| let str = string.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "") | |
| obj?.pointee = str as AnyObject | |
| return true |
This file contains hidden or 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
| private let firstpart = "[A-Z0-9a-z]([A-Z0-9a-z._%+-]{0,30}[A-Z0-9a-z])?" | |
| private let serverpart = "([A-Z0-9a-z]([A-Z0-9a-z-]{0,30}[A-Z0-9a-z])?\\.){1,5}" | |
| private let emailRegex = firstpart + "@" + serverpart + "[A-Za-z]{2,8}" | |
| private let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegex) | |
| extension String { | |
| var isEmail: Bool { | |
| return emailPredicate.evaluate(with: self) | |
| } | |
| } |
This file contains hidden or 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
| abstract class InjectedFragment<T> : Fragment(), KodeinAware { | |
| private val activityKodein by closestKodein() | |
| override val kodein: Kodein by retainedKodein { | |
| extend(activityKodein) | |
| import(fragmentModule(parseBundle(arguments))) | |
| } | |
| open fun fragmentModule(data: T?) = Kodein.Module("activityModule") {} |
This file contains hidden or 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 PlaygroundSupport | |
| extension UIView { | |
| static func roundedView(x: Int, y: Int) -> UIView { | |
| let customView = UIView() | |
| customView.frame = CGRect( | |
| x: x, y: y, | |
| width: 60, height: 60) | |
| customView.backgroundColor = .green |
This file contains hidden or 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
| CameraManager manager = | |
| (CameraManager) view.getContext().getSystemService(CAMERA_SERVICE); | |
| try { | |
| for (String cameraId : manager.getCameraIdList()) { | |
| CameraCharacteristics chars | |
| = manager.getCameraCharacteristics(cameraId); | |
| App.logException(Log.DEBUG, "PhotoAction", chars.toString()); | |
| manager.openCamera(cameraId, new CameraDevice.StateCallback() { | |
| @Override |
This file contains hidden or 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
| fun twofer(name: String = "you"): String { | |
| return "One for ${name}, one for me." | |
| } |
This file contains hidden or 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 org.junit.Ignore | |
| import org.junit.Test | |
| import kotlin.test.assertEquals | |
| class TwoferTest { | |
| @Test | |
| fun noNameGiven() { | |
| assertEquals("One for you, one for me.", twofer()) | |
| } |
This file contains hidden or 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
| public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService { | |
| @Override | |
| public void onMessageReceived(RemoteMessage remoteMessage) { | |
| super.onMessageReceived(remoteMessage); | |
| try { | |
| if (remoteMessage.getData().size() > 0) { | |
| // do stuff..... | |
| } |
This file contains hidden or 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
| public class FirebaseMessagingHelper extends FirebaseInstanceIdService { | |
| static public String token; | |
| @Override | |
| public void onCreate() { | |
| super.onCreate(); | |
| token = FirebaseInstanceId.getInstance().getToken(); | |
| if(token != null) Timber.d("Token %s", token); |