Skip to content

Instantly share code, notes, and snippets.

View egze's full-sized avatar

Aleksandr Lossenko egze

View GitHub Profile
@egze
egze / snowjob.sh
Created December 15, 2023 11:24 — forked from sontek/snowjob.sh
Make your terminal snow
#!/bin/bash
LINES=$(tput lines)
COLUMNS=$(tput cols)
declare -A snowflakes
declare -A lastflakes
clear
@egze
egze / yarn_checker.ex
Created June 1, 2021 05:34
Ensure Hex ans Npm have the same version
defmodule MyApp.YarnChecker do
use Credo.Check,
run_on_all: true,
category: :consistency,
base_priority: :high,
param_defaults: [
package_json: "assets/package.json",
yarn_lock: "assets/yarn.lock",
packages: ["phoenix", "phoenix_html", "phoenix_live_view"]
],
@egze
egze / ets_cache.ex
Created September 23, 2020 19:01 — forked from raorao/ets_cache.ex
Simple ETS based cache with TTL
defmodule RequestCache do
@moduledoc """
Simple ETS-based cache.
"""
use GenServer
@type t :: %{ttl: integer, invalidators: %{}}
@type cache_key :: any
@type cache_value :: any
@egze
egze / foo.ex
Created June 12, 2020 16:16 — forked from 0x6a68/foo.ex
Spec to Callback
defmodule MyApp.Foo do
@on_definition MyApp.SpecToCallback
@spec bar(String.t()) :: String.t()
def bar(foobar) do
impl().bar(foobar)
end
defp impl, do: Application.get_env(:my_app, :my_app_foo_impl, __MODULE__.DefaultImpl)
end
@egze
egze / syntax.txt
Last active May 25, 2020 12:50
LiveView syntax
{ name = 'string.quoted.other.sigil.live_view';
comment = 'live_view sigil (allow for interpolation)';
begin = '\s?(~L""")$';
end = '^\s*("""[a-z]*)$';
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.elixir'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.string.end.elixir'; }; };
patterns = (
{ include = 'text.elixir'; },
{ include = 'text.html.basic'; },
{ include = '#meta.embedded.line.elixir'; },
@egze
egze / with_example.ex
Created February 15, 2020 17:46 — forked from devonestes/with_example.ex
Further refactoring of a with statement
# Step 1
def create_subscription(email, plan_id, payment_method_id) do
with %User{customer_id: nil, name: name} = user <-
Repo.get_by(User, email: email),
{:ok, %Stripe.Customer{id: customer_id}} <-
Stripe.Customer.create(%{
name: name,
email: email,
payment_method: payment_method_id,
@egze
egze / fix_id3_encoding.rb
Created July 18, 2019 11:41
Fixes wrong cp1251 encoding (Ïîñòàðàåìñÿ áîëüøå) in ID3 tags
require 'rubygems'
require 'taglib'
files_names = Dir["*.mp3"].sort
files_names.each do |file_name|
TagLib::MPEG::File.open(file_name) do |mp3_file|
## ID3 tag
@egze
egze / day8.ex
Last active December 28, 2018 14:03
day8
defmodule Day8 do
defmodule Node do
defstruct children_count: 0, metadata_count: 0, metadata: [], children: []
def parse_header(numbers) do
{[children_count, metadata_count], numbers} = Enum.split(numbers, 2)
node = %Node{children_count: children_count, metadata_count: metadata_count}
{node, numbers}
end
@egze
egze / day5.ex
Last active December 7, 2018 16:07
AoC Day5 solution
defmodule Polymer do
defstruct data: []
def new do
%Polymer{}
end
def size(%Polymer{data: data}) do
data |> Enum.count()
end
@egze
egze / README.md
Created May 8, 2018 19:01 — forked from sevos/README.md
Rails 5.2 + Komponent + Turbolinks + Stimulus

Usage

rails new my_app --rc=template.rc -m template.rb