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
@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 / 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 / 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]] = [
@mecid
mecid / AnimatableCGPointVector.swift
Created June 17, 2020 23:40
The type that holds array of CGPoints and conforms to VectorArithmetic
import SwiftUI
struct AnimatableCGPointVector: VectorArithmetic {
static var zero = AnimatableCGPointVector(values: [.zero])
static func - (lhs: AnimatableCGPointVector, rhs: AnimatableCGPointVector) -> AnimatableCGPointVector {
let values = zip(lhs.values, rhs.values)
.map { lhs, rhs in lhs.animatableData - rhs.animatableData }
.map { CGPoint(x: $0.first, y: $0.second) }
return AnimatableCGPointVector(values: values)
@mecid
mecid / AnimatableVector.swift
Last active December 27, 2023 21:43
High-performance Animatable Vector for SwiftUI
import SwiftUI
import enum Accelerate.vDSP
struct AnimatableVector: VectorArithmetic {
static var zero = AnimatableVector(values: [0.0])
static func + (lhs: AnimatableVector, rhs: AnimatableVector) -> AnimatableVector {
let count = min(lhs.values.count, rhs.values.count)
return AnimatableVector(values: vDSP.add(lhs.values[0..<count], rhs.values[0..<count]))
}
@mecid
mecid / Calendar.swift
Last active October 2, 2024 08:34
SwiftUI Calendar view using LazyVGrid
import SwiftUI
extension Calendar {
func generateDates(
inside interval: DateInterval,
matching components: DateComponents
) -> [Date] {
var dates: [Date] = []
dates.append(interval.start)
//
// BottomSheetView.swift
//
// Created by Majid Jabrayilov
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
fileprivate enum Constants {
static let radius: CGFloat = 16
@mecid
mecid / PagerView.swift
Last active August 15, 2024 06:38
PagerView in SwiftUI
//
// PagerView.swift
//
// Created by Majid Jabrayilov on 12/5/19.
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
struct PagerView<Content: View>: View {
let pageCount: Int
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",
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 {