Skip to content

Instantly share code, notes, and snippets.

@macshome
macshome / EnvironmentVariables.swift
Created May 2, 2024 12:48
A playground to see different ways to get environment variables in Swift
import Foundation
// A playground to see different ways to get environment variables in Swift
// Foundation is the easiest way using the awesome ProcessInfo class.
// Get all of the environment variables for your running process in a Dictionary.
let foundationEnv = ProcessInfo().environment
print("********** ProcessInfo Environment **********")
@schwa
schwa / SwiftUI for macOS Missing Features.md
Last active January 31, 2024 02:45
SwiftUI for macOS Missing Features

https://mastodon.social/@schwa/111801520286334341

My list:

  • Tap location for contextual menus. A lot of apps need to know exactly where a context menu is being triggered from (e.g. canvas style editors etc).
  • Modifier key observation during button presses/gestures etc.
  • Cursor support
  • Native Undo Manager support (SwiftUI has Environment.undoManager but it just exposes Cocoa's UndoManager which doesn't feel very SwiftUI like).
  • Expanded File Dialog options (e.g. adding buttons to the dialog).
  • The outline variant of List (List(… children: …)) is missing a lot of the flexibility of NSOutlineView (TODO: flesh this out with concrete example).
@arthurschiller
arthurschiller / RealityRendererTest.swift
Last active April 25, 2024 18:59
RealityRenderer Test (visionOS)
//
// RealityRendererView.swift
// RealityRendererTest
//
// Created by Arthur Schiller on 11.01.24.
//
import SwiftUI
import Metal
import MetalKit
@MahdiBM
MahdiBM / vapor+openapi+tasklocals.swift
Last active February 27, 2024 20:14
swift-openapi-vapor + `TaskLocal`s to pass the `Request` to the OpenAPI handler
/// PREREQUISITES:
/// Add https://github.com/pointfreeco/swift-dependencies as a dependency of your target, currently it looks like so:
/// `.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.0.0"),`
// MARK: '+DependencyValues.swift'
import Vapor
import Dependencies
extension DependencyValues {
@bgolus
bgolus / PostDepthToWorldPos.shader
Last active October 30, 2023 18:14
Get the world position from the camera depth texture with no external dependencies. Works as a post process or on an transparent object in the scene.
Shader "PostDepthToWorldPos"
{
Properties
{
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
LOD 100
Shader "Pristine Triplanar Grid"
{
Properties
{
[KeywordEnum(World,Object,ObjectAlignedWorld)] _GridSpace ("Grid Space", Float) = 0.0
_GridScale ("Grid Scale", Float) = 1.0
[Toggle(USE_VERTEX_NORMALS)] _UseVertexNormals ("Use Vertex Normals", Float) = 0.0
[Toggle] _ShowOnlyTwo ("Show Only Two Grid Axis", Float) = 0.0
@bgolus
bgolus / PristineRadialGrid.shader
Last active January 31, 2024 11:01
An application of the Pristine Grid technique onto radial grid with atan derivative discontinuity fixes applied. https://bgolus.medium.com/the-best-darn-grid-shader-yet-727f9278b9d8 https://bgolus.medium.com/distinctive-derivative-differences-cce38d36797b
Shader "Pristine Radial Grid"
{
Properties
{
[Toggle] _WorldUV ("Use World Space UV", Float) = 1.0
_GridScale ("Grid Scale", Float) = 1.0
[Toggle] _UseAdaptiveAngularSegments ("Use Adaptive Angular Segment Count", Float) = 0.0
[IntRange] _AngularSegments ("Angular Segments", Range(1,360)) = 4.0
Shader "Pristine Grid"
{
Properties
{
[KeywordEnum(MeshUV, WorldX, WorldY, WorldZ)] _UVMode ("UV Mode", Float) = 2.0
_GridScale ("Grid Scale", Float) = 1.0
_LineWidthX ("Line Width X", Range(0,1.0)) = 0.01
_LineWidthY ("Line Width Y", Range(0,1.0)) = 0.01
@insidegui
insidegui / devicectl.sh
Created October 19, 2023 21:58
Helper functions for using devicectl to kill processes on connected iOS devices
# Add to your zsh profile
function devicepid() {
if [ -z "$1" ]; then
echo "Usage: devicepid <device-name> <search>"
echo "Example: devicepid 'iPhone 15 Pro Max' SpringBoard"
return 1
fi
if [ -z "$2" ]; then
@gerner
gerner / goap_toy.py
Last active February 15, 2023 17:17
import sys
import logging
import enum
import collections
import math
import time
import pdb
from dataclasses import dataclass
from typing import Sequence, Tuple, List, Mapping, MutableMapping, Any, Set, Collection, Iterator, Optional
import sortedcontainers # type: ignore