Skip to content

Instantly share code, notes, and snippets.

View jorimvanhove's full-sized avatar

Jorim Van Hove jorimvanhove

View GitHub Profile
@jorimvanhove
jorimvanhove / setFinalStatic.java
Created March 2, 2023 05:16
How to change a private static final int field from outside the class in java using reflection
/**
* Copied from <a href="https://stackoverflow.com/questions/2474017/using-reflection-to-change-static-final-file-separatorchar-for-unit-testing/2474242#2474242">Stack Overflow</a>
* Do exercise extreme caution with this technique.
* Devastating consequences aside, the following actually works:
* <pre>{@code
* setFinalStatic(Boolean.class.getField("FALSE"), true);
* System.out.format("Everything is %s", false); // "Everything is true"}</pre>
*/
static void setFinalStatic(Field field, Object newValue) throws Exception {
field.setAccessible(true);
@jorimvanhove
jorimvanhove / setup-git-hook-commit-msg.sh
Last active February 20, 2023 09:06
Git commit message validation setup script
#!/usr/bin/env bash
# regex to validate in commit msg
# https://regex101.com/r/VTEL5G/3
commit_regex='(Merge(.*)|([A-Z_]+-[0-9]+)|((\d+\.)?(\d+\.)?(\d+).(RELEASE|SNAPSHOT)))'
error_msg="Commit message must start with JIRA issue (eg. 'MME-xxx', 'INC-xxx'), 'x.x.x.RELEASE', 'x.x.x-SNAPSHOT' or 'Merge(d)'"
echo "#!/usr/bin/env bash
commit_regex='$commit_regex'
error_msg=\"$error_msg\"
if ! grep -qE \"\$commit_regex\" \"\$1\"; then
@jorimvanhove
jorimvanhove / CantorPairCalculator.cs
Last active February 20, 2023 09:08
Function that calculates a commutative cantor pair. The lowest input parameter is assigned to x, the highest to y.
// C# 10
namespace Helpers;
public static class CantorPairCalculator
{
/// <summary>Calculates the cantor pair of input parameters a & b
/// Commutative operation, the lowest input parameter is assigned to x, the highest to y
/// </summary>
/// <returns>Returns a cantor pair integer</returns>
public static int CalculateCommutativeCantorPair(this int a, int b)