Skip to content

Instantly share code, notes, and snippets.

View StanisLove's full-sized avatar

Stanislav Kravchenko StanisLove

View GitHub Profile
@StanisLove
StanisLove / CleanArchitecture.md
Created April 14, 2022 10:55 — forked from ygrenzinger/CleanArchitecture.md
Summary of Clean Architecture by Robert C. Martin

Summary of book "Clean Architecture" by Robert C. Martin

Uncle Bob, the well known author of Clean Code, is coming back to us with a new book called Clean Architecture which wants to take a larger view on how to create software.

Even if Clean Code is one of the major book around OOP and code design (mainly by presenting the SOLID principles), I was not totally impressed by the book.

Clean Architecture leaves me with the same feeling, even if it's pushing the development world to do better, has some good stories and present robust principles to build software.

The book is build around 34 chapters organised in chapters.

# Minikube update script file
minikube delete && \
sudo rm -rf /usr/local/bin/minikube && \
sudo curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && \
sudo chmod +x minikube && \
sudo cp minikube /usr/local/bin/ && \
sudo rm minikube && \
minikube start &&\
@StanisLove
StanisLove / rails-models-to-typescript-schema.rb
Created September 25, 2021 07:22 — forked from zealot128/rails-models-to-typescript-schema.rb
Simple ruby script to generate Active Record Typescript information with enums + associations
# USAGE:
# rails runner rails-models-to-typescript-schema.rb > app/javascript/types/schema.d.ts
Rails.application.eager_load!
models = ActiveRecord::Base.descendants.reject { |i| i.abstract_class? }
belongs_to = true
has_many = true
@StanisLove
StanisLove / task_for_gen_server_use
Created August 30, 2020 08:59 — forked from Apelsinka223/task_for_gen_server_use.md
Задачка на использование GenServer
# Онлайн магазин
Необходимо создать API для онлайн магазина. Для покупки необходимо создать корзину, добавить туда товары и затем купить все товары из корзины. API подразумевает возможности просматривать список всех продуктов, список корзин.
Ожидается использование GenServer для хранения данных корзин.
## Методы API:
### 1. create_item
import * as React from 'react';
import removeHTMLTags from './removeHTMLTags';
const safetySetInnerHTML = (text?: string) => {
if (!text) return null;
const allowedTags = ['div', 'p', 'li', 'ul', 'ol', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']
.map((tag) => [`<${tag}>`, `</${tag}>`])
.flat();
@StanisLove
StanisLove / blocksToHtml.js
Created August 18, 2020 10:14 — forked from hagemann/blocksToHtml.js
Render EditorJS blocks to HTML.
const renderHtml = (blocks) => {
var html = blocks.map(block => {
switch (block.type) {
case 'code':
return `<pre><code>${ block.data.code }</pre></code>`
/**
* Original type is 'header' but I renamed the block to follow correct terminology:
* https://github.com/editor-js/header/issues/21
*/

The Complete Guide to Nested Forms in Phoenix

I recently spent some time dealing with nested forms in Phoenix. Nested forms are great when you want to create multiple database records in a single transaction and associate them with each other. I am new to Phoenix and really struggled to find any resources that helped me with my specific problem. I decided to document what I learned in the process in hopes of helping others that are new to Elixir and Phoenix.

Here is my attempt at a one stop shop to learn everything you will need to know about nested forms. If you would like to view the GitHub repo you can check it out here.

Thanks to Heartbeat and Jose for excellent blog posts on nested forms. Also shoutout to Josh for showing me some examples at Ruby

@StanisLove
StanisLove / class_controller.ex
Created August 12, 2020 19:31 — forked from elderbas/class_controller.ex
Elixir — Inserting Multiple Changesets Into Database - create batch
def create_batch(conn, %{"people" => people_params}) do
changesets = Enum.map(people_params, fn class ->
Person.changeset(%Person{}, person)
end)
result = changesets
|> Enum.with_index()
|> Enum.reduce(Ecto.Multi.new(), fn ({changeset, index}, multi) ->
Ecto.Multi.insert(multi, Integer.to_string(index), changeset)
end)
@StanisLove
StanisLove / pg_flatten_json.sql
Created August 11, 2020 17:06 — forked from imamdigmi/pg_flatten_json.sql
Flattening json data in PostgreSQL
create or replace function create_jsonb_flat_view
(table_name text, regular_columns text, json_column text)
returns text language plpgsql as $$
declare
cols text;
begin
execute format ($ex$
select string_agg(format('%2$s->>%%1$L "%%1$s"', key), ', ')
from (
select distinct key
threads = Array.new(8) do
Thread.new do
while arr.any?
mutex.synchronize do
end
elem = arr.pop
next if elem.nil?
end