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
{
@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);
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>
public class DisableMultipleQueuedItemsFilter : JobFilterAttribute, IClientFilter, IServerFilter
{
private static readonly TimeSpan LockTimeout = TimeSpan.FromSeconds(5);
private static readonly TimeSpan FingerprintTimeout = TimeSpan.FromHours(1);
public void OnCreating(CreatingContext filterContext)
{
if (!AddFingerprintIfNotExists(filterContext.Connection, filterContext.Job))
{
filterContext.Canceled = true;
@tuscen
tuscen / gist:86ac357434531e40acb7a8a57758663b
Created December 8, 2017 16:45 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@tuscen
tuscen / tap.md
Created September 23, 2017 02:01 — forked from ripesunflower/tap.md
The Task-based Asynchronous Pattern