Skip to content

Instantly share code, notes, and snippets.

View mgjam's full-sized avatar

Milan Gatyás mgjam

View GitHub Profile
class EmailValidator
{
/* dependencies */
bool IsEmailValid(string email)
{
if ((email?.Length ?? 0) < 3) return false;
if (!Regex.IsMatch(email, myPattern)) return false;
if (myBlacklistService.IsEmailBlacklisted(email)) return false;
return true;
@mgjam
mgjam / kis-3.cs
Last active November 4, 2020 14:58
class MyService
{
private readonly ISerialCodeValidator serialCodeValidator;
private readonly IExternalIdService externalIdService;
private readonly IDataService dataService;
private readonly IReportingService reportingService;
MyResult Process(MyParams params)
{
if (!serialCodeValidator.IsSerialCodeValid(params.SerialCode)) return MyResult.InvalidSerialCode;
@mgjam
mgjam / kis-2.cs
Last active November 4, 2020 14:44
class MyService
{
/* ... dependencies ... */
MyResult Process(MyParams params)
{
if (!IsSerialCodeValid(params.SerialCode)) return MyResult.InvalidSerialCode;
var externalId = GetExternalId(params.SerialCode);
StoreData(params.SerialCode, externalId);
Report(params.SerialCode, externalId);
@mgjam
mgjam / kis-1.cs
Last active November 4, 2020 14:44
class MyService
{
/* ... dependencies ... */
MyResult Process(MyParams params)
{
if (!Regex.IsMatch(params.SerialCode, myPattern)) return MyResult.InvalidSerialCode;
var externalData = httpClient.Get<ExternalData>("...get external data from HTTP endpoint");
db
.Execute("...insert data into database...")
dashboard.addWidgets(invocationWidget);
dashboard.addWidgets(latencyWidget);
import { GraphWidget, IWidget, Metric } from "@aws-cdk/aws-cloudwatch";
import { Construct, Duration } from "@aws-cdk/core";
const latencyWidget = new GraphWidget({
width: 24,
title: 'API Latency',
left: [new Metric({
metricName: 'Latency',
namespace: 'AWS/ApiGateway',
dimensions: {'ApiName': 'apiName'},
import { GraphWidget, IWidget, Metric } from "@aws-cdk/aws-cloudwatch";
import { Construct, Duration } from "@aws-cdk/core";
const invocationWidget = new GraphWidget({
width: 24,
title: 'title',
left: [new Metric({
metricName: 'Count',
namespace: 'AWS/ApiGateway',
dimensions: {'ApiName': 'apiName'},
import { Dashboard } from "@aws-cdk/aws-cloudwatch";
const dashboard = new Dashboard(scope, 'id', {
dashboardName: 'name'
});
const fn = new Function(this, 'id', {
...,
logRetention: RetentionDays.ONE_WEEK,
...
});
class SubscriptionParams
{
User User;
BillingPeriod BillingPeriod;
PaymentMethod PaymentMethod;
}
interface ISubscriptionService
{
SubscriptionResult Subscribe(SubscriptionParams params);