Skip to content

Instantly share code, notes, and snippets.

View thomsmed's full-sized avatar
:octocat:
✌️😎👌

Thomas Asheim Smedmann thomsmed

:octocat:
✌️😎👌
View GitHub Profile
@thomsmed
thomsmed / asset-upload.sh
Created July 22, 2021 19:31
Upload asset to GitHub Release
#!/bin/sh
# GitHub REST API ref: https://docs.github.com/en/rest/reference/repos#releases
#
#
# Expects the following arguments:
#
# REPOSITORY - GitHub Repository
# TOKEN - GitHub token
# RELEASE_ID - ID of GitHub Release
@thomsmed
thomsmed / UITableView+Extensions.swift
Last active September 3, 2021 15:41
Useful UITableView extensions
//
// UITableView+Extensions.swift
//
import Foundation
import UIKit
protocol ReusableCell: AnyObject {
static var reuseIdentifier: String { get }
}
@thomsmed
thomsmed / UIView+Extensions.swift
Last active August 25, 2021 12:32
Useful UIView extensions
//
// UIView+Extensions.swift
//
import UIKit
extension UIView {
convenience init(autolayout: Bool) {
self.init()
translatesAutoresizingMaskIntoConstraints = !autolayout
@thomsmed
thomsmed / String+Extensions.swift
Created August 25, 2021 12:34
Useful String extensions
//
// String+Extensions.swift
//
import Foundation
extension String {
var isEmail: Bool {
// https://www.tutorialspoint.com/email-and-phone-validation-in-swift
let regularExpressionForEmail = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
//
// UIStoryboard+Extensions.swift
//
import Foundation
import UIKit
extension UIStoryboard {
static func instantiate<T>(fromStoryboardWithName name: String = "Main", inBundle bundle: Bundle = .main) -> T where T: UIViewController {
let identifier = String(describing: T.self)
@thomsmed
thomsmed / RoundedView.swift
Created September 11, 2021 15:32
Rounded UIView with shadow and border
//
// RoundedView.swift
//
@IBDesignable
class RoundedView: UIView {
private let borderView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
@thomsmed
thomsmed / CircularView.swift
Created October 29, 2021 20:42
Simple circular view where corner radius is controled by the shortes side of the view
//
// CircularView.swift
//
import Foundation
import UIKit
class CircularView: UIView {
override func layoutSubviews() {
super.layoutSubviews()
@thomsmed
thomsmed / debounce.swift
Last active November 7, 2021 15:02
Basic debounce function in Swift
//
// debounce.swift
//
import Fundation
func debounce(delay: TimeInterval, queue: DispatchQueue = .main, action: @escaping (() -> Void)) -> () -> Void {
var currentWorkItem: DispatchWorkItem?
var lastFire: TimeInterval = 0
@thomsmed
thomsmed / throttle.swift
Created November 7, 2021 14:51
Basic throttle function in Swift
//
// trottle.swift
//
import Foundation
func throttle(interval: TimeInterval, queue: DispatchQueue = .main, action: @escaping (() -> Void)) -> () -> Void {
var lastFire: TimeInterval = 0
return {
@thomsmed
thomsmed / FullScreenPresentationController.swift
Last active December 19, 2021 23:24
FullScreenPresentationController.swift - From "Transition images to full screen animated" @ medium.com
//
// FullScreenPresentationController.swift
//
import Foundation
import UIKit
import TinyConstraints
final class FullScreenPresentationController: UIPresentationController {
private lazy var closeButtonContainer: UIVisualEffectView = {