Skip to content

Instantly share code, notes, and snippets.

View KTRosenberg's full-sized avatar

Karl Toby Rosenberg KTRosenberg

  • New York University
View GitHub Profile
@jamesporter
jamesporter / ContentView.swift
Created April 17, 2024 21:59
Metal and Swift(UI) Raymarching App
import SwiftUI
struct ContentView: View {
let startDate = Date()
var body: some View {
GeometryReader { gp in
TimelineView(.animation) { ctx in
Rectangle()
.ignoresSafeArea()
@naphipps
naphipps / box2d_v3_alpha_task_api_with_npe.cpp
Last active June 25, 2024 19:17
Example of how to hook up to box2d V3-alpha task API
/*
I used this in sample.cpp/hpp of the box2d V3-alpha project.
This is just an example of a non-enkiTS job system used with box2d V3-alpha
- Nathan Phipps 1/14/24
*/
// --------- begin of inside sample.cpp ---------
@neubig
neubig / dispatch_openai_requests.py
Last active February 19, 2024 17:55
A simple script to get results from the OpenAI Asynchronous API
# NOTE:
# You can find an updated, more robust and feature-rich implementation
# in Zeno Build
# - Zeno Build: https://github.com/zeno-ml/zeno-build/
# - Implementation: https://github.com/zeno-ml/zeno-build/blob/main/zeno_build/models/providers/openai_utils.py
import openai
import asyncio
from typing import Any
@Hirrolot
Hirrolot / CoC.ml
Last active May 24, 2024 23:57
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@d7samurai
d7samurai / .readme.md
Last active May 26, 2024 19:16
Minimal D3D11 sprite renderer

Minimal D3D11 sprite renderer

Minimal D3D11 sprite renderer: basic back-to-front sprite rendering reference code with example sprite sheet animation logic. As usual: Complete, runnable single-function app. No modern C++ / OOP / obscuring cruft.

adventurer

Swap out the sprite sheet with a font atlas for a lightweight GUI / text renderer. Clip individual sprites and glyphs by offsetting screenPos and atlasPos to top left corner of visible area and adjusting size accordingly (all values in pixels):

sprite.screenPos.x += 17;
sprite.screenPos.y += 10;
<!--
Go to Line 153 for the start of Uniform Buffer Object related code and intro
Prerequsite:
You at least know what uniforms are in the context of WebGL
and mininally understand the concepts involved in creating a square in WebGL
-->
<html>
@caiorss
caiorss / CMakeLists.txt
Created November 27, 2020 14:05
QuickJS engine sample project - shows how to embedded in C++
cmake_minimum_required(VERSION 3.9)
project(QuickJS-Experiment)
#========== Global Configurations =============#
#----------------------------------------------#
set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_VERBOSE_MAKEFILE ON )
set( CMAKE_CXX_EXTENSIONS OFF)
@tesselode
tesselode / swept-aabb.lua
Last active March 31, 2023 04:18
swept AABB collision detection implemented in Lua (commentated)
--[[
moves rectangle A by (dx, dy) and checks for a collision
with rectangle B.
if no collision occurs, returns false.
if a collision does occur, returns:
- the time within the movement when the collision occurs (from 0-1)
- the x component of the normal vector
- the y component of the normal vector
#include "camera.hpp"
#include "../input.hpp"
#include "assert.h"
void Camera_View::calc_frustrum () {
// frustrum_corners set to cam space by perspective_matrix() or orthographic_matrix()
for (int i=0; i<8; ++i)
frustrum.corners[i] = cam_to_world * frustrum.corners[i];
@hasenj
hasenj / app_metal.c
Created December 30, 2019 12:46
Pure C Cocoa Application with Window and Metal
// How to build:
// # compile the metal shaders
// xcrun -sdk macosx metal -c shaders.metal -o shaders.air
// xcrun -sdk macosx metallib shaders.air -o shaders.metallib
// # compile the c file
// clang app_metal.c -framework Cocoa -framework Metal -o metal_c.app
//
//
// Draw a triangle using metal
// Metal tutorial followed here: https://www.raywenderlich.com/7475-metal-tutorial-getting-started