Skip to content

Instantly share code, notes, and snippets.

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

Christian Treffs ctreffs

💭
🏊 🚴‍♂️ 🏃
View GitHub Profile
@ctreffs
ctreffs / withUnsafeCStringBufferPointer.swift
Created June 10, 2021 07:25
[Swift] C-String buffer pointer from array of Strings
extension Array where Element == String {
@inlinable
public func withUnsafeCStringBufferPointer<R>(_ body: (UnsafeBufferPointer<UnsafePointer<CChar>?>) throws -> R) rethrows -> R {
func translate(_ slice: inout Self.SubSequence,
_ offset: inout Int,
_ buffer: UnsafeMutableBufferPointer<UnsafePointer<CChar>?>,
_ body: (UnsafeBufferPointer<UnsafePointer<CChar>?>) throws -> R) rethrows -> R {
guard let string = slice.popFirst() else {
return try body(UnsafeBufferPointer(buffer))
@ctreffs
ctreffs / VulkanClear.cc
Created May 18, 2021 07:42 — forked from Overv/VulkanClear.cc
Vulkan code for clearing the screen
#include <iostream>
#include <vector>
#define GLFW_INCLUDE_VULKAN
#define VK_USE_PLATFORM_WIN32_KHR
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3native.h>
@ctreffs
ctreffs / AlignValue.swift
Last active February 5, 2021 23:01
Metal buffer size alignment calculation
/// In Metal buffers (MTLBuffer) require a specific alignment, this function helps with that.
/// <https://developer.apple.com/documentation/metal/mtlcomputecommandencoder/2928169-setbuffers#discussion>
public func align<I>(_ value: I, to alignment: I) -> I where I: BinaryInteger {
assert(alignment == 0 || (alignment & (alignment-1)) == 0, "Alignment must be 0 or power of 2")
if alignment == 0 {
return value
} else if (value & (alignment - 1)) == 0 {
return value
} else {
@ctreffs
ctreffs / increate-build-number.sh
Created February 5, 2021 13:38
Increase build number in plist
#!/bin/sh
# fail fast & fail uninizialized
set -ex
GIT=`xcrun -find git`
if [[ -n $1 && $1 == "YES" ]]; then paket=true; else paket=false; fi
if [[ -n $2 && $2 == "YES" ]]; then watch=true; else watch=false; fi
if [[ -n $3 && $3 == "YES" ]]; then appex=true; else appex=false; fi
@ctreffs
ctreffs / get-version-number-from-git.sh
Created February 5, 2021 13:37
Get version string from git
#!/bin/sh
GIT=$1
if [[ -z $GIT ]]; then
GIT=git
fi
## Use the last annotated 'develop' tag as CFBundleShortVersionString
version=`"${GIT}" tag --merged HEAD --list 'develop/*' --sort=v:refname | tail -n 1`
@ctreffs
ctreffs / get-build-number-from-git.sh
Created February 5, 2021 13:36
Get build number from git
#!/bin/sh
GIT=$1
if [[ -z $GIT ]]; then
GIT=git
fi
# Use the commit count before HEAD as CFBundleVersion
head_date=`"${GIT}" show -s --format=%cI`
@ctreffs
ctreffs / generate-global-app-config.sh
Created February 5, 2021 13:31
Generate Swift & Objective-C Xcode config file from environment variables
#!/bin/sh
# generate-global-app-config.sh
# DPAG-DHL
#
# Created by Christian Treffs on 26.01.17.
#
# This is a script to aggregate all export constants into *.h/*.m and *.swift global configuration files.
# It allows access to Xcode build settings that are managed via *.xcconfig files or the build settings tab.
# A maintaned version may be found at https://gitlab.7p-group.com/snippets/6
@ctreffs
ctreffs / Queue.swift
Last active January 22, 2021 09:04
FIFO Queue in Swift
/// A First-in first-out queue (FIFO).
///
/// - New elements are added to the end/tail of the queue.
/// - Dequeuing pulls elements from the front/head of the queue.
public struct Queue<Element> {
private var tail: ContiguousArray<Element?>
private var head: Int
/// Creates a new, empty queue.
@ctreffs
ctreffs / GLSL-Noise.md
Created November 19, 2020 13:43 — forked from patriciogonzalezvivo/GLSL-Noise.md
GLSL Noise Algorithms

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}