Skip to content

Instantly share code, notes, and snippets.

View CheetahChrome's full-sized avatar

William Wegerson CheetahChrome

View GitHub Profile
@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 / 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)
{
@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 / 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 / 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 / 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
{