Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
#####################################################
# COMMANDS
# Commands are under "space space".
#
# Most commands may be run in a floating (f), down (j), or right (l) pane.
# The "j" and "l" align with the movement keys (i.e. h,j,k,l).
#
# For example, to run a test under cursor in a pane below:
#
# "tab" = open command menu
layout {
default_tab_template {
children
pane size=2 borderless=true {
plugin location="zellij:status-bar"
}
}
tab name="dev" focus=true {
pane split_direction="vertical" {
// Static tasks configuration.
[
{
"label": "Sublime Merge",
"command": "smerge .",
"reveal": "never",
"hide": "always"
},
{
"label": "Lazygit",
[
////////////////////////////////////////////
// All Contexts
////////////////////////////////////////////
{
"bindings": {
// Open Project
"cmd-shift-p": "projects::OpenRecent",
// Left Dock
{
"assistant": {
"default_model": {
"provider": "copilot_chat",
"model": "gpt-3.5-turbo"
},
"version": "2"
},
"auto_update": true,
"theme": {
@baldwindavid
baldwindavid / crud.ex
Last active April 8, 2021 16:40
Macros to perform context crud operations
defmodule MyApp.Crud do
defmacro list(config) do
quote bind_quoted: [config: config] do
def unquote(:"list_#{config.plural_name}")(queries \\ & &1) do
unquote(config.schema)
|> queries.()
|> unquote(config.repo).all()
end
end
end
@baldwindavid
baldwindavid / build_stubbed_strategy.ex
Created April 2, 2021 17:37
Build Stubbed Strategy for ExMachina
defmodule MyApp.Factories.BuildStubbedStrategy do
use ExMachina.Strategy, function_name: :build_stubbed
alias Ecto.Association.BelongsTo
alias Ecto.Association.Has
alias Ecto.Association.NotLoaded
alias Ecto.UUID
def handle_build_stubbed(record, _opts \\ []) do
record
############################################################
# APP ROLES
############################################################
def insert_app_super_admin_role, do: insert(:super_admin) |> Roles.role_for()
def insert_app_admin_role, do: insert(:admin) |> Roles.role_for()
def insert_app_marketer_role, do: insert(:marketer) |> Roles.role_for()
def insert_app_user_role, do: insert(:user) |> Roles.role_for()
def insert_all_app_roles, do: insert_app_roles(@roles)
unit_statuses =
# There is a Unit schema that is tied to a "units" table
from(unit in Unit,
# grab a lease tied to a unit (office space)
# Leases have start and end dates so the lease must be during the week
# of the given `date`. This will scope leases to that requirement.
left_join: lease in ^Leasing.filter_active_leases_during_week(Lease, date),
on: lease.unit_id == unit.id,
# join the unit type (Salon, Office, Focus, etc)
join: unit_type in assoc(unit, :unit_type),
defmodule Capturepipe do
@doc """
A pipe-operator that extends the normal pipe
in one tiny way:
It allows the syntax of having a bare `&1` capture
to exist inside a datastructure as one of the pipe results.
This is useful to insert the pipe's results into a datastructure
such as a tuple.