Skip to content

Instantly share code, notes, and snippets.

View niaeashes's full-sized avatar

Nia niaeashes

  • Cookpad
  • Fukuoka
  • 12:00 (UTC +09:00)
View GitHub Profile
import SwiftUI
// MARK: - Basic
public struct CellLayout<Icon: View, Content: View, Accessory: View>: View {
@State var cellHeight: CGFloat = 0
var horizontalGap: CGFloat
var verticalGap: CGFloat
@niaeashes
niaeashes / DebugJsonView.swift
Last active March 15, 2024 05:57
SwiftUI JSON View for Debugging
#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct DebugJsonView: View {
let json: JsonElement
init(_ json: String) {
self.json = JsonElement.parse(json)
import SwiftUI
struct ContentView: View {
var body: some View {
ScrollView {
LazyVStack {
ForEach(0..<10000, id: \.self) { i in
Text("No.\(i)")
.padding()
import SwiftUI
struct OffsetKey: PreferenceKey {
static var defaultValue: CGFloat = .zero
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}
struct ContentView: View {
@niaeashes
niaeashes / InfinityScrollView.swift
Last active January 26, 2022 04:54
SwiftUI Only Infinity Scrolling (get data from datasource class)
import SwiftUI
import Combine
protocol InfinityScrollDataSource: AnyObject {
associatedtype Element: Identifiable
typealias Index = Int
associatedtype ObjectWillChangePublisher : Publisher = ObservableObjectPublisher where ObjectWillChangePublisher.Failure == Never
var count: Int { get }
var objectWillChange: ObjectWillChangePublisher { get }
@niaeashes
niaeashes / Camera.swift
Last active January 18, 2022 08:58
iOS Camera Implementation
//
// Camera.swift
// CameraTest
//
import UIKit
import CoreImage
import VideoToolbox
import AVFoundation
const validate = require('json-schema').validate;
const YAML = require('yaml');
const fs = require('fs').promises;
const main = async () => {
const doc = YAML.parse(await fs.readFile('./doc.yml', { encoding: 'utf-8' }));
const schema = YAML.parse(await fs.readFile('./schema.yml', { encoding: 'utf-8' }));
console.log({ doc, schema });
console.log(validate(doc, schema));
}
@niaeashes
niaeashes / diceroll.ts
Last active January 21, 2021 15:51
diceroll.ts
const rollSingle = (face: number, rolled: number[]): number => {
const r = Math.ceil(Math.random() * face)
rolled.push(r)
return r
}
const roll = (count: number, face: number, rolled: number[]): number => [...Array(count)].reduce(r => r + rollSingle(face, rolled), 0)
globalThis.roll = roll
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@niaeashes
niaeashes / HexCell.swift
Created December 29, 2019 01:46
ゲーム作る.Hex座標系.log
class HexCell {
let coordinate: HexCoordinate
private(set) var field: Field = .none
private var isFreezed: Bool = false
init(coordinate: HexCoordinate) {
self.coordinate = coordinate
}