Skip to content

Instantly share code, notes, and snippets.

View kmorcinek's full-sized avatar

Krzysztof Morcinek kmorcinek

View GitHub Profile
@kmorcinek
kmorcinek / bash.bashrc
Created April 24, 2017 16:00
bash.bashrc for git
alias noyp="cd C:/SRC/NameOfYourProject/" # noyp is example abbreviation from NameOfYourProject
alias blef="cd C:/Work/Github/Blef/"
alias brlocal="git br | grep local"
using Newtonsoft.Json;
using Xunit;
[Fact]
public void SerializationTest()
{
var money = Money.Create(1, "USD");
string json = JsonConvert.SerializeObject(money);
Money result = JsonConvert.DeserializeObject<Money>(json);
using System;
using System.Collections.Generic;
using System.Linq;
public static class CollectionExtensions
{
public static void RemoveAll<T>(this ICollection<T> @this, Func<T, bool> predicate)
{
List<T> list = @this as List<T>;
@kmorcinek
kmorcinek / .gitattributes
Last active May 5, 2017 17:58
Example .gitattributes file I use for C#/JS projects on Windows
# Auto detect text files and perform LF normalization: http://stackoverflow.com/questions/170961/whats-the-best-crlf-carriage-return-line-feed-handling-strategy-with-git/10855862#10855862
* text=auto
*.sql diff
*.ts diff
*.xml diff
using System;
using System.Diagnostics.CodeAnalysis;
public struct Option<T> : IEquatable<Option<T>>
{
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly Option<T> None = new Option<T>();
private readonly T _value;
private readonly bool _hasValue;
using System;
using System.ComponentModel;
using System.Diagnostics;
public static class EitherExtensions
{
[DebuggerStepThrough]
public static Either<TNew, TFailure> IfSuccess<TCurrent, TNew, TFailure>(this Either<TCurrent, TFailure> either, Func<TCurrent, Either<TNew, TFailure>> continuation)
{
if (!either.Succeeded)
using System;
using System.ComponentModel;
using System.Diagnostics;
public static class OptionExtensions
{
public static Either<TSuccess, TFailure> ToEither<TSuccess, TFailure>(this Option<TSuccess> option, TFailure failureValue)
{
if (option.HasValue)
return new Either<TSuccess, TFailure>(option.Value);
@kmorcinek
kmorcinek / NegativeLong
Last active September 21, 2015 19:24
Used for integration database tests, when we want to avoid Id clashes with current DB entities. It sets long value, but every time we retrieve it we get negative value.
/// <summary>
/// Class should be used only by AutoFixture. Used for integration database tests, when we want to avoid Id clashes with current DB entities.
/// It sets long value, but every time we retrieve it we get negative value.
/// <remarks>
/// Class should be used only by <see cref="Fixture"/>, either directly by Create() method or by <see cref="AutoDataAttribute"/>.
/// </remarks>
/// </summary>
/// <example>
/// This sample shows how to use the <see cref="NegativeLongId"/> class
/// <code>
@kmorcinek
kmorcinek / AutoMapperExtensions.cs
Last active April 7, 2016 21:17
AutoMapper convenient extensions for simple mapping
public static class AutoMapperExtensions
{
/// <summary>
/// Maps properties as ignored.
/// </summary>
public static IMappingExpression<TSource, TDestination> Ignore<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> map,
Expression<Func<TDestination, object>> selector)
{
map.ForMember(selector, config => config.Ignore());
public static class IQueryableExtensions
{
public static IOrderedQueryable<TSource> OrderBy<TSource, TKey>(
this IQueryable<TSource> source,
Expression<Func<TSource, TKey>> keySelector,
bool isAscending)
{
if (isAscending)
{
return source.OrderBy(keySelector);