Skip to content

Instantly share code, notes, and snippets.

View m-usmansaeed's full-sized avatar
👋
Nice to meet u

Usman m-usmansaeed

👋
Nice to meet u
View GitHub Profile
@m-usmansaeed
m-usmansaeed / UIFont+Ext.swift
Created March 25, 2024 16:55
Auto scaling font.
extension CGFloat {
var dp: CGFloat {
var finalSize = (self / 375) * UIScreen.main.bounds.width
if UIScreen.main.bounds.width <= 320 { // For iPhone 5S
finalSize = self * 0.95
}
return finalSize
}
}
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@m-usmansaeed
m-usmansaeed / sync-http.swift
Created February 11, 2024 20:16
Synchronous http request in Swift
func query(address: String) -> String {
let url = URL(string: address)
let semaphore = DispatchSemaphore(value: 0)
var result: String = ""
let task = URLSession.shared.dataTask(with: url!) {(data, response, error) in
result = String(data: data!, encoding: String.Encoding.utf8)!
semaphore.signal()
}
//
// NotificationScheduler.swift
// LocationNotifier
//
import UIKit
import UserNotifications
protocol NotificationSchedulerDelegate: UNUserNotificationCenterDelegate {
//
// PieChart.swift
// NokiaGame
//
// Created by Prafulla Singh on 13/9/20.
// Copyright © 2020 Prafulla Singh. All rights reserved.
//
import SwiftUI
@m-usmansaeed
m-usmansaeed / TypeCasting.swift
Created September 29, 2020 17:22 — forked from pisces/TypeCasting.swift
[Swift 4] Extensions for data type casting
import Foundation
public extension Int {
public var int32Value: Int32 { return Int32(self) }
public var int64Value: Int64 { return Int64(self) }
public var uintValue: UInt { return UInt(self) }
public var doubleValue: Double { return Double(self) }
public var floatValue: CGFloat { return CGFloat(self) }
public var float64Value: Float64 { return Float64(self) }
public var numberValue: NSNumber { return NSNumber(integerLiteral: self) }
@m-usmansaeed
m-usmansaeed / UIView+Extension.swift
Created July 7, 2020 09:20 — forked from bishalg/UIView+Extension.swift
Swift UIView Extension for Inspectable CornerRadius, BorderWidth and BoarderColors etc
//
// UIView+Extension.swift
//
// Created by Bishal Ghimire on 4/30/16.
// Copyright © 2016 Bishal Ghimire. All rights reserved.
//
import UIKit
//
@m-usmansaeed
m-usmansaeed / UIView+round.swift
Created July 7, 2020 09:20 — forked from Sorix/UIView+round.swift
Round specified corners of UIView
// Example: view.round([.TopLeft, .TopRight], radius: 15)
extension UIView {
/**
Rounds the given set of corners to the specified radius
- parameter corners: Corners to round
- parameter radius: Radius to round to
*/
func round(corners: UIRectCorner, radius: CGFloat) {
func evaluateJavaScript(to webView: WKWebView) {
let p = "var y = document.getElementsByTagName(\"P\"); var i; for (i = 0; i < y.length; i++) {y[i].style.fontSize = \"500%\";}"
webView.evaluateJavaScript(p) {(result, error) in
guard error == nil else {
print(error!)
return
}
print(String(describing: result))
}
//
// ImagePicker.swift
// UIImagePicker
//
// Created by M Usman on 08/11/2019.
// Copyright © 2019 M Usman. All rights reserved.
//
import SwiftUI
import Combine