Skip to content

Instantly share code, notes, and snippets.

@leandrocp
leandrocp / app-name.component.js
Last active March 8, 2016 17:56
Basic Component Render
import Ember from 'ember';
export default Ember.Component.extend({
appName: 'SISPREV COMPONENT'
});
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: pass123
host: localhost
port: 5432
development:
@leandrocp
leandrocp / database.yml
Last active February 5, 2016 00:08
rails database config
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: pass123
host: localhost
port: 5432
development:
@leandrocp
leandrocp / elixir_immutability.ex
Last active January 7, 2016 17:58
Ruby vs Elixir immutability
# elixir
ages = [10, 18, 25]
def calc(x) do
# reuse x for some reason
List.delete(x, 10)
end
calc(ages)
ages
@leandrocp
leandrocp / elixir_with.ex
Last active April 10, 2016 05:48
Elixir With special form
case File.read("my_file.ex") do
{:ok, contents} ->
case Code.eval_string(contents) do
{res, _binding} ->
{:ok, res}
error ->
error
error -> error
error
end
@leandrocp
leandrocp / elixir_pipe.ex
Last active January 7, 2016 16:30
Elixir Pipe Operator
# Find customer, get all his orders, calc 5% tax
# Multiple line
customer = DB.find_customer(20)
orders = DB.find_orders_of_customer(customer)
taxed_orders = tax_orders(orders, 5)
# One line
tax_orders(DB.find_orders_of_customer(DB.find_customer(20)), 5)
@leandrocp
leandrocp / elixir_pattern_matching.ex
Last active January 7, 2016 16:18
Elixir Pattern Matching
iex> x = 1
1
iex> 1 = x
1
iex> 2 = x
** (MatchError) no match of right hand side value: 1
@leandrocp
leandrocp / elixir_parallel.exs
Last active January 6, 2016 16:51
Elixir Parallel Example. Based on https://www.manning.com/books/elixir-in-action ch 5
# function that blocks for 2 seconds and return the param
slow_calc = fn(input) ->
:timer.sleep(2000)
input
end
1..5 |> Enum.map(&slow_calc.(&1)) # call slow_calc from 1 to 5
#> [1, 2, 3, 4, 5] # takes 10 seconds to return (2 secs each)
# parellelize slow_calc
@leandrocp
leandrocp / lotus_db_mig_doc.rb
Created January 5, 2016 12:58
Lotus DB Migrations Tips 6
Lotus::Model.migration do
up do
create_table :my_table do
column :code, :integer, null: false
end
execute %Q(COMMENT ON TABLE my_table IS 'You should do it')
execute %Q(COMMENT ON COLUMN my_table.code IS 'Easy and useful')
end
end
@leandrocp
leandrocp / lotus_db_index.rb
Created January 5, 2016 12:57
Lotus DB Migrations Tips 4
Lotus::Model.migration do
up do
create_table :my_table do
column :code, :integer, null: false
index :code
end
end
end