Skip to content

Instantly share code, notes, and snippets.

View alexdresko's full-sized avatar
💭
I'm not a player, I just code a lot.

Alex Dresko alexdresko

💭
I'm not a player, I just code a lot.
View GitHub Profile
@alexdresko
alexdresko / Identity.cs
Created July 15, 2010 18:08
SharePointSiteAndWebHelper
namespace CSI.ESS.ServiceModel.Contracts
{
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;
/// <summary>
/// This class manages the creation of an impersonation to the Application
/// Pool's context for a defined scope.
@alexdresko
alexdresko / GetSublimeTextKeyBindings.vb
Created March 5, 2012 21:36
GetSublimeTextKeyBindingsFromVisualStudioKeyboardShortcuts
Sub GetSublimeTextKeyBindings()
Dim cmd As Command
Dim ow As OutputWindow = DTE.Windows.Item(Constants.vsWindowKindOutput).Object
Dim owp As OutputWindowPane
Dim exists As Boolean
Dim i As Integer
Dim sArray() As String
Dim dict As New System.Collections.Generic.Dictionary(Of String, String)()
@alexdresko
alexdresko / T4TS.tt
Last active February 25, 2017 22:56
T4 template to generate TypeScript interface definitions with BreezeJS support.
<#@ template language="C#" debug="true" hostspecific="true" #>
<#@ output extension=".d.ts" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="EnvDTE80" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="EnvDTE" #>
@alexdresko
alexdresko / gist:7358904
Created November 7, 2013 17:54
Pair for Eric Lippert
void Main()
{
var result = GetStatusMessage(40);
}
struct Pair<T, V>
{
public T Key;
public V Value;
}
// To use, just do something like :
// ViewBag.Stats = GetClicks(context);
private static List<Stats> GetClicks(AppContext context)
{
var result = new List<Stats>();
results.Add(GetStats(context, Period.Week))
results.Add(GetStats(context, Period.Month))
results.Add(GetStats(context, Period.Today))
@alexdresko
alexdresko / soundy.js
Created March 25, 2014 03:19
Greasemonkey/tampermonkey script that plays a sound whenever a matched page is finished loading.
// ==UserScript==
// @name Soundy
// @namespace http://www.alexdresko.com/
// @version 0.1
// @description Plays some kind of noise whenever a matched page finishes loading
// @match https://localhost:44300/*
// @match https://gist.github.com/*
// @copyright 2014+, Alex Dresko
// ==/UserScript==
var stringToCache = "tada!!!";
var absoluteExpirationForCache =
DateTime.Now.AddSeconds(10);
var yeResult = (string) MemoryCache.Default
.AddOrGetExisting
("AnyOleKey", stringToCache, absoluteExpirationForCache);
@alexdresko
alexdresko / AccountController Login POST action
Created July 31, 2014 10:51
Identity v2 Login with email confirmation and 2FA support
var user = await UserManager.FindByNameAsync(model.UserName);
if (user != null)
{
if (!await UserManager.IsEmailConfirmedAsync(user.Id)) return View(Mvc.Account.Views.ErrorNotConfirmed);
}
//var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: true);
var result = await SignInManager.SignInAsync(model.UserName, model.Password, model.RememberMe);
@alexdresko
alexdresko / gist:5b3075d12a9b5abebb4c
Last active August 29, 2015 14:04
Create POCO and CsvHelper map classes from pipe delimited file.linq
void Main()
{
var dir = @"C:\temp\OptumFtp\Root\Extracted\";
foreach (var file in Directory.GetFiles(dir, "*.txt"))
{
var header = File.ReadAllLines(file)[0];
var map = Regex.Replace(header, @"([^|]*).", @"Map(m => m.$1).Name(""$1"");
");
var properties = Regex.Replace(header, @"([^|]*).", @"public string $1 { get; set; }
");
@alexdresko
alexdresko / tfsonlinekeyboardshortcuts.user.js
Last active August 29, 2015 14:07
Additional TFS online keyboard shortcuts ala TamperMonkey/GreaseMonkey
// ==UserScript==
// @name TFS online shortcuts
// @author Alex Dresko
// @namespace http://www.alexdresko.com
// @version 0.5
// @description Some additional shortcuts for TFS online
// @match https://*.visualstudio.com/*
// @copyright 2014+, Alex Dresko
// @require 'http://code.jquery.com/jquery-1.11.1.min.js'
// @updateURL 'https://gist.githubusercontent.com/alexdresko/1ebd8ff2b1db2fe66c85/raw/tfsonlinekeyboardshortcuts.user.js'