Skip to content

Instantly share code, notes, and snippets.

View braynm's full-sized avatar

Bry braynm

View GitHub Profile
## Example unit test for `AmountFormatter` module
defmodule GroceryBudget.AmountFormatterTest do
use ExUnit.Case
alias GroceryBudget.Utils.AmountFormatter
describe "AmountFormatter" do
@tag :amount_formatter
test "to_db/1 should multiply by 100" do
assert AmountFormatter.to_db(500) == 50000
end
@braynm
braynm / postgres_queries_and_commands.sql
Created May 23, 2022 04:11 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@braynm
braynm / big-o.md
Created March 12, 2022 10:25 — forked from PJUllrich/big-o.md
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for < 32 elements, O(log n) for >= 32 elements [2]
Deletion O(n) for < 32 elements, O(log n) for >= 32 elements
@braynm
braynm / README.md
Last active January 28, 2022 01:09
List branches with last commit, subject, author and last activity

List local branches

git for-each-ref --sort=-committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
@braynm
braynm / 2021init.vim
Created October 16, 2021 15:57
neovim configuration 2021
" Plug
call plug#begin()
Plug 'ayu-theme/ayu-vim'
Plug 'morhetz/gruvbox'
Plug 'Pocco81/Catppuccino.nvim'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/vim-journal'
@braynm
braynm / README.md
Created June 19, 2021 23:36 — forked from jonathantneal/README.md
Nearest Normal Ratio Calculator

Nearest Normal Aspect Ratio

This function returns the nearest aspect ratio of a width and height within a limited range of possible aspect ratios.

In other words, while 649x360 technically has an aspect ratio of 649:360, it’s often useful to know that the nearest normal aspect ratio is actually 9:5 (648x360).

nearestNormalAspectRatio(width, height, [side], [maxWidth], [maxHeight])
@braynm
braynm / query.exs
Last active March 26, 2021 03:10
Ecto query by date
...
import Ecto.Query
date = ~D[2021-03-22]
# fetch by date
query = from a in Schema, where: fragment("?::date", a.createdAt) == ^date
Repo.all(query) # fetch
# fetch by range
@braynm
braynm / README.md
Created February 11, 2021 16:14 — forked from rbishop/README.md
A super simple Elixir server for sending Server Sent Events to the browser.

Generate a new Elixir project using mix and add cowboy and plug as dependencies in mix.exs:

  defp deps do
    [
      {:cowboy, "~> 1.0.0"},
      {:plug, "~> 0.8.1"}
    ]
  end
@braynm
braynm / websites.txt
Created June 7, 2020 03:29
Websites that uses tailwind css
https://lynk.sh/
https://treact.owaiskhan.me/
https://mertjf.github.io/tailblocks/
https://cantabriadigital.es/
https://roar.market/
@braynm
braynm / setup_tailwind_in_phoenix.md
Created May 17, 2020 09:37 — forked from josephan/setup_tailwind_in_phoenix.md
Add Tailwind CSS to an Elixir/Phoenix Project with PurgeCSS