Skip to content

Instantly share code, notes, and snippets.

View ahbou's full-sized avatar
shipping

Ahmed Bouchfaa ahbou

shipping
View GitHub Profile
@groue
groue / Trigger.swift
Created February 14, 2024 12:27
A Trigger type that helps SwiftUI views control when cancellable async jobs are run.
import SwiftUI
extension View {
/// Adds a task to perform before this view appears or when the trigger
/// is fired.
///
/// This method behaves like `View.task(id:priority:_:)`, except that it
/// cancels and recreates the task when the `fire` method of the
/// trigger is called.
///
@IanKeen
IanKeen / Abstraction.swift
Created August 16, 2022 17:41
TCA Scoping Abstraction
// MARK: - TCAView
public protocol TCAView: View where Body == WithViewStore<ScopedState, ScopedAction, Content> {
associatedtype ViewState
associatedtype ViewAction
associatedtype ScopedState
associatedtype ScopedAction
associatedtype Content
@nicklockwood
nicklockwood / CodableVersioning.swift
Last active January 29, 2024 11:31
Example demonstrating how to use versioning for Codable structs
// This gist demonstrates how you can implement versioning for a Codable struct to support loading
// old serialized data after changing the structure. Notable features of this solution:
//
// * No need to make new properties optional, or to perform post-processing on the struct after
// loading in ordeer to populate missing values
// * No need to change the call site - from the outside this struct behaves just the same
// as if we had implemented codable directly in the normal way.
// * Versioning can be applied individually to parents or leaves in a larger tree of
// structs without affecting the other elements
// * This approach will work even if the original struct was not designed with versioning in mind
@steipete
steipete / URLCacheTest.swift
Last active April 4, 2024 18:16
Using URLCache with download tasks (NSURLCache & NSURLSessionDownloadTask)
import Foundation
import os.log
class URLCacheTest {
let logger = Logger(subsystem: "URLCacheTest", category: "main")
// HTTP HEADERS:
// Date: Wed, 04 Nov 2020 11:13:24 GMT
// Server: Apache
// Strict-Transport-Security: max-age=63072000; includeSubdomains; preload
@DreamingInBinary
DreamingInBinary / Best in Class iOS Checklist
Last active January 29, 2024 18:18
This is a public checklist updated every year after the latest version of iOS and iPadOS are shipped. It's a boiled down version of a "Best in Class" app checklist created by Jordan Morgan.
# A Best in Class Checklist
A boiled down checklist adapted from this [post](https://www.swiftjectivec.com/a-best-in-class-app/), created by @jordanmorgan10.
> To use this, create a Github Issue in your own repo, and simply copy and paste this text.
## iOS Core Technology
_Things any iOS app can benefit from_
- [ ] iCloud Sync
- [ ] Focus Filter Support
@michaelevensen
michaelevensen / AVPlayerCrossFade.swift
Last active November 10, 2023 07:48
Handles cross-fading between two individual AVPlayers, creates a smooth, undulating loop between two AVPlayerItem's.
import UIKit
import AVFoundation
class ViewController: UIViewController {
// Duplicate players to handle optional cross-fading.
let playerQueue = [AVPlayer(), AVPlayer()]
var timeObserverToken: Any?
@mattt
mattt / UIViewControllerPreview.swift
Last active January 8, 2024 23:09
Generic structures to host previews of UIView and UIViewController subclasses.
import UIKit
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable {
let viewController: ViewController
init(_ builder: @escaping () -> ViewController) {
viewController = builder()
}
@RenGate
RenGate / InAppPurchaseManager.swift
Last active May 10, 2023 14:42
Sample implementation of In-App purchase manager class
// MIT License
//
// Copyright (c) 2019 Rostyslav Dovhaliuk
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@ole
ole / UIAlertController+TextField.swift
Last active September 13, 2022 14:20
A UIAlertController with a text field and the ability to perform validation on the text the user has entered while the alert is on screen. The OK button is only enabled when the entered text passes validation. More info: https://oleb.net/2018/uialertcontroller-textfield/
import UIKit
/// A validation rule for text input.
public enum TextValidationRule {
/// Any input is valid, including an empty string.
case noRestriction
/// The input must not be empty.
case nonEmpty
/// The enitre input must match a regular expression. A matching substring is not enough.
case regularExpression(NSRegularExpression)
@andyyou
andyyou / rails_webpacker_bootstrap_expose_jquery.md
Last active August 9, 2022 07:38
Rails 5.2 with webpacker, bootstrap, stimulus starter

Rails 5.2 with webpacker, bootstrap, stimulus starter

This gist will collects all issues we solved with Rails 5.2 and Webpacker

Create Project

# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-test