Skip to content

Instantly share code, notes, and snippets.

@geor-kasapidi
geor-kasapidi / SKError.swift
Created July 20, 2021 17:02
SKError codes
@available(iOS 3.0, *)
public enum Code : Int {
public typealias _ErrorType = SKError
case unknown = 0
case clientInvalid = 1 // client is not allowed to issue the request, etc.
case paymentCancelled = 2 // user cancelled the request, etc.
@geor-kasapidi
geor-kasapidi / mangalib_images.js
Created January 4, 2024 08:17
mangalib script to download images and open next chapter
async function xxx() {
for (page of window.__pg) {
const blob = await fetch(window.__info.servers[window.__info.img.server] + window.__info.img.url + page.u).then(res => res.blob());
const blob_url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = blob_url;
a.download = window.__info.current.number + '_' + page.u;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
static func _compile(data: Data, configuration: MLModelConfiguration = .init()) async throws -> MLModel {
let tmp = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
try data.write(to: tmp, options: .atomic)
let url = try await MLModel.compileModel(at: tmp)
try FileManager.default.removeItem(at: tmp)
let model = try MLModel(contentsOf: url, configuration: configuration)
try FileManager.default.removeItem(at: url)
return model
}
@geor-kasapidi
geor-kasapidi / MetalCapture.swift
Last active December 12, 2021 10:53
Metal capture extension for Alloy
extension MTLCaptureManager {
@discardableResult
func capture<T>(with commandQueue: MTLCommandQueue, _ action: () throws -> T) throws -> T {
let scope = self.makeCaptureScope(commandQueue: commandQueue)
let descriptor = MTLCaptureDescriptor()
descriptor.captureObject = scope
try self.startCapture(with: descriptor)
scope.begin(); defer { scope.end() }
@geor-kasapidi
geor-kasapidi / metal.py
Created November 16, 2021 10:30
Metal AST
import sys
import os
import clang.cindex
shaders_file = sys.argv[1]
assert(shaders_file.endswith(“.metal”))
ast_file = shaders_file.rstrip(“.metal”) + “.ast”
os.system(f”xcrun metal -emit-ast {shaders_file}“)
xcode_path = os.popen(“xcode-select -p”).read().rstrip()
@geor-kasapidi
geor-kasapidi / classes.txt
Created May 27, 2021 11:24
VNClassifyImageRequest.knownClassifications(forRevision: VNClassifyImageRequestRevision1)
abacus
accordion
acorn
acrobat
adult
adult_cat
agriculture
aircraft
airplane
airport
@geor-kasapidi
geor-kasapidi / swf.sh
Last active September 17, 2021 10:15
swiftformat shell script
swiftformat \
--self insert \
--wrapcollections before-first \
--wraparguments before-first \
--wrapparameters before-first \
--header strip \
--ifdef no-indent \
--enable wrapSwitchCases \
--enable organizeDeclarations \
--swiftversion 5.3 .
@geor-kasapidi
geor-kasapidi / OOM.swift
Created June 11, 2021 09:12
FOOM logger
private final class AppInfo {
private struct Keys {
static let lastKnownAppVersion = "app_data.last_known_app_version"
static let appWasInBackground = "app_data.app_was_in_background"
static let appWasTerminated = "app_data.app_was_terminated"
}
struct State {
let appVersionIsChanged: Bool
let appWasInBackground: Bool
struct EnumSet<T: RawRepresentable & CaseIterable>: OptionSet where T.RawValue == Int {
let rawValue: T.RawValue
init(rawValue: T.RawValue) {
self.rawValue = rawValue
}
init(_ value: T) {
self.rawValue = 1 << value.rawValue
}
@geor-kasapidi
geor-kasapidi / swiftformat
Created August 16, 2021 14:34
Swiftformat rules
--self insert
--wrapcollections after-first
--wraparguments after-first
--wrapparameters after-first
--header strip
--enable wrapSwitchCases
--enable organizeDeclarations