Skip to content

Instantly share code, notes, and snippets.

id
binary_id
integer
float
boolean
string
binary
{:array, inner_type}
{:map, inner_type}
map
@motephyr
motephyr / gist:e5db9a0682008e9a7e4d88a0f459023e
Created July 10, 2017 08:48
middle2 執行elixir phoenix專案
Aptfile加入
wget
=======================
m2-build.sh chmod 755,加入
export HOME=/root
wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && dpkg -i erlang-solutions_1.0_all.deb
apt-get update -y
目標:盡可能讓使用者使用上覺得迅速。
改進點:資料下載量少,下載速度快、反應速度快。
Single Page Application:
優點
1.更好的用户体验,让用户在web app感受native app的速度和流畅,
2.於第一次載入時將html,css,js等預先載入,
其後只需透過ajax(非同步載入)方式做資料的傳輸,資料傳輸量較少,只需取得資料即可展現畫面
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:house_id])
|> cast_attachments(params, [:image], allow_paths: true)
|> validate_required([:image, :house_id])
end
import Ecto.Query
alias YourApp.Repo
alias YourApp.User
#(這也許是一個改名字的流程)
#你要query user.id = 1的人
#抓到這個人之後
#改他的名字
#更新
result = from(u in User, where: u.id == 1) |> Repo.one |> Repo.preload(:user_info)
result = from(u in User, where: u.id == 1, preload: [:user_info]) |> Repo.one
@motephyr
motephyr / .ex
Last active September 11, 2017 16:46
defmodule BidhouseWeb.HouseBidController do
use BidhouseWeb, :controller
alias Bidhouse.Origins
alias Bidhouse.Origins.HouseBid
alias Bidhouse.Coherence.User
alias BidhouseWeb.HouseEmail
alias BidhouseWeb.Coherence.Mailer
@motephyr
motephyr / .ex
Created September 11, 2017 17:31
#...
@spec init(Keyword.t) :: [tuple]
def init(opts) do
login =
case opts[:login] do
true -> true
fun when is_function(fun) ->
fun
other ->
case opts[:protected] do
@motephyr
motephyr / .ex
Created September 12, 2017 04:59
def password_match(conn, _) do
owner = Coherence.current_user(conn)
house = conn.assigns[:house]
password = conn.params["house_bid"]["password"]
result = Config.user_schema.checkpw(password, Map.get(owner, Config.password_hash))
if result do
conn
else
@motephyr
motephyr / .ex
Created September 12, 2017 05:04
defmodule BidhouseWeb.Router do
use BidhouseWeb, :router
use Coherence.Router # Add this
use ExAdmin.Router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery