This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Constant do | |
@moduledoc """ | |
Allows generating dynamic functions for the given list of values. | |
Accepts an enumerable with the of keys and values to be generated as functions. | |
""" | |
defmacro __using__(constants) do | |
[define_constants(constants), define_helpers()] | |
end | |
defp define_constants(constants) when is_list(constants) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (!) This is a first-effort/ naive script to find unused CSS in HTML files. | |
# This should (hopefully) work as the opposite of what you get from PURGE CSS. | |
# Configure the variables bellow and execute the file with `elixir purge_html_css.exs`. | |
# Configures the default location to look for the outputed CSS. | |
# Ideally this file should not be transformed to preserve new lines. | |
outputed_css = "priv/static/css/app.css" | |
# Configures the default pattern to look for files that may contain CSS to purge. | |
# Currently inculdes .eex and .heex files. Change this if necessary. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Resets a input to a value when a form is updated by LiveView. | |
* Add phx-hook="FormReset" to the form and phx-reset="" to the input you want to reset. | |
* The attribute phx-reset must contain the value that the input value will be reseted to. | |
*/ | |
Hooks.FormReset = { | |
updated() { | |
let input = this.el.querySelector('[phx-reset]:not(.invalid-feedback)') | |
let value = input.getAttribute('phx-reset') | |
input.value = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule CounterCache do | |
@moduledoc """ | |
This module provides a way of generating embedded schemas that contain the definition of cached fields. | |
A module is automatically created for each and contains the definition values passed in the list. | |
By accessing the generated module, those fields can be queried from the schema that contains them. | |
# Usage | |
- Add `use CounterCache` to your module. | |
- Invoke `counter_cache_field` inside your schema definition: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
NewerOlder