Skip to content

Instantly share code, notes, and snippets.

View boriscy's full-sized avatar
🏠
Working from home

Boris Barroso boriscy

🏠
Working from home
  • Lead With Purpose
  • Samaipata, Bolivia
View GitHub Profile
defmodule Brote.Ledger do
@moduledoc """
This is the module where most of the transactions happen
"""
use Brote.Web, :model
import Ecto.Query
alias Brote.{Category, Contact, Payment, Organization, Ledger, Repo}
@derive {Poison.Encoder, only: [:id, :amount, :balance, :date, :contact_id, :category_id, :description, :currency,
alias Cart.{Repo, Item, Invoice, InvoiceItem}
Repo.insert(%Item{name: "Chocolates", price: Decimal.new("5")})
Repo.insert(%Item{name: "Gum", price: Decimal.new("2.5")})
Repo.insert(%Item{name: "Milk", price: Decimal.new("1.5")})
Repo.insert(%Item{name: "Rice", price: Decimal.new("2")})
defmodule Bonsai.Payment do
use Bonsai.Web, :model
alias Bonsai.{User, Ledger, Repo}
@zero Decimal.new(0)
@primary_key {:id, :binary_id, autogenerate: true}
embedded_schema do
field :amount, :decimal
field :date, Ecto.Date
@boriscy
boriscy / user_session.rb
Created June 10, 2016 14:11
Stores state user
class UserSession
class << self
attr_reader :user
delegate :id, :email, to: :user
# Stores using de application_controller the current_user for devise
def user=(usr)
raise 'You must pass a User class' unless usr.is_a?(User)
@user = usr
end
@boriscy
boriscy / tutorial.md
Last active June 28, 2016 22:50
Ecto tutorial
mix new ecto_tut --module EctoTut

* creating README.md
* creating .gitignore
* creating mix.exs
* creating config
* creating config/config.exs
* creating lib
* creating lib/ecto_tut.ex
@boriscy
boriscy / description.md
Last active March 19, 2020 19:50
Phoenix + React + Elm config with webpack

Attemp to make work react with elm on a phoenix project.

The project directory for elm is

web
├── channels
├── controllers
│   └── api
│   └── v1
@boriscy
boriscy / map.ex
Created March 9, 2016 22:06
Elixir notes
alias Hello.User
user = Repo.get!(User, 1)
umap = Map.delete(Map.from_struct(user), :__meta__)
to_string Poison.Encoder.encode(umap, [])
$.ajax({
headers: {token: 'OUy_IJxQveSiKGYPPqYQnAumNCSJSilBAX5A9upF4JU'},
method: "POST",
url: "http://demo.bonsaierp.com/api/v1/incomes",
data: {
income: {
"date":"2015-11-13",
"due_date":"2015-11-16",
"contact_id":1,
"currency":"BOB",
class CodigoControlGen
# Verhoeff Digit table variables
TABLE_D = [
[0,1,2,3,4,5,6,7,8,9],
[1,2,3,4,0,6,7,8,9,5],
[2,3,4,0,1,7,8,9,5,6],
[3,4,0,1,2,8,9,5,6,7],
[4,0,1,2,3,9,5,6,7,8],
[5,9,8,7,6,0,4,3,2,1],
[6,5,9,8,7,1,0,4,3,2],
@boriscy
boriscy / items-count.json
Last active September 24, 2015 22:34
JSON responses bonsaiERP API for items
{
"count": 88
}