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 / 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 / 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 / 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 / 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 / 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")]
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 / 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 (
@josheinstein
josheinstein / New-PSObject.ps1
Created October 9, 2012 15:37
I wish PowerShell object literals worked like this...
# PowerShell 3 adds the new [PSCustomObject] pseudo type attribute which
# lets you declare an object literal using a syntax very similar to that
# of an ordinary Hashtable. (There's also a new [Ordered] attribute that
# creates a hash table with the order of keys preserved.)
#
# But it only lets you declare an object literal with NoteProperties.
# What I would really love to have seen is the syntax look for script
# blocks and create ScriptProperties out of them if there is no param
# block or ScriptMethods out of them if there is a param block.
#
@josheinstein
josheinstein / index.html
Created March 5, 2013 18:24
A CodePen by Josh Einstein. Keyboard Navigation in Table Cells - Uses jQuery to enable arrow key functionality in tables. Pressing up/down/left/right in input fields will move focus to adjacent cells. Doesn't currently deal with column spans or custom input scenarios such as on-the-fly input fields.
<table id="people">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Phone Number</th>
<th>Location</th>
</thead>
<tbody>
<tr>
<td><input /></td>
@josheinstein
josheinstein / Disable-TemporaryRules.ps1
Last active December 16, 2015 01:30
Create temporary rules in Outlook by naming them with " (Until date)" or " (Until date time)" and then run this script at periodic intervals to disable those rules when they expire.
##############################################################################
#.SYNOPSIS
# Scans your Outlook rules (Outlook must be running) and disables any rules
# whose name matches a specific pattern such as:
# Move Stuff (Until 4/10/2013 5:00 PM)
# Ignore Stuff (Until 4/11/2013)
#
#.DESCRIPTION
#
# To create temporary rules in Outlook, just create rules as you would