Skip to content

Instantly share code, notes, and snippets.

View sviataslau's full-sized avatar

Slava Seviaryn sviataslau

View GitHub Profile
@sviataslau
sviataslau / Resilience
Created March 19, 2021 14:57
Resilience
public async Task<ActionResult> BuyProductAsync(ProductPurchase purchase) {
Customer customer = await dbContext.Customers.FindAsync(purchase.CustomerId);
Order order = await orderService.CreateOrderAsync(customer, purchase);
Payment payment = await paymentService.PostPaymentAsync(order);
await emailService.SendEmailAsync(customer.Email, new Email("Payment was processed!"));
await bus.PublishAsync(new OrderCreatedEvent { Id = order.Id });
}
@sviataslau
sviataslau / Calculator.cs
Created January 30, 2013 07:02
Sample String Calculator TDD Kata 2 implementation. http://osherove.com/tdd-kata-2/ Based on Kata implementation from http://osherove.com/tdd-kata/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
namespace StringCalculator
{
public class Calculator : ICalculator
{
@sviataslau
sviataslau / info.plist
Created January 28, 2013 16:55
An extension for amazing Alfred.app to quickly download files using Axel (http://axel.alioth.debian.org)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>action</key>
<false/>
<key>category</key>
<string>SCRIPTS</string>
<key>command</key>
<string>#Desc: Downloads given link with axel
@sviataslau
sviataslau / Calculator.cs
Created January 28, 2013 06:19
Sample String Calculator TDD Kata implementation. http://osherove.com/tdd-kata-1/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace StringCalculator
{
public class Calculator
{
private static readonly Regex _inputParsingRegex = new Regex(@"(?<definition>//(?<delimiter>.+)\n).*");
@sviataslau
sviataslau / Expression.cs
Last active December 11, 2015 20:09
Often you need to display and sort data loaded from database using Entity Framework. In general the displayed data is a set of model/viewmodel objects that are not directly mapped to EF model. Such a trivial task! But in reality it is not so trivial if you're using EF. So this gist is about a way to provide generic sorting mechanism for such sit…
namespace Sorting
{
public static class Expression
{
public static Type GetExpressionReturningType(this LambdaExpression expression)
{
MemberInfo memberInfo = GetMemberInfo(expression);
if (memberInfo != null)
return GetMemberUnderlyingType(memberInfo);
@sviataslau
sviataslau / EnlargedTapButton.h
Last active December 11, 2015 19:38
iOS button with enlarged tap area.
#import <UIKit/UIKit.h>
@interface EnlargedTapButton : UIButton
@end