Skip to content

Instantly share code, notes, and snippets.

@rpbeukes
rpbeukes / NewtonsoftJsonFormatter.cs
Created May 6, 2024 00:33
NewtonsoftJsonFormatter.OrderedPropertiesAlphabeticallyAsc
public static class NewtonsoftJsonFormatter
{
public static object OrderedPropertiesAlphabeticallyAsc(dynamic dynamicJsonObj)
{
if (dynamicJsonObj is JObject jObj)
{
var sortedProperties = jObj.AsJEnumerable().OrderBy(x => x.Path).ToList();
var sortedObj = new JObject();
foreach (var item in sortedProperties)
@rpbeukes
rpbeukes / LocalNugetFolder.pubxml
Created August 5, 2022 02:22
Visual Studio Publish to local NuGet directory with a file suffix of local datetime.
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Configuration>Debug</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>..\..\..\..\NuGetLocal</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netstandard2.1</TargetFramework>
<VersionSuffix>$([System.DateTime]::Now.ToString("yyyyMMddHHmmss"))</VersionSuffix>
</PropertyGroup>
@rpbeukes
rpbeukes / EnumForEach.cs
Created June 23, 2022 04:40
Foreach over an Enum value
public class Enum<EnumT> where EnumT : Enum
{
public static void ForEach(Action<EnumT> action)
{
foreach (EnumT status in Enum.GetValues(typeof(EnumT)))
action(status);
}
}
@rpbeukes
rpbeukes / check_node_version.js
Last active October 1, 2021 08:09
Verify node version via npm package check-node-version
const {engines} = require('./package');
// https://github.com/parshap/check-node-version
const check = require('check-node-version');
const {execSync} = require('child_process');
check({node: engines.node}, async (error, result) => {
if (error) {
throw new Error(error);
}
@rpbeukes
rpbeukes / check_node_version.js
Last active October 1, 2021 08:13
Verify node version via npx.
const { exec } = require("child_process");
const {engines} = require('./package');
exec("npx check-node-version --package", (error, stdout) => {
const requiredNodeVersion = engines.node;
if (error) {
console.error(stdout);
exec("node --version", (error, stdout) => {
@rpbeukes
rpbeukes / EmailRedactor.cs
Last active July 13, 2021 00:25
Redact/Mask the email address eg: some@gmail.com => s**e@g****.com
/// <summary>
/// Redact/Mask the email address eg: some@gmail.com => s**e@g****.com
/// </summary>
public class EmailRedactor
{
/// <summary>
/// eg: "some@gmail.com" => "s**e@g****.com"
/// </summary>
/// <param name="email"></param>
/// <returns></returns>
@rpbeukes
rpbeukes / angular-reactive-forms-helper.ts
Last active August 1, 2020 19:03
Angular typesafe reactive forms
import { FormGroup, FormControl, FormBuilder, AbstractControl } from '@angular/forms';
export type FormGroupControlsOf<T> = {
[P in keyof T]: FormControl | FormGroup;
};
export abstract class FormGroupTypeSafe<T> extends FormGroup {
//give the value a custom type s
value: T;
public static class CSVHelperExtentions
{
public static string ToCSVString<T>(this IEnumerable<T> objectToConvert) where T : class
{
using (var memoryStream = new MemoryStream())
{
var config = new Configuration();
using (var streamWriter = new StreamWriter(memoryStream))
using (var csvWriter = new CsvWriter(streamWriter))
@rpbeukes
rpbeukes / create.cognito.test.user.js
Last active November 27, 2019 12:43
Create AWS Cognito test user
/*
node ./deployment-scripts/create.cognito.test.user.js dev ap-southeast-2_ISEDf22 admin@test.com password123456789
*/
const { region, environment, username, password, userPoolId } = readArguments();
const AWS = require('aws-sdk');
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider({ region: region });
if (environment === 'dev' || environment === 'test') {
testUser().create$(environment, username, password);
@rpbeukes
rpbeukes / reflection-nameof.ts
Last active November 27, 2019 12:44
nameof-typescript
export class Reflection {
constructor() {
}
//If you need more than just a property name eg: full type name try this - https://github.com/dsherret/ts-nameof#nameofto--
static nameOf<T>(propertyFunction: (typeVal: T) => any): string {
return /\.([^\.;]+);?\s*\}$/.exec(propertyFunction.toString())[1];
}
static nameOfClass<T>(classObject: Function): string {