Skip to content

Instantly share code, notes, and snippets.

View chivandikwa's full-sized avatar
🏆
winning

Thulani Chivandikwa chivandikwa

🏆
winning
View GitHub Profile
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nodejs" version="14.17.3" />
<package id="dotnet-6.0-sdk" />
<package id="netfx-4.8-devpack" />
<package id="vscode" />
<package id="vscode-vsliveshare" />
<package id="vscode-codespellchecker" />
@chivandikwa
chivandikwa / decorator.py
Created May 29, 2020 12:04
Pycharm live templates
import functools
def $NAME$(func):
@functools.wraps(func)
async def _$NAME$(*args, **kwargs):
# optionally do something before
result = await func(*args, **kwargs)
# optionally do something after
return result
@chivandikwa
chivandikwa / decorator_pycharm.py
Created May 25, 2020 09:55
Python code snippets / template / live templates (raw, pycharm and vscode)
import functools
def $NAME$(func):
@functools.wraps(func)
async def _$NAME$(*args, **kwargs):
# optionally do something before
result = await func(*args, **kwargs)
# optionally do something after
return result
@chivandikwa
chivandikwa / CONTRIBUTING.md
Created May 25, 2020 09:24
Github templates

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
@chivandikwa
chivandikwa / AsyncClassContextManager.py
Last active March 22, 2020 12:14
Example implementations of context managers
import asyncio
from typing import Callable
class ScopedActions(object):
startup: Callable[[], None]
cleanup: Callable[[], None]
name: str
def __init__(self, name: str, startup: Callable[[], None], cleanup: Callable[[], None]):
@chivandikwa
chivandikwa / ValidatorExtension.cs
Created October 31, 2019 09:10
FluentValidation abosolute uri validator rule builder
using FluentValidation;
using System;
public static class ValidatorExtension
{
public static IRuleBuilderOptions<T, Uri> IsAbsoluteUri<T>(this IRuleBuilder<T, Uri> ruleBuilder) =>
ruleBuilder.Must(setting => setting != null && setting.IsAbsoluteUri)
.WithMessage("Setting must be an absolute URI");
}
@chivandikwa
chivandikwa / NullableDatePropertyConverter.cs
Last active October 31, 2019 09:08
DynamoDB nullable date property converter
using System;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
public class NullableDatePropertyConverter : IPropertyConverter
{
public DynamoDBEntry ToEntry(object value)
{
DynamoDBEntry entry = new Primitive {
@chivandikwa
chivandikwa / DynamoDBEnumPropertyConverter.cs
Last active October 31, 2019 09:08
DynamoDB enum property converter
using System;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
public class DynamoDBEnumPropertyConverter<TEnum> : IPropertyConverter
{
public object FromEntry(DynamoDBEntry entry)
{
var valueAsString = entry.AsString();
@chivandikwa
chivandikwa / EnumMapper.cs
Last active October 31, 2019 09:08
Enum to enum / string to enum mapper
using System;
public static class EnumMapper
{
public static TEnum MapToEnum<TEnum>(this Enum originalEnumValue, bool ignoreCase = true) where TEnum : struct, IConvertible
{
if (!typeof(TEnum).IsEnum)
{
throw new ArgumentException("TEnum must be an enumerated type");
}
@chivandikwa
chivandikwa / Result.cs
Last active October 15, 2019 10:22
Result class for use across boundaries
public enum ResultState : byte
{
Faulted,
Success
}
public struct Result<T>
{
internal readonly ResultState State;
private readonly T _content;