Skip to content

Instantly share code, notes, and snippets.

View PathogenDavid's full-sized avatar
🪄
Math goes in, pixels come out!

David Maas PathogenDavid

🪄
Math goes in, pixels come out!
View GitHub Profile
@PathogenDavid
PathogenDavid / gist:bdd313ad49d1990059d2
Created May 31, 2014 11:56
A small playground showing that extension methods do not win over generics like they would if they were part of the extended class.
using System;
namespace ObservedSerialization
{
/// <summary>
/// Like SerializerMode
/// </summary>
enum ThingMode
{
SwapValues,
@PathogenDavid
PathogenDavid / Texture.cs
Created June 14, 2014 03:34
Texture.Download method
/// <summary>
/// Downloads this texture from the GPU.
/// </summary>
/// <returns>A bitmap representing this texture. You are responsible for disposing it.</returns>
public Bitmap Download()
{
Bitmap bitmap = null;
try
{
bitmap = new Bitmap(Width, Height);
@PathogenDavid
PathogenDavid / Oculus.cs
Last active August 29, 2015 14:03
Quick and dirty LibOVR test in C#
using System;
using System.Runtime.InteropServices;
namespace Protoscratch
{
static class Oculus
{
[DllImport("LibOVRDll64.dll", EntryPoint = "ovr_Initialize", CallingConvention=CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]//LibOVR uses 1 byte booleans
public static extern bool Initialize();
@PathogenDavid
PathogenDavid / main.cpp
Created July 10, 2014 16:11
WaitableTimerTest1
#include <Windows.h>
#include <stdio.h>
#include <assert.h>
#define NANOSECONDS_PER_SECOND ( 1000000000LL )
#define NANOSECONDS_PER_TIMER ( 100LL )
int main()
{
LARGE_INTEGER begin;
@PathogenDavid
PathogenDavid / main.cpp
Created July 10, 2014 16:14
WaitableTimerTest2
#include <Windows.h>
#include <stdio.h>
#include <assert.h>
#define NANOSECONDS_PER_SECOND ( 1000000000LL )
#define NANOSECONDS_PER_TIMER ( 100LL )
int main()
{
LARGE_INTEGER begin;
@PathogenDavid
PathogenDavid / main.cpp
Created July 13, 2014 02:36
EnumDisplayDevices
#include <Windows.h>
#include <stdio.h>
void PrintDisplayDevice(DISPLAY_DEVICEA* displayDevice, const char* indent = "")
{
printf("%sDeviceName: %s\n", indent, displayDevice->DeviceName);
printf("%sDeviceString: %s\n", indent, displayDevice->DeviceString);
printf("%sStateFlags:", indent);
if (displayDevice->StateFlags & DISPLAY_DEVICE_ACTIVE) { printf(" ACTIVE"); }
if (displayDevice->StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) { printf(" MIRRORING_DRIVER"); }
@PathogenDavid
PathogenDavid / output.txt
Created July 13, 2014 02:37
EnumDisplayDevices Output
======= Display Device 0 =======
DeviceName: \\.\DISPLAY1
DeviceString: AMD Radeon HD 7800 Series
StateFlags: ACTIVE
DeviceID: PCI\VEN_1002&DEV_6819&SUBSYS_E221174B&REV_00
Total display modes: 95
======= Display Device 0,0 =======
DeviceName: \\.\DISPLAY1\Monitor0
DeviceString: Generic PnP Monitor
StateFlags: ACTIVE
@PathogenDavid
PathogenDavid / systime.c
Created August 5, 2014 07:28
tsk_switch_handler
void tsk_switch_handler()
{
tm_current_slice--; //609
if (tm_current_slice == 0) //610
{
//Timeslice exhausted, switch to another thread as long as we can get access to the kernel critical section...
if (kernel_critical_section) //612, 613
{
//Thread is in kernel critical section, so we give the thread
//some extra time to leave it. (We can't do anything until it
@PathogenDavid
PathogenDavid / TupleSerializer.cs
Last active August 26, 2017 18:40
A partially-finished ValueTuple serializer for SharpYaml.
using SharpYaml;
using SharpYaml.Events;
using SharpYaml.Serialization;
using SharpYaml.Serialization.Descriptors;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization;
namespace YamlPlayground
@PathogenDavid
PathogenDavid / ModuleWeaver.cs
Last active April 10, 2018 10:08
Evil Fody weaver for force writing readonly fields with test program to be weaved by it.
using Fody;
using Mono.Cecil;
using Mono.Cecil.Cil;
using System.Collections.Generic;
using System.Linq;
namespace Evil.Fody
{
public class ModuleWeaver : BaseModuleWeaver
{