Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View zachdaniel's full-sized avatar

Zach Daniel zachdaniel

View GitHub Profile
@zachdaniel
zachdaniel / prewalk_with_branch.ex
Created November 14, 2023 02:29
An implementation of `Macro.prewalk/2` with a branch accumulator
defmodule Macro do
@doc """
Copy of `Macro.prewalk/2` w/ a branch accumulator
"""
def prewalk(ast, fun) when is_function(fun, 1) do
elem(prewalk(ast, nil, nil, fn x, nil, nil -> {fun.(x), nil} end), 0)
end
@doc """
Copy of `Macro.prewalk/3` w/ a branch accumulator
@zachdaniel
zachdaniel / libraries_and_frameworks.md
Last active June 29, 2023 16:42
EEF Working Group Proposal: Libraries and Frameworks Working Group

Libraries and Frameworks Working Group

Mission Statement

  • To provide resources for library and framework authors to ensure that BEAM languages have a rich, vibrant ecosystem with a high degree of developer experience. Main Objectives
  • Provide and maintain best practices on library and framework standardization, documentation, code, and distribution. Collaborate to work on and make proposals for underlying tooling that improve the experience for library/framework authors and users.
  • Provide more visibility into the library ecosystem of Elixir on behalf of both authors and users.
  • (if Build and Packaging want to move this here, we could also take this over) Improve the user experience in generating and accessing documentation from the shell, IDEs, web pages, and more.

There are more than a few different ways you could do that. The simplest one would be to modify the actions that are created, by defining them yourself or adding behavior to them.

  1. creating them yourself, if you do this, AshAuthentication will just validate that the action contains the correct elements:
read :sign_in_with_password do 
  ...
  # can also put it in a module: prepare RequireGoogleSignInForFoo
  prepare fn query, result -> 
 if is_foo(Ash.Changeset.get_argument(query, :email)) do 
defmodule Mochi.Deck do
use Ash.Resource,
data_layer: AshJsonApiWrapper.DataLayer
actions do
defaults [:read]
end
json_api_wrapper do
finch Mochi.Finch
@zachdaniel
zachdaniel / sat_solver.gleam
Last active October 19, 2022 19:13
sat_solver.gleam
// This heavily borrows (and is essentialy just a port) of https://andrew.gibiansky.com/blog/verification/writing-a-sat-solver/
import gleam/io
import gleam/list
import gleam/int
import gleam/option.{None, Option, Some}
type Expr {
Var(Int)
And(Expr, Expr)
Or(Expr, Expr)
defmodule BetterComponent do
defmodule Live do
defmacro __using__(opts) do
quote do
import BetterComponent
use Surface.LiveComponent
def update(assigns, socket) do
case assigns[:__event__] do
defmodule BetterComponent do
defmodule Live do
defmacro __using__(opts) do
quote do
import BetterComponent
use Surface.LiveComponent
def update(assigns, socket) do
case assigns[:__event__] do
defmodule Helpdesk.Tickets.Ticket.Relationships.TicketsAboveThreshold do
use Ash.Resource.ManualRelationship
use AshPostgres.ManualRelationship
require Ash.Query
require Ecto.Query
def load(records, _opts, %{query: query, actor: actor, authorize?: authorize?}) do
rep_ids = Enum.map(records, & &1.id)
{:ok,
defmodule Mix.Tasks.DumpHackerNews do
@moduledoc "Grabs the current first few pages of hackernews and saves them to a json file"
use Mix.Task
defmodule TopStory do
@moduledoc false
use Ash.Resource,
data_layer: AshJsonApiWrapper.DataLayer
json_api_wrapper do
@zachdaniel
zachdaniel / source_manipulation.ex
Last active August 17, 2022 19:13
Soource Manipulation
code_change =
CodeChange.new() # just one potential idea for what the multi-file tracking would be called
|> CodeChange.create_file(path, initial_contents)
|> CodeChange.update_file(path, [
Operation.add_defmodule(module_name),
Operation.add_use_to_module(module_name, thing_it_uses),
MyCustomOperations.do_my_special_thing(...)
], instructions_on_failure: "Add x to your module.")
# I need this for my use case because individual code changes may depend on the current state of other files