Skip to content

Instantly share code, notes, and snippets.

View numanayhan's full-sized avatar
🏈
Coding

Numan Ayhan numanayhan

🏈
Coding
  • Istanbul
View GitHub Profile
func urlSession(
_ session: URLSession,
task: URLSessionTask,
didReceive challenge: URLAuthenticationChallenge,
completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
) {
// SERVER TRUST
if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate {
guard
@jdanthinne
jdanthinne / PemToP12.swift
Last active July 27, 2023 21:31
Convert PEM certificate to P12 (PKCS#12)
import Foundation
import OpenSSL
static func pkcs12(fromPem pemCertificate: String,
withPrivateKey pemPrivateKey: String,
p12Password: String = "",
certificateAuthorityFileURL: URL? = nil) throws -> NSData {
// Create sec certificates from PEM string
let modifiedCert = pemCertificate
.replacingOccurrences(of: "-----BEGIN CERTIFICATE-----", with: "")
@dsmailes
dsmailes / DayMonthView.swift
Last active April 1, 2023 10:31
Current Day and Month calendar style view for SwiftUI with Date() extension to retrieve the values as strings.
struct DayMonthView: View {
@State var monthString = Date().getMonthString()
@State var dayString = Date().getDayString()
var body: some View {
VStack {
Text(monthString)
.foregroundColor(Color.red)
@Coder-ACJHP
Coder-ACJHP / Connectivity.swift
Created August 13, 2020 15:24
Network connectivity checker, It can be used instead of Reachability.swift
//
// Connectivity.swift
// Test App
//
// Created by Onur Işık on 14.05.2020.
// Copyright © 2020 Onur Işık. All rights reserved.
//
// NOTE: This struct needs to Alomafire pod to work (Alomafire includes NetworkReachabilityManager)
@AD-Paladins
AD-Paladins / ShareBase64PDF.swift
Last active November 16, 2022 08:24
Store base64 String to file and share it
import UIKit
class ViewController: UIViewController {
@IBAction func sharePDFActionButton(_ sender: Any) {
do {
try savePdf()
loadPDFAndShare()
} catch {
print("FALLO EL GUARDAR EL PDF")
@alana-mullen
alana-mullen / ConnectivityExtension.kt
Created January 16, 2020 00:28
Android Kotlin extension to check network connectivity
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
val Context.isConnected: Boolean
get() {
val connectivityManager = this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { HttpClientModule } from "@angular/common/http";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { NavComponent } from "./nav/nav.component";
import { HomeComponent } from "./home/home.component";
import { RegisterComponent } from "./register/register.component";
import { JobsComponent } from "./jobs/jobs.component";
@yusuke024
yusuke024 / ViewController.swift
Created November 16, 2018 03:15
Recording video with AVAssetWriter
import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .notDetermined:
@fuxingloh
fuxingloh / UILabelSize.swift
Last active March 29, 2024 07:26
iOS Swift: How to find text width, text height or size of UILabel.
extension UILabel {
func textWidth() -> CGFloat {
return UILabel.textWidth(label: self)
}
class func textWidth(label: UILabel) -> CGFloat {
return textWidth(label: label, text: label.text!)
}
class func textWidth(label: UILabel, text: String) -> CGFloat {
@bagpack
bagpack / X509.swift
Created February 16, 2018 06:48
X.509/P12
enum X509Error: Error {
case certificateError(message: String)
case publicKeyError(message: String)
}
class X509 {
// A DER (Distinguished Encoding Rules) representation of an X.509 certificate.
let publicKey: SecKey