Skip to content

Instantly share code, notes, and snippets.

View matthiesenj's full-sized avatar

Jesper Matthiesen matthiesenj

  • Denmark
View GitHub Profile
@matthiesenj
matthiesenj / luassert_luaunit_adapter.lua
Created June 26, 2024 15:22
Adapt luassert failure messages to luanit to avoid luaunit interpreting them as errors
-- execute dofile("luassert_luaunit_adapter.lua")
-- then execute dofile("file_with_your_tests.lua"
local luaunit = require("luaunit")
local astate = require("luassert.state")
local util = require("luassert.util")
---prepends LuaUnit FAILURE_PREFIX to luassert custom failure message
---in order to make LuaUnit pick up test failures as failures instead of errors.
local function prepender(state, arguments, level)
@matthiesenj
matthiesenj / gist:9b8c239ab467158a886f11776e512a95
Created November 22, 2023 12:20
Change logging level of Common.Logging.ILog logger backed by log4net logger, using reflection
// This is just an example - requires error checking
// Due to reflection, it is not necessary to reference the log4net assembly
var iLog = LogManager.GetLogger(typeof(TcpStreamFactory));
var field = iLog.GetType().GetField("_logger", BindingFlags.Instance | BindingFlags.NonPublic);
var log4netlog = field.GetValue(iLog);
var propLogger = log4netlog.GetType().GetProperty("Logger");
var logger = propLogger.GetValue(log4netlog);
var propLevel = logger.GetType().GetProperty("Level");
var origLevel = propLevel.GetValue(logger);
@matthiesenj
matthiesenj / gist:ebdee052d65815969506497d2a60380d
Last active January 16, 2020 15:00
Pause if bat/cmd script is run by double-clicking it in Windows Explorer
rem pause if run from windows explorer (match 'cmd.exe /c ""%~0"')
rem note that this is not bulletproof - other tools may use cmd /c <your file> to run your script!
echo %cmdcmdline%|find /i /c "cmd.exe /c """"%~0""" >nul && pause