Skip to content

Instantly share code, notes, and snippets.

@artemeff
artemeff / dbg.sql
Created March 22, 2021 12:26
debug sql indexes performance in production using transactions
BEGIN;
drop index <IDX_NAME>;
create index test_1 on <TABLE> (...);
create index test_2 on <TABLE> (...) where field = true;
EXPLAIN ANALYZE <QUERY>
ROLLBACK;
@artemeff
artemeff / brefc.ex
Created March 22, 2021 12:24
erlang/elixir binary reference counters grouped by their id
defmodule BinaryRefc do
def run(take \\ 50, sort_by \\ :pids_count) do
ref_procs =
Enum.reduce(Process.list(), %{}, fn(pid, acc) ->
[binary: refc_list] = Process.info(pid, [:binary])
Enum.reduce(refc_list, acc, fn({ref, size, _count}, acc) ->
acc
|> Map.put_new({ref, size}, [])
|> Map.update!({ref, size}, fn(list) -> [pid | list] end)
@artemeff
artemeff / fish_prompt
Last active April 29, 2017 08:13
My fish prompt
# ~/.config/fish/functions/fish_prompt.fish
# name: Robbyrussell edited
# author: Bruno Ferreira Pinto, edit by Yuri Artemev
function fish_prompt
if not set -q -g __fish_robbyrussell_art_functions_defined
set -g __fish_robbyrussell_art_functions_defined
function _git_branch_name
echo (git rev-parse --abbrev-ref HEAD ^/dev/null)
@artemeff
artemeff / 2015.md
Last active November 25, 2016 15:34
  • Ушел из компании мечты (фейл, пришлось), а потом ее купила Airbnb (вин);
  • Запустил второй проект на Эрланге в продакшн (трекер общественного транспорта, щас он уже все);
  • Для этого проекта на Эрланге сделал красивое приложение для Windows Phone в продакшн (прям качали с магазина);
  • Затащил лучшего друга в программирование, всячески ему помогал и сейчас он уже на зарплате;
  • Затащил этот проект с трекингом транспорта в дипломную и защитил на отлично, закончил универ;
  • Попал в сильную команду рубистов, там немного научили в DDD и поставили на путь, куда идти дальше в ООП;
  • Попал в другую сильную команду рубистов, где хорошо прокачал теорию и практику распределенных систем;
  • Возненавидел тех, кто использует Elasticsearch не по назначению (никогда в жизни не устану это повторять, это травма);
  • Прокачался во фронтенде (react, babel и все такое модное с БД на клиенте и иммутабельными стейтами);
  • Попал в команду ROM, написал два адаптера в продакшн (rom-elasticsearch, rom-redis) и один для себя (rom-rethin
class SharePhoto
attr_reader :image
SRC_PATH = Rails.root.join("app/assets/images/private_share/")
def self.update_all
source_files = SRC_PATH.join("src/backgrounds")
Dir.foreach(source_files).each do |image_name|
class GemfileParser
attr_reader :gemfile
EXCLUDED = ["rails"]
def self.gems_status gemfile
new(gemfile).gems_status
end
def initialize gemfile
class BaseWall
def self.Wall length, width, material
Module.new do
define_method(:length) { length }
define_method(:width) { width }
define_method(:material) { material }
def self.included clazz
private :length, :width, :material
end
@artemeff
artemeff / tip.rb
Last active December 19, 2015 11:29
Ruby tips
# string merging
"asd" "qwe" "zxc"
# => "asdqwezxc"
# separators may be a space
% sometext .size
# => 8
lager:debug("throughput ~p num/s", [length(State)]).
% transforms to
case {whereis(lager_event), whereis(lager_event), lager_config:get({lager_event, loglevel}, {0, []})} of
{undefined, undefined, _} ->
fun () -> {error, lager_not_running} end();
{undefined, _, _} ->
fun () -> {error, {sink_not_configured, lager_event}} end();
{__Pidfb_throughput43, _, {__Levelfb_throughput43, __Tracesfb_throughput43}} when __Levelfb_throughput43 band 128 /= 0 orelse __Tracesfb_throughput43 /= [] ->
lager:do_log(debug, [{application, fb}, {module, fb_throughput}, {function, handle_info}, {line, 43}, {pid, pid_to_list(self())}, {node, node()} | lager:md()], "throughput ~p num/s", [length(State)], 4096, 128, __Levelfb_throughput43, __Tracesfb_throughput43, lager_event, __Pidfb_throughput43);
@artemeff
artemeff / run
Created August 9, 2015 19:49
runit with erlang and relx
#!/bin/sh
APP=<application_name>
USER=user
ROOT=/home/$USER/apps/$APP/_rel/$APP
export HOME=/home/$USER
exec 2>&1
exec chpst -u $USER $ROOT/bin/$APP foreground