Skip to content

Instantly share code, notes, and snippets.

View tiagoefmoraes's full-sized avatar

Tiago Moraes tiagoefmoraes

View GitHub Profile
@zkayser
zkayser / unverified_mocks.ex
Created April 17, 2024 13:06
Credo Check for Validating Mox Users Verify Expectations
defmodule MyApp.Checks.UnverifiedMocks do
@moduledoc """
#{__MODULE__} looks for test files that import Mox and use
the `expect/4` function, but do not enforce any assertions that
the expectations have been called or not either by running `verify_on_exit`
from a setup block or calling `verify!/0` or `verify!/1` inline
in a test block.
"""
@message """
@aglassman
aglassman / async_assigns.ex
Last active July 23, 2023 12:36
LiveView - Async Assigns Helper
defmodule AsyncAssigns do
import Phoenix.LiveView, only: [connected?: 1, assign: 2, assign: 3]
@doc """
Provides ability to assign default values to the socket, and kick off a
process that will send a message to the LiveView. The message payload will
be assigned as specified.
## Usage
Add the following lines to a specific LiveView, or to the web module
@wingyplus
wingyplus / ci.exs
Last active January 31, 2024 12:28
Mix.install([
{:dagger, "~> 0.9.4"}
])
defmodule Ci do
alias Dagger.{Client, Container, Directory, Host}
@workdir "/app"
# TODO: change to your release name.
@release "hello_world_dagger"
@sorentwo
sorentwo / start_oban_web.livemd
Created July 27, 2022 16:38
Single Page Oban Web

Single Page Oban Web

Application.put_env(:sample, Sample.Repo, database: "oban_dev")

Application.put_env(:phoenix, :json_library, Jason)

Application.put_env(:sample, Sample.Endpoint,
  http: [ip: {127, 0, 0, 1}, port: 5001],
  server: true,
@tiagoefmoraes
tiagoefmoraes / defstruct_test.ex
Created April 6, 2022 11:34
DefStructTest - cover all `defstruct` calls on your elixir app
defmodule MyApp.DefStructTest do
use ExUnit.Case, async: true
test "to cover defstruct" do
project_structs()
|> Enum.each(&assert &1.__struct__(), to_string(&1))
end
defp project_structs do
{:ok, modules} = :application.get_key(:my_app, :modules) # change to your app's name
@rponte
rponte / using-uuid-as-pk.md
Last active December 14, 2024 19:23
Não use UUID como PK nas tabelas do seu banco de dados

Pretende usar UUID como PK em vez de Int/BigInt no seu banco de dados? Pense novamente...

TL;TD

Não use UUID como PK nas tabelas do seu banco de dados.

Um pouco mais de detalhes

@wosephjeber
wosephjeber / instructions.md
Last active December 17, 2024 07:26
Ecto migration for renaming table with indexes and constraints

Renaming table in Ecto migration

I recently wanted to rename a model and its postgres table in a Phoenix app. Renaming the table was simple and documented, but the table also had constraints, sequences, and indexes that needed to be updated in order for the Ecto model to be able to rely on default naming conventions. I couldn't find any examples of what this would look like but was eventually able to figure it out. For anyone else in the same situation, hopefully this example helps.

In the example below, I'm renaming the Permission model to Membership. This model belongs to a User and an Account, so it has foreign key constraints that need to be renamed.

defmodule MyApp.Repo.Migrations.RenamePermissionsToMemberships do
  use Ecto.Migration
@noelbundick
noelbundick / LICENSE
Last active November 6, 2024 11:46
Exclude WSL installations from Windows Defender realtime protection
MIT License
Copyright (c) 2018 Noel Bundick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@taketo1113
taketo1113 / Replace 'be_success' to 'be_successful'.md
Created May 11, 2018 02:13
Fix 'DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful?'
  • Error
DEPRECATION WARNING: The success? predicate is deprecated and will be removed in Rails 6.0. Please use successful?
  • Sample code
  # deprecated
  expect(response).to be_success
 
@LostKobrakai
LostKobrakai / date_time_generators.ex
Last active March 17, 2024 17:21
stream_data generators to create elixir date/time structs
defmodule DateTimeGenerators do
use ExUnitProperties
@time_zones ["Etc/UTC"]
def date do
gen all year <- integer(1970..2050),
month <- integer(1..12),
day <- integer(1..31),
match?({:ok, _}, Date.from_erl({year, month, day})) do