Skip to content

Instantly share code, notes, and snippets.

View churcho's full-sized avatar

Churchill Aboge churcho

  • Nairobi/Kenya
View GitHub Profile
@churcho
churcho / unverified_mocks.ex
Created April 17, 2024 15:46 — forked from zkayser/unverified_mocks.ex
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 """
@churcho
churcho / authorized_introspection.ex
Created August 24, 2023 17:04 — forked from afhammad/authorized_introspection.ex
Disable GraphQL schema introspection in Elixir Absinthe using a plugin
defmodule MyAppWeb.Schema.Middleware.AuthorizedIntrospection do
@moduledoc """
Disable or restrict schema introspection to authorized requests
"""
@behaviour Absinthe.Plugin
@impl Absinthe.Plugin
def before_resolution(%{context: %{admin: true}} = exec), do: exec
def before_resolution(exec) do
@churcho
churcho / class_controller.ex
Created September 16, 2022 12:38 — forked from elderbas/class_controller.ex
Elixir — Inserting Multiple Changesets Into Database - create batch
def create_batch(conn, %{"people" => people_params}) do
changesets = Enum.map(people_params, fn class ->
Person.changeset(%Person{}, person)
end)
result = changesets
|> Enum.with_index()
|> Enum.reduce(Ecto.Multi.new(), fn ({changeset, index}, multi) ->
Ecto.Multi.insert(multi, Integer.to_string(index), changeset)
end)
@churcho
churcho / app.js
Created November 22, 2021 22:18 — forked from cblavier/app.js
Responsive Phoenix LiveView
const Hooks = { ViewportResizeHooks}
const connectLiveSocket = () => {
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute('content')
const liveSocket = new LiveSocket('/my_app/live', Socket, {
params: {
_csrf_token: csrfToken,
viewport: {
width: window.innerWidth,
height: window.innerHeight
@churcho
churcho / iframe.html
Created August 19, 2021 05:31 — forked from cirocosta/iframe.html
Sending messages from child iframe to parent webpage
<!DOCTYPE html>
<html>
<head>
<title>My Iframe</title>
</head>
<body>
<button>Botão</button>
<script type="text/javascript">
@churcho
churcho / .vimrc
Created January 5, 2021 05:51 — forked from lorenzosinisi/.vimrc
Vimrc config for Elixir
"""""""""""""""""""""""""""""""""""""
" Lorenzo Sinisi Vimrc configuration
"""""""""""""""""""""""""""""""""""""
set nocompatible
syntax on
set nowrap
set ignorecase
set smartcase
set encoding=utf8
set mouse=nicr
@churcho
churcho / docker-compose.yml
Created July 24, 2020 19:58 — forked from Mau5Machine/docker-compose.yml
Traefik Configuration and Setup
version: "3.3"
services:
################################################
#### Traefik Proxy Setup #####
###############################################
traefik:
image: traefik:v2.0
restart: always
@churcho
churcho / text_example.ex
Created January 9, 2020 21:37 — forked from chiragtoor/text_example.ex
Example Elixir code for sending a text message through ExTwilio
def send_text_message(phone_number, message) do
ExTwilio.Api.create(ExTwilio.Message,
[to: phone_number,
from: Application.get_env(:ex_twilio, :send_number),
body: message])
end
@churcho
churcho / remove_postgres_on_mac_os.md
Created December 17, 2019 10:01 — forked from Atlas7/remove_postgres_on_mac_os.md
Note - How completely uninstall PostgreSQL 9.X on Mac OSX

This blog post has helped me clean up my postgres development environment on Mac. So making a copy!

How completely uninstall PostgreSQL 9.X on Mac OSX

This article is referenced from stackoverflow:

If installed PostgreSQL with homebrew , enter brew uninstall postgresql

If you used the EnterpriseDB installer , follow the following step.
@churcho
churcho / usaCities.js
Created April 27, 2019 21:36 — forked from Lwdthe1/usaCities.js
JSON of 5,950+ USA Cities and Their States
[
{'city': 'Abbeville', 'state': 'Louisiana'},
{'city': 'Aberdeen', 'state': 'Maryland'},
{'city': 'Aberdeen', 'state': 'Mississippi'},
{'city': 'Aberdeen', 'state': 'South Dakota'},
{'city': 'Aberdeen', 'state': 'Washington'},
{'city': 'Abilene', 'state': 'Texas'},
{'city': 'Abilene', 'state': 'Kansas'},