Skip to content

Instantly share code, notes, and snippets.

import SQLite3
import Foundation
func main(dbPath: String) {
// Pointer for database connection
var db: OpaquePointer?
// Open database
guard sqlite3_open(dbPath, &db) == SQLITE_OK else {
print("Error opening database: \(String(cString: sqlite3_errmsg(db)))")
@heckj
heckj / Shell.swift
Created November 27, 2024 07:22 — forked from finestructure/Shell.swift
Tim's Process helpers
// Via Tim Condon
@discardableResult
func shell(_ args: String..., returnStdOut: Bool = false, stdIn: Pipe? = nil) throws -> (Int32, Pipe) {
return try shell(args, returnStdOut: returnStdOut, stdIn: stdIn)
}
@discardableResult
func shell(_ args: [String], returnStdOut: Bool = false, stdIn: Pipe? = nil) throws -> (Int32, Pipe) {
let task = Process()
@finestructure
finestructure / Shell.swift
Created November 27, 2024 07:17
Tim's Process helpers
// Via Tim Condon
@discardableResult
func shell(_ args: String..., returnStdOut: Bool = false, stdIn: Pipe? = nil) throws -> (Int32, Pipe) {
return try shell(args, returnStdOut: returnStdOut, stdIn: stdIn)
}
@discardableResult
func shell(_ args: [String], returnStdOut: Bool = false, stdIn: Pipe? = nil) throws -> (Int32, Pipe) {
let task = Process()
@MahdiBM
MahdiBM / benchmark-update.yml
Last active September 16, 2024 22:29
Update Benchmark Thresholds
name: update-benchmark-thresholds
on:
workflow_dispatch:
inputs:
# This will have to be an exhastive list of all benchmarks.
# If there is a benchmark name missing, just update this list and push.
benchmark:
type: choice
required: true
@MahdiBM
MahdiBM / benchmark.yml
Last active September 18, 2024 12:51
Using package-benchmark for benchmarking Swift code
name: benchmark
on:
workflow_dispatch:
pull_request: { types: [opened, reopened, synchronize] }
push: { branches: [main] }
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
@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 November 9, 2024 09:18
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