Skip to content

Instantly share code, notes, and snippets.

View aleandros's full-sized avatar
💻
Building!

Edgar Cabrera aleandros

💻
Building!
View GitHub Profile
@aleandros
aleandros / config.el
Created August 18, 2020 00:21
Doom.d emacs configuration
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;; Place your private configuration here! Remember, you do not need to run 'doom
;; sync' after modifying this file!
;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets.
(setq user-full-name "E..."
user-mail-address "e....")

Keybase proof

I hereby claim:

  • I am aleandros on github.
  • I am aleandros (https://keybase.io/aleandros) on keybase.
  • I have a public key ASDuXGZwmWw69y2N5o5gVX2XWRbgm1_Nkg8ZhZXZeJWTSQo

To claim this, I am signing this object:

@aleandros
aleandros / ecto_model_relationships_non_defaults.ex
Last active March 22, 2017 19:08
Ecto model relationships with non-default column names
defmodule MyApp.User do
use MyApp.Web, :model
@primary_key {:UserId, :id, autogenerate: true}
schema "user" do
has_one :credential, MyApp.Credential,
foreign_key: :UserId,
references: :UserId
many_to_many :roles, MyApp.Role,
join_through: MyApp.UserRole,
@aleandros
aleandros / ecto_model_correct_access.ex
Created March 22, 2017 18:57
Ecto model access field with uppercase
[bank|_] = Repo.all(Bank)
bank.'BankId' # That's it. That's all it takes and it works
# Same for database queries
query = from b in Bank,
where: b.'BankName' == "Bank Inc"
@aleandros
aleandros / ecto_field_query_legacy.ex
Created March 22, 2017 18:52
Ecto field example for legacy databases
query = from b in Bank,
where: field(b, :BankName) == "Bank Inc."
@aleandros
aleandros / ecto_model_non_default_access.ex
Created March 22, 2017 18:46
Ecto model access with CamelCase column names
[bank|_] = Repo.all(Bank)
# bank is a struct. Structs are maps.
%{BankId: id} = bank # this works
Map.get(bank, :BankId) # this works too
bank.BankId # This does not compile.
# Ecto queries would break as well
@aleandros
aleandros / ecto_model_default_access.ex
Created March 22, 2017 18:39
Ecto Model default access
[bank|_] = Repo.all(Bank)
bank.id # Everything works as expected.
@aleandros
aleandros / ecto_schema_non-defaults.ex
Created March 22, 2017 18:06
Ecto schema non-default conventions
defmodule MyApp.Bank do
use MyApp.Web, :model
@primary_key {:BankId, :id, autogenerate: true} # 1
schema "bank" do # 2
field :BankName, :string # 3
timestamps(inserted_at: :BankCreateDate, # 4
updated_at: :BankUpdateDate)
end
end
@aleandros
aleandros / ecto_schema_defaults.ex
Created March 22, 2017 18:01
Ecto schema with defaults
defmodule MyApp.Bank do
use MyApp.Web, :model
schema "banks" do
field :name, :string
timestamps()
end
end
class Symbol
def to_proc
proc do |obj|
obj.send(self)
end
end
end