Skip to content

Instantly share code, notes, and snippets.

View SmallJoker's full-sized avatar

SmallJoker

View GitHub Profile
@SmallJoker
SmallJoker / xdg-grep.sh
Created December 30, 2024 19:14
grep + xdg-open to open files based on text contents from your terminal
#!/usr/bin/env bash
# "xdg-grep" script for $HOME/.local/bin/
set -e
if [ -z "$1" ]; then
echo "Missing keyword"
exit 0
fi
@SmallJoker
SmallJoker / autonullptr.cpp
Created October 7, 2024 18:37
Re-inventing std::weak_ptr
#include <set>
#include <stdexcept> // std::runtime_error
#include <stdio.h>
#define DO_ERROR() do { throw std::runtime_error("fault"); } while(0)
class PtrAutoNullOMatic {
public:
PtrAutoNullOMatic() = default;
~PtrAutoNullOMatic()
@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 October 4, 2024 15:41
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─────┘