Skip to content

Instantly share code, notes, and snippets.

@marciol
marciol / with.exs
Created April 15, 2016 14:25 — forked from nsomar/with.exs
Handling errors with `with`
res =
with {:ok} <- validate_request(request),
{:ok, user} <- get_user(request),
{:ok} <- update_db(user),
{:ok} <- send_email(user) do
return_http_message
end
case res do
{:error, x} -> IO.inspect("Error: " <> x)
@marciol
marciol / postgres_queries_and_commands.sql
Created October 21, 2016 17:03 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
Pry.config.editor = "vim --noplugin"
if defined?(PryByebug)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
Pry.commands.alias_command 'b', 'break'
Pry.commands.alias_command 'bda', 'break --disable-all'
end
import (
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"github.com/lib/pq"
_ "github.com/lib/pq"
"math/rand"
"net/url"
"strings"
@marciol
marciol / config.ex
Created February 22, 2017 18:08 — forked from bitwalker/config.ex
Useful config wrapper for Elixir
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
"""
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.
@marciol
marciol / second.erl
Created February 26, 2017 02:29
Functional Erlang Mooc
-module(second).
-export([hypotenuse/2, perimeter/2]).
hypotenuse(A, B) ->
AA = first:square(A),
BB = first:square(B),
math:sqrt(AA + BB).
perimeter(A, B) ->
C = hypotenuse(A, B),
@marciol
marciol / vim_remove_unicode
Created June 16, 2017 19:39
VIM - Remove zero-width spaces
# Remove zero-width spaces
:%s/\%u200b//g
@marciol
marciol / vim_remove_unicode
Created June 16, 2017 19:39
VIM - Remove zero-width spaces
# Remove zero-width spaces
:%s/\%u200b//g
@marciol
marciol / psql-with-gzip-cheatsheet.sh
Created October 30, 2018 20:23 — forked from brock/psql-with-gzip-cheatsheet.sh
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database