Skip to content

Instantly share code, notes, and snippets.

View zachdaniel's full-sized avatar

Zach Daniel zachdaniel

View GitHub Profile
class Calculator
def initialize(value="")
@value ||= value
end
def method_missing(method, *args, &block)
@value += tokenize(method.to_s)
self
end
defmodule MyApp.Query do
require Ecto.Query
defmacro from(expr, kw \\ []) do
expr = alter_from(expr)
kw = alter_kw(kw)
quote do
Ecto.Query.from(unquote(expr), unquote(kw))
end
end
defmodule Mandark.Web.Plug.IndexedArrays do
@moduledoc """
Looks for any
Attaches hostname as a response heade to requests.
"""
@behaviour Plug
@impl Plug
@spec init(Keyword.t) :: Keyword.t

An example of a resource with authorization rules declared.

  defmodule Author do
    use Ash.Resource, name: "authors", type: "author"
    use Ash.DataLayer.Ets, private?: true

    actions do
      read :default, authorization_steps: [authorize_if: always()]
defmodule AshExample.Representative do
use Ash.Resource, type: "representative", name: "representatives"
use AshPostgres, repo: AshExample.Repo
use AshJsonApi.JsonApiResource
use AshGraphql.GraphqlResource
use AshPolicyAccess
policies do
defmodule AshExample.Ticket do
use Ash.Resource,
data_layer: AshPostgres.DataLayer,
authorizers: [
AshPolicyAuthorizer.Authorizer
],
extensions: [
AshJsonApi.Resource
]
defmodule AshPhoenix.Components.DataTable2 do
use Surface.LiveComponent
import AshPhoenix.LiveView
alias AshPhoenix.Components.FilterBuilder2
data data, :list, default: []
data fields, :list
data apply_filter, :boolean, default: true
data filter, :any, default: []
@zachdaniel
zachdaniel / changed.ex
Created November 6, 2021 15:22
Check if an AshPhoenix Form is changed
defp changed?(form) do
is_changed?(form) ||
Enum.any?(form.forms, fn {_key, forms} ->
forms
|> List.wrap()
|> Enum.any?(&changed?/1)
end)
end
defp is_changed?(form) do
let habits = new Set();
const linksToHabits = {};
let days = [];
function compareName(a, b) {
if (a.file.name < b.file.name) {
return -1;
}
if (a.file.name > b.file.name) {
return 1;
}
defmodule MyApp.Extensions.Archive.Transformers.SetupArchival do
@moduledoc "Sets up the required resource structure for archival"
use Ash.Dsl.Transformer
@after_transformers [
Ash.Resource.Transformers.SetPrimaryActions
]
@before_transformers [
Ash.Resource.Transformers.DefaultAccept,