Skip to content

Instantly share code, notes, and snippets.

@motephyr
motephyr / gist:e947e98b527e11bc5cb6963c2f632b60
Last active January 18, 2018 03:11
elixir phoneix install (mac os environment)
brew update
brew install elixir
mix local.hex
mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez
//install node.js版本(建議8.0之後)
//install postgres版本(建議至少9.4之後)
取得dev.secret.exs
設定資料庫 mix ecto.setup
@motephyr
motephyr / gist:3e32513549f586042ec9ae2cb75e2c98
Created November 7, 2017 09:41
Guardian router pipline
...
pipeline :api do
plug :accepts, ["json"]
plug Guardian.Plug.Pipeline, module: GuardianSimpleAuth.Guardian, error_handler: GuardianSimpleAuth.ErrorHandler
plug Guardian.Plug.VerifySession, claims: %{"typ" => "access"}
plug Guardian.Plug.VerifyHeader, claims: %{"typ" => "access"}
plug Guardian.Plug.LoadResource, allow_blank: true
end
pipeline :auth do
@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
@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 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
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
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
import Ecto.Query
alias YourApp.Repo
alias YourApp.User
#(這也許是一個改名字的流程)
#你要query user.id = 1的人
#抓到這個人之後
#改他的名字
#更新
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:house_id])
|> cast_attachments(params, [:image], allow_paths: true)
|> validate_required([:image, :house_id])
end
目標:盡可能讓使用者使用上覺得迅速。
改進點:資料下載量少,下載速度快、反應速度快。
Single Page Application:
優點
1.更好的用户体验,让用户在web app感受native app的速度和流畅,
2.於第一次載入時將html,css,js等預先載入,
其後只需透過ajax(非同步載入)方式做資料的傳輸,資料傳輸量較少,只需取得資料即可展現畫面