Skip to content

Instantly share code, notes, and snippets.

public static class ObjectExtend
{
public static dynamic Extend(this object source, params object[] objs)
{
var result = new ExpandoObject();
var props = (IDictionary<string, object>)result;
foreach (var o in new[] { source }.Union(objs))
{
var expandoProperties = (
const usingSorter = <T>(...selectors: ((t: T) => string | number)[]) => (a: T, b: T): -1 | 0 | 1 => {
for (const selector of selectors) {
const sa = selector(a)
const sb = selector(b)
if (sa < sb) return -1
if (sa > sb) return 1
}
return 0
}
@TheWorstProgrammerEver
TheWorstProgrammerEver / CreateSP_DropUnnamedDefaultConstraint.sql
Created April 18, 2018 23:33
SQL Stored Proc - Drop Unnamed Default Constraint
CREATE PROCEDURE DropUnnamedDefaultConstraint (@Table NVARCHAR(MAX), @Column NVARCHAR(MAX))
AS
BEGIN
DECLARE @Drop NVARCHAR(MAX) = (
SELECT TOP 1 'ALTER TABLE ' + @Table + ' DROP CONSTRAINT '+name
FROM sys.default_constraints A
JOIN sysconstraints B on A.parent_object_id = B.id
WHERE id = OBJECT_ID(@Table)
AND COL_NAME(id, colid) = @Column
AND OBJECTPROPERTY(constid, 'IsDefaultCnst') = 1
@TheWorstProgrammerEver
TheWorstProgrammerEver / Scanner.cs
Created February 6, 2017 22:09
Symantec Protection Engine - scan stream in chunks
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
//-------------------------------------------------------
// You'll need this thing from Symantec!
//-------------------------------------------------------
using com.symantec.scanengine.api;
@TheWorstProgrammerEver
TheWorstProgrammerEver / StorageAccountType.cs
Last active August 29, 2015 14:27
Create Azure storage accounts automatically. Mmm...
// Only here because the library doesn't provide an enum or anything.
public static class StorageAccountType
{
public readonly static string LocallyRedundant = "Standard_LRS";
public readonly static string GeographicallyRedundant = "Standard_GRS";
public readonly static string ReadAccessGeographicallyRedundant = "Standard_RAGRS";
public readonly static string ZoneRedundant = "Standard_ZRS";
}
var ClientSecret = "kSRsdf7rU323rf2ff2gfdssfdAnKI1mcOf98djfidIGx38="; // A key you add for your AAD app.
var ClientId = "17dfab36-1c33-4ffe-9ddd-533ddddfs378"; // The unique identifier for your AAD app..
var userObjectId = "12345667-1234-1234-1234-123412341234"; // LET'S SAY YOU WANNA GET A USER'S GROUPS... You'll need their ObjectId for querying later.
var authority = "https://login.microsoftonline.com/{tenant guid}/oauth2/authorize?api-version=1.0"; // This is the "OAuth Authorize" Endpoint for your AAD app.
var authContext = new AuthenticationContext(authority);
// Graph endpoint comes from Azure Portal "Graph Connection Endpoint"
var client = new ActiveDirectoryClient(new Uri("https://graph.windows.net/{tenant guid}"), () =>