Skip to content

Instantly share code, notes, and snippets.

View marka2g's full-sized avatar
🎯
Focusing

Mark Sadegi marka2g

🎯
Focusing
View GitHub Profile
@marka2g
marka2g / Dockerfile
Created June 12, 2023 17:24 — forked from petelacey/Dockerfile
Docker Compose setup for Elixir, Phoenix, and Postgres
FROM elixir:latest
# Install debian packages
RUN apt-get update && \
apt-get install --yes build-essential inotify-tools postgresql-client git && \
apt-get clean
ADD . /app
# Install Phoenix packages
@marka2g
marka2g / ecto_multi_bank_account_example.ex
Last active April 14, 2023 19:41
Ecto.Multi BankAccount Example
deposit_query = from(BankAccount, where: [id: 2]) #deposit target bank account
withdraw_query = from(BankAccount, where: [id: 1]) #withdraw from bank account
deposit_update = [inc: [balance: 100]]
withdraw_update = [inc: [balance: -100]
alias Ecto.Multi
# iex> h Ecto.Multi # Multi.new() creates a one-time op that atomically groups transactions
# iex> h Ecto.Multi.update_all # def update_all(multi, name, queryable_or_fun, updates, opts \\ [])
@marka2g
marka2g / shopping_bag.ex
Last active April 12, 2023 03:23
Elixir Genserver ShoppingCart with Registry and TimeToLive Example
# genserver with registry
defmodule MyApp.Workers.ShoppingCartCache do
use GenServer
require Logger
# one month
@ttl System.get_env("SHOPPING_CART_CACHE_PUBLIC_TTL") |> String.to_integer()
def start_link(shopping_cart_id) do
GenServer.start_link(__MODULE__, [shopping_cart_id], name: via_tuple(shopping_cart_id))
@marka2g
marka2g / app.html.eex
Created January 18, 2023 00:18 — forked from joenoon/app.html.eex
Phoenix LiveView main/nested setup
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
</head>
<body>
<div id="phx_root">
@marka2g
marka2g / app.css
Created October 29, 2022 20:44 — forked from alvises/app.css
Phoenix LiveView Gallery with Slideshow
/* to add to assets/css/app.css */
.thumb-selected {
border: 4px solid #0069d9;
}
.thumb-unselected {
opacity: 0.5;
}

If .DS_Store was never added to your git repository, simply add it to your .gitignore file.

If you don't have one, create a file called

.gitignore

In your the root directory of your app and simply write

@marka2g
marka2g / leex_to_heex.ex
Created July 27, 2022 21:56 — forked from toranb/leex_to_heex.ex
inline conditional css comparison of leex and heex
##### phx live view 0.16 with leex
def render(assigns) do
~L"""
<button class="<%= if @foo && @bar && @baz do %>text-blue-600<% else %>text-red-600<% end %>">hello</button>
"""
end
##### phx live view 0.16 with heex -inline edition
@marka2g
marka2g / using-asdf.md
Created July 9, 2022 21:45 — forked from philiph/using-asdf.md
Using asdf to manage ruby, erlang, elixir, node.js, Postgres

Note: this assumes you are using ZSH shell.

Installation

Install asdf:

$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.4.0
$ echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.zshrc
$ echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.zshrc
@marka2g
marka2g / gist:dbc716ccfa4e9d365c7873560946550e
Created June 17, 2022 02:37 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@marka2g
marka2g / knapsack_problem_dp_in_ruby.md
Created May 30, 2022 21:23 — forked from denis-mironov/knapsack_problem_dp_in_ruby.md
Knapsack problem in Ruby (Dynamic Programming)

Maximum Amount of Gold

Problem Introduction

You are given a set of bars of gold and your goal is to take as much gold as possible into your bag. There is just one copy of each bar and for each bar you can either take it or not (hence you cannot take a fraction of a bar).

Problem Description

Task.

Given 𝑛 gold bars, find the maximum weight of gold that fits into a bag of capacity 𝑊.

Input Format.

The first line of the input contains the capacity 𝑊 of a knapsack and the number 𝑛 of bars