Skip to content

Instantly share code, notes, and snippets.

View MyoThuraZaw's full-sized avatar

Myo Thura Zaw MyoThuraZaw

View GitHub Profile
@MyoThuraZaw
MyoThuraZaw / joi-locale.ts
Created January 18, 2022 12:46 — forked from arifmahmudrana/joi-locale.ts
joi localization internationalization error messages
import { object, string, number, ValidationError } from '@hapi/joi';
const schema = object({
searchCode: string()
.required()
.label('Search code'),
id: number().required()
}),
messages = {
'alternatives.all': '{{#label}} does not match all of the required types',
// A URLSession extension that fetches data from a URL and decodes to some Decodable type.
// Usage: let user = try await URLSession.shared.decode(UserData.self, from: someURL)
// Note: this requires Swift 5.5.
extension URLSession {
func decode<T: Decodable>(
_ type: T.Type = T.self,
from url: URL,
keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys,
dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .deferredToData,
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate
@subdigital
subdigital / radars.txt
Last active December 6, 2022 09:29
Xcode Vim Radars
These are feedbacks I've filed against Xcode 13's Vim support. Please dupe!
Vim mode needs option to turn off audible bell - FB9136734
Vim mode needs option to disable/hide help bar - FB9138240
Vim mode needs CTRL+SHIFT+V columnar select mode - FB9138552
Vim mode missing macros for repeated text operations - FB9138595
Vim mode - support for plugins? - FB9138670
Vim mode - :w should save the file - FB9138695
Vim mode - shift-V doesn’t correctly select the first full line - FB9138796
Vim mode - Allow repeated editing operations with “.” - FB9154817
@V8tr
V8tr / RefactoringAppDelegate-Composite.swift
Last active June 13, 2021 18:26
Refactoring Massive App Delegate using Composite pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
class PushNotificationsAppDelegate: AppDelegateType {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Registered successfully
}
}
class StartupConfiguratorAppDelegate: AppDelegateType {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Perform startup configurations, e.g. build UI stack, setup UIApperance
return true
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@bradtraversy
bradtraversy / myscript.sh
Last active July 16, 2024 10:39
Basic Shell Scripting
#! /bin/bash
# ECHO COMMAND
# echo Hello World!
# VARIABLES
# Uppercase by convention
# Letters, numbers, underscores
NAME="Bob"
# echo "My name is $NAME"
@anitaa1990
anitaa1990 / CurvedUIView.swift
Last active May 18, 2022 16:22
A Swift extension of UIView to display a curved view
import UIKit
extension UIView {
/* Usage Example
* bgView.addBottomRoundedEdge(desiredCurve: 1.5)
*/
func addBottomRoundedEdge(desiredCurve: CGFloat?) {
@budidino
budidino / string-truncate.swift
Last active April 3, 2024 20:11 — forked from vicc/string-truncate.swift
String truncate extension for Swift 4
extension String {
/*
Truncates the string to the specified length number of characters and appends an optional trailing string if longer.
- Parameter length: Desired maximum lengths of a string
- Parameter trailing: A 'String' that will be appended after the truncation.
- Returns: 'String' object.
*/
func trunc(length: Int, trailing: String = "") -> String {
return (self.count > length) ? self.prefix(length) + trailing : self
@leilee
leilee / UIView+GradientBorder.swift
Last active March 29, 2024 12:05
Add gradient border to UIView
public extension UIView {
private static let kLayerNameGradientBorder = "GradientBorderLayer"
public func setGradientBorder(
width: CGFloat,
colors: [UIColor],
startPoint: CGPoint = CGPoint(x: 0.5, y: 0),
endPoint: CGPoint = CGPoint(x: 0.5, y: 1)
) {
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0" />
</head>
<body>
<div id="editor" contenteditable="true"></div>
</body>
</html>