Skip to content

Instantly share code, notes, and snippets.

View define-private-public's full-sized avatar
🔮
(´・ω・`)

Benjamin Summerton define-private-public

🔮
(´・ω・`)
View GitHub Profile
@define-private-public
define-private-public / CMakeLists.txt
Last active April 16, 2024 23:30
C++ `final` keyword experiment (TODO blog link)
option(WITH_FINAL "Use the `final` specifier on derived classes (faster?)" OFF)
# ...
if (WITH_FINAL)
message(STATUS "Using `final` spicifer (faster?)")
target_compile_definitions(PSRayTracing_StaticLibrary PUBLIC USE_FINAL)
else()
message(STATUS "Turned off use of `final` (slower?)")
endif()
# `Linguist` is required
find_package(Qt6 COMPONENTS Linguist REQUIRED)
# ...
# Have your app specified
qt_add_executable(myapp ...
# ...
@define-private-public
define-private-public / 1.CMakeLists.txt
Last active August 21, 2022 17:45
PSRayTracing Qt GUI Blog Post
# Check if we're building for iOS (and put it into a more friendly variable)
set(IOS FALSE)
if (${CMAKE_SYSTEM_NAME} STREQUAL iOS)
set(IOS TRUE)
endif()
# If we're building for Android or iOS, turn on the UI
set(IS_MOBILE FALSE)
if (ANDROID OR IOS)
set(IS_MOBILE TRUE)
@define-private-public
define-private-public / main.cpp.diff
Last active July 7, 2021 19:24
Automated Testing of a Ray Tracer
@@ -157,8 +166,15 @@ int main(int argc, char *argv[]) {
}
// Print some info
- const rreal renderTime = rreal(chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count()) / 1000.0f;
- cout << "Render took " << renderTime << " seconds" << endl;
+ if (run_in_testing_mode) {
+ // For machines, we show nanoseconds (as integers)
+ const auto render_time_us = chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count();
+ cout << render_time_us << " ns" << endl;
#!/usr/bin/python3
import sys
import random
import math
import matplotlib.pyplot as plt
class Vec3:
__slots__ = (
@define-private-public
define-private-public / setup-osx-partial.py
Created March 15, 2020 18:52
Fix ids and rpaths for some OS X dylibs
# If on OS, we need to fix some issues with the dylibs
# namely the rpath stuff & dylib IDs, it's a bit of a pain
if is_osx:
cmds = []
# First fix Ids
dylibs = ['ogg', 'vorbis', 'vorbisenc', 'vorbisfile', 'sndfile']
for lib in dylibs:
lib_filename = 'lib%s.dylib' % (lib)
cmd = 'install_name_tool -id "@rpath/{0}" lib/{0}'.format(lib_filename)
@define-private-public
define-private-public / guess.nim
Last active September 14, 2017 16:41
Guess my number [from rosetta code]
import random, rdstdin, strutils
randomize()
let iRange = 1..100
echo "Guess my target number that is between ", iRange.a, " and ", iRange.b, " (inclusive)."
let target = random(iRange)
var answer, i = 0
while answer != target:
@define-private-public
define-private-public / auto_compile.nim
Last active March 13, 2017 02:27
For an article on hot loading w/ Nim
import osproc
# Where your Nim compiler is located
const nimEXE = "/home/ben/bin/Nim/bin/nim"
# Compile and wait for it to be done
let
compile = startProcess(nimEXE, "", ["c", "--app:lib", "game"])
compileStatus = waitForExit(compile)
close(compile)
@define-private-public
define-private-public / rotate_y_hit_snippet.nim
Created January 3, 2017 18:50
Peter Shirley Ray Tracing Mini-Books (in Nim); a code snippet that drove me nuts
method hit*(ry: rotate_y, r: ray, t_min, t_max: float, rec: var hit_record): bool=
# I thought this was copying the vec3 data, but it wasn't. It was copying the pointer...
var
origin = r.origin()
direction = r.direction()
# origin and direction are modified after this which caused the issue...
@define-private-public
define-private-public / stb_image_example.c
Last active December 30, 2016 21:33
stb_image-Nim blog post code snippets
#include "stb_image.h"
// Get the image data
int width, height, channels;
unsigned char *data = stbi_load("kevin_bacon.jpeg", &width, &height, &channels, STBI_default);
// Do what you want...
// Cleanup
stbi_image_free(data);