Skip to content

Instantly share code, notes, and snippets.

View shadeglare's full-sized avatar
👨‍💻
Pressing keys

Max Koverdyaev shadeglare

👨‍💻
Pressing keys
View GitHub Profile
@shadeglare
shadeglare / ApproachOne.cs
Last active February 21, 2021 14:12
Discriminating Unions
using System;
using System.Text.Json;
var inProgress = StatusFactory.InProgress();
var complete = StatusFactory.Complete("Expected data");
var failure = StatusFactory.Failure(404);
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
@shadeglare
shadeglare / UnionSerialization.cs
Last active February 28, 2025 11:59
Serialize and deserialize a generic union type with System.Text.Json
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Hexarc.Annotations;
namespace Hexarc.Union
const table = {
"а": "a", "А": "A",
"б": "b", "Б": "B",
"в": "v", "В": "V",
"г": "g", "Г": "G",
"д": "d", "Д": "D",
"е": "e", "Е": "E",
"ё": "e", "Ё": "Е",
"ж": "zh", "Ж": "Zh",
"з": "z", "З": "Z",
@shadeglare
shadeglare / webstoemp-gulpfile.js
Created February 23, 2020 09:54 — forked from jeromecoupe/webstoemp-gulpfile.js
Gulp 4 sample gulpfile.js. For a full explanation, have a look at https://www.webstoemp.com/blog/switching-to-gulp4/
"use strict";
// Load plugins
const autoprefixer = require("autoprefixer");
const browsersync = require("browser-sync").create();
const cp = require("child_process");
const cssnano = require("cssnano");
const del = require("del");
const eslint = require("gulp-eslint");
const gulp = require("gulp");
@shadeglare
shadeglare / DeserializeTaggedType.md
Last active May 12, 2022 10:10
Deserialize JavaScript/TypeScript tagged type (discriminated union) with C# and Newtonsoft.Json

TypeScript protocol for a JSON response object (from node.js backend for example):

interface Circle {
  type: "circle";
  radius: number;
}

interface Square {
  type: "square";
  size: number;
@shadeglare
shadeglare / splitString.ts
Created May 8, 2018 06:49
Split a string into chunks with the specified size
function splitString (value: string, chunkSize: number) {
let re = new RegExp('.{1,' + chunkSize + '}', 'g');
return value.match(re);
}
type Primitive = string | number | boolean;
module Iters {
export function* where<T>(
generator: () => IterableIterator<T>,
predicate: (value: T, index: number) => boolean
) {
let index = 0;
for (let item of generator()) {
if (predicate(item, index)) {
com.datastax.driver.core.exceptions.ReadFailureException: Cassandra failure during read query at consistency LOCAL_ONE (1 responses were required but only 0 replica responded, 2 failed)
at com.datastax.driver.core.exceptions.ReadFailureException.copy(ReadFailureException.java:95)
at com.datastax.driver.core.Responses$Error.asException(Responses.java:128)
at com.datastax.driver.core.DefaultResultSetFuture.onSet(DefaultResultSetFuture.java:179)
at com.datastax.driver.core.RequestHandler.setFinalResult(RequestHandler.java:184)
at com.datastax.driver.core.RequestHandler.access$2500(RequestHandler.java:43)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.setFinalResult(RequestHandler.java:798)
at com.datastax.driver.core.RequestHandler$SpeculativeExecution.onSet(RequestHandler.java:617)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:1005)
at com.datastax.driver.core.Connection$Dispatcher.channelRead0(Connection.java:928)
use TestDB
if object_id('tempdb..#ProductEmployee') is not null drop table #ProductEmployee
if object_id('tempdb..#Employee') is not null drop table #Employee
if object_id('tempdb..#Product') is not null drop table #Product
-- No PK/FK definitions for brevity
create table #Employee
(
ID int,
@shadeglare
shadeglare / CsvConverter.cs
Last active May 27, 2019 10:22
Simple csv serializer for c#
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Globalization;
using System.Collections.Generic;
namespace Shadeglare.Utils
{