Skip to content

Instantly share code, notes, and snippets.

View sgissinger's full-sized avatar

Sebastien Gissinger sgissinger

View GitHub Profile
@sgissinger
sgissinger / CustomAttributeContractResolver.cs
Last active October 22, 2018 22:31
Json ContractResolver using custom attribute
public class CustomAttributeContractResolver<T> : DefaultContractResolver
where T : Attribute
{
private static List<string> typeOnePropertiesToSerialize = new List<string>();
private static List<string> typeTwoPropertiesToSerialize = new List<string>();
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
var properties = base.CreateProperties(type, memberSerialization).ToList();
@sgissinger
sgissinger / IFilterable.cs
Last active October 25, 2018 15:56
Dynamic Linq
public interface IFilterable
{
string ColumnName { get; }
string Operator { get; }
string Value { get; }
}
@sgissinger
sgissinger / MCD.puml
Created November 8, 2018 23:01
PlantUML with customizations
@startuml
!define table(x) class x << (T,#FFAAAA) >>
!define view(x) class x << (V,#33CCFF) >>
!define pk(x) +<u>x</u>
!define fk(x,y) ~x <i>references y</i>
!define pkfk(x,y) -<u>x</u> <i>references y</i>
hide methods
hide stereotypes
skinparam shadowing false
@sgissinger
sgissinger / GetFileAsBase64.js
Created December 5, 2018 17:30
Retrieve a file content as Base64 string
/**
*
* @param blob
*/
function getBase64(blob: Blob): Promise<string> {
return new Promise<string>((resolve, reject) => {
let reader = new FileReader();
reader.onloadend = function() {
let dataUrl = reader.result as string;
let base64 = dataUrl.split(',')[1];
@sgissinger
sgissinger / DynamicLinq.cs
Created January 24, 2019 10:54
DynamicLinq
public static IQueryable<T> OrderBy<T>(this IEnumerable<T> source, IEnumerable<ISortable> sortables, IEnumerable<string> persistentColumnNames)
{
return source.AsQueryable().OrderBy(sortables, persistentColumnNames);
}
public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, IEnumerable<ISortable> sortables, IEnumerable<string> persistentColumnNames)
{
if (source == null)
throw new ArgumentNullException("source");
@sgissinger
sgissinger / Group_By_XML_Path.sql
Created January 24, 2019 16:07
Group by XML PATH
with partitioned_data as
(
select dossier, dos from (
select dossier, ntile(50) over(order by dossier) as dos from [dbo].[input_legacy_excel]
) x
)
Select P.dos, SUBSTRING(STUFF(
@sgissinger
sgissinger / recursive_cte.sql
Created February 25, 2019 15:11
Recursive CTE
DECLARE @str varchar(100) = '1721,1603,1063,1683,2049'
DECLARE @delimiter varchar(10) = ','
;
WITH mycte AS
(
SELECT 0 a, 1 b
UNION ALL