Skip to content

Instantly share code, notes, and snippets.

View NSStudent's full-sized avatar
🏠
Working from home

Omar NSStudent

🏠
Working from home
View GitHub Profile
@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
@nikitamounier
nikitamounier / PredicateSet.swift
Created October 25, 2021 10:18
A simple PredicateSet type, with only one property of type (Element) -> Bool, which (nearly) conforms to SetAlgebra.
struct PredicateSet<Element: Equatable> {
var contains: (Element) -> Bool
init(_ contains: @escaping (Element) -> Bool) {
self.contains = contains
}
}
extension PredicateSet: SetAlgebra {
init() {
@tanner0101
tanner0101 / vapor-4-fluent-authc.swift
Last active May 2, 2024 14:24
Example of authentication with Fluent in Vapor 4
import Fluent
import Vapor
func routes(_ app: Application) throws {
app.post("users") { req -> EventLoopFuture<User> in
try User.Create.validate(req)
let create = try req.content.decode(User.Create.self)
guard create.password == create.confirmPassword else {
throw Abort(.badRequest, reason: "Passwords did not match")
}
//
// Diagrams.swift
// DiagramsSample
//
// Created by Chris Eidhof on 16.12.19.
// Copyright © 2019 objc.io. All rights reserved.
//
import SwiftUI
@chriseidhof
chriseidhof / viewmirror.swift
Last active April 3, 2025 08:40
View Mirror
import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
Text("Hello")
.padding()
.background(.blue)
.overlay {
Color.yellow
@AliSoftware
AliSoftware / Bindings.swift
Last active March 26, 2025 12:10
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
@perja12
perja12 / delete_artifacts.groovy
Created July 30, 2018 11:25
Delete artifacts from Jenkins with Groovy script.
// Delete old artifacts that fills up the disk on the master node.
// Run this from the Jenkins console (Manage Jenkins, Manage Nodes, master, Script Console)
def project = Jenkins.get().getItemByFullName('your-project-id')
def jobs = project.getAllJobs()
def total_size = 0
jobs.each{ job ->
def builds = job.getBuilds()
import UIKit
public struct Style<View: UIView> {
public let style: (View) -> Void
public init(style: @escaping (View) -> Void) {
self.style = style
}
@kharrison
kharrison / RSSFeed.swift
Last active September 1, 2021 01:59
Swift Decodable With Multiple Custom Dates
import Foundation
extension DateFormatter {
static let iso8601Full: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
formatter.calendar = Calendar(identifier: .iso8601)
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.locale = Locale(identifier: "en_US_POSIX")
return formatter
@Serchinastico
Serchinastico / SuperHeroControlsViewController.swift
Last active January 17, 2018 20:16
View controller sobre el que haremos las pruebas de las acciones con KIF
// --------------------------------------------- //
// -------------- VIEW CONTROLLER -------------- //
// --------------------------------------------- //
import UIKit
class SuperHeroControlsViewController: UIViewController {
var textField: UITextField!
var slider: UISlider!