Skip to content

Instantly share code, notes, and snippets.

View griffin-stewie's full-sized avatar

griffin-stewie griffin-stewie

View GitHub Profile
@niw
niw / README.md
Created November 6, 2025 05:47
Unsafe `Binding` access on SwiftUI

Unsafe Binding Access on SwiftUI

It’s not always safe to access a Binding within a callback that isn’t part of SwiftUI’s event system. An example is illustrated in the following sample code:

extension Notification.Name {
    static let event = Notification.Name("event")
}
@niw
niw / RunOnMainRunLoopExitScheduler.swift
Created November 5, 2025 23:53
A Combine Scheduler to delay on `exit` observer on main run loop.
//
// RunOnMainRunLoopExitScheduler.swift
// RunOnMainRunLoopExitScheduler
//
// Created by Yoshimasa Niwa on 11/5/25.
//
import Combine
import Foundation
import SwiftUI
import Foundation
import FoundationModels
import AudioToolbox
enum Role: Hashable {
case user
case assistant
}
@mono0926
mono0926 / index.ts
Last active September 18, 2025 03:38
Apple ⇄ Google Maps convert function
import * as logger from 'firebase-functions/logger'
import { defineSecret } from 'firebase-functions/params'
import { HttpsError, onRequest } from 'firebase-functions/v2/https'
const secretKey = defineSecret('convertMapSecretKey')
const googleMapsApiKey = defineSecret('convertMapGoogleMapsApiKey')
async function getFtidFromShortUrl(shortUrl: string): Promise<string> {
const response = await fetch(shortUrl, {
method: 'GET',
import SwiftUI
import MapKit
struct MonotoneMap: View {
@State var position = MapCameraPosition.region(
MKCoordinateRegion(
center: CLLocationCoordinate2DMake(35.685175, 139.7528),
span: MKCoordinateSpan(latitudeDelta: 0.03, longitudeDelta: 0.03)
)
)
@niw
niw / use_var_in_struct.md
Last active December 1, 2025 02:11
Use `var` in `struct` in Swift

Use var in struct in Swift

TL;DR: Use var for properties in struct as long as it serves as a nominal tuple. In most cases, there is no obvious benefit to using let for struct properties.

Simple Example

Let's start with a simple example:

struct MyStruct {
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
TextSampleView(style: .foreground)
TextSampleView(style: .mint)
TextSampleView(style: linearGradient)
}
.font(.largeTitle)
import SwiftUI
struct ContentView: View {
@State var rating: Double = 0
var body: some View {
HStack(spacing: 18) {
Button(
action: { withAnimation { rating -= 1 } },
label: { Image(systemName: "minus.circle") }
@usagimaru
usagimaru / DumpAllMethods.swift
Last active March 28, 2024 19:52
Get all methods of an class or instance in Swift
// Dump all NSApplication’s class methods
let dump = NSApplication.perform(NSSelectorFromString("fp_methodDescription")).takeUnretainedValue() as? String
// Dump all NSApplication’s instance methods
let dump = NSApp.perform(NSSelectorFromString("fp_methodDescription")).takeUnretainedValue() as? String
// or
print(NSApplication.value(forKey: "fp_methodDescription"))
print(NSApp.value(forKey: "fp_methodDescription"))
#include <M5StickC.h>
#include <WiFi.h>
#include <ssl_client.h>
#include <HTTPClient.h>
#define PIN_SW 26
const char* ssid = "ssid";
const char* password = "pass";
const char* WEBHOOK_URL = "url";