Skip to content

Instantly share code, notes, and snippets.

View dasjestyr's full-sized avatar

Nunja dasjestyr

  • Scottsdale, AZ
View GitHub Profile
@dasjestyr
dasjestyr / build-docker.ps1
Last active December 20, 2018 20:19
[netcore build scripts] Build scripts used to play well with build servers, primarily Bitbucket pipelines
#!/usr/bin/pwsh
Param(
[parameter(Mandatory, HelpMessage = "The name of the project that will be dockerized. Dockerfile must be in that directory")]
[Alias("Project")][String] $project_name,
[parameter(Mandatory, HelpMessage = "The image name that will be used to tag the image.")]
[Alias("Name")][String] $image_name,
[parameter(Mandatory, HelpMessage = "The tag that will be used to tag the image.")]
[Alias("Tag")][String] $image_tag,
[parameter(Mandatory, HelpMessage = "MyGet pre-auth'd URL")]
@dasjestyr
dasjestyr / kong_gke.md
Last active November 21, 2018 22:13
Setting up simple service routing via Kong in GKE

Setup

  1. Install Kong to Kubernetes cluster via Marketplace
    • It installs a few pods: Proxy, Admin, and Postgres

Administration

Administration is done via CLI but don't expose the admin service to the internet. Instead, you need to tunnel into the admin pod:

Problem

Because the backend system is asynchronous over a message bus (NSB with RMQ), it is difficult to receive feedback on whether or not something has succeeded.

Sample scenario

  • Client UI issues a command to the API "Create new user".

In a traditional synchronous system, the client would make the request and then wait until it got a response before continuing. All steps to create a user would be completed before responding to the request with a 201 Created . In the asynchronous system, the commands are accepted from the client and then dropped on the bus and the server replies with a 202 Accepted. If there are any failures down the line, the UI does not know.

Typically, the standard solution for this is for the edge client to send the message and then immediately subscribe to response queue where it waits for the system to give it feedback. Alternatively, a popular solution is to have the server communicate this information over WebSocket which is what I am trying to do.

@dasjestyr
dasjestyr / Identity Management.md
Last active October 14, 2018 20:11
.Net Core Auth/Identity

Creating a custom Identity Provider (without using EF)

A few interfaces need to be implemented:

  • IUserStore<TUserType>
  • IRoleStore<TRoleType>

TUserType and TRoleType are custom classes that represent a user or a role. There are other interfaces that can be implemented which also implement one of the interfaces above. For example IUserRoleStore or IUserPasswordStore which both also implement IUserStore. Use them in combination to obtain more customization, for example if you want to override how roles get stored against the user.

Once those are implemented, you need to enable identity and also set the user and role store implementations:

@dasjestyr
dasjestyr / dialing_code.js
Last active August 31, 2017 00:22
Country code tree
// https://en.wikipedia.org/wiki/List_of_country_calling_codes
{
"zones": {
"1": {
"code": "",
"description": "North American Numbering Plan"
},
"2": {
"0": {
"code": "EG",
@dasjestyr
dasjestyr / new-dev.sh
Last active August 27, 2017 00:20
Install Ubuntu .Net development environment
# GATHER KEYS AND REPOS
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg;
mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg;
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-zesty-prod zesty main" > /etc/apt/sources.list.d/dotnetdev.list';
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg;
mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg;
sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list';
@dasjestyr
dasjestyr / shortguid_test.cs
Created July 31, 2017 17:34
ShortGuid Test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApp7.CSharpVitamins;
namespace ConsoleApp7
{
class Program
@dasjestyr
dasjestyr / Replication.cs
Created May 11, 2017 21:42
EventStore replication
public class EventReplicationService
{
private readonly string _sourceName;
private readonly string _destinationName;
private readonly IEventStoreConnection _sourceConnection;
private readonly IEventStoreConnection _destinationConnection;
private readonly MongoRepository<ReplicationIndexCache> _mongoRepository;
private EventStoreAllCatchUpSubscription _subscription;
internal EventReplicationService(
@dasjestyr
dasjestyr / DelimitedFieldLexer.cs
Last active May 5, 2017 21:17
A lexer that will pull fields from a delimited line of text
internal class DelimitedFieldLexer : IFieldLexer
{
private const int NoData = -1;
private const int Delimiter = -2;
private const int Initialized = -3;
private const int EndOfLine = 0x0A;
private const int WindowsEndOfLine = 0x0D;
private const int Quote = 0x22;
private const LexingState BreakCondition = LexingState.NoData | LexingState.EndOfLine |LexingState.StartingNextField;
public class TryParseFactory
{
public delegate bool TryParseDelegate<T>(string s, out T result);
private readonly Dictionary<Type, Delegate> _tryParsers = new Dictionary<Type, Delegate>();
public TryParseFactory()
{
Register<Guid>(Guid.TryParse);
Register<int>(int.TryParse);