Skip to content

Instantly share code, notes, and snippets.

View MojtabaHs's full-sized avatar
🏆
Worldwide 2nd in SwiftUI - According to StackOverflow

Seyed Mojtaba Hosseini Zeidabadi MojtabaHs

🏆
Worldwide 2nd in SwiftUI - According to StackOverflow
View GitHub Profile
@MojtabaHs
MojtabaHs / MotionEffect.swift
Created January 31, 2024 11:35
Enabling binding to the device motion sensor
struct MotionEffectModifier: ViewModifier {
@ObservedObject private(set) var manager = MotionManager.shared
@Binding var pitch: Double
@Binding var roll: Double
let magnitude: Double
func body(content: Content) -> some View {
content
.onAppear { manager.startUpdate() }
.onDisappear { manager.stopUpdate() }
@MojtabaHs
MojtabaHs / NumberAbbreviationFormatter.swift
Last active January 24, 2024 08:13
Converts between number and its abbreviation (1000 -> 1K -> 1000)
import Foundation
@dynamicMemberLookup
class NumberAbbreviationFormatter {
// MARK: - Internal properties
var formatter = NumberFormatter()
// MARK: - Static configurations
@MojtabaHs
MojtabaHs / Task.synchronous.swift
Created November 25, 2023 12:17
Performs an async task in a sync context
import Foundation
public extension Task where Failure == Error {
/// Performs an async task in a sync context.
///
/// - Note: This function blocks the thread until the given operation is finished. The caller is responsible for managing multithreading.
@discardableResult
static func synchronous(
priority: TaskPriority? = nil,
@_implicitSelfCapture operation: @escaping @Sendable () async -> Success
@MojtabaHs
MojtabaHs / countries.json
Last active June 15, 2023 14:53
The list of supported countries for the OvpnTree
[
{
"name": "Afghanistan",
"dial_code": "+93",
"code": "AF"
},
{
"name": "Albania",
"dial_code": "+355",
"code": "AL"
@MojtabaHs
MojtabaHs / ArchiveHelper.sh
Created March 4, 2023 09:33
An archive helper for changing the Archived files and with the given options and generating the corresponding IPAs
#
# Created by Seyed Mojtaba Hosseini Zeidabadi.
#
# StackOverflow: https://stackoverflow.com/story/mojtabahosseini
# Linkedin: https://linkedin.com/in/MojtabaHosseini
# GitHub: https://github.com/MojtabaHs
#
COLOR='\033[1;36m'
NO_COLOR='\033[0m'
@MojtabaHs
MojtabaHs / UIImage+imageByReplacingColor.swift
Created December 15, 2022 09:59
UIImage Color Replace using pixel buffer
// MARK: - Color Replacement
extension UIImage {
func image(byReplacing sourceColor: UIColor, with destinationColor: UIColor, minTolerance: Float, maxTolerance: Float) -> UIImage? {
guard let inputCGImage = cgImage else {
print("unable to get cgImage")
return self
}
let colorSpace = CGColorSpaceCreateDeviceRGB()
let width = inputCGImage.width
let height = inputCGImage.height
extension View {
func flexible(width: Bool, height: Bool) -> some View {
self.modifier(MatchingParentModifier(width: width, height: height))
}
}
struct MatchingParentModifier: ViewModifier {
@State private var intrinsicSize: CGSize = UIScreen.main.bounds.size
private let intrinsicWidth: Bool
private let intrinsicHeight: Bool

Since iOS 12, the system can read the one-time password from the received SMS automatically and add it above the keyboard, So users can use the code with only one touch. There are rules and limitations for doing this as I tried to list most of them below:

  1. The message must contain the Code prase. Some other words like passcode and password are ok too in English.
  2. The Code phrase (with or without :) must be separate with only one space with your numbers.

example:

Code 1111111
Code: 111111
switch identifier {
// MARK: - iPhone Identifiers
case "iPhone1,1": return "iPhone"
case "iPhone1,2": return "iPhone 3G"
case "iPhone2,1": return "iPhone 3GS"
case "iPhone3,1": return "iPhone 4"
case "iPhone3,2": return "iPhone 4 GSM Rev A"
case "iPhone3,3": return "iPhone 4 CDMA"
case "iPhone4,1": return "iPhone 4S"