Skip to content

Instantly share code, notes, and snippets.

View saud978's full-sized avatar
👋

Saud saud978

👋
View GitHub Profile
//
// ImagePicker.swift
// Image for Instagram
//
// Created by Saud Almutlaq on 09/05/2020.
// Copyright © 2020 Saud Soft. All rights reserved.
// Code from https://stackoverflow.com/questions/24625687/swift-uiimagepickercontroller-how-to-use-it
import AVFoundation
import Photos
import UIKit
import CommonCrypto
//MARK: - String extentions
extension String {
var isValidURL: Bool {
let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
if let match = detector.firstMatch(in: self, options: [], range: NSRange(location: 0, length: self.utf16.count)) {
// it is a link, if the match covers the whole string
@saud978
saud978 / ArabicToHindiNumberConverter.swift
Created June 14, 2022 07:42
Convert numbers in string from Arabic to Hindi
extension String {
func convertToArbic () -> String? {
let formatter = NumberFormatter()
formatter.locale = Locale(identifier: "EN")
guard let number = formatter.number(from:self ) else{
return nil
}
formatter.locale = Locale(identifier: "AR")
guard let number2 = formatter.string(from: number) else{
return nil
@saud978
saud978 / UIImageView load from URL.swift
Last active June 14, 2022 07:39
Swift extension to load image from URL to UIImageView
extension UIImageView {
func loadFrom(URLAddress: String) {
guard let url = URL(string: URLAddress) else {
return
}
DispatchQueue.main.async { [weak self] in
if let imageData = try? Data(contentsOf: url) {
if let loadedImage = UIImage(data: imageData) {
self?.image = loadedImage
@saud978
saud978 / gpg.conf
Created September 8, 2021 06:20 — forked from o-can/gpg.conf
Setting up GPG signature on Mac OS X with Xcode
# Add these lines
batch
passphrase-file <Full path to the key.txt file (without tilda)>
@saud978
saud978 / NotificationService.swift
Created June 28, 2020 20:05
OneSignal Push Notifications Settings
import UserNotifications
import OneSignal
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var receivedRequest: UNNotificationRequest!
var bestAttemptContent: UNMutableNotificationContent?
@saud978
saud978 / CalculateAge.swift
Last active February 19, 2019 17:59 — forked from andatta/CalculateAge.swift
Swift code to calculate age in years, months and days from a person's dob
// Updated to swift 4.2
func calculateAge(dob : String) -> (Int, Int, Int){
let df = DateFormatter()
df.dateFormat = "yyyy-MM-dd"
let date = df.date(from: dob)
guard let val = date else {
return (0, 0, 0)
}
var years = 0
@saud978
saud978 / iptables_color.txt
Last active December 24, 2018 15:43 — forked from nega0/iptables_color.txt
colorize your `iptables` output
## based on the blogpost here: http://blog.sjas.de/posts/colored-iptables-output.html
iptables --line-numbers -vnL |\
sed -E 's/^Chain.*$/\x1b[4m&\x1b[0m/' |\
sed -E 's/^num.*/\x1b[33m&\x1b[0m/' |\
sed -E '/([^y] )((REJECT|DROP))/s//\1\x1b[31m\3\x1b[0m/' |\
sed -E '/([^y] )(ACCEPT)/s//\1\x1b[32m\2\x1b[0m/' |\
sed -E '/([ds]pt[s]?:)([[:digit:]]+(:[[:digit:]]+)?)/s//\1\x1b[33;1m\2\x1b[0m/' |\
sed -E '/([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(\/([[:digit:]]){1,3}){0,1}/s//\x1b[36;1m&\x1b[0m/g' |\
sed -E '/([^n] )(LOGDROP)/s//\1\x1b[33;1m\2\x1b[0m/'|\