Skip to content

Instantly share code, notes, and snippets.

View fakhrulhilal's full-sized avatar
🎯
Focusing

Fakhrulhilal M fakhrulhilal

🎯
Focusing
View GitHub Profile
@fakhrulhilal
fakhrulhilal / docker-compose.yml
Created August 18, 2023 03:13
A docker compose for running multiple services and joining into global private net
version: "3.9"
name: common-services
services:
dbserver:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: mssql
ports:
- "1433:1433"
networks:
@fakhrulhilal
fakhrulhilal / EndpointExtensions.cs
Last active July 5, 2023 00:59
Bind query/command from MediatR to ASP.NET core endpoint using monad
using System.Diagnostics.CodeAnalysis;
using MediatR;
using static StatusCodes;
// sample usages
app.MapCommand<RegisterCustomerDto, RegisterCustomer.Command>("customers", dto => new(dto.Name, dto.Email));
app.MapQuery<GetCustomerDetailDto, GetCustomerDetail.Query>("customers/{CustomerId:int}", dto => new(dto.CustomerId));
public class RegisterCustomerDto
{
@fakhrulhilal
fakhrulhilal / Result.cs
Last active July 5, 2023 00:48
C# monad class for handling outcome
public abstract record Result
{
#region Helper methods
public static Success Ok() => new();
public static Success.WithValue<T> Ok<T>(T value) => new(value);
public static Failure Fail(string reason) => new(Codes.Unprocessable, reason);
public static Failure Error(Exception exception) => new(Codes.Unknown, exception.Message);
public static Failure NotFound(string entity) => new(Codes.NotFound, $"{entity} is not found.");
public static Failure.Invalid Reject(IDictionary<string, string[]> errors) => new(errors);
@fakhrulhilal
fakhrulhilal / JwtSessionMiddleware.cs
Created June 13, 2023 08:52
ASP.NET core middleware to block JWT token containing blacklisted JTI
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.IdentityModel.Tokens;
/// <summary>
/// Reject JWT token containing blacklisted JTI. The JTI is registered into cache provider to be blacklisted,
@fakhrulhilal
fakhrulhilal / dotnet-nodejs.Dockerfile
Created January 16, 2023 08:30
Docker image for .NET with nodejs
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV ASPNETCORE_URLS "https://+,http://+"
ENV ASPNETCORE_HTTPS_PORT 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
ENV NODE_VERSION 18.x
@fakhrulhilal
fakhrulhilal / openssl.cnf
Last active July 22, 2021 12:38
OpenSSL config
#
# OpenSSL example configuration file.
# This is mostly being used for generation of certificate requests.
#
# Note that you can include other files from the main configuration
# file using the .include directive.
#.include filename
# This definition stops the following lines choking if HOME isn't
function ConvertTo-Mockaco {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[object]
$Har,
# Output path to Mockaco Mocks folder
[Parameter(Mandatory=$false)]
[string]
@fakhrulhilal
fakhrulhilal / GivenSemaphoreSlim.cs
Last active May 26, 2021 14:51
Unit test for semaphore slim for throttling asynchronous tasks
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace UnitTests
{
[TestFixture]
class GivenSemaphoreSlim
@fakhrulhilal
fakhrulhilal / CSGODedicatedServerManager.psm1
Created July 28, 2019 12:06
Manage CS GO dedicated server using RCON protocol
using namespace System.IO
using namespace System.Net
using namespace System.Net.Sockets
class RconClient {
hidden [Socket]$_socket
hidden [int]$_id = 1
RconClient([Socket]$socket) {
$this._socket = $socket
@fakhrulhilal
fakhrulhilal / lenovo-driver
Last active September 22, 2017 14:38
Get the driver list from lenovo. Useful for creating download list with download manager and generate file checksum
(function(d, w) {
var utility = {
trim: word => word.replace(/(^\s+|\s+$)/g, ''),
empty: word => !word || /^\s*$/.test(word),
createNode: (node, text) => {
let element = d.createElement(node);
if (text) element.innerText = text;
return element;
},
toArray: list => list instanceof Array ? list : Array.prototype.slice.call(list)