Skip to content

Instantly share code, notes, and snippets.

View jonahaung's full-sized avatar

Aung Ko Min jonahaung

View GitHub Profile
@jonahaung
jonahaung / String+Extension.swift
Created April 18, 2024 06:11
Credit cards number formatting
extension String {
func insertStringAt(indexes: [Int], string: String) -> String {
var formatted = String()
for (i, str) in self.enumerated() {
if indexes.contains(i) {
formatted.append("\(str)\(string)")
} else {
formatted.append(str)
}
}
@jonahaung
jonahaung / SingaporeNRICValidator.swift
Last active January 30, 2024 04:47
Validate Singapore NRIC
func validateSingaporeNRIC(_ nricString: String) -> Bool {
let str = nricString.uppercased()
let characters = [Character](str)
if characters[0] == "M" {
return true
}
guard str.count == 9 else { return false }
var weight = 0
func bigSorting(unsorted: [String]) -> [String] {
let strings = unsorted.sorted { (left, right) -> Bool in
if left.count > right.count {
return false
}
if left.count < right.count {
return true
}
if let l = Int(left), let r = Int(right) {
import Foundation
public class MyanmarNames {
private var keyValues = [String: String]()
public static let shared = MyanmarNames()
private init() {
dataString.components(separatedBy: .newlines).forEach { line in
import SwiftUI
private struct OffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = .zero
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {}
}
struct CustomScrollView<Content: View>: View {
public class Quiz {
public static void main(String[] args) {
// Question 1
MultipleChoiceQuestion question1 = new MultipleChoiceQuestion(
"Name the most popular programming language used for developing Android Apps.", // question
"Python", // A
"Swift", // B
"Java", // C
"HTML", // D
#Helper Functions
def clear_screen():
print("")
print("")
print("")
print("")
# convert english calender year to Myanmar calender year
def convert_to_mm_year(year_int, is_born_before_new_year):
"""
The following application calculates
- BMI,
- Ideal Weight and
- Amount of extra weight
from a person's weight and height.
"""
# convert meter to inch
@jonahaung
jonahaung / coreImageFilters+Extension.swift
Last active April 23, 2020 09:29
All Core Image Filters
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
static func accordionFoldTransition(inputImage: CIImage, inputTargetImage: CIImage, inputBottomHeight: NSNumber = 0, inputNumberOfFolds: NSNumber = 3, inputFoldShadowAmount: NSNumber = 0.1, inputTime: NSNumber = 0) -> CIFilter? {
@jonahaung
jonahaung / safeAsync.swift
Last active March 20, 2020 16:02
This method will dispatch the `block` to self. If `self` is the main queue, and current thread is main thread, the block. will be invoked immediately instead of being dispatched.
extension DispatchQueue {
func safeAsync(_ block: @escaping ()->()) {
if self === DispatchQueue.main && Thread.isMainThread {
block()
} else {
async { block() }
}
}
}