Skip to content

Instantly share code, notes, and snippets.

@csokun
csokun / cuda.sh
Created February 12, 2024 11:19
Install CUDA on Arch Linux (Majaro)
sudo pacman -S cuda cudnn
export PATH=$PATH:/opt/cuda/bin
nvcc --version
@csokun
csokun / stellar_export.sh
Last active January 30, 2024 05:14
Using stellar-etl to export ledgers|transactions|operations|effects|trades|assets|diagnostic_events
#!/bin/bash
# ref. https://github.com/stellar/stellar-etl/tree/master?tab=readme-ov-file#history-archive-commands
if [ $# -lt 3 ]; then
echo "Usage: $0 <export_type> <start_ledger> <end_ledger> [network]"
echo " $0 ledgers 2 500"
echo " $0 transactions 2 500 --futurenet"
echo " $0 operations 2 500 --testnet"
echo " $0 effects 2 500"
echo " $0 assets 2 500 --futurenet"
echo "===== History Archive URLs ====="
docker run -v $PWD/history:/working stellar/stellar-etl stellar-etl export_ledger_entry_changes \
--start-ledger 2 \
--end-ledger 500 \
--output /working/ \
--gcs-bucket "" \
--testnet \
-x /usr/bin/stellar-core \
-c docker/stellar-core_testnet.cfg
@csokun
csokun / eks-alb-actions-conditions.yml
Created January 15, 2024 01:43
EKS ALB Controller actions & conditions
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2 # tells deployment to run 2 pods matching the template
template:
@csokun
csokun / spike.yml
Created January 8, 2024 05:29
Helm loop n times
{{ $times := 2 }}
{{- range $i := until $times }}
#{{ $i }}
{{- end }}
@csokun
csokun / ecto_query.exs
Created October 13, 2023 05:04
Ecto Query - aggr many-to-many count child
# user <1---*> playlist <1---*> playlist_song
(from p in Playlist,
join: u in assoc(p, :user),
left_join: ps in assoc(p, :songs),
where: p.id == ^1 and u.id == ^1,
group_by: p.id,
select: %{
playlist_id: p.id,
song_count: count(ps.id)
}
@csokun
csokun / pg.sql
Created September 10, 2023 09:18
postgres disconnect all clients
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
AND pid <> pg_backend_pid();
@csokun
csokun / .iex.exs
Created August 11, 2023 02:45
Elixir using Finch to stream Stellar Horizon transaction
Finch.start_link(name: MyFinch)
url = "https://horizon.stellar.org/accounts/GAFNBDOZBFUKHB4ZY5ANCQ25PM33YLTMWQKW25J7LXNZM3YSHRH3BELY/transactions?limit=200&cursor=119456526699307008&include_failed=true"
Finch.build(:get, url, [{"Accept", "text/event-stream"}])
|> Finch.stream(MyFinch, nil, fn
{:status, status}, _acc ->
IO.inspect(status)
{:headers, headers}, _acc ->
IO.inspect(headers)
@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: