Skip to content

Instantly share code, notes, and snippets.

View auramagi's full-sized avatar

Mike Apurin auramagi

View GitHub Profile
@auramagi
auramagi / decompress_ecd.py
Last active April 26, 2018 08:14
3DS ECD archive decompression
def bit_is_set(byteval,idx):
return ((byteval&(1<<idx))!=0)
def read_int_bbo(f, s, signed=False):
return int.from_bytes(f.read(s), byteorder='big', signed=signed)
def decompressECD(f, out_fname): #file handle at ECD start position, out file name
magic = f.read(3)
if not magic == b'ECD':
return
@auramagi
auramagi / RoundedButton.swift
Created January 14, 2019 09:11
Rounded opaque buttons for iOS
// Rounded opaque buttons for iOS
// Drop-in replacement for UIButton with Interface Builder support
// UIButton.buttonType type should be set to .custom
// Color is chosen based on the tint color. Supports highlighted and selected states
// Assumes that tint color has high brightness and saturation (e.g. not white or black)
// Written for iOS 12 with Swift 4.2
import UIKit
let kRoundedButtonDefaultFont = UIFont.systemFont(ofSize: 14.0, weight: .medium)
@auramagi
auramagi / PickerLabel.swift
Created February 18, 2019 16:52
Present UIPicker on a UILabel to select from a few options. Supports a placeholder value. For this example the picker selects a weekday.
import UIKit
enum Weekday: Int {
case monday = 1
case tuesday = 2
case wednesday = 3
case thursday = 4
case friday = 5
case saturday = 6
case sunday = 0
// reloadDataを使わないようにしましょう
import UIKit
import DiffableDataSources // https://github.com/ra1028/DiffableDataSources
@available(iOS, introduced: 13.0)
typealias TableViewDiffableDataSource = UITableViewDiffableDataSource
@available(iOS, introduced: 13.0)
typealias DiffableDataSourceSnapshot = NSDiffableDataSourceSnapshot
@auramagi
auramagi / Cats.swift
Last active December 11, 2020 03:21
Swift cat images
enum Cats {
private struct CatResponse: Decodable {
let url: URL
}
@discardableResult
static func getRandomImageURL(completion: @escaping (URL?) -> Void) -> URLSessionDataTask {
let request = URLRequest(url: URL(string: "https://api.thecatapi.com/v1/images/search")!)
let task = URLSession.shared.dataTask(with: request) { data, _, _ in
let catURL: URL? = {
@auramagi
auramagi / ConsoleOutput.txt
Last active August 5, 2021 03:47
SwiftUI _viewDebugData
// Output of print(_viewDebugData), formatted for easier viewing
[SwiftUI._ViewDebug.Data(
data: [
SwiftUI._ViewDebug.Property.value: SwiftUI._SafeAreaInsetsModifier(elements: [], nextInsets: nil),
SwiftUI._ViewDebug.Property.displayList: (display-list
(item #:identity 2 #:version 6
(frame (143.66666666666666 354.0; 88.0 20.333333333333332))
(text "Hello World" #:size (88.0, 20.333333333333332))
)
@auramagi
auramagi / ToDoApp.swift
Last active September 2, 2021 10:36
ForEachでBindingを渡す書き方のサンプルコード
import SwiftUI
@main
struct ToDoApp: App {
@StateObject var model: Model = .init()
var body: some Scene {
WindowGroup {
ScrollView {
VStack(alignment: .leading) {
@auramagi
auramagi / BracketScanner.swift
Created November 29, 2021 03:27
Parse Swift type into a tree where the child nodes are the generic types. Useful for making trees from SwiftUI View types.
import Foundation
final class BracketScanner {
let text: String
init(text: String) {
self.text = text.trimmingCharacters(in: CharacterSet(charactersIn: "()"))
}
lazy var scanner: Scanner = {
@auramagi
auramagi / PTRBug.swift
Created January 12, 2022 19:57
UIRefreshControl stuck when changing tabs in UITabBarController
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
func makeRefreshControl() -> UIRefreshControl {
let refresh = UIRefreshControl()
@auramagi
auramagi / ImageRendererModifier.swift
Created June 7, 2022 08:08
Using SwiftUI ImageRenderer in view modifier-like view extension
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello WWDC22")
.rendered(scale: 2)
}
}
struct ContentView_Previews: PreviewProvider {