Skip to content

Instantly share code, notes, and snippets.

View ghstahl's full-sized avatar
💭
coding always coding

Herb Stahl ghstahl

💭
coding always coding
  • Santa Monica, CA
View GitHub Profile
@ghstahl
ghstahl / gist:2a556a98f5cb91eee797
Last active August 29, 2015 14:14
My First Boxstarter Script
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions
Enable-RemoteDesktop
cinst sublimetext2
cinst dotpeek
@ghstahl
ghstahl / TryWithAwaitInCatch.cs
Last active October 24, 2022 08:41
A try/catch wrapper for C# async functions up to lucky 7 argument.
using System;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
namespace AsynWrapper
{
public class TryWithAwaitInCatchExcpetionHandleResult<TResult>
{
public bool RethrowException { get; set; }
public TResult DefaultResult { get; set; }
@ghstahl
ghstahl / UsersController.cs
Last active July 4, 2016 23:53
ASP.NET MVC WebApi2 Controller showing async in that proxys async to another REST endpoint
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Newtonsoft.Json;
@ghstahl
ghstahl / IdentityTokenHelper.cs
Created October 13, 2016 17:30
JWT Identity Helper
public static class IdentityTokenHelper
{
public const string WellKnown_VerifyAccountEmailAction = "b3d17698-011b-4a74-aa0d-1301e01bbb8f";
public const string WellKnown_NortonAction = "norton::action";
public const string ValidIssuer = "Norton";
public static ClaimsPrincipal ValidateJWT(string tokenString,TokenValidationParameters tokenValidationParameters, out SecurityToken validatedToken)
{
var tokenHandler = new JwtSecurityTokenHandler();
var principal = tokenHandler.ValidateToken(tokenString, tokenValidationParameters, out validatedToken);
@ghstahl
ghstahl / simple-table.tag
Last active October 20, 2016 17:51
RiotJs simple-table Tag
<simple-table>
<table class="highlight">
<thead>
<tr>
<h5>{title}</h5>
<th each={ name, i in cols }>{name}</th>
</tr>
</thead>
<tbody>
@ghstahl
ghstahl / Program.cs
Created November 12, 2016 20:31
GeoLite2 console app that fetches the GeoLite2 DB, decompresses it, and looks up an IP
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.IO.Compression;
using System.Threading;
using MaxMind.GeoIP2;
@ghstahl
ghstahl / GraphQLStarWarsExtension
Created December 23, 2016 19:32
Autofac registration for the GraphQL StarWars types
// https://github.com/graphql-dotnet/graphql-dotnet
public static class GraphQLStarWarsExtension
{
public static void RegisterGraphQLTypes(this ContainerBuilder builder)
{
builder.RegisterInstance(new DocumentExecuter()).As<IDocumentExecuter>();
builder.RegisterInstance(new DocumentWriter()).As<IDocumentWriter>();
builder.RegisterInstance(new StarWarsData()).As<StarWarsData>();
@ghstahl
ghstahl / PublicRefreshTokenExtensionGrantValidator
Created March 1, 2017 16:12
IdentityServer4 Extension Grant that lets me refresh another clients token.
public class PublicRefreshTokenExtensionGrantValidator : IExtensionGrantValidator
{
internal class ResultDto
{
public string access_token { get; set; }
public int expires_in { get; set; }
public string token_type { get; set; }
public string refresh_token { get; set; }
}
using System.Dynamic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Hello
{
public static class ExpandoObjectExtensions
{
public static ExpandoObject Clone(this ExpandoObject original)
{
@ghstahl
ghstahl / gremlin-queries.txt
Created January 27, 2019 16:44
gremlin simple queries
1. Add
g.addV('template').property('id', '061430dc-a267-4140-964d-a046470c9273').property('category','cat1').property('version','1.0.0')
g.addV('cct').property('id', '762d3cc4-2447-46d3-aa6d-ad3bc17444b6').property('category','cctCat1').property('version','1.0.0')
g.addV('colp').property('id', '067a6bb2-19da-4d6c-af46-b66473b04c35').property('category','colpCat1').property('version','1.0.0')
2. Find by id
g.V('061430dc-a267-4140-964d-a046470c9273')
3. add a new property