Skip to content

Instantly share code, notes, and snippets.

View CheetahChrome's full-sized avatar

William Wegerson CheetahChrome

View GitHub Profile
@CheetahChrome
CheetahChrome / Program.cs
Created November 25, 2011 17:05
Regex Vs Xml
using System;
using System.Linq;
using System.IO;
using System.Xml;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace RegexVsXml
{
@CheetahChrome
CheetahChrome / Extension.cs
Created December 1, 2011 14:08
Extension String - Date Validation
public static bool ValidDate( this string date )
{
bool valid = false;
DateTime targetDate;
if (valid = DateTime.TryParse( date, out targetDate ))
valid = (targetDate >= new DateTime( 1753, 1, 1 )) &&
(targetDate <= new DateTime( 9999, 12, 31 ));
return valid;
@CheetahChrome
CheetahChrome / StackOverflow.xsd
Created December 12, 2011 17:23
Constraint or Restriction on xsi:type
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="EventBase">
<xs:annotation>
<xs:documentation>***Abstract***</xs:documentation>
</xs:annotation>
<xs:attribute name="Name"/>
</xs:complexType>
<xs:element name="Event" type="EventBase">
<xs:annotation><xs:documentation>A generic event derived from abstract.</xs:documentation></xs:annotation>
@CheetahChrome
CheetahChrome / ReadTableExtractColumnInfoForDeclareStatement.SQL
Last active July 8, 2018 23:54
SQL Server: Read Target Table and create a Declare statement usable in a stored procedure
SELECT
COLUMN_NAME,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
concat('DECLARE @', COLUMN_NAME, N' ', DATA_TYPE,
IIF(CHARACTER_MAXIMUM_LENGTH IS not null
, CONCAT(N' (', CHARACTER_MAXIMUM_LENGTH, N')')
, N''
)
) AS [declare]
@CheetahChrome
CheetahChrome / SQLExtension.cs
Created February 10, 2019 21:13
A SQL Extension to read JSON generated from SQL Server in C#
public static class SQLExtensions
{
/// <summary>
/// Microsoft doesn't handle JSON well, it wants to use XML methods which then retrieve
/// the JSON. Sometimes the JSON has characters in it which
/// </summary>
public static SqlJSONReader ExecuteJsonReader(this SqlCommand cmd)
{
var rdr = cmd.ExecuteReader();
return new SqlJSONReader(rdr);
@CheetahChrome
CheetahChrome / NotifiedProperty.snippet
Created June 27, 2019 18:04
Visual Studio Snippet to Work on a VM to add a Notified Property
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>NotifiedProperty</Title>
<Author>William Wegerson</Author>
<Description>Same as the propfull snippet except it adds OnPropertyChanged to the setter.
@CheetahChrome
CheetahChrome / People.cs
Created February 14, 2020 00:59
ItemsControl which has the content control
public class People : List<Person> { }
public class Person
{
public string First { get; set; }
public string Last { get; set; }
public string Phone { get; set; }
}
public class OperationCommand : ICommand
{
#region Variables
private Func<object, bool> CanExecuteHandler { get; set; }
private Action<object> ExecuteActionHandler { get; set; }
public bool InSeparateThread { get; set; }
#endregion
@CheetahChrome
CheetahChrome / ChasingCircles.Xaml
Last active February 12, 2021 04:14
Chasing Circles Xaml Vector Example
<Window.Resources>
<!--Vector Image Attribution: https://materialdesignicons.com/-->
<Path x:Key="ChasingCircles" Data="M12,6V9L16,5L12,1V4A8,8 0 0,0 4,12C4,13.57 4.46,15.03 5.24,16.26L6.7,14.8C6.25,13.97 6,13 6,12A6,6 0 0,1 12,6M18.76,7.74L17.3,9.2C17.74,10.04 18,11 18,12A6,6 0 0,1 12,18V15L8,19L12,23V20A8,8 0 0,0 20,12C20,10.43 19.54,8.97 18.76,7.74Z" />
<Style x:Key="ChasingCircleStyle"
TargetType="{x:Type Path}">
<Setter Property="Stretch"
Value="Uniform" />
<Setter Property="Data"
Value="{Binding Data, Source={StaticResource ChasingCircles}}" />
</Style>
@CheetahChrome
CheetahChrome / GetSelectedFileInExplorerAddToClipboard.cs
Last active October 15, 2021 22:35
Get Selected file in Explorer and Put it on the Clipboard in C#
// Add reference Com -> `Microsoft Shell Controls` and `Microsoft Internet Controls`
// and System.Windows & PresentationCore for Clipboard
foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows())
{
var filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
if (filename.ToLowerInvariant() == "explorer")
{
Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
foreach (Shell32.FolderItem item in items)
{