Skip to content

Instantly share code, notes, and snippets.

# based off the longer gist at https://gist.github.com/mwhite/6887990
[alias]
# one-line log
l = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
# staging
a = add
ac = !git add . && git commit -am
ap = add -p
@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",
@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 / 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();
# 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 / 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) {
@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 / 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 / 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 / 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";