Skip to content

Instantly share code, notes, and snippets.

View tuscen's full-sized avatar
🐼

Aleksey Usatov tuscen

🐼
View GitHub Profile
@tuscen
tuscen / DiscriminatedJsonConverter.cs
Created June 27, 2021 12:40 — forked from sliekens/DiscriminatedJsonConverter.cs
Configurable JsonConverter for deserializing discriminated JSON
using System;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Infrastructure
{
public sealed class DiscriminatedJsonConverter : JsonConverter
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
public class CommandParser
{
private Regex _regex;
public CommandParser(
@tuscen
tuscen / gist:beae355611f28d50f0da5ee80121e936
Created July 14, 2018 23:43 — forked from rodrigokono/gist:2907855
IQueryable Dynamic Expressions
public static class QueryableExtensions
{
public static IQueryable<T> Filter<T>(this IQueryable<T> queryable, IEnumerable<KeyValuePair<string, string>> filters) where T : class
{
foreach (var filter in filters)
{
var propertyName = typeof(T).GetProperties().Select(x => x.Name).SingleOrDefault(x => x.ToLower() == filter.Key.ToLower());
if (propertyName.IsNullOrWhiteSpace()) continue;
var parameterExpression = Expression.Parameter(typeof(T));
var propertyExpression = Expression.Property(parameterExpression, propertyName);
@tuscen
tuscen / bot.js
Created June 9, 2018 10:33
In-browser Telegram bot
import { HttpPoller } from './httpPoller.js';
function last(array) {
return array[array.length - 1];
}
const token = "BOT_TOKEN";
const url = `https://api.telegram.org/bot${token}/getUpdates`;
const poller = new HttpPoller(url, "POST");
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
namespace MihaZupan
{
/// <summary>
/// A simple request scheduler to help you conform to rate limiting
/// </summary>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace MihaZupan
{
// Block the caller of WaitOne as long as necesarry
public class RequestScheduler
@tuscen
tuscen / <Custom>DbContext.cs
Created April 23, 2018 01:51 — forked from werwolfby/<Custom>DbContext.cs
EF Core DateTime Utc kind
public class CustomDbContext : DbContext
{
// ...
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
// Replace default materializer source to custom, to convert DateTimes
options.ReplaceService<IEntityMaterializerSource, DateTimeKindEntityMaterializerSource>();
base.OnConfiguring(options);
@tuscen
tuscen / Ansible Let's Encrypt Nginx setup
Created April 9, 2018 23:48 — forked from mattiaslundberg/Ansible Let's Encrypt Nginx setup
Let's Encrypt Nginx setup with Ansible
Ansible playbook to setup HTTPS using Let's encrypt on nginx.
The Ansible playbook installs everything needed to serve static files from a nginx server over HTTPS.
The server pass A rating on [SSL Labs](https://www.ssllabs.com/).
To use:
1. Install [Ansible](https://www.ansible.com/)
2. Setup an Ubuntu 16.04 server accessible over ssh
3. Create `/etc/ansible/hosts` according to template below and change example.com to your domain
4. Copy the rest of the files to an empty directory (`playbook.yml` in the root of that folder and the rest in the `templates` subfolder)
@tuscen
tuscen / MutexAttribute.cs
Created February 5, 2018 17:22 — forked from odinserj/MutexAttribute.cs
MutexAttribute.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Hangfire.Common;
using Hangfire.States;
using Hangfire.Storage;
namespace Hangfire.Pro
{
/// <summary>
using System;
using System.Text;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
public class MarkdownEntitiesTransformer
{
public string Transform(string message, MessageEntity[] entities)
{
var currentEntityIndex = 0;