Skip to content

Instantly share code, notes, and snippets.

View keith9820's full-sized avatar

Keith Harris keith9820

  • automotiveMastermind
  • San Francisco, CA
View GitHub Profile
@keith9820
keith9820 / eval.cs
Created March 23, 2017 22:46
C# dynamic evaluation
private static object Eval(string __code)
{
var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
var p = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, null, true);
p.GenerateInMemory = true;
p.GenerateExecutable = false;
CompilerResults r = csc.CompileAssemblyFromSource(p, "using System; class p {public static object c(){"+__code+"}}");
if (r.Errors.Count > 0)
{
r.Errors.Cast<CompilerError>().ToList().ForEach(error => Console.WriteLine(error.ErrorText));

Keybase proof

I hereby claim:

  • I am keith9820 on github.
  • I am keith9820 (https://keybase.io/keith9820) on keybase.
  • I have a public key whose fingerprint is B3FA 1E49 7F13 552D F7E9 6AAF 8EAE 8193 F573 7C3C

To claim this, I am signing this object:

@keith9820
keith9820 / closest match.linq
Created February 10, 2017 21:25
LINQ find closest numeric match in collection
var sought = 13;
int[] array = new int[5]{5,7,8,15,20};
array.OrderBy(a => Math.Abs(a - sought)).First().Dump();
CAST(CAST(year AS VARCHAR(4)) +RIGHT('0' + CAST(month AS VARCHAR(2)), 2) +RIGHT('0' + CAST(day AS VARCHAR(2)), 2) AS DATE)
CREATE FUNCTION [dbo].[ToBinary]
(
@Input int
)
RETURNS varchar(255)
AS
BEGIN
DECLARE @Output varchar(32) = ''
CREATE FUNCTION [dbo].[GetPart](@inputString AS VARCHAR(MAX), @index AS int, @delimiter AS CHAR(1) = '~') RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @ResultVar AS VARCHAR(MAX), @start INT, @end INT, @current INT
SELECT @start = 1, @end = CHARINDEX(@delimiter, @inputString), @current = 0
WHILE @start < LEN(@inputString) + 1
BEGIN
IF @end = 0
SET @end = LEN(@inputString) + 1
@keith9820
keith9820 / setup.md
Last active December 30, 2016 22:02
Register existing app to use Azure AD

To Configure Admin Panel for AD Integrated Security:

  • Set SSL = True
  • Install Nuget Packages:
    • Install-Package Microsoft.IdentityModel.Protocol.Extensions
    • Install-Package Microsoft.Owin.Security.OpenIdConnect
    • Install-Package Microsoft.Owin.Security.Cookies
    • Install-Package Microsoft.Owin.Host.SystemWeb
    • Install-Package System.IdentityModel.Tokens.Jwt
  • In web.config
@keith9820
keith9820 / FixOrphan.sql
Created October 17, 2016 21:16
Fix Sql Orphan User
ALTER USER devuser WITH LOGIN = devuser
@keith9820
keith9820 / repos.md
Last active September 16, 2016 20:44
Repo cleanup tasks

#Cleanup repo filesystem tasks

use git mv to move or rename indexed fies
use git rm xxx --cached to remove a file from the index but keep it in the filesystem

###Repos:

  1. WebJobs.DMSData (James)
  • move multiple projects into own repo
  • rename DMSData.WebJob/ as src/
@keith9820
keith9820 / ApplyVersionWithHashToAssemblies.ps1
Created September 8, 2016 23:13
Apply version number to assembly, with git commit hash & branch
# Work in progress, modified from:
##-----------------------------------------------------------------------
## <copyright file="ApplyVersionToAssemblies.ps1">(c) Microsoft Corporation. This source is subject to the Microsoft Permissive License. See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. All other rights reserved.</copyright>
##-----------------------------------------------------------------------
# Look for a 0.0.0.0 pattern in the build number.
# If found use it to version the assemblies.
#
# For example, if the 'Build number format' build process parameter
# $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
# then your build numbers come out like this: