Skip to content

Instantly share code, notes, and snippets.

View mxgrn's full-sized avatar

Max Gorin mxgrn

View GitHub Profile
@mxgrn
mxgrn / lv_modal_close_confirm.md
Last active April 11, 2024 06:42
LiveView modal close confirmation on dirty form
# 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 / 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
@mxgrn
mxgrn / gist:663933
Created November 5, 2010 10:24
Git's pre-commit hook to remove trailing whitespaces/tabs
#!/bin/sh
#
# This will abort "git commit" and remove the trailing whitespaces from the files to be committed.
# Simply repeating the last "git commit" command will do the commit then.
#
# Put this into .git/hooks/pre-commit, and chmod +x it.
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
@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

@mxgrn
mxgrn / gist:5402155
Last active October 19, 2018 02:19 — forked from billygoat/gist:5320505
Adds a new entry in nvALT, with title set to page title, tags set to "bookmarks", and body containing page title, link, and text selected on page (if present).
/* Source code */
javascript:(function(){
var w=window,d=document,pageSelectedTxt=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pageTitle=d.title,pageUri=w.location.href,tmplt="";
tmplt="Title: "+pageTitle+"\nLink: "+pageUri+"\n";
if (pageSelectedTxt != "") {
pageSelectedTxt="\n---\n"+pageSelectedTxt;
}
w.location.href="nvalt://make/?txt="+encodeURIComponent(tmplt+pageSelectedTxt)+"&title="+encodeURIComponent(pageTitle)+"&tags=bookmarks";
})();
Verifying that "maxgorin.id" is my Blockstack ID. https://onename.com/maxgorin
### 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: