Skip to content

Instantly share code, notes, and snippets.

View ukcoderj's full-sized avatar

Justin ukcoderj

View GitHub Profile
@ukcoderj
ukcoderj / state-machine-page.component.html
Created April 26, 2021 11:05
Angular XState State Machine - Using Events
<h3>State Machine</h3>
<button (click)="moveBack()">Back</button>
<button (click)="moveNext()">Next</button>
<p>State: {{currentState}}</p>
@ukcoderj
ukcoderj / combobox-component.html
Last active May 20, 2021 13:58
Angular combobox (a box you can type in, or select an option from - not a typeahead!)
<div class="cbx-container">
<div class="input-group">
<!--combobox style view -->
<input class="form-control cbx-input" type="text"
autocomplete="off"
(click)="closeOptionsDialog()"
[(ngModel)]="state.displayValue"
(input)="onValueTypedChange($event.target.value)"
#inputBox="ngModel" />
<button type="button" class=" btn btn-outline-dark cbx-button"
// backup copy of https://github.com/denniske/ngx-translate-multi-http-loader
import {HttpClient} from "@angular/common/http";
import {TranslateLoader} from "@ngx-translate/core";
import {Observable, forkJoin, of} from "rxjs";
import {catchError, map} from "rxjs/operators";
import merge from 'deepmerge';
export interface ITranslationResource {
@ukcoderj
ukcoderj / delete-all-but-master.ps1
Created September 9, 2021 08:59
Delete All Branches Except Master Windows
#The command to delete all branches except master on linux is:
#git branch | grep -v "master" | xargs git branch -D
#To use the same command in Windows use powershell and CD to your repo
#Or, WINDOWS - we can use PowerShell command that do the same thing that above command do:
# Tried this and it worked nicely...
git branch | %{ $_.Trim() } | ?{ $_ -ne 'master' } | %{ git branch -D $_ }
#or WINDOWS -
#git branch -D @(git branch | select-string -NotMatch "master" | Foreach {$_.Line.Trim()})
@ukcoderj
ukcoderj / HttpClientApiCall.cs
Last active December 8, 2021 10:24
HttpClient API Call
public void SendData(string authToken, MyDataClass myData)
{
try
{
var url = $"https://www.something.com/api/something/post";
HttpClient client = new HttpClient();
//client.BaseAddress = new Uri(url);
// Add an Accept header for JSON format.
@ukcoderj
ukcoderj / CacheHelper.cs
Created March 29, 2022 08:49
Caching in .NET6+ Using IMemoryCache - Console Example
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Primitives;
using System;
namespace CacheTest
{
public class CacheHelper
{
private IMemoryCache _memoryCache { get; } = new MemoryCache(
@ukcoderj
ukcoderj / get-spid.ps1
Created April 8, 2022 09:31
Get Service Principle ObjectID from Azure
$webAppObjectId = (Get-AzADServicePrincipal -DisplayName $webAppName).Id
@ukcoderj
ukcoderj / api-with-problem.cs
Created May 3, 2022 12:49
Example API Problem Return
using Microsoft.AspNetCore.Mvc;
namespace TestForAPIM.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
@ukcoderj
ukcoderj / Akka-Net-Programs.cs
Created May 23, 2022 06:50
AKKA.NET - Very Basic Example with Tell and Ask
using Akka.Actor;
using AkkaHelloWorld;
Console.WriteLine("Enter a string to update the actor, or 'ask' to get its value");
var system = ActorSystem.Create("MySystem");
var greeter = system.ActorOf<SimpleMessageActor>("simplemsg");
greeter.Tell(new SimpleMessage("Starting"));
@ukcoderj
ukcoderj / app-insights-microservices-program.cs
Created October 7, 2022 10:27
App Insights Set Cloud Role Name - Multiple Microservices off one App Insights (one workspace too)
// 0. Create Application insights (workspace version - You could set up a 'log analytics workspace' first)
// 1. In web app, Nuget -> Microsoft.ApplicationInsights.AspNetCore
// 2. Config (can either pass in app insights key, or use whole connection string in config)
// 3. (if using connectionstring, appsettings.json looks like)
//"ApplicationInsights": {
// "ConnectionString": "InstrumentationKey=...;IngestionEndpoint=https://...-0.in.applicati...ights.azure.com/;LiveEndpoint=https://........livediagnostics.monitor.azure.com/"
// },