Skip to content

Instantly share code, notes, and snippets.

View Aayush9029's full-sized avatar
🚢
A bigger ship is harder to steer.

Aayush Aayush9029

🚢
A bigger ship is harder to steer.
View GitHub Profile
@Aayush9029
Aayush9029 / a29_ed25519.pub
Last active September 1, 2021 20:54
Public Key
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDbiwd0Ssu+NHqav4i6TlABli7p/YxDa08t79FMeCX9H aayushpokharel36@gmail.com
@Aayush9029
Aayush9029 / TransparentTitleBar.swift
Last active April 8, 2022 03:59
Transparent title bar for mac catalyst app.
// Usage
ContentView()
.withHostingWindow { window in
#if targetEnvironment(macCatalyst)
if let titlebar = window?.windowScene?.titlebar {
titlebar.titleVisibility = .hidden
titlebar.toolbar = nil
}
#endif
}
@Aayush9029
Aayush9029 / View+Extensions.swift
Last active March 9, 2023 17:14
NSView Floating View
#if os(macOS)
extension View {
private func newWindowInternal(with title: String, isTransparent: Bool = false) -> NSWindow {
let window = NSWindow(
contentRect: NSRect(x: 20, y: 20, width: 640, height: 360),
styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
backing: .buffered,
defer: false
)
@Aayush9029
Aayush9029 / Bundle+Extensions.swift
Created April 8, 2022 03:55
Build + Release Version Number
extension Bundle {
var releaseVersionNumber: String? {
return infoDictionary?["CFBundleShortVersionString"] as? String
}
var buildVersionNumber: String? {
return infoDictionary?["CFBundleVersion"] as? String
}
}
@Aayush9029
Aayush9029 / AppDelegate.swift
Last active May 17, 2022 16:30
macOS pure SwiftUI Popover View Code
/*
// Add this to @main App Struct
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
// Add Application is agent (UIElement) = YES in info.plist
*/
import SwiftUI
// MARK: - Menu Bar and Icon Setup
@Aayush9029
Aayush9029 / Vison.swift
Last active July 29, 2023 21:53
CoreML Vision SwiftUI
//
// SuperResViewModel.swift
// Future Filters
//
// Created by Aayush Pokharel on 2022-04-29.
//
import SwiftUI
import CoreML
import Vision
@Aayush9029
Aayush9029 / FetchAsyncVM.swift
Last active December 29, 2022 19:58
Async, Fetch, Swift
func fetch() async {
do {
let (data, _) = try await URLSession.shared.data(from: Constants.ApiURL)
let result = try JSONDecoder().decode([VideoModel].self, from: data)
DispatchQueue.main.sync {
self.videos = result
}
} catch let DecodingError.valueNotFound(value, context) {
print("Value '\(value)' not found:", context.debugDescription)
print("codingPath:", context.codingPath)
@Aayush9029
Aayush9029 / JsonErrorCatch.swift
Last active December 29, 2022 20:00
JSON Error handling
catch let DecodingError.valueNotFound(value, context) {
print("Value '\(value)' not found:", context.debugDescription)
print("codingPath:", context.codingPath)
} catch let DecodingError.typeMismatch(type, context) {
print("Type '\(type)' mismatch:", context.debugDescription)
print("codingPath:", context.codingPath)
} catch {
print(String(describing: error))
}
@Aayush9029
Aayush9029 / compres.sh
Created May 11, 2022 03:40
Image Compression Batch
# compress png images recursively in a dir/**
find . -name '*.png' -print0 | xargs -0 -P8 -L8 pngquant --ext .png --force 256
# L "8" is images compressed at once
# P "8" is cpu cores used at once
@Aayush9029
Aayush9029 / FancyCardView.swift
Created May 12, 2022 01:06
SwiftUI Gradient Text Border Card
struct FancyTitleCard: View {
let title: String
var body: some View {
HStack {
Text(title)
.bold()
.foregroundStyle(.primary)
Spacer()