Skip to content

Instantly share code, notes, and snippets.

Avatar
🧙
Doing some Elixir wizardry

Thiago Majesk Goulart thiagomajesk

🧙
Doing some Elixir wizardry
View GitHub Profile
@thiagomajesk
thiagomajesk / benchmark.exs
Last active Jul 7, 2020
XML parsing benchmark
View benchmark.exs
# Dependencies: {:saxy, "~> 1.2"}, {:sax_map, "~> 0.2"}, {:benchee, "~> 1.0"}
#
# Samples
#
simple = """
<?xml version="1.0"?>
<?xml-stylesheet href="catalog.xsl" type="text/xsl"?>
<catalog>
@thiagomajesk
thiagomajesk / application.ts
Last active Jul 3, 2019
Knockout & Typescript & Webpack bootstrap code
View application.ts
// Component definition (holds information about template and view model)
class ClickCounterComponent extends Component {
constructor(name: string, viewModel: ViewModelClass) {
super(name, viewModel, template)
}
}
// Actual view model (This separation allows us to reuse view models for components)
class ClickCounterViewModel extends ViewModel {
public count: ko.Observable<number> = ko.observable<number>(0);
@thiagomajesk
thiagomajesk / AutoFacModule.cs
Last active Jan 7, 2021
Generic Handlers & Commands for MediatR (+ AutoFac config)
View AutoFacModule.cs
public class GenericHandlersModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<CreateCommandHandler<Foo, CreateFooCommand>>().As<IRequestHandler<CreateFooCommand, bool>>();
builder.RegisterType<DeleteCommandHandler<Foo, DeleteFooCommand>>().As<IRequestHandler<DeleteFooCommand, bool>>();
builder.RegisterType<ListQueryHandler<Foo, ListFooQuery>>().As<IRequestHandler<ListFooQuery, IEnumerable<Foo>>>();
builder.RegisterType<UpdateCommandHandler<Foo, UpdateFooCommand>>().As<IRequestHandler<UpdateFooCommand, bool>>();
}
}
@thiagomajesk
thiagomajesk / AutoMapperModule.cs
Created Jan 25, 2018
AutoMapper configuration for AutoFac
View AutoMapperModule.cs
public class AutoMapperModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register(c => new MapperConfiguration(config => { config.AddProfiles(GetType().Assembly); })).AsSelf().SingleInstance();
builder.Register(c => c.Resolve<MapperConfiguration>().CreateMapper(c.Resolve)).As<IMapper>().InstancePerLifetimeScope();
}
}
@thiagomajesk
thiagomajesk / ModelStateHelper.cs
Created Sep 30, 2017
ASP.NET Core PRG TempData Helpers
View ModelStateHelper.cs
public class ModelStateTransferValue
{
public string Key { get; set; }
public string AttemptedValue { get; set; }
public object RawValue { get; set; }
public ICollection<string> ErrorMessages { get; set; } = new List<string>();
}
public static class ModelStateHelper
{
@thiagomajesk
thiagomajesk / brunch-config.js
Last active Aug 8, 2017
ASP.NET Core Brunch Config (Babel + Bootstrap 4 + LESS + Font Awesome)
View brunch-config.js
module.exports = {
paths: {
public: "wwwroot",
watched: ["wwwroot/javascripts", "wwwroot/stylesheets"]
},
npm: {
styles: {
"bootstrap": ["dist/css/bootstrap.css"],
"font-awesome": ["css/font-awesome.css"],
"animate.css": ["animate.css"]
View IServiceCollectionExtensions.cs
public static class IServiceCollectionExtensions
{
public static IServiceCollection ConnectImplementations<TService>(this IServiceCollection services, Assembly assembly)where TService : class
{
return services.ConnectImplementations(typeof (TService), assembly);
}
public static IServiceCollection ConnectImplementations(this IServiceCollection services, Type serviceType, Assembly assembly)
{
if (!serviceType.IsInterface) throw new ArgumentException($"{nameof(serviceType)} must be an interface");
@thiagomajesk
thiagomajesk / CharacterController.cs
Last active May 26, 2017
ViewModelFactory (Mediator Pattern)
View CharacterController.cs
public class CharacterController : Controller
{
/*[...]*/
public IActionResult Profile(int id)
{
/*[...]*/
var viewModel = viewFactory.Build<int, CharacterProfileViewModelBuilder>(id);
return View(viewModel);
}
}
@thiagomajesk
thiagomajesk / Controller.cs
Created Feb 11, 2017
View Model Factories in ASP.NET Core with Mediator + IoC Extension
View Controller.cs
public class FooController : Controller
{
private readonly IViewFactory viewFactory;
public FooController(IViewFactory viewFactory) { this.viewFactory = viewFactory; }
public IActionResult Index()
{
var viewModel = viewFactory.Create<CreateFooViewModel>();