Skip to content

Instantly share code, notes, and snippets.

View alexgeek's full-sized avatar

Alexander Brook Perry alexgeek

View GitHub Profile
template<typename CallbackType>
struct callback_test final
{
callback_test(CallbackType&& callback)
: callback(std::forward<CallbackType>(callback))
{
}
template<typename... U>
@alexgeek
alexgeek / callback_streambuf.h
Created November 25, 2022 10:59
Hooks into any writes to the given ostream.
#include <functional>
#include <streambuf>
#include <iostream>
/**
* \brief Hooks into any writes to the given ostream.
* \tparam Duplicate If duplicate is true then it will pass through to the original stream.
*/
template<bool Duplicate>
class callback_streambuf final : public std::streambuf
// Add in a BP function library:
/**
* Create a transient render target. This version exposes bForceLinearGamma.
*/
UFUNCTION(BlueprintCallable, Category = "Liv", meta = (WorldContext = "WorldContextObject"))
static UTextureRenderTarget2D* CreateRenderTarget2D(
UObject* WorldContextObject,
int32 Width,
int32 Height,
@alexgeek
alexgeek / gist:18f7ff1cab07b7d70e38ecf72d088d1b
Created April 17, 2020 21:47
Plastic SCM Google Cloud Logging
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message%newline" />
</layout>
</appender>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="loader.log.txt" />
<appendToFile value="true" />
@alexgeek
alexgeek / LinkModel.py
Created September 5, 2019 19:57
Link model collection in another file
import bpy
import os
rig_file = bpy.data.filepath
model_file = rig_file.replace('.Rig.', '.Model.')
if not os.path.exists(model_file):
raise Exception("Model file does not exist.")
if bpy.data.collections['Model'] is not None:
@alexgeek
alexgeek / ParentMeshesToArmature.py
Last active October 29, 2023 22:55
Parent meshes in a collection to an armature in Blender
import bpy
scene = bpy.context.scene
def get_root_armature(collection):
for obj in collection.objects:
if obj.type == 'ARMATURE':
return obj
else:
return collection.objects['Root']
@alexgeek
alexgeek / SGenericStructList.h
Created August 24, 2017 14:59
UE4 Slate: Generic wrapper to show list of structs
#pragma once
#include "CoreMinimal.h"
#include "Layout/Margin.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/SCompoundWidget.h"
#include "Widgets/SNullWidget.h"
#include "Widgets/SWidget.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Text/STextBlock.h"
@alexgeek
alexgeek / header.h
Created March 11, 2015 17:46
C in C++ Boilerplate Header
#ifndef FOO_H
#define FOO_H
#ifdef __cplusplus
extern "C" {
#endif
int foo();
#ifdef __cplusplus
@alexgeek
alexgeek / reverse-string.c
Last active August 29, 2015 14:16
Reversing a String
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
inline void swap(char * str, int a, int b) {
char * tmp = str[a];
str[a] = str[b];
str[b] = tmp;
}
@alexgeek
alexgeek / test.sh
Created March 6, 2015 14:47
Bash Execution Timer
#!/bin/bash
die() { echo "$@" 1>&2 ; exit 1; }
[ $# -gt 2 ] && die "Max 2 arguments."
PROGRAM=$1
[ -z "$PROGRAM" ] && die "No arguments passed."
[ ! -f "$PROGRAM" ] && die "Program does not exist."
ITER=${2:-1000} # default 1000 iterations
echo "Executing $ITER tests on $PROGRAM."
for i in `seq 1 $ITER`; do