Skip to content

Instantly share code, notes, and snippets.

@battleguard
battleguard / gc_utils.py
Created December 1, 2023 14:48
Circular reference detection methods
def obj_from_id(obj_id: int):
# <https://stackoverflow.com/a/15702647>
return ctypes.cast(obj_id, ctypes.py_object).value
def print_referrers_tree(obj_id: int, level=0, prev_ids: set[int] | None = None) -> None:
if prev_ids is None:
prev_ids = set[int]()
if level > 20:
return
@battleguard
battleguard / main.cpp
Last active October 24, 2023 15:45
compile time conversion of global strings to snake case
#include <iostream>
#include <string>
#include <string_view>
#include "WsfPythonNaming.hpp"
void Foo()
{
}
struct FuncHolder
{
std::function<void(double)> mFunc;
};
py::class_<FuncHolder> funcHolder(aModule, "FuncHolder");
aModule.def("AddCallback", [](std::function<void(double)> func, py::list aHolder)
{
FuncHolder* holder = new FuncHolder{ func };
#include <iostream>
#define PYBIND11_HANDLE_REF_DEBUG
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
namespace py = pybind11;
using namespace pybind11::literals;
@battleguard
battleguard / astrobin_daily_scraper.py
Last active March 18, 2022 16:09
grabs the latest todays image off astrobin. Can be used with a daily service runner to auto populate a wallpaper folder over time.
from bs4 import Tag, BeautifulSoup
import requests
from pathlib import Path
def get_todays_page():
page = requests.get('https://www.astrobin.com/iotd/archive/')
soup = BeautifulSoup(page.content, 'html.parser')
image_html: Tag = soup.find('div', class_="iotd-archive-image")
@battleguard
battleguard / main.cpp
Created June 12, 2021 02:41
c wrapper multiple inheritance
#include <iostream>
struct AuxData
{
virtual ~AuxData() = default;
virtual void PrintAuxData()
{
std::cout << "AuxData a: " << a << " b: " << b << std::endl;
@battleguard
battleguard / ParseOutput.cmake
Last active December 12, 2019 14:57
utilizing cmake to print out cmake cache variables
cmake_minimum_required(VERSION 3.12)
function(print_list lines header)
message(STATUS "** ${header} ***")
foreach(line ${lines})
message(STATUS "\t" ${line})
endforeach()
message(STATUS "** End ${header} ***")
endfunction(print_list)
@battleguard
battleguard / ELK.conf
Last active June 25, 2018 19:42
Docker Compose for Elastic and Kibana
<Location /kibana/>
ProxyPass http://kibana:5601/
ProxyPassReverse http://kibana:5601/
</Location>
@battleguard
battleguard / docker-compose.yml
Last active June 21, 2018 14:08
Example usage of logspout routing docker logs to ELK
# Logspout portion of the ELK Demo locally
# Maintainer: Gary A. Stafford <garystafford@rochester.rr.com>
version: '3.1'
services:
elk:
image: garystafford/custom-elk:latest
ports:
- "5601:5601/tcp" # Kibana web interface
- "9200:9200/tcp" # Elasticsearch JSON interface
@battleguard
battleguard / DEBUG-CMakeCache.txt
Created April 13, 2018 20:43
CmakeCaches for osgearth vcpkg build
# This is the CMakeCache file.
# For build in directory: c:/Users/battl/OneDrive/Documents/Work/vcpkg/buildtrees/osgearth/x64-windows-dbg
# It was generated by CMake: C:/Program Files/CMake/bin/cmake.exe
# You can edit this file to change values found and used by cmake.
# If you do not want to change any of the values, simply exit the editor.
# If you do want to change a value, simply edit, save, and exit the editor.
# The syntax for the file is as follows:
# KEY:TYPE=VALUE
# KEY is the name of a variable in the cache.
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.