Skip to content

Instantly share code, notes, and snippets.

View ihamadfuad's full-sized avatar
🧑‍💻
Swifting with UI and server

Hamad Fuad ihamadfuad

🧑‍💻
Swifting with UI and server
View GitHub Profile
@ollieatkinson
ollieatkinson / HTTPStatusCode.swift
Last active April 12, 2025 22:44
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
@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
@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) {
@michaelevensen
michaelevensen / EventKit.swift
Last active March 31, 2025 01:27
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)
}
/********************/