Skip to content

Instantly share code, notes, and snippets.

View SmallJoker's full-sized avatar

SmallJoker

View GitHub Profile
@SmallJoker
SmallJoker / ptrlock_macro.cpp
Last active December 29, 2023 18:52
C++ RAII mutex locking, bound to userdata
// Auto-unlock wrapper for larger operations
/*
Exmaple usage:
struct MyStruct {
PtrLock<decltype(m_value)> getValues()
{
return PtrLock<decltype(m_value)>(m_lock, &m_value);
}
@SmallJoker
SmallJoker / v3s16_optimization.cpp
Last active October 1, 2022 07:00
v3s16_optimization.cpp
#include <iostream>
#include <stdint.h>
#include <vector>
#include "vector3d.h"
using u8 = unsigned char;
using s16 = int16_t;
using u16 = uint16_t;
using v3s16 = irr::core::vector3d<s16>;
local ft = {}
ft.__index = ft
function FSTile(w, h)
local self = {}
setmetatable(self, ft)
-- init stuff here
self.containers = {}
self.width = w
self.height = h
cd irrlicht
# Fake installation dir
mkdir -p __output/include
mkdir -p __output/lib/cmake/IrrlichtMt
ln -sf ../../include __output/include/irrlichtmt
cp -f IrrlichtMt*.cmake __output/lib/cmake/IrrlichtMt/
cp -fP lib/Linux/libIrrlichtMt* __output/lib/
cp -fr CMakeFiles/Export/lib/cmake __output/lib/
@SmallJoker
SmallJoker / github_cleanup_notification_window.txt
Last active November 16, 2022 07:40
Clean up the new clutter in the notifications
Filter Rules
==============
Works for:
- AdblockPlus
- ublock origin
- ??
Group by: Repository
minetest.register_privilege( "lava", "Can place lava at any depth.")
local LAVA_PLACE_DEPTH = -50
function override_on_place(item_name)
local def = minetest.registered_items[item_name]
local old_on_place = def.on_place
def.on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type ~= "node" then
@SmallJoker
SmallJoker / pr_apply.sh
Last active January 14, 2024 15:08
Applies PRs to any repository. Place into ~/.local/bin and run in the target git directory
#!/bin/bash
remote="upstream"
url=$(LANG=C git remote -v get-url $remote 2>&1)
if [[ $url == fatal* || $url == error* ]]; then
remote="origin"
url=$(LANG=C git remote -v get-url $remote 2>&1)
fi
if [[ $url == fatal* || $url == error* ]]; then
@SmallJoker
SmallJoker / neuron.cpp
Last active September 7, 2019 18:25
neuron.cpp
/*
Example structure
┌─── NeuralLayer 1 ────┐
│ Inputs (source data) │
│ Outputs (1) │
└─────vvvvvvvvvvvv─────┘
┌─── NeuralLayer 2 ────┐
│ Inputs = Outputs (1) │
│ Outputs (2) │
└─────vvvvvvvvvvvv─────┘
@SmallJoker
SmallJoker / init_22_ascii_biome.lua
Last active February 17, 2019 08:47
ASCII-Art in the terminal based on the biome information
-- Minetest Lua mod to have a rudimentary display of the biomes in your world
-- CC0, Written by Krock/SmallJoker 2019
-- Sample image: https://krock-works.uk.to/u/ethereal_cc57167_ASCII_map.png
local STEPSIZE = 32
local X_RADIUS = 1000
local Z_RADIUS = 1000
local CHARACTERS = {
"x", ".", "+", "@", "#",
"▨", "□", "■",
// g++ vectortest.cpp
/*
emplace_back: 553305 ticks
push_back: 665359 ticks
resize: 437487 ticks
*/
// g++ -O3 -ffast-math vectortest.cpp
/*
emplace_back: 165961 ticks
push_back: 165695 ticks