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
class Option < ActiveRecord::Base
validates :key , :presence => {:message => '<span style= "color: red">Es necesario este Campo</span>'}
validates :key, :uniqueness => { :message => '<span style= "color: red">Ya se establecio el valor de este parametro.</span>'}
enum prime: [:no,:yes]
enum quote: [:quote_1]
VALUES_BY_DEFAULT = %w(shopping_cart_default_value
shopping_cart_max_value
minimun_weight_product
limit_quantity_product
maximun_number_product_cart
# web/services/messaging_service.ex
defmodule Publit.MessagingService do
@moduledoc """
Service to send notifications to the user
"""
@message_api Application.get_env(:publit, :message_api)
def status_code(resp) do
{_s, msg} = resp
{:error, msg}
@boriscy
boriscy / registration.ex
Created November 9, 2016 01:24
Define types on structs Elixir
defmodule Registration do
defstruct [:email, :password, :name, :category, :address]
@type t :: %RegistrationService{
email: String.t,
password: String.t,
name: String.t,
category: String.t,
address: String.t
}
@boriscy
boriscy / queries.md
Last active August 3, 2016 14:45
Guide for queries done on PostgreSQL

JSON, JSONB

Select inside a json field with array

select f.id, f.file_name, p->'trade_name' as trade_name, m->'cin_add' as cin_add
from frac_reports f, jsonb_array_elements((f.data->>'products')::jsonb) p,
jsonb_array_elements(p->'materials') m
where f.id = 65933
@boriscy
boriscy / permit_and_plug_ohio.js
Created July 26, 2016 19:31
Download data for Permits and Plug for Ohio
var casper = require('casper').create();
var url = 'http://apps.ohiodnr.gov/oilgas/rbdmsreports/Downloads_PermitAndPlug.aspx';
casper.userAgent("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36");
casper.start(url);
casper.then(function(arg) {
//this.capture('a.png', {top: 100, left: 100, width: 700, height: 500});
this.fillSelectors('#aspnetForm', {
'#ctl00_ContentPlaceholder1_rdp_ApplicationIssuedStart_dateInput': '12/1/2014',
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