Skip to content

Instantly share code, notes, and snippets.

View ctreffs's full-sized avatar
💭
🏊 🚴‍♂️ 🏃

Christian Treffs ctreffs

💭
🏊 🚴‍♂️ 🏃
View GitHub Profile
@kinjalkishor
kinjalkishor / game_loops.cpp
Created February 11, 2023 03:07
Game Loops
//----------------------
// Gaffer On Games
// https://gafferongames.com/post/fix_your_timestep/
//----------------------
// Fixed delta time
// If delta time match the display refresh rate, and you can ensure that your update loop takes less than one frame worth of real time.
double t = 0.0;
double dt = 1.0 / 60.0;
while (!quit) {
@wakinchan
wakinchan / generate-target-dependencies.sh
Last active August 20, 2024 22:32
Generate Target Dependencies for Package.swift
#!/usr/bin/env sh
# usage: sh ./generate-target-dependencies.sh | dot -Tsvg -o target-graph.svg
packages=`swift package describe --type json`
targets=`echo $packages | jq '.targets'`
target_names=`echo $targets | jq -r '.[] | .name'`
body=""
template=`cat <<EOF
digraph DependenciesGraph {
@brettohland
brettohland / 1.0 FormatStyle in Excruciating Detail.md
Last active April 16, 2025 17:37
FormatStyle in Excruciating Detail

Motivation

Swift’s type system supports a number of different ways of taking a function or type and abstracting it. Usually, this is done by adding a generic parameter and an associated set of constraints. Similarly, a function that takes a particular type of argument can be abstracted to any number of those arguments by making it variadic with triple-dot (...) syntax. Today, both of these features are permitted separately: you can define a generic function that takes a variable number of arguments, such as

func debugPrint<T>(_ items: T...) 
  where T: CustomDebugStringConvertible
{   
  for (item: T) in items {
    stdout.write(item.debugDescription)
@keith
keith / README.md
Last active January 8, 2025 18:59
A test of `@_dynamicReplacement` in Swift

Usage

  1. swiftc main.swift -emit-module-path main.swiftmodule -emit-executable -enable-private-imports -Xfrontend -enable-implicit-dynamic
  2. ./main -> prints From original bar()
  3. swiftc -emit-library inject.swift -o inject.dylib -I . -Xlinker -undefined -Xlinker suppress -Xlinker -flat_namespace -Xfrontend -disable-access-control
  4. DYLD_INSERT_LIBRARIES=inject.dylib ./main -> prints From replacement bar()

Notes

  • Passing -Xfrontend -enable-implicit-dynamic removes you from having to add dynamic to everything you want to be replacable
@T1T4N
T1T4N / CVPixelBuffer+Data.swift
Last active October 21, 2024 00:31
A format-agnostic way of converting CVPixelBuffer to Data and back
extension CVPixelBuffer {
public static func from(_ data: Data, width: Int, height: Int, pixelFormat: OSType) -> CVPixelBuffer {
data.withUnsafeBytes { buffer in
var pixelBuffer: CVPixelBuffer!
let result = CVPixelBufferCreate(kCFAllocatorDefault, width, height, pixelFormat, nil, &pixelBuffer)
guard result == kCVReturnSuccess else { fatalError() }
CVPixelBufferLockBaseAddress(pixelBuffer, [])
defer { CVPixelBufferUnlockBaseAddress(pixelBuffer, []) }
@seanbaxter
seanbaxter / appglfw.hxx
Last active March 24, 2021 06:25
Circle glTF viewer. C++ shaders.
#pragma once
// #include <imgui.h>
// #include <examples/imgui_impl_glfw.h>
// #include <examples/imgui_impl_opengl3.h>
#include <stb_image.h>
#include <gl3w/GL/gl3w.h>
#include <GLFW/glfw3.h>
#include <cmath>
#include <cstdio>
#include <cfloat>
@YukiSnowy
YukiSnowy / main.cpp
Last active April 3, 2025 13:45
example SDL2 Vulkan application
// Windows
// g++ *.cpp -o vulkan -lSDL2main -lSDL2 -lvulkan-1
// Linux
// g++ *.cpp -o vulkan -lSDL2main -lSDL2 -lvulkan
// https://vulkan-tutorial.com/
#include <iostream>
using namespace std;
#include <SDL2/SDL.h>
@ddunbar
ddunbar / deployable-artifacts.md
Last active June 27, 2021 07:46
Deployable Artifacts thoughts

My hopes for deployable artifacts:

  1. Packages would be able to just describe how the things they build should get laid out in a tarball.
  2. We would implement this as part of the build, it should be super fast (we might want to consider actually generating the tar directly for portability & control purposes).
  3. Packages could have control over the permissions inside the tar file (ideally without having to manipulate the permissions in the filesystem, problematic sometimes if root permission in the tar is desired).
  4. The mechanism would support knowing how to handle RPATH issues.
  5. The mechanism would know how to handle libswift* portability issues.
  6. The mechanism would know how to handle cross-Linux distro issues.
  7. Unlike below, I wouldn't expect the mechanism to handle the GIT REVISION stuff, that belongs in a separate proposal.
  8. The mechanism would support typical Unix-y things, like bin, lib, libexec, share.
  9. The mechanism could support vendored assets like other DSOs or frameworks that can't l
@dabrahams
dabrahams / StaticArrayInsertRemove.swift
Last active September 7, 2022 06:20
Static Array With Functional Insert and Remove Operations
// The point of this prototype is to prove that we can generate efficient code
// for single-element insertion and deletion on a statically-sized array, with
// stable types for the end products i.e.,
//
// type(of: a.removing(at: i).inserting(x, at: j)) == type(of: a)
//
// and
//
// type(of: a.inserting(x, at: j).removing(at: i)) == type(of: a)