Skip to content

Instantly share code, notes, and snippets.

View tobitech's full-sized avatar
🌎
Changing the World

Tobi Omotayo tobitech

🌎
Changing the World
View GitHub Profile
@tobitech
tobitech / Package.swift
Created April 23, 2024 15:02
Ratio App Modularisation Structure.
// swift-tools-version: 5.7
import PackageDescription
let package = Package(
name: "ratioapp",
platforms: [
.iOS("16.6")
],
products: [
@tobitech
tobitech / MockURLProtocol.swift
Created March 19, 2024 17:58
Mocking URLSession with URLProtocol
import Foundation
import XCTest
// 1. mocking url session with URLProtocol
// this approach allows us to intercept the network request.
// Steps:
// i. subclass URLProtocol
// ii. implement these methods from the prototol canInit, canonicalRequest, startLoading, stopLoading.
// iii. add implementation to startLoading based on a requestHandler closure.
// iv. send received response to the client: URLProtocolClient
import SwiftUI
import SensitiveContentAnalysis
struct ContentView: View {
enum AnalysisState {
case notStarted
case analyzing
case isSensitive
case notSensitive
@tobitech
tobitech / models.kt
Last active June 14, 2023 07:10
Creating Realm Model Objects in Kotlin
// Define a Category object type that has a name and a color
class Category() : RealmObject {
@PrimaryKey
var _id: ObjectId = ObjectId.create()
var name: String
var color: String
constructor(name: String, color: String) : this() {
this.name = name
this.color = color
}
@tobitech
tobitech / AppView.swift
Last active July 11, 2022 22:43
A SwiftUI app using The Composable Architecture.
import ComposableArchitecture
import SwiftUI
let appReducer: Reducer<AppState, AppAction, AppEnvironment> = Reducer.combine(
onboardingReducer
.optional()
.pullback(
state: \AppState.onboarding,
action: /AppAction.onboarding,
environment: { _ in OnboardingEnvironment() }
@tobitech
tobitech / PullDownScrollViewGesture.swift
Last active June 14, 2022 17:31
Implement a pull down gesture on a ScrollView to perform an action in SwiftUI. The idea is to monitor the vertical y offset of the ScrollView.
import SwiftUI
struct OverviewView: View {
private let threshold: CGFloat = 100.0
@State private var showModal = false
var body: some View {
GeometryReader { geometry in
ScrollView(showsIndicators: false) {
VStack {
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
music_data = pd.read_csv('music.csv')
X = music_data.drop(columns=['genre'])
y = music_data['genre']
model = DecisionTreeClassifier()
model.fit(X, y)
@tobitech
tobitech / WebViewExampleViewController.swift
Created June 10, 2020 21:05 — forked from fxm90/WebViewExampleViewController.swift
Show progress of WKWebView in UIProgressBar that is attached to an UINavigationBar
//
// WebViewExampleViewController.swift
//
// Created by Felix Mau on 06.01.18.
// Copyright © 2018 Felix Mau. All rights reserved.
//
import UIKit
import WebKit
@tobitech
tobitech / ImageDownloader.swift
Created May 27, 2020 12:05
Reactive ImageDownloader with Alamofire + Cache
//
// ImageDownloader.swift
// ImageDownloader
//
// Created by Oluwatobi Omotayo on 27/05/2020.
// Copyright © 2020 Oluwatobi Omotayo. All rights reserved.
//
import UIKit
import RxSwift
@tobitech
tobitech / Timer.swift
Created May 25, 2020 19:14
Count down timer with RxSwift
let timer = Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance)
.take(60)
.startWith(0)
.share(replay: 1)
timer
.map { 60 - $0 }
.map { "\($0)" }
.bind(to: timerLabel.rx.text)
.disposed(by: disposeBag)
timer