Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
// 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.
@baldwindavid
baldwindavid / s3_direct.ex
Last active October 1, 2019 05:54
Some methods to generate fields to be used for direct s3 upload
defmodule S3.DirectUpload do
import ExAws.Auth.Utils, only: [amz_date: 1]
import ExAws.S3.Utils
@default_max_size_kilobytes 5_242_880
@default_expiry_seconds 3600
@type canned_acl ::
:private
| :public_read
defmodule Elevate.Networking.NetworkUpdater do
alias Elevate.Networking.NetworkConnection, as: Connection
alias Elevate.Networking.SubnetBuilder
def disable_access(
user_id: user_id,
network_id: network_id,
vlan_only_id: vlan_only_id,
site_id: site_id
) do