Skip to content

Instantly share code, notes, and snippets.

@treytomes
treytomes / Window.xaml
Created January 14, 2016 14:20
WPF UserControl with a nice looking title line.
<UserControl x:Class="OS.NET.Widgets.Window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="24" />
<RowDefinition />
</Grid.RowDefinitions>
@treytomes
treytomes / ExtendedASCIIConsole.cs
Created January 18, 2016 19:22
Dump the Extended ASCII character set to the console window using DllImport.
using System;
using System.Runtime.InteropServices;
namespace ConsoleTest
{
class Program
{
public const int STD_OUTPUT_HANDLE = -11;
public struct COORD
@treytomes
treytomes / EventLogger.cs
Created February 1, 2016 14:54
Example of how to write to the Windows Event Log.
using System.Diagnostics;
using System.Reflection;
public class EventLogger
{
#region Constants
private const string DEFAULT_TYPE = "Application";
#endregion
@treytomes
treytomes / Application.xaml
Created February 2, 2016 15:18
MvvmLight for VB.NET
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MyMvvmApplication.ViewModel"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d1p1:Ignorable="d"
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006"
StartupUri="MainWindow.xaml">
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
@treytomes
treytomes / PagingControls.xaml
Created February 22, 2016 14:39
Using Path elements to create paging controls.
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Command="{Binding GotoFirstPageCommand}" Margin="4" Padding="2" ToolTip="Go to the first page.">
<Button.Content>
<Path HorizontalAlignment="Center" Stroke="Black" StrokeThickness="1" StrokeLineJoin="Round" Fill="Green" Data="M 0,0 L 2,0 2,8 0,8 Z M 2,4 L 8,8 8,0 Z" />
</Button.Content>
</Button>
<Button Command="{Binding GotoPreviousPageCommand}" Margin="4" Padding="2" ToolTip="Go to the previous page.">
<Button.Content>
<Path HorizontalAlignment="Center" Stroke="Black" StrokeThickness="1" StrokeLineJoin="Round" Fill="Green" Data="M 0,4 L 8,8 8,0 Z" />
</Button.Content>
@treytomes
treytomes / InverseBooleanConverter.vb
Created February 29, 2016 16:55
Make the Xceed WPF Toolkit SplitButton control look correct on a toolbar.
Imports System.Globalization
Namespace Utility
Public Class InverseBooleanConverter
Implements IValueConverter
Public Function Convert(pValue As Object, pTargetType As Type, pParameter As Object, pCulture As CultureInfo) As Object Implements IValueConverter.Convert
Return Not DirectCast(pValue, Boolean)
End Function
@treytomes
treytomes / FileSystemHelper.vb
Created March 3, 2016 16:29
List directories and check if a directory is empty using Kernel32 calls.
Imports System.IO
Imports System.Runtime.InteropServices
''' <remarks>
''' I don't think this is actually faster than the .NET Directory functions.
''' </remarks>
Public Class FileSystemHelper
Private Shared ReadOnly conInvalidHandleValue As IntPtr = New IntPtr(-1)
<Flags>
@treytomes
treytomes / StructureMapServiceLocator.vb
Created June 2, 2016 14:56
This VB.NET class will provide the glue between the StructureMap IOC library and Microsoft's CommonServiceLocator.
Imports Microsoft.Practices.ServiceLocation
Imports StructureMap
Public Class StructureMapServiceLocator
Inherits ServiceLocatorImplBase
Private _Container As IContainer
Public Sub New(pContainer As IContainer)
_Container = pContainer
@treytomes
treytomes / color.lua
Created February 14, 2017 15:22
Convert to and from html colors, rgb <-->hsl colors, and darken html colors by a percentage.
-- Convert an html color in the format of #RRGGBB into red, green, and blue values on the range of [0..255].
local function hex_to_rgb(html_color)
html_color = html_color:gsub("#", "")
return tonumber("0x"..html_color:sub(1, 2)), tonumber("0x"..html_color:sub(3, 4)), tonumber("0x"..html_color:sub(5, 6))
end
-- Convert the red, green, and blue color components back into an html color string.
local function rgb_to_hex(red, green, blue)
return string.format("#%02X%02X%02X", red, green, blue)
using System;
using System.Linq;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class PerfectOverride
{
public int referenceOrthographicSize;