Skip to content

Instantly share code, notes, and snippets.

@gongdo
gongdo / Program.cs
Created April 10, 2020 07:00
Constructor mapping is not working for class but struct.
using AutoMapper;
using System.Diagnostics;
namespace ConstructorMappingTest
{
class Program
{
static void Main(string[] args)
{
var configuration = new MapperConfiguration(cfg =>
@gongdo
gongdo / Id.cs
Last active June 8, 2019 08:58
General purpose string id struct.
using System;
using System.Text.RegularExpressions;
namespace Alpaca
{
/// <summary>
/// Represents an identity of a domain object that must be unique in certain system.
/// An empty Id should be treated as invalid. You must check if the id was empty.
/// It can be treated as a string when it used to outside the system.
/// </summary>
@gongdo
gongdo / NullableTest.cs
Created June 6, 2019 08:26
Method return types: Non-nullable reference, nullable reference, struct and Nullable<struct>.
using System;
using System.Linq;
using Xunit;
namespace Something
{
public class NullableTest
{
public struct FooS
{
@gongdo
gongdo / LambdaVsLocalFunction.cs
Last active September 29, 2017 07:21
Lambda vs Local Function
using System;
namespace ConsoleApp6
{
public class LambdaVsLocalFunction
{
private int member = 42;
private int PlainLambda()
{
@gongdo
gongdo / BitCounter.cs
Last active July 6, 2017 04:44
BitCounter
// code from https://en.wikipedia.org/wiki/Hamming_weight
public static class BitCounter
{
/// <summary>
/// Count the number of bits set to 1 in a given value
/// </summary>
public static int BitCount(this int value)
{
return BitCount((UInt64)(value & UInt32.MaxValue));
}
/*
* This is an implementation of wcwidth() and wcswidth() (defined in
* IEEE Std 1002.1-2001) for Unicode.
*
* http://www.opengroup.org/onlinepubs/007904975/functions/wcwidth.html
* http://www.opengroup.org/onlinepubs/007904975/functions/wcswidth.html
*
* In fixed-width output devices, Latin characters all occupy a single
* "cell" position of equal width, whereas ideographic CJK characters
* occupy two such cells. Interoperability between terminal-line
@gongdo
gongdo / Startup.cs
Created March 24, 2017 02:37
ApplicationInsights behaviour test
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WebApplication2
{
public class Startup
{
@gongdo
gongdo / TaskExtensions.cs
Last active April 25, 2022 06:53
Task extensions for parallelism
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Gist
{
public static class TaskExtensions
{
@gongdo
gongdo / uniqueness.md
Last active December 9, 2016 04:08
Uniqueness
<?php
function replaceInterXmlWhiteSpace($xml) {
return preg_replace('/>\s*<\//', '></', $xml);
}
// 이메일의 예제
$replaced = replaceInterXmlWhiteSpace('</span></p><p><span style="font-size:13.3333px;"> </span></p><p><span style="font-size:13.3333px;">');
echo htmlspecialchars($replaced);
echo '<br />';