Skip to content

Instantly share code, notes, and snippets.

Benjamin Todts btodts

  • Team4Talent
Block or report user

Report or block btodts

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Startup.cs
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
var exceptionHandlingFeature = context.Features.Get<IExceptionHandlerPathFeature>();
if (exceptionHandlingFeature?.Error is GuardException ex)
View GuardWithGuardException.cs
public static class Guard
{
public static void GuidNotEmpty(Guid argument, string argumentName)
{
if (argument == Guid.Empty)
throw new GuardException(argumentName, "Guid should not be empty.");
}
public static void StringNotNullOrEmpty(string argument, string argumentName)
{
View GuardException.cs
public sealed class GuardException : Exception
{
public string ArgumentName { get; }
public GuardException(string argumentName, string message)
: base(message)
{
ArgumentName = argumentName;
}
}
View Guard.cs
public static class Guard
{
public static void GuidNotEmpty(Guid argument, string argumentName)
{
if (argument == Guid.Empty)
throw new ArgumentException("Guid should not be empty.", argumentName);
}
public static void StringNotNullOrEmpty(string argument, string argumentName)
{
View GuardedController.cs
[HttpPost]
public async Task<IActionResult> Post(Guid id, string name)
{
Guard.GuidNotEmpty(id, nameof(id));
Guard.StringNotNullOrEmpty(name, nameof(name));
// handle the request
}
View AnimatedLoopCallback.js
animateWidth() {
Animated.sequence([
Animated.delay(3000),
Animated.timing(this.state.width, {
toValue: 400,
duration: 2000
})
]).start(() => {
// Logic whenever an iteration finishes...
this.animateWidth()
View AmimatedLoop.js
Animated.loop(
Animated.sequence([
Animated.delay(3000),
Animated.timing(this.state.width, {
toValue: 400,
duration: 2000
})
]),
{
iterations: 10
@btodts
btodts / ConfigurationModule.cs
Last active Aug 1, 2018
The autofac module that contains configuration
View ConfigurationModule.cs
using System.IO;
using System.Reflection;
using Autofac;
using Newtonsoft.Json;
using Foo.Configuration;
using Module = Autofac.Module;
namespace Foo.Modules
{
public class ConfigurationModule : Module
@btodts
btodts / Configuration.cs
Last active Sep 17, 2018
Configuration.cs
View Configuration.cs
namespace Foo.Configuration
{
public interface IConfiguration
{
string ApiBaseAddress { get; set; }
}
public class Configuration : IConfiguration
{
[JsonConstructor]
@btodts
btodts / Foo.csproj
Last active Aug 1, 2018
config.json as an Embedded Resource
View Foo.csproj
<ItemGroup>
<EmbeddedResource Include="Configuration\config.json" />
</ItemGroup>
You can’t perform that action at this time.