Skip to content

Instantly share code, notes, and snippets.

@MisterJames
MisterJames / AaaTestMethod.snippet
Last active December 9, 2020 22:38
This is a code snippet that you can invoke via tab completion. Type aaa and get a full test method with Arrange, Act, Assert parts, with encouragement to help name your test method following Roy Osherove's lead (http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html).
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>AAA Test Method</Title>
<Shortcut>aaa</Shortcut>
<Description>Code snippet for a test method with Arrange, Act, Assert</Description>
@MisterJames
MisterJames / Twitter.Bootstrap Icons
Last active January 4, 2016 22:15
All of the Glyphicons from Twitter.Bootstrap as strings in a c# constants class.
public static class Icons
{
public const string Glass = "icon-glass";
public const string Music = "icon-music";
public const string Search = "icon-search";
public const string Envelope = "icon-envelope";
public const string Heart = "icon-heart";
public const string Star = "icon-star";
public const string StarEmpty = "icon-star-empty";
public const string User = "icon-user";
@MisterJames
MisterJames / Building Hour and Minute Selections
Created March 13, 2013 01:28
An easy way to build out hour and minute select list items.
class Program
{
static void Main(string[] args)
{
IEnumerable<int> hours =
Enumerable.Range(0, 24);
IEnumerable<int> minutes =
Enumerable.Range(0, 2).Select(x => x * 30);
@MisterJames
MisterJames / Build a list of valid times
Created March 13, 2013 01:39
A condensed version of building a list of valid times for a user to select from.
List<string> times = new List<string>();
Enumerable.Range(0, 24).ToList()
.ForEach(hour => Enumerable.Range(0, 2).ToList()
.Select(x => string.Format("{0}:{1:00}", hour, x * 30))
.ToList()
.ForEach(timeslot=>times.Add(timeslot)));
@MisterJames
MisterJames / gist:5413118
Created April 18, 2013 14:24
Update a CouchDb document from c#.
private void PutDocument(string postUrl, string document)
{
byte[] data = new ASCIIEncoding().GetBytes(document);
var request = (HttpWebRequest)WebRequest.Create(postUrl);
request.Credentials = new NetworkCredential(_username, _password);
request.Method = "PUT";
request.ContentType = "text/json";
request.ContentLength = data.Length;
@MisterJames
MisterJames / stringDictionary.js
Last active December 24, 2015 05:09
A simple JavaScript function that gives you a way to maintain a unique list of strings, by a string key, similar in function to a c# dictionary<string, List<string>>.
"use strict";
$.stringDictionary = function () {
this.data = {};
// adds a unique value to the array stored in 'key'
this.add = function (key, value) {
var editors = this.data[key];
if (editors) {
# launch browser tabs
Start-Process "https://employer.harvestapp.com/time"
Start-Process "https://github.com/Client_Folder/"
Start-Process "https://app.box.com/files/0/f/0"
# launch VS solutions
Start-Process "C:\james\code\project name\src\solution.sln "
# start development apps
& C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\Ssms.exe
@MisterJames
MisterJames / CreatingGitHubAuthTicket.cs
Created April 26, 2016 12:53
CreatingGitHubAuthTicket
private static async Task CreatingGitHubAuthTicket(OAuthCreatingTicketContext context)
{
// Get the GitHub user
var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted);
response.EnsureSuccessStatusCode();
@MisterJames
MisterJames / AddClaims
Created April 26, 2016 12:55
AddClaims method for GitHub Auth
private static void AddClaims(OAuthCreatingTicketContext context, JObject user)
{
var identifier = user.Value<string>("id");
if (!string.IsNullOrEmpty(identifier))
{
context.Identity.AddClaim(new Claim(
ClaimTypes.NameIdentifier, identifier,
ClaimValueTypes.String, context.Options.ClaimsIssuer));
}
@MisterJames
MisterJames / GitHubOptions
Created April 26, 2016 13:23
GitHubOptions for Auth in ASP.NET Core
private OAuthOptions GitHubOptions =>
new OAuthOptions
{
AuthenticationScheme = "GitHub",
DisplayName = "GitHub",
ClientId = Configuration["GitHub:ClientId"],
ClientSecret = Configuration["GitHub:ClientSecret"],
CallbackPath = new PathString("/signin-github"),
AuthorizationEndpoint = "https://github.com/login/oauth/authorize",