Skip to content

Instantly share code, notes, and snippets.

View ihamadfuad's full-sized avatar
🧑‍💻
Coding

Hamad Fuad ihamadfuad

🧑‍💻
Coding
View GitHub Profile
@michaelevensen
michaelevensen / EventKit.swift
Last active January 10, 2023 05:40
Steps for fetching events from EventKit. NOTE! For iOS10+ remember to add: Privacy – Calendars Usage Description in .plist
// Helper function for showing UIAlert prompts
func showMessagePrompt(_ title: String, message: String) {
let alert = UIAlertController.init(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction.init(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
/********************/
@B-Lach
B-Lach / NetworkManager.swift
Created November 13, 2016 19:56
Public Key Pinning Example
struct Constants {
static let resource = "certificate"
static let type = "der"
}
// https://infinum.co/the-capsized-eight/articles/how-to-make-your-ios-apps-more-secure-with-ssl-pinning
extension NetworkManager: URLSessionDelegate {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
@ruiwen
ruiwen / command.sh
Last active May 8, 2022 07:26
Obtain Base64-encoded SHA256 hash of a servers OpenSSL pubkey used with `curl`'s `--pinnedpubkey`
# Obtaining server certificate
openssl s_client -CAfile ca.crt -connect "server.domain.com:443" < /dev/null 2> /dev/null | openssl x509 -outform PEM > server.crt
# You may get an error like the following
# CONNECTED(00000003)
# 140048174458520:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:s23_lib.c:177:
# ---
# no peer certificate available
# ---
# No client certificate CA names sent
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 15, 2024 18:34
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
@quocnb
quocnb / UserNotificationsExample.swift
Last active March 16, 2022 12:28
UserNotifications iOS 10 Example
import UserNotifications
// 1. Request Permission
func requestAuthorization() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { (granted, error) in
if granted {
// Success
} else {
// Error
print(error?.localizedDescription)
//
// CodableExtensionExample.swift
//
// Created by Pramod Kumar on 05/15/20.
// Copyright © 2020 Swift Commmunity. All rights reserved.
//
import UIKit
let json = """
@inket
inket / PreviewScreenshot.swift
Last active July 28, 2024 23:57
How to take screenshots of SwiftUI previews
#if DEBUG
import SwiftUI
private let screenshotDirectory = "/Users/inket/Desktop/"
struct PreviewScreenshot: ViewModifier {
struct LocatorView: UIViewRepresentable {
let tag: Int
func makeUIView(context: Context) -> UIView {
@insidegui
insidegui / ScrollViewOffsetModifier.swift
Created July 20, 2021 20:28
A SwiftUI ViewModifier that can be used to read a ScrollView's offset and store it into a @State property of the view
struct ScrollViewOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGPoint = .zero
static func reduce(value: inout CGPoint, nextValue: () -> CGPoint) {
value = nextValue()
print("value = \(value)")
}
typealias Value = CGPoint
@ihamadfuad
ihamadfuad / UniversalAlert.swift
Last active January 24, 2022 07:03
SwiftUI: Present Alert From Anywhere Using @Environment
// ºººº----------------------------------------------------------------------ºººº \\
//
// Credit Hamad Fuad.
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created At: 24/01/2022
// Last modified: 24/01/2022
//
@ihamadfuad
ihamadfuad / SheetViewPresenter.swift
Created January 24, 2022 07:02
SwiftUI: Present Sheet From Anywhere Using @Environment
// ºººº----------------------------------------------------------------------ºººº \\
//
// Credit Hamad Fuad.
//
// Author: Hamad Fuad
// Email: ihamadfouad@icloud.com
//
// Created At: 24/01/2022
// Last modified: 24/01/2022
//