Skip to content

Instantly share code, notes, and snippets.

View SmallJoker's full-sized avatar
:octocat:
Absent

SmallJoker

:octocat:
Absent
View GitHub Profile
@SmallJoker
SmallJoker / itemdrop_whatever_again.lua
Created May 19, 2014 18:11
An other item drop thingie
-- collect items (based on PilzAdam's item_drop mod)
local ttime = 0
minetest.register_globalstep(function(dtime)
ttime = ttime + dtime
if ttime < 1 then return end
ttime = 0
for _,player in ipairs(minetest.get_connected_players()) do
if player:get_hp() > 0 and not player:get_player_control().LMB then
@SmallJoker
SmallJoker / Data_RW.cs
Last active October 3, 2015 13:48
Code to serialize and deserialize a world
/*
Code to serialize and deserialize a world
Copyright (C) 2015 Krock/SmallJoker <mk939@ymail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
@SmallJoker
SmallJoker / MT-replace-deprecated.sh
Last active March 9, 2022 00:54
Minetest - Replace deprecated function calls
#!/bin/bash
# License: CC0
# How to use:
# 1) Open the terminal in the target mod directory
# 2) Call the script
files=$(find . -name "*.lua")
ref_call()
@SmallJoker
SmallJoker / network_sqrt_log2.cpp
Last active July 25, 2018 18:39
Test script to measure different methods of eoncoding and decoding floats over the network
#include <cmath>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <chrono>
#include <cassert>
typedef uint8_t u8;
typedef int8_t s8;
Values below show absolute/relative times spend per server step by the instrumented function.
A total of 8885 samples were taken
instrumentation | min µs | max µs | avg µs | min % | max % | avg %
-------------------------------------------------------- | --------- | --------- | --------- | ----- | ----- | ------
mesecons: | 1 | 161770 | 86 | 0.0 | 99.1 | 3.3
- globalstep[1] ..................................... | 1 | 161768 | 84 | 0.0 | 99.0 | 2.5
- on_placenode[1] ................................... | 17 | 25 | 21 | 2.5 | 6.3 | 4.8
- on_dignode[1] ..................................... | 13 | 49 | 21 | 0.6 | 10.3 | 6.2
// 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
@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", ".", "+", "@", "#",
"", "", "",
@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 / 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
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