Skip to content

Instantly share code, notes, and snippets.

@csokun
csokun / upsert.ex
Created May 9, 2023 13:45
Ecto conditional upsert
defmodule App.Posts do
# ref. https://amandasposito.com/elixir/ecto/macro/2021/01/22/macro-ecto-custom-on-conflict.html
# ref. https://elixirforum.com/t/upsert-conditional-update-e-g-update-only-when-existing-data-is-outdated/55503/2
defmacro custom_on_conflict_update_replace_all(queryable) do
values =
:fields
|> Post.__schema__()
|> Enum.map(fn f ->
{f, quote(do: fragment(unquote("EXCLUDED.#{f}")))}
---
# shared-volume
# ├── app1
# └── app2
---
apiVersion: v1
kind: Pod
metadata:
name: app1
spec:
# .env
# POSTGRES_PASSWORD=
# PGADMIN_DEFAULT_EMAIL=admin@localhost
# PGADMIN_DEFAULT_PASSWORD=
version: "3.3"
services:
pgsql:
image: postgres:11-alpine
restart: always
volumes:
@csokun
csokun / get-golang.sh
Created September 18, 2020 12:14
Download & Install Golang (Linux)
#!/bin/bash
GOPATH=$(which go)
if [ -n "$GOPATH" ]; then
echo "Go installed: $GOPATH"
go version
exit 1
fi
VERSION=1.15.2
PKG_NAME="go${VERSION}.linux-amd64.tar.gz"
@csokun
csokun / elixir-bashrc
Last active November 2, 2019 00:55
Elixir docker playground, let keep your workstation clean while experimenting the language
# setup Elixir aliases
export ELIXIRROOT="$HOME/elixir"
if [ ! -d "$ELIXIRROOT" ]; then
mkdir -p $ELIXIRROOT
fi
export MIXPATH="/root/.mix"
export HEXPATH="/root/.hex"
export ELIXIR_VOLUMES="-v ${ELIXIRROOT}/.mix:${MIXPATH} -v ${ELIXIRROOT}/.hex:${HEXPATH} --workdir /src"
alias iex='docker run -it ${ELIXIR_VOLUMES} -v ${PWD}:/src --rm --network=host elixir'
alias iexm='docker run -it ${ELIXIR_VOLUMES} -v ${PWD}:/src --rm --network=host elixir iex -S mix'
@csokun
csokun / Dockerfile
Created November 7, 2017 05:29
nod:8.9.0-alpine cmake taglib2
FROM node:8.9.0-alpine as builder
RUN apk add --no-cache cmake make gcc g++ libc-dev linux-headers git
RUN npm install taglib2 -g
@csokun
csokun / eth01
Created September 25, 2017 02:09
eth validation
// testing