Skip to content

Instantly share code, notes, and snippets.

View tiagopog's full-sized avatar

Tiago Guedes tiagopog

View GitHub Profile
@tiagopog
tiagopog / config_deps_cache.yml
Last active February 20, 2018 07:03
CircleCI's config by examples
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6.2-stretch-browsers
environment:
FLASK_CONFIG: testing
TEST_DATABASE_URL: postgresql://ubuntu@localhost/circle_test?sslmode=disable
- image: circleci/postgres:9.6.5-alpine-ram
environment:
@tiagopog
tiagopog / event_machine.rb
Created August 30, 2017 13:15
Event Machine usage example.
# em.rb
EM.run do
EM.add_timer(1) do
puts 'sleeping...'
EM.system('sleep 1') { puts "woke up!" }
puts 'continuing...'
end
EM.add_timer(3) { EM.stop }
end
$ ruby em.rb
puts "Iniciando deploy..."
tasks = []
tasks << Thread.new do
sleep(3)
puts "> Executar tarefa de IO intenso"
puts "= Tarefa inicial finalizada \n"
end
# 256 colors for vim
set -g default-terminal "screen-256color"
# Start window numbering at 1
set-option -g base-index 1
set-window-option -g pane-base-index 1
# Cycle panes with C-b C-b
unbind ^B
bind ^B select-pane -t :.+
# 256 colors for vim
set -g default-terminal "screen-256color"
# Start window numbering at 1
set-option -g base-index 1
set-window-option -g pane-base-index 1
# Cycle panes with C-b C-b
unbind ^B
bind ^B select-pane -t :.+
@tiagopog
tiagopog / metaprogramming_1.exs
Last active April 18, 2017 02:51
Elixir - Quoted expressions
# Quote an expression (turn it into an AST)
foobar = quote do
_ * _ = 42
end
IO.inspect(foobar)
# Define the function to be used when traversing the AST
answers = [2, 21]
put_awnsers = fn
@tiagopog
tiagopog / exprotobuf.ex
Last active April 4, 2017 12:09
Exprotobuf - Prototyping the use of :gpb.compile/2
defmodule Protobuf do
# alias Protobuf.Parser
# alias Protobuf.Builder
# alias Protobuf.Config
# alias Protobuf.ConfigError
# alias Protobuf.Field
# alias Protobuf.OneOfField
# alias Protobuf.Utils
alias Mix.Compilers.Erlang
@tiagopog
tiagopog / exercise-errors.go
Last active March 16, 2017 01:21
Go - Learning
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprintf("cannot Sqrt negative number: %f", float64(e))
@tiagopog
tiagopog / quicksort.exs
Last active February 15, 2017 14:32
Elixir - Quicksort sample
defmodule Quicksort do
def sort(list) when length(list) < 2, do: list
def sort(list) do
pivot = Enum.random(list)
less = Enum.filter(list, &(&1 < pivot))
greater = list -- (less ++ [pivot])
sort(less) ++ [pivot] ++ sort(greater)
end
end
@tiagopog
tiagopog / account.ex
Last active April 11, 2019 06:15
Elixir - Processes (spawn, send, receive, Async, Agent)
defmodule Account do
defstruct name: nil, amount: 0
def start(%Account{} = account) do
spawn fn -> run(account) end
end
defp run(account) do
account = receive do
{:debit, value} -> %{account | amount: account.amount - value}