Skip to content

Instantly share code, notes, and snippets.

View kkebo's full-sized avatar
📱
Using iPad Pro 13” (M4)

Kenta Kubo kkebo

📱
Using iPad Pro 13” (M4)
View GitHub Profile
@kkebo
kkebo / ExportIPA.swift
Last active November 13, 2023 09:23 — forked from rileytestut/ExportIPA.swift
Export Swift Playgrounds .ipa
import class Foundation.Bundle
import class Foundation.FileManager
import class Foundation.NSFileAccessIntent
import class Foundation.NSFileCoordinator
import class Foundation.NSMutableDictionary
import struct Foundation.URL
import struct Foundation.UUID
import var Foundation.kCFBundleIdentifierKey
import var Foundation.kCFBundleNameKey
@kkebo
kkebo / ContentView.swift
Created September 13, 2021 15:42
iOS の Light/Dark mode 選択の設定みたいな Picker
import PlaygroundSupport
import SwiftUI
struct ContentView: View {
@State var selection = 0
var body: some View {
HStack {
Button {
self.selection = 0
@kkebo
kkebo / Box.swift
Last active July 30, 2021 21:08
Rust の Box 的なやつを Swift で (Box はヒープに置くことが目的、BoxObject は参照にすることが目的)
@propertyWrapper
public struct Box<Value> {
private var object: BoxObject<Value>
public var value: Value {
get { self.object.value }
set {
if !isKnownUniquelyReferenced(&self.object) {
self.object = self.object.copy()
}
@kkebo
kkebo / main.swift
Created July 29, 2021 16:36
https://zenn.dev/harumaru/articles/6f7ec2659261f6 の記事の LivePhotoView を Swift Playgrounds で表示するサンプルコード
import PhotosUI
import PlaygroundSupport
import SwiftUI
struct LivePhotoView: View {
let livePhoto: PHLivePhoto
var body: some View {
_LivePhotoView(livePhoto: livePhoto)
.aspectRatio(
@kkebo
kkebo / ContentView.swift
Last active July 10, 2021 07:06
Toast UI implemented in SwiftUI
// Swift Playgrounds での利用例
import PlaygroundSupport
import SwiftUI
struct ContentView {
@State var toastDuration: DispatchTimeInterval?
@State var toastMessage: LocalizedStringKey = ""
}
@kkebo
kkebo / ShazamKit.swift
Last active June 21, 2022 17:38
ShazamKit on Swift Playgrounds 3.4 on iPadOS 15
import Foundation
import AVFoundation
Bundle(path: "/System/Library/Frameworks/ShazamKit.framework")!.load()
class SHSession {
static let rawType = NSClassFromString("SHSession") as! NSObject.Type
let rawValue: NSObject
var delegate: SHSessionDelegate? {
@kkebo
kkebo / error_log.md
Last active May 23, 2021 09:44
import coremltools on Carnets Plus
import coremltools
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-5bf9ddba4efd> in <module>
----> 1 import coremltools
@kkebo
kkebo / vmstat.swift
Last active May 15, 2021 17:40
vmstat of iPadOS
import Darwin
func getVMStatistics64() -> vm_statistics64? {
let hostPort = mach_host_self()
var hostSize = mach_msg_type_number_t(MemoryLayout<vm_statistics64_data_t>.size / MemoryLayout<integer_t>.size)
var vmstat = vm_statistics64()
let result = withUnsafeMutablePointer(to: &vmstat) {
$0.withMemoryRebound(to: integer_t.self, capacity: Int(hostSize)) {
host_statistics64(
hostPort,
@kkebo
kkebo / Demo.swift
Created April 7, 2021 13:53
PlaygroundHandler
import Logging
LoggingSystem.bootstrap { label in
var handler = PlaygroundHandler(label: label)
handler.logLevel = .trace
return handler
}
let logger = Logger(label: "hoge")
extension Result {
func expect(_ message: String) -> Success {
switch self {
case let .success(value):
return value
case let .failure(error):
preconditionFailure("\(message): \(error.localizedDescription)")
}
}