Skip to content

Instantly share code, notes, and snippets.

@natpenguin
natpenguin / SpreadsheetView.swift
Last active February 18, 2023 03:38
A view like spreadsheet in SwiftUI
import SwiftUI
struct SpreadsheetView<ColumnView: View, RowView: View, ContentView: View, Column: Hashable, Row: Hashable>: View {
init(
columns: [Column],
rows: [Row],
columnWidth: CGFloat,
columnHeight: CGFloat,
rowWidth: CGFloat,
rowHeight: CGFloat,
public protocol LayoutItem { // `UIView`, `UILayoutGuide`
var superview: UIView? { get }
}
extension UIView: LayoutItem {}
extension UILayoutGuide: LayoutItem {
public var superview: UIView? { owningView }
}
public struct Alignment {
@V8tr
V8tr / AutoLayoutDSL.swift
Last active October 31, 2023 17:42
Auto Layout DSL
import UIKit
/// Represents a single `NSLayoutConstraint`
enum LayoutAnchor {
case constant(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
constant: CGFloat)
case relative(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
@SBourgon
SBourgon / UIView+TinyConstraints.swift
Last active March 23, 2021 10:55
TinyConstraint extension for superview layout margins
//
// UIView+TinyConstraints.swift
// CommonSwift
//
// Created by Sebastien on 2020-08-21.
// Copyright © 2020 Powerband Exchange. All rights reserved.
//
import Foundation
import TinyConstraints
@yasirmturk
yasirmturk / UIStackView+RemoveAll.swift
Created April 15, 2020 07:49
Remove all arranged subviews from UIStackView properly
import UIKit
extension UIStackView {
@discardableResult
func removeAllArrangedSubviews() -> [UIView] {
return arrangedSubviews.reduce([UIView]()) { $0 + [removeArrangedSubViewProperly($1)] }
}
func removeArrangedSubViewProperly(_ view: UIView) -> UIView {
removeArrangedSubview(view)
//
// TurnipCalculator
//
// Translated from https://gist.github.com/Treeki/85be14d297c80c8b3c0a76375743325b#file-turnipprices-cpp
//
// TODO: Calculation is slightly off from C++ impl still
import Foundation
@Treeki
Treeki / TurnipPrices.cpp
Last active May 27, 2024 15:18
AC:NH turnip price calculator
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// munged from https://github.com/simontime/Resead
namespace sead
{
class Random
{
@leonid-s-usov
leonid-s-usov / RecordAudio.swift
Last active March 20, 2024 09:12 — forked from hotpaw2/RecordAudio.swift
Swift Audio Recording class. Reads buffers of input samples from the microphone using the iOS RemoteIO Audio Unit API
//
// RecordAudio.swift
//
// This is a Swift class (updated for Swift 5)
// that uses the iOS RemoteIO Audio Unit
// to record audio input samples,
// (should be instantiated as a singleton object.)
//
// Created by Ronald Nicholson on 10/21/16.
// Copyright © 2017,2019 HotPaw Productions. All rights reserved.
@drumnkyle
drumnkyle / ButtonScrollPerformanceTest.m
Last active February 12, 2019 14:54
Full Scroll Performance Framework
/*
The MIT License
Copyright (c) 2010-2018 Google, Inc. http://angularjs.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@Busta117
Busta117 / ObjectMapperRealmHelper.swift
Last active March 1, 2020 16:56
map Realm arrays into ObjectMapper
//
// ObjectMapperRealmHelper.swift
//
// Created by Santiago Bustamante on 07/27/18.
//
//
import ObjectMapper
import RealmSwift