Skip to content

Instantly share code, notes, and snippets.

View josheinstein's full-sized avatar

Josh Einstein josheinstein

  • Einstein Technologies
  • USA
View GitHub Profile
@josheinstein
josheinstein / index_stats.sql
Last active July 18, 2019 20:03
Index Statistics (SQL)
USE CDR
GO
DECLARE @DatabaseName nvarchar(50) = 'CDR'
DECLARE @SchemaName nvarchar(50) = NULL
DECLARE @ObjectName nvarchar(50) = NULL
DECLARE @DatabaseID smallint = DB_ID(@DatabaseName)
SELECT *
FROM (
Set-Location ~\Dropbox\Work\Journal\201207
Import-CSV numbers.csv -Header From,To | %{
if ($_.From -match '^\d+$') {
[Int64]$From = $_.From
[Int64]$To = $(if ($_.To) { $_.To } else { $From })
[Int64]$i = $From
@josheinstein
josheinstein / New-Password.ps1
Created July 19, 2012 17:40
Simple PowerShell password generator
[CmdletBinding(DefaultParameterSetName='Normal')]
param(
[Parameter()]
[Int32]$Length = 8,
[Parameter(ParameterSetName="Complex")]
[Switch]$Complex,
[Parameter(ParameterSetName="Easy")]
@josheinstein
josheinstein / InstallClickOnceApp.cs
Created July 19, 2012 15:57
Install ClickOnce application programmatically (C#)
using System;
using System.Collections.Generic;
using System.Deployment.Application;
using System.Linq;
using System.Text;
using System.Threading;
namespace InstallClickOnceApp
{
@josheinstein
josheinstein / DisableDevExpressMapAnimation.cs
Created July 13, 2012 16:33
Disable DevExpress MapControl animation using reflection
/// <summary>
/// Uses reflection to disable the UseSprings dependency property which is read-only on map layers.
/// This will stop animations from occurring when the center point or zoom level of the map is changed.
/// </summary>
/// <param name="map">The map control to disable the animations for.</param>
/// <remarks>
/// Note that this method disables the UseSprings property in the layers currently added to the map. If
/// new layers are added, this method will need to be called again.
/// </remarks>
public static void DisableAnimation( this MapControl map )
@josheinstein
josheinstein / RemoveWhere.cs
Created July 11, 2012 20:12
RemoveWhere Extension Method
/// <summary>
/// Modifies a collection in-place by removing items from the collection that match
/// a given <see cref="T:Predicate[T]"/>.
/// </summary>
/// <remarks>
/// The type of collection passed in will affect how the method performs. For collections
/// with a built-in method to remove in-place (such as sets) the existing implementation
/// will be used. For collections implementing IList[T], the method will perform better
/// because the collection can be enumerated more efficiently. For all other collections,
/// the items to remove will be buffered and Remove will be called individually which,
@josheinstein
josheinstein / Utils.TryParseInt64.Test.sql
Created June 27, 2012 16:15
T-SQL Parse Int without fear of exception
-- these should not parse because of the string format
IF Utils.TryParseInt64(NULL) IS NOT NULL RAISERROR('Fail', 16, 1);
IF Utils.TryParseInt64('') IS NOT NULL RAISERROR('Fail', 16, 1);
IF Utils.TryParseInt64(' ') IS NOT NULL RAISERROR('Fail', 16, 1);
IF Utils.TryParseInt64(' ') IS NOT NULL RAISERROR('Fail', 16, 1);
IF Utils.TryParseInt64('.') IS NOT NULL RAISERROR('Fail', 16, 1);
IF Utils.TryParseInt64('0.0') IS NOT NULL RAISERROR('Fail', 16, 1);
IF Utils.TryParseInt64('0.') IS NOT NULL RAISERROR('Fail', 16, 1);
IF Utils.TryParseInt64('.0') IS NOT NULL RAISERROR('Fail', 16, 1);
IF Utils.TryParseInt64('1,000') IS NOT NULL RAISERROR('Fail', 16, 1);
@josheinstein
josheinstein / ObservableBase.cs
Created June 6, 2012 15:05
No-frills INPC base class in C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace Einstein
{
@josheinstein
josheinstein / DynamicNull.cs
Created May 25, 2012 18:50
Handling "null" values in a more dynamic fashion in C#
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Einstein.Dynamic
{
@josheinstein
josheinstein / SCoreShell.cs
Created May 21, 2012 15:28
SCoreShell - Windows Server Core PowerShell prompt at login with auto-logoff on exit
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
namespace SCoreShell
{
/// <summary>
/// This application's sole purpose in life is to sit in for the default "shell" on a