Skip to content

Instantly share code, notes, and snippets.

View ntxinh's full-sized avatar
💭
❤️ .NET & JavaScript

Xinh Nguyen ntxinh

💭
❤️ .NET & JavaScript
View GitHub Profile
@ntxinh
ntxinh / FluentValidationAlternative.cs
Created January 8, 2024 09:42 — forked from olivier5741/FluentValidationAlternative.cs
An alternative library API to FluentValidation
namespace Validation.Tests
{
using System;
using System.Collections.Generic;
using Xunit;
public class User
{
public string Name { get; set; }
public int Age { get; set; }
using System;
using NodaTime;
namespace Sample
{
public class NodaDateTimeUtil
{
public static DateTime ConvertToUtcFromCustomTimeZone(string timezone, DateTime datetime)
{
var zone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(timezone);
@ntxinh
ntxinh / azure-pipelines-windows.yml
Last active January 15, 2021 04:50
.NET Azure Pipeline multiple stage
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- main
pool:
vmImage: 'windows-latest'
@ntxinh
ntxinh / azure-pipelines.yml
Last active January 15, 2021 08:27
Angular Azure Pipeline multiple stage
trigger: [dev, main]
pr: [dev, main]
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: build_dev
displayName: Build development
@ntxinh
ntxinh / HashingOptions.cs
Last active August 5, 2020 07:08
Storing Passwords in .NET Core
// Source: https://medium.com/dealeron-dev/storing-passwords-in-net-core-3de29a3da4d2
namespace Core.Services.Hash
{
public sealed class HashingOptions
{
public const string Hashing = "Hashing";
public int Iterations { get; set; } = 10000;
}
}
@ntxinh
ntxinh / CheckNull.cs
Last active June 21, 2020 14:41
parameter null validation
// https://dev.to/callmewhy/yo-yo-check-null-320m
// replace == null with is null because the == operator can be overloaded.
internal static class ThrowIf
{
public static class Argument
{
public static void IsNull<T>(T argument)
{
if (argument is null)
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Threading.Tasks;
namespace Infrastructure.Services
{
public class HttpClientService : IHttpClientService
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.ApplicationInsights;
namespace Infrastructure.Services
{
public class AppInsightService : IAppInsightService
{
private TelemetryClient _telemetry;
@ntxinh
ntxinh / gulpfile.js
Created February 5, 2020 07:31
SonarQube Scanner for npm
var gulp = require('gulp');
var minimist = require('minimist');
var sonarqubeScanner = require('sonarqube-scanner');
var knownOptions = {
string: 'projectVersion',
default: { projectVersion: '1.0' }
};
var options = minimist(process.argv.slice(2), knownOptions);
@ntxinh
ntxinh / unsaved-changes-guard.ts
Created October 3, 2019 04:41 — forked from Splaktar/unsaved-changes-guard.ts
Guard against navigating away when there are unsaved changes
import {CanDeactivate, Router} from '@angular/router';
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Observer} from 'rxjs/Observer';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
export interface CanComponentDeactivate {
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
}