Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace="Common.Entities" assembly="Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns="urn:nhibernate-mapping-2.2">
<class name="DerivedClass2" lazy="false" table="DERIVED_CLASS_2">
<id name="Id" type="Int32">
<generator class="assigned" />
</id>
<property name="ClassProp1" />
<property name="ClassProp2" column="CLASS_PROP_2" />
<property name="BaseProp1" column="BASE_PROP_1" />
<property name="BaseProp2" column="BASE_PROP_2" />
@alfeg
alfeg / delegate.cs
Created January 30, 2022 14:56
Get object property by path with nesting
Func<T, object?>? CreateDelegate(string path)
{
var type = typeof(T);
var param = Expression.Parameter(type);
var parts = path.Split('.');
var prop = Expression.Property(param, parts[0]);
foreach (var part in parts.Skip(1))
{
@alfeg
alfeg / docker-compose.yml
Created September 28, 2020 09:27
SuSu sample
version: '3.8'
services:
hq:
image: 'surveysolutions/surveysolutions'
depends_on:
- "db"
environment:
ASPNETCORE_ENVIRONMENT: Production
HQ_ConnectionStrings__DefaultConnection: 'Persist Security Info=true;Server=db;Port=5432;User Id=postgres;Password=pg_password;Database=SurveySolutions'
HQ_Headquarters__BaseUrl: http://hq.lvh.me
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace WB.Core.GenericSubdomains.Portable
{
/// </remarks>
public class NamedLocker
{
@alfeg
alfeg / PartialFileContentResult.cs
Last active November 8, 2018 20:31
PartialFileContentResult to return 206 partial responses from MVC 5
public class PartialFileContentResult : ActionResult
{
private readonly Stream stream;
private readonly string contentType;
private readonly CancellationToken token;
/// <summary>Initializes a new instance of the <see cref="T:System.Web.Mvc.FileContentResult" /> class by using the specified file contents and content type.</summary>
/// <param name="fileContents">The byte array to send to the response.</param>
/// <param name="contentType">The content type to use for the response.</param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="fileContents" /> parameter is null.</exception>
@alfeg
alfeg / split.ps1
Created November 5, 2018 08:16
Split m4v video file at some point of time
param([string] $i, [string] $time, [string] $output)
ffmpeg -i $i -acodec copy -vcodec copy -to $time "$output-1.m4v"
ffmpeg -i $i -acodec copy -vcodec copy -ss $time "$output-2.m4v"
@alfeg
alfeg / Project.csproj
Last active September 5, 2018 11:04
MSBuild target file that handle Grpc.Tools generation, And example on how to include
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.6.1" />
<PackageReference Include="Grpc" Version="1.14.2" />
<PackageReference Include="Grpc.Tools" Version="1.14.2" />
</ItemGroup>
public class PerHostJsonConfigBuilder : ConfigurationBuilder
{
public string Directory { get; set; }
JObject hostConfig = null;
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
JObject LoadByHostName(string host)
@alfeg
alfeg / OneToManyAttribute.cs
Last active June 15, 2017 06:52
SqliteLiteExtensions.cs
public class OneToManyAttribute : RelationAttribute
{
public string ForeignKey { get; }
public OneToManyAttribute(string foreignKey)
{
this.ForeignKey = foreignKey;
}
public override void SetProperty(PropertyInfo info)
@alfeg
alfeg / Wrappers.cs
Created February 24, 2017 15:51
Jerbrain.profile wrappers
public class DotMemoryProfile : IDisposable
{
public DotMemoryProfile()
{
if (MemoryProfiler.IsActive && MemoryProfiler.CanControlAllocations)
MemoryProfiler.EnableAllocations();
MemoryProfiler.Dump();
}
public void Dispose()