Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
// Zed settings
//
// For information on how to configure Zed, see the Zed
// documentation: https://zed.dev/docs/configuring-zed
//
// To see all of Zed's default settings without changing your
// custom settings, run the `open default settings` command
// from the command palette or from `Zed` application menu.
{
"theme": "One Dark",
[
// Bindings that apply to all contexts
{
"bindings": {
"cmd-f": "workspace::NewSearch",
"cmd-t": "terminal_panel::ToggleFocus"
}
},
{
"context": "Editor && VimControl && !VimWaiting && !menu",
@baldwindavid
baldwindavid / personal-to-org-account.md
Created December 12, 2011 21:35
How to turn a personal account into an org account

You can turn your personal account into an organization by going to Account Settings > Organizations, clicking "Turn into an organization", and following the instructions in the pop up dialog.

The history of the account and the repositories will be preserved.

I'll explain each point of the warning you'll get:

You will no longer be able to log into YOURACCOUNT (all administrative privileges will be bestowed upon the organization owners you choose)

This just means that you need to choose a new personal account(s) to add as the owner(s) of your new organization. You need to do that anyway, because you can't log in as an organization. You need to create at least one new personal account for you.

@baldwindavid
baldwindavid / thesaurus.rb
Last active April 15, 2021 16:09
You'll need an API key from words.bighugelabs.com
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'cgi'
# Get a free API key at https://words.bighugelabs.com/account/getkey
API_KEY = '[YOUR API KEY HERE]'
API_VERSION = 2
WORDS_PER_LINE = 4
@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