Skip to content

Instantly share code, notes, and snippets.

View jakesays-old's full-sized avatar

Big Jake jakesays-old

View GitHub Profile
@jakesays-old
jakesays-old / EstimateSize.cs
Last active May 11, 2016 20:50
Estimate the size of a .net object
using System;
using System.Collections;
using System.Linq;
using System.Reflection;
namespace Std.Utility
{
public static class ObjectHelpers
{
/// <summary>
[100%] Built target cxx
Scanning dependencies of target check-libcxx
[100%] Running libcxx tests
lit.py: lit.cfg:42: note: Using configuration variant: libcxx
lit.py: config.py:652: note: inferred target_triple as: 'armv7l-unknown-linux-gnueabihf'
lit.py: config.py:208: note: inferred use_system_cxx_lib as: False
lit.py: config.py:219: note: inferred use_clang_verify as: True
lit.py: config.py:300: note: inferred language dialect as: c++1z
lit.py: target_info.py:66: warning: The locale fr_FR.UTF-8 is not supported by your platform. Some tests will be unsupported.
lit.py: target_info.py:66: warning: The locale ru_RU.UTF-8 is not supported by your platform. Some tests will be unsupported.
@jakesays-old
jakesays-old / thing.cs
Created March 1, 2016 22:44
c# traits thing
abstract class ArrayTrait
{
public abstract int Dimensions { get; }
}
class TwoDimensionalArrayTrait : ArrayTrait
{
public override int Dimensions { get; } => 2;
}
@jakesays-old
jakesays-old / Thing.cs
Last active December 17, 2015 23:23
DInv sample
public class Thing
{
public int Whatever{get;set;}
}
public interface IFoo
{
int DoSomething(int a, int b);
}
@jakesays-old
jakesays-old / DecToBinary.cs
Created December 10, 2015 00:53
DecToBinary
ulong x = 547978988;
ulong mask = 0x8000000000000000;
var sb = new StringBuilder();
var oneSeen = false;
while (mask > 0)
{
var bit = (x & mask) != 0;
if (!oneSeen && bit)
@jakesays-old
jakesays-old / DecToOctal.cs
Last active December 10, 2015 00:48
Octal converter
ulong x = 289;
char[] octalDigits = { '0', '1', '2', '3', '4', '5', '6', '7'};
var sb = new StringBuilder();
ulong digitIndex;
while (x > 0)
{
digitIndex = x % 8;
@jakesays-old
jakesays-old / MethodCallHeader.cs
Created November 4, 2015 18:28
Method Call Header
using System.Runtime.InteropServices;
namespace Std.ServiceFramework.Communication
{
[StructLayout(LayoutKind.Sequential)]
internal struct MethodCallHeader
{
public uint Version;
public MethodCallOptions Options;
public ulong InterfaceId;
@jakesays-old
jakesays-old / MessagePacketHeader.cs
Last active November 4, 2015 18:26
Packet Header
namespace Std.ServiceFramework.Communication
{
internal enum PacketSignature : uint
{
Valid = 0x42424242,
Failover = 0x43434343
}
[StructLayout(LayoutKind.Sequential)]
internal struct MessagePacketHeader
@jakesays-old
jakesays-old / ForwardingBinder.cs
Last active October 29, 2015 22:26
Simple lambda based forwarding binder
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Std
{
public class ForwardingBinder<TPropertyType> : INotifyPropertyChanged
{
private readonly Func<TPropertyType> _getter;
private readonly Action<TPropertyType> _setter;
@jakesays-old
jakesays-old / DictionaryBinder.cs
Last active October 29, 2015 22:17
Simple dictionary binder for wpf.
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Std
{
public class DictionaryBinder : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;