Skip to content

Instantly share code, notes, and snippets.

View Clemapfel's full-sized avatar

Clem Cords Clemapfel

View GitHub Profile
@Clemapfel
Clemapfel / 01_thread_pool.lua
Last active April 1, 2024 22:36
ThreadPool in love2D
-- licensed MIT, created by https://github.com/clemapfel
if rt == nil then rt = {} end
--- @class rt.ThreadPool
rt.ThreadPool = {}
--- @brief constructor
--- @param n_threads Number number of threads, default: 1
--- @return rt.ThreadPool
function rt.ThreadPool:new(n_threads)
@Clemapfel
Clemapfel / main.lua
Last active December 9, 2023 22:04
Powder Snow effect in löve2d using geometry instancing
-- Author: C. Cords (https://github.com/clemapfel/)
-- licensed MIT, see https://opensource.org/license/mit/
rt = {}
rt.snow_effect_shader_source = [[
#pragma language glsl3
// GPU-side random generator
vec3 mod289(vec3 x) {
return x - floor(x * (1.0 / 289.0)) * 289.0;
#
# Author: C. Cords (mail@clemens-cords.com)
# https://github.com/clemapfel/mousetrap.jl
#
# Copyright © 2023, Licensed under lGPL3-0
#
using Test
using mousetrap
using BenchmarkTools
function meshgrid(a, b)
x = a' .* ones(length(b))
y = ones(length(a))' .* b
return x, y
end
savetxt(filename, array) = open(filename, "w") do io
for row in eachrow(array)
@Clemapfel
Clemapfel / complex_iterator.jl
Last active February 7, 2023 22:30
Julia Complex Iterator Example
using Random
# The iterable instance
struct Iterable
_ids::Vector{Int64}
_other::Vector{String}
Iterable() = new(rand(Int64, 10), [Random.randstring(3) for i in 1:10])
end
# Iterator, holds reference to instance
@Clemapfel
Clemapfel / julia_swizzling_hello_world.jl
Last active September 11, 2022 18:29
Swizzling in Julia: Basic Mechanism
# Basic mechanism for how to implement GLSL-like swizzling in Julia
mutable struct Vec2
_private_00::Float32
_private_01::Float32
Vec2(x, y) = new(x, y)
end
function Base.getproperty(instance::Vec2, sym::Symbol)
#include <thread>
#include <chrono>
#include <jluna.hpp>
// references https://github.com/Clemapfel/jluna/issues/33
int main()
{
using namespace jluna;
initialize(2);
#include <jluna.hpp>
#include <.benchmark/benchmark.hpp>
#include <.benchmark/benchmark_aux.hpp>
#include <thread>
#include <future>
#include <queue>
using namespace jluna;
int main()
//
// Copyright 2022 Clemens Cords
// Created on 14.03.22 by clem (mail@clemens-cords.com)
//
#include <jluna.hpp>
using namespace jluna;
// this code are examples given as a response to https://github.com/Clemapfel/jluna/issues/12
@Clemapfel
Clemapfel / why.jl
Last active March 4, 2022 20:24
Find all k-sized subsets of arbitrary integer set such that xor is 0
function set_xor(set::Set{T}) where T
res = undef
front::Bool = true
for e in set
if front
res = e
front = false
else
res = Base.xor(res, e)