Skip to content

Instantly share code, notes, and snippets.

View yannisalexiou's full-sized avatar
🎯
Focusing

Yannis Alexiou yannisalexiou

🎯
Focusing
View GitHub Profile
@lnfnunes
lnfnunes / internalDecodableDefault.swift
Created May 14, 2021 04:33
Generic property-wrapper to provide default values for non-optional properties when they are not present or have a nil value.
//
// Decodable.swift
//
// Copyright © 2021 Leandro Nunes Fantinatto. All rights reserved.
// Ref: https://github.com/gonzalezreal/DefaultCodable
// Ref: https://github.com/JohnSundell/Codextended
//
import Foundation
@saroar
saroar / RefreshToken.swift
Last active February 17, 2024 02:19
RefreshToken URLSession + Combine swift
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, macCatalyst 13.0, *)
extension JSONDecoder {
public static let ISO8601JSONDecoder: JSONDecoder = {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
decoder.dateDecodingStrategy = .iso8601
return decoder
}()
}
extension UISearchBar {
public var textField: UITextField? {
if #available(iOS 13, *) {
return searchTextField
}
let subViews = subviews.flatMap { $0.subviews }
guard let textField = (subViews.filter { $0 is UITextField }).first as? UITextField else {
return nil
}
return textField
@abhi21git
abhi21git / ExtensionURLRequest.swift
Last active February 19, 2024 12:23
Swift cURL Printer
//
// ExtensionURLRequest.swift
//
// Created by Abhishek Maurya on 16/07/20.
// Copyright © 2020. All rights reserved.
//
import Foundation
extension URLRequest {
@vinczebalazs
vinczebalazs / SheetModalPresentationController.swift
Last active July 21, 2024 15:36
A presentation controller to use for presenting a view controller modally, which can be dismissed by a pull down gesture. The presented view controller's height is also adjustable.
import UIKit
extension UIView {
var allSubviews: [UIView] {
subviews + subviews.flatMap { $0.allSubviews }
}
func firstSubview<T: UIView>(of type: T.Type) -> T? {
allSubviews.first { $0 is T } as? T
import Foundation
// OAuth2Token structure
struct OAuth2Token: Codable {
let date = Date() // date when the token was initialized
var accessToken: String // access token
var refreshToken: String? // refresh token (optional)
var expiresIn: Int // seconds until token expires
var tokenType: String // for example "Bearer"
@nanoxd
nanoxd / Collection+anySatisfy.swift
Created December 10, 2018 12:17
[Collection.anySatisfy] With the introduction of allSatisfy, we can cleanly represent the inverse.
extension Collection {
func anySatisfy(_ p: (Element) -> Bool) -> Bool {
return !self.allSatisfy { !p($0) }
}
}
@MathildeRoussel
MathildeRoussel / PkpassGenerator3000.cs
Last active July 21, 2023 09:20
Pkpass Generator for Wallet
using System;
using System.Configuration;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Security.Cryptography.Pkcs;
@Shourai
Shourai / namecheap SSL.md
Created October 21, 2017 12:49
Letsencrypt SSL certificate with namecheap hosting

source: https://savedlog.com/uncategorized/letsencrypt-ssl-certificate-namecheap-hosting/

The “Positive SSL” certificate I bought along with my domain is invalid with any of my subdomains and cannot be used with wildcards. One annoying thing is that namecheap doesn’t offer auto installation of free let’s encrypt certificates, even though, they are saying “Namecheap is dedicated to data security and privacy for all internet users. We believe the movement to encrypt nearly all web traffic is a positive direction. As more sites embrace HTTPS and use of security products, providers of free SSL are beginning to come online.”

Let me show you what it needs to be done in order to “encrypt nearly all web traffic”.

First, not required but it’s helpful to enable ssh access, it is not enabled by default on the base hosting plans, just go an start a live chat and request ssh access.

/// Every view interacting with a `SayHelloViewModel` instance can conform to this.
protocol SayHelloViewModelBindable {
var disposeBag: DisposeBag? { get }
func bind(to viewModel: SayHelloViewModel)
}
/// TableViewCells
final class TextFieldCell: UITableViewCell, SayHelloViewModelBindable {
@IBOutlet weak var nameTextField: UITextField!
var disposeBag: DisposeBag?