Skip to content

Instantly share code, notes, and snippets.

View sergio1990's full-sized avatar
🇺🇦

Serhii Herniak sergio1990

🇺🇦
View GitHub Profile
@sergio1990
sergio1990 / erl_crash.dump
Created September 21, 2014 16:59
Erlang crash dump
=erl_crash_dump:0.3
Sun Sep 21 19:46:07 2014
Slogan: Kernel pid terminated (application_controller) ({application_start_failure,kernel,{{shutdown,{failed_to_start_child,user,{undef,[{'Elixir.IEx.CLI',start,[],[]},{user_sup,start_user,3,[{file,"user_su
System version: Erlang/OTP 17 [erts-6.1] [source-d2a4c20] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Compiled: Thu Jun 26 17:08:00 2014
Taints:
Atoms: 4994
=memory
total: 10668648
processes: 3510784
@sergio1990
sergio1990 / bet_profit.sql
Created October 3, 2014 10:59
Calculating bet profit using custom postgresql function
CREATE OR REPLACE FUNCTION bet_profit(state character varying, stake float, odds float) RETURNS float AS $$
DECLARE
result float := 0;
half_stake float :=0;
BEGIN
CASE state
WHEN 'in_process' THEN
result := 0;
WHEN 'guessed' THEN
result := (stake * odds);
@sergio1990
sergio1990 / module_inc_prep.rb
Created December 6, 2014 18:45
Difference between including and prepending modules into class
puts '===> INCLUDE EXAMPLE'
module M1
def run
puts 'M1 run'
end
end
class C1
include M1
@sergio1990
sergio1990 / capybara cheat sheet
Created September 30, 2015 08:40 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@sergio1990
sergio1990 / pipable.rb
Created October 27, 2015 14:29 — forked from pcreux/pipable.rb
*nix has pipes, Elixir has pipes, Ruby deserves pipes.
# Elixir has pipes `|>`. Let's try to implement those in Ruby.
#
# I want to write this:
#
# email.body | RemoveSignature | HighlightMentions | :html_safe
#
# instead of:
#
# HighlightMentions.call(RemoveSignature.call(email.body)).html_safe
#
#!/bin/bash
PROJECT_NAME="<YOUR-PROJECT-NAME>"
PROJECT_PATH=" ~/Work/railsapps/${PROJECT_NAME}"
CD_INTO_PROJECT="cd ${PROJECT_PATH}"
tmux has-session -t $PROJECT_NAME
if [ $? != 0 ]
then
@sergio1990
sergio1990 / cursor_shape_in_dif_mode
Last active January 18, 2016 10:19
Change cursor shape in different modes
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
@sergio1990
sergio1990 / Dockerfile
Created May 29, 2016 14:00
Elixir in Docker
FROM elixir:1.2.3
MAINTAINER Sergey Gernyak <[email protected]>
ENV MIX_ENV=prod
RUN apt-get update && apt-get install -y build-essential git-core
RUN mkdir -p /app
WORKDIR /app
@sergio1990
sergio1990 / setup_exunit_ecto_sandbox.ex
Created June 14, 2016 18:57
Setup ExUnit Ecto sandbox
setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(RemarkApi.Repo)
Ecto.Adapters.SQL.Sandbox.mode(RemarkApi.Repo, {:shared, self()})
:ok
end
@sergio1990
sergio1990 / ecto_helper.ex
Last active February 27, 2020 15:20
Prettify Ecto errors
defmodule EctoHelper do
@moduledoc """
Provides helper functions
"""
@doc """
Prettifies changeset error messages.
By default `changeset.errors` returns errors as keyword list, where key is name of the field
and value is part of message. For example, `[body: "is required"]`.
This method transforms errors in list which is ready to pass it, for example, in response of