This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "sort" | |
| // This is not particularly efficient. | |
| // A more efficient implementation might either be B-Tree like, | |
| // might eliminate the index, might distinguish parents and leaves, | |
| // and might strip parents of their values; | |
| // to alleviate the mem management overhead, I'd wish | |
| // for an arena allocator, but this isn't Zig | |
| type PSlice[T any] struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env luajit | |
| -- See https://content.minetest.net/help/api/ | |
| local http_request = require"http.request" | |
| local lunajson = require"lunajson" | |
| do | |
| -- URI escaping utilities | |
| -- See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI | |
| local uri_unescaped_chars = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Rules for programs which must run under both LuaJIT and PUC Lua 5.1 | |
| # and which thus may not rely on the 5.2 LuaJIT compatibility features | |
| # See http://luajit.org/extensions.html | |
| rules: | |
| - id: xpcall-args | |
| pattern-either: | |
| # theoretically could be fine e.g. if (empty vararg!), but practically never is | |
| - pattern: xpcall($FN, $ERRHAND, $EXP, ...) | |
| # the following could also theoretically be fine, but practically are a major code smell | |
| - pattern: xpcall($FN1, $FN2(...)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local vars = {} | |
| for i = 1, 50 do table.insert(vars, ("v%d"):format(i)) end | |
| local all_vars, all_vals = table.concat(vars, ", "), "1" .. (", 2"):rep(#vars - 1) | |
| local pathological_code = ([[ | |
| local %s = %s | |
| return function(get_all) | |
| if get_all then return %s end | |
| return v1 | |
| end | |
| ]]):format(all_vars, all_vals, all_vars) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <unistd.h> | |
| #include <assert.h> | |
| int main(int argc, char** argv) { | |
| if (argc < 1) { | |
| printf("Arguments: <program> {args}\n"); | |
| return 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Solution to https://leetcode.com/problems/cheapest-flights-within-k-stops/description/ | |
| // probably not the intended solution; uses an abridged Dijkstra to solve the much more general problem | |
| // of finding all shortest paths to a given node using exactly k nodes | |
| package main | |
| import ( | |
| "math" | |
| "container/heap" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Lookup table for format strings | |
| local formats = {} | |
| for i = 1, 17 do | |
| formats[i] = ("%%.%dg"):format(i) | |
| end | |
| local function _number_to_string(num, min_digits, max_digits) | |
| if min_digits > max_digits then | |
| return | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --[[ | |
| Small, hacky Minetest utility to get rid of "unknown entities" as they are activated. Licensed under CC0. | |
| Caveat: `/spawnentity <name>` will fail with "<name> failed to spawn" rather than "Cannot spawn an unknown entity." | |
| for unknown entities as the unknown entity will immediately be removed inside `on_activate`. | |
| ]] | |
| setmetatable(minetest.registered_entities, { | |
| __index = function(_, name) | |
| -- Default entity def if `minetest.registered_entities[name]` would otherwise be `nil` | |
| -- Necessarily leads to `minetest.registered_entities[name]` being truthy for unknown entities as well |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local eye_pos = player:get_pos() | |
| eye_pos.y = eye_pos.y + player:get_properties().eye_height | |
| local first, third = player:get_eye_offset() | |
| if not vector.equals(first, third) then minetest.log("warning", "First & third person eye offsets don't match, assuming first person") end | |
| eye_pos = vector.add(eye_pos, vector.divide(first, 10)) | |
| local def = player:get_wielded_item():get_definition() | |
| for pointed_thing in minetest.raycast(eye_pos, vector.add(eye_pos, vector.multiply(player:get_look_dir(), def.range or 4)), true, def.liquids_pointable) do if pointed_thing.ref ~= player then --[[do something]] end end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Written by appgurueu, licensed under the MIT license | |
| local function patch_tile_texture(tex) | |
| if not (tex:match"^%[combine:" or tex:match"^%[inventorycube{") then | |
| return | |
| end | |
| -- Prevent Minetest 5.5 from prepending "blank.png^" for 5.4 and older clients which don't support [png | |
| -- See https://github.com/minetest/minetest/pull/12210 | |
| return "(" .. tex .. ")" | |
| end |