Skip to content

Instantly share code, notes, and snippets.

View ming4883's full-sized avatar

Ka-ming Chan ming4883

  • Tencent Games
  • Hong Kong
View GitHub Profile
@ming4883
ming4883 / AutoRegister.cpp
Created March 2, 2019 06:03
C++ Auto Register
#include <iostream>
//int a = 0;
template <typename T, T /*unnamed*/>
struct nnb_ForceInit { };
template<
class T
>
#include <iostream>
template<typename Owner, typename MemType>
struct Attr {
typedef int Owner::*MemPtr;
MemPtr ptr;
Attr() {}
void Bind(MemPtr memptr) {
@ming4883
ming4883 / install_vboxsf.sh
Last active June 22, 2024 03:08
Alpine Virtual Box shared folder setup
apk update
apk add virtualbox-guest-additions virtualbox-guest-modules-virthardened
# auto load vboxsf kernel module
echo vboxsf > /etc/modules-load.d/vboxsf.conf
reboot
@ming4883
ming4883 / OrthoNormalize.h
Last active February 17, 2017 07:14
Unreal Engine 4 OrthoNormalize
struct FCustomUtils
{
static void OrthoNormalize(FVector& Normal, FVector& Tangent)
{
Normal = Normal.GetUnsafeNormal();
Tangent = Tangent - (Normal * FVector::DotProduct(Tangent, Normal));
Tangent = Tangent.GetUnsafeNormal();
}
}
@ming4883
ming4883 / SelectToBegining.ahk
Created November 9, 2015 10:24
mapping LCtrl + LShift as LShift + Home in AutoHotkey
LCtrl & LShift::
Send {RShift down}
Send {Home down}
Sleep 30
Send {Home up}
Send {RShift up}
@ming4883
ming4883 / FillArray.cpp
Created June 11, 2015 04:02
Fill a static c-array with loop unroll support
// view the assembly output in https://goo.gl/VEyRNK or https://gcc.godbolt.org/#
#include <iostream>
using namespace std;
struct Array
{
template<typename T, int N>
struct Elem
{
@ming4883
ming4883 / Invoke NDK build
Created May 13, 2015 12:00
Manual invoke ndk-build for each BuildType in Android Studio
def readLocalProp () {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
return properties
}
def invokeNDKBuild (debuggable, cleaning) {
def properties = readLocalProp()
def ndkDir = properties.getProperty('ndk.dir')
def osName = System.getProperty('os.name').toLowerCase()
@ming4883
ming4883 / gist:bde1b516e4c1a1df1a00
Created March 12, 2015 02:22
Native Code Debugging hotfix for Android 4.3 or above
For rooted devices running a custom recovery:
- reboot to recovery
- find the mount system and check it
- open a terminal and type: adb shell
- type: chmod 4750 /system/bin/run-as
- uncheck the System mount and reboot!
@ming4883
ming4883 / doNotOptimizeAway
Created August 12, 2014 04:28
Avoiding compiler optimization on a variable with minimum impact on performance
/*
Usage example:
int a = my_rand();
int b = my_rand();
int c = a + b;
doNotOptimizeAway (c);
*/
template<class T>
inline void doNotOptimizeAway (T&& x)
{
@ming4883
ming4883 / gist:8375b4a70522e80ab452
Created July 9, 2014 08:45
Where is the problem?
//
// extract from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
//
template<typename T>
struct AABB
{
Vec3<T> min;
Vec3<T> max;
bool intersect(const Ray<T> &r)