Skip to content

Instantly share code, notes, and snippets.

View mxgrn's full-sized avatar

Max Gorin mxgrn

View GitHub Profile
Application.put_env(:sample, Example.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 5001],
server: true,
live_view: [signing_salt: "aaaaaaaa"],
secret_key_base: String.duplicate("a", 64)
)
Mix.install([
{:plug_cowboy, "~> 2.5"},
{:jason, "~> 1.0"},
@mxgrn
mxgrn / audit-logs.sql
Created December 9, 2024 10:13
Track Postgres table changes in audit_logs
-- Step 1: Create the audit logs table
CREATE TABLE audit_logs (
id SERIAL PRIMARY KEY,
table_name TEXT NOT NULL,
operation TEXT NOT NULL,
json_diff JSONB,
inserted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Step 2: Create the trigger function
# It's only a POC for now
defmodule ContextBase do
@moduledoc """
Abstracts away common schema functions, such as list, get, create, update, delete, etc.
Assumes that the schema module has a `changeset` function.
Usage:
defmodule MyContext do
use ContextBase, repo: MyApp.Repo, schema: MyApp.MySchema
end
@mxgrn
mxgrn / renaming-phoenix-app.md
Created December 23, 2023 03:26
Renaming Elixir Phoenix app

Say, at some point you generated your Phoenix app with mix phx.new my_app, but later decided to change its name to "new_app".

See this little memo as a checklist to avoid possible pitfalls.

1. Project-wide search and replace

Use your favorite text editor to search and replace as follows (use case-sensitive search for minimizing chances for a mistake):

  • MyApp -> NewApp
  • my_app -> new_app
@mxgrn
mxgrn / lv_modal_close_confirm.md
Last active June 15, 2024 14:18
LiveView modal close confirmation on dirty form
@mxgrn
mxgrn / book.ex
Created November 4, 2023 16:24
Book Ash Resource
defmodule AshTable.Book do
use Ash.Resource, data_layer: AshPostgres.DataLayer
postgres do
table "books"
repo AshTable.Repo
end
attributes do
uuid_primary_key :id
# install wkhtmltopdf
RUN apt-get -q update && \
apt-get -qy install --no-install-recommends wget && \
wget --no-check-certificate -nv -O /tmp/wkhtmltox.deb https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.bullseye_amd64.deb && \
apt-get -qy install /tmp/wkhtmltox.deb && \
cd /usr/local/bin && \
cp wkhtmltoimage /usr/bin/wkhtmltoimage && \
cp wkhtmltopdf /usr/bin/wkhtmltopdf
Verifying that "maxgorin.id" is my Blockstack ID. https://onename.com/maxgorin
@mxgrn
mxgrn / dvorak-to-colemak.md
Last active January 9, 2019 19:02
Dvorak -> Colemak

I switched to Dvorak about 9 years ago. It was my 3rd touch-typed layout, after ЙЦУКЕН and QWERTY, both of which I was using daily. Now, that I look back, I think choosing Dvorak wasn't ideal: while it's been a huge relief after QWERTY (this ubiquitous finger twister), Dvorak showed certain drawbacks I should have noticed from the very beginning. A good example would be the frequent "sl" combination (slow, sleep, slide, etc), which is a same-finger combination for the right pinkie. Recently, some extra research showed it must have always been Colemak.

Learning a new layout is akin to learning a musical instrument: the cognitive effort required for deliberate practice feels pleasingly mind stretching. So, I decided to switch again. Below this paragraph I'll be posting everything I have typed so far during my Colemak practice, including some report on the progress - for what it's worth. Minor editing here and there is possible for readability. Let's see how much typing it takes to get back to a reasonable spee

### Keybase proof
I hereby claim:
* I am mxgrn on github.
* I am mxgrn (https://keybase.io/mxgrn) on keybase.
* I have a public key ASAawdHU72TBx7thfEqkiCLt2j4IXULM4npcWfbwHkpGaQo
To claim this, I am signing this object: