Skip to content

Instantly share code, notes, and snippets.

@abdusco
abdusco / requirements.txt
Last active February 1, 2020 19:38
Convert TTML to SRT
bs4
lxml
@abdusco
abdusco / DbContextBase.cs
Created April 13, 2020 08:51
c# soft delete
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Scratch.Core.Shared;
namespace Scratch.Infrastructure.Data
{
public class DbContextBase : DbContext
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
namespace LinqDemo.Cli
{
class Person
{
public string Name { get; set; }
@abdusco
abdusco / cloudflaredns.py
Created February 20, 2021 10:03
Create Cloudflare DNS records with Python
import logging
from os import getenv
import httpx
logging.basicConfig(level=logging.DEBUG)
# go to https://dash.cloudflare.com/profile/api-tokens
# and create a token with Zone.DNS permissions
CLOUDFLARE_TOKEN = getenv('CLOUDFLARE_TOKEN')
@abdusco
abdusco / HostBuilderExtensions.cs
Last active March 12, 2021 12:52
Execute ConfigureServices without IWebHostBuilder
public static class HostBuilderExtensions
{
public static IHostBuilder UseStartup<TStartup>(this IHostBuilder hostBuilder)
where TStartup : class =>
hostBuilder.ConfigureServices((ctx, sc) =>
{
var startupType = typeof(TStartup);
var startupArgs = startupType
.GetConstructors().First()
.GetParameters()
@abdusco
abdusco / EfCustomIdGenerator.csproj
Created March 14, 2021 11:23
EF Core use custom Guid generator for ids
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.4" />
<PackageReference Include="NewId" Version="3.0.3" />
@abdusco
abdusco / LoginType.cs
Last active March 22, 2021 04:29
ASP.NET Core custom model binder
public sealed class LoginType
{
public string Name { get; set; }
public static ICollection<LoginType> All { get; set; } = new List<LoginType>();
public static LoginType Internal = new LoginType(nameof(Internal));
public static LoginType Customer = new LoginType(nameof(Customer));
public static LoginType Impersonation = new LoginType(nameof(Impersonation));
@abdusco
abdusco / JsonQuery.cs
Created March 30, 2021 18:32
ASP.NET Core json query string with Swagger support
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net.Http;
using System.Net.Mime;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
import dataclasses
import functools
import io
import pathlib
from datetime import timedelta, datetime
from io import FileIO
from typing import Callable
import httpx
@abdusco
abdusco / Startup.cs
Created May 4, 2021 08:40
SwashBuckle configuration for bearer tokens
services.AddSwaggerGen(c =>
{
// ...
c.AddSecurityDefinition("bearer", new OpenApiSecurityScheme
{
Description =
"Authenticate with an existing JWT token. **Prefix the token with `Bearer`, i.e. `Bearer eyJ...`**",
In = ParameterLocation.Header,
Name = HeaderNames.Authorization,