Skip to content

Instantly share code, notes, and snippets.

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

Majid Jabrayilov mecid

🏠
Working from home
View GitHub Profile
private func fetchRepos(matching query: String) {
githubService
.search(matching: query)
.replaceError(with: [])
.subscribe(on: DispatchQueue.global())
.receive(on: OperationQueue.main)
.assign(to: \.repos, on: self)
}
@Published private var query: String = ""
private func fetchRepos(matching query: String) {
$query.flatMap {
self.githubService
.search(matching: $0)
.replaceError(with: [])
}
.subscribe(on: DispatchQueue.global())
.receive(on: OperationQueue.main)
let subject = CurrentValueSubject<String, Never>("Hello")
subject.sink { value in print(value) }
subject.send("World")
import UIKit
import BackgroundTasks
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BGTaskScheduler.shared.register(
forTaskWithIdentifier: "pl.snowdog.example.refresh",
using: DispatchQueue.global()
func applicationDidEnterBackground(_ application: UIApplication) {
scheduleAppRefresh()
}
private func scheduleAppRefresh() {
do {
let request = BGAppRefreshTaskRequest(identifier: "pl.snowdog.example.refresh")
request.earliestBeginDate = Date(timeIntervalSinceNow: 3600)
try BGTaskScheduler.shared.submit(request)
} catch {
import UIKit
import BackgroundTasks
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BGTaskScheduler.shared.register(
forTaskWithIdentifier: "pl.snowdog.example.train",
@mecid
mecid / .swiftlint.yml
Last active March 13, 2020 15:59
SwiftLint config file
opt_in_rules:
- force_unwrapping
- empty_count
- contains_over_first_not_nil
- fatal_error_message
- first_where
- number_separator
- operator_usage_whitespace
- trailing_closure
- toggle_bool
@mecid
mecid / Sidebar.swift
Created February 15, 2021 17:34
SwiftUI Sidebar example
import SwiftUI
struct Mail: Identifiable, Hashable {
let id = UUID()
let date: Date
let subject: String
let body: String
var isFavorited = false
}
@mecid
mecid / apollo-code-gen.sh
Last active October 7, 2022 15:00
Apollo GraphQL Run Script for Xcode
# Go to the build root and search up the chain to find the Derived Data Path where the source packages are checked out.
DERIVED_DATA_CANDIDATE="${BUILD_ROOT}"
while ! [ -d "${DERIVED_DATA_CANDIDATE}/SourcePackages" ]; do
if [ "${DERIVED_DATA_CANDIDATE}" = / ]; then
echo >&2 "error: Unable to locate SourcePackages directory from BUILD_ROOT: '${BUILD_ROOT}'"
exit 1
fi
DERIVED_DATA_CANDIDATE="$(dirname "${DERIVED_DATA_CANDIDATE}")"
@mecid
mecid / ContentView.swift
Last active January 14, 2023 21:46
SwiftUI Drag and Drop example for grid items
import SwiftUI
extension RandomAccessCollection {
func indexed() -> Array<(offset: Int, element: Element)> {
return Array(enumerated())
}
}
struct ContentView: View {
@State private var items: [[String]] = [