Skip to content

Instantly share code, notes, and snippets.

View levantAJ's full-sized avatar
💭
🌵🌵🌵

levantAJ levantAJ

💭
🌵🌵🌵
View GitHub Profile
@levantAJ
levantAJ / auto-fill-getting-form.js
Created October 15, 2022 05:56
Auto Fill - Getting Form Input Values
// Method use for logging for debugging
function autoFillGettingLog(message) {
window.webkit.messageHandlers.autoFillGettingShippingInfoLog.postMessage(message);
}
autoFillGettingLog("Beginning....");
/// The configuration xpath will be replace before injected to IAB
/// format: [{xPath, key, value}]
var autoFillGettingConfigurationXPathsString = "checkout-configuration-xpaths";
@levantAJ
levantAJ / auto-fill-filling-form.js
Last active October 15, 2022 05:55
Auto Fill - Filling Form
function autoFillFillingLog(message) {
window.webkit.messageHandlers.autoFillFillingShippingInfoLog.postMessage(message);
}
autoFillFillingLog("Beginning....");
/// The configuration xpath will be replace before injected to IAB
/// format: [{xPath, key, value}]
var autoFillFillingConfigurationXPathsString = "checkout-configuration-xpaths";
@levantAJ
levantAJ / String+AES256ECBPKCS5.swift
Last active June 22, 2022 19:29
Encrypt a String with AES256/ECB/PKCS5 with a password
// MARK: - String
extension String {
func aes256ECBPKCS5(hexKey: String) throws -> Data {
let keyData: NSData = try Data(hex: hexKey) as NSData
let data: NSData = Data(utf8) as NSData
guard let cryptData: NSMutableData = NSMutableData(length: Int(data.length) + kCCBlockSizeAES128) else {
throw NSError(domain: "", code: 1234, userInfo: [NSLocalizedDescriptionKey: "Prepare crypt data failed"])
@levantAJ
levantAJ / payload.json
Created June 1, 2021 03:27
Testing push notifications on the iOS simulator
{
"Simulator Target Bundle": "com.yourapp.YourAppName",
"aps": {
"alert": {
"body": "Testing Message",
"title": "Test Notification"
}
}
}
@levantAJ
levantAJ / USDZNode.swift
Last active October 20, 2021 15:01
Create SCNNode from USDZ file
class USDZNode: SCNReferenceNode {
init?(
name: String,
position: SCNVector3? = nil,
scale: SCNVector3? = nil,
pivot: SCNMatrix4? = nil
) {
guard let usdzURL: URL = Bundle.main.url(forResource: name, withExtension: "usdz") else { return nil }
super.init(url: usdzURL)
if let scale: SCNVector3 = scale {
@levantAJ
levantAJ / OpenFileWithAnApp.sh
Created May 28, 2021 02:36
Open a file with a specific app from Terminal
open -a AppName FileName
@levantAJ
levantAJ / ObservableType+Previous.swift
Created May 27, 2021 04:14
Get previous & current value of a Observable
extension ObservableType {
func withPrevious() -> Observable<(previous: Element?, current: Element?)> {
return scan([]) { (previous, current) in
return Array(previous + [current]).suffix(2)
}
.map { array -> (previous: Element?, current: Element?) in
let previous = array.count > 1 ? array.first : nil
let current = array.last
return (previous, current)
}
@levantAJ
levantAJ / UIViewController+Reactive.swift
Last active June 1, 2021 02:22
Observe presented UIViewController is dismissed with UIModalPresentationStyle is custom
extension Reactive where Base: UIViewController {
var presenting: Observable<UIViewController> {
return sentMessage(#selector(Base.present(_:animated:completion:)))
.compactMap({ args -> UIViewController? in
return args.first as? UIViewController
})
.do(onError: { error in
assertionFailure("\(error)")
})
}
@levantAJ
levantAJ / UIView+Animation.swift
Created December 21, 2020 13:51
Set UIView hidden with fade animated
extension UIView {
func setHidden(_ isHidden: Bool, animated: Bool, completion: (() -> Void)? = nil) {
if animated {
let startAlpha: CGFloat
let animatingAlpha: CGFloat
if isHidden {
startAlpha = 1
animatingAlpha = 0
} else {
startAlpha = 0
@levantAJ
levantAJ / UIApplication+Swizzle.swift
Created May 25, 2020 06:54
Swizzle UIApplication openURL
extension UIApplication {
static let classInit: () -> () = {
swizzle(UIApplication.self, #selector(openURL(_:)), #selector(swizzledOpenURL(_:)))
swizzle(UIApplication.self, #selector(open(_:options:completionHandler:)), #selector(swizzledOpen(_:options:completionHandler:)))
}
@objc func swizzledOpenURL(_ url: URL) {
print(">>>>>url", url)
}