Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
struct ContentView: View {
@StateObject private var viewModel = RectsViewModel()
var body: some View {
GeometryReader { geometry in
TimelineView(.animation) { timeline in
Canvas {context, size in
let rects = viewModel.rects
@niw
niw / use_var_in_struct.md
Last active June 13, 2025 17:21
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 {
@realvjy
realvjy / ChoasLinesShader.metal
Last active July 25, 2025 10:21
Choas Lines - Metal Shader
// Lines
float hash( float n ) {
return fract(sin(n)*753.5453123);
}
// Slight modification of iq's noise function.
float noise(vector_float2 x )
{
vector_float2 p = floor(x);
vector_float2 f = fract(x);
@Koshimizu-Takehito
Koshimizu-Takehito / OscillatingEffect.swift
Last active November 25, 2024 13:15
ホームスクリーンのアイコンのブルブルするやつ
import SwiftUI
let symbols = [
"pencil",
"trash",
"folder",
"camera",
"photo",
"clock",
"arrow.right.circle.fill",
@AlexKobachiJP
AlexKobachiJP / EditMode.swift
Last active May 14, 2025 05:36
Reimplementation of SwiftUI EditMode enum for macOS
// Documentation comments are copied from the official documentation for iOS.
import SwiftUI
#if os(macOS)
/// Reimplemenation of [EditMode](https://developer.apple.com/documentation/swiftui/editmode) for macOS.
public enum EditMode {
/// The user can edit the view content.
@mecid
mecid / Calendar.swift
Last active July 16, 2025 00:02
SwiftUI Calendar view using LazyVGrid
import SwiftUI
extension Calendar {
func generateDates(
inside interval: DateInterval,
matching components: DateComponents
) -> [Date] {
var dates: [Date] = []
dates.append(interval.start)
@PaulWoodIII
PaulWoodIII / SelectedItems.swift
Created August 19, 2019 00:02
quick example of how to use selection in a SwiftUI list, an ObservableObject provides the content as well
//: [Previous](@previous)
import SwiftUI
import Combine
import PlaygroundSupport
class Context: ObservableObject {
@Published var selectedItems: Set<String>
@Published var items: Array<String>
@Oranzh
Oranzh / AES-256 encryption and decryption in PHP and C#.md
Created March 24, 2018 04:19
AES-256 encryption and decryption in PHP and C#

AES-256 encryption and decryption in PHP and C#

Update: There is a more secure version available. Details

PHP

<?php

$plaintext = 'My secret message 1234';
@zacwest
zacwest / ios-font-sizes.swift
Last active July 24, 2025 22:08
iOS default font sizes - also available on https://www.iosfontsizes.com
let styles: [UIFont.TextStyle] = [
// iOS 17
.extraLargeTitle, .extraLargeTitle2,
// iOS 11
.largeTitle,
// iOS 9
.title1, .title2, .title3, .callout,
// iOS 7
.headline, .subheadline, .body, .footnote, .caption1, .caption2,
]
@jtdp
jtdp / gist:5443498
Last active July 7, 2025 19:33
Revert file permission changes in local git repository.. Very useful when you change permissions due to working on a samba share. Lifted from: http://stackoverflow.com/questions/2517339/git-how-to-recover-the-file-permissions-git-thinks-the-file-should-be
git diff -p \
| grep -E '^(diff|old mode|new mode)' \
| sed -e 's/^old/NEW/;s/^new/old/;s/^NEW/new/' \
| git apply