Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / worker.ex
Last active March 13, 2018 04:37
global variable
defmodule Dresser.Worker do
@moduledoc "The store, based on `Agent`."
def start_link do
result = Agent.start_link(fn -> %{} end, name: __MODULE__)
__MODULE__.put(:free_dress, 3)
result
end
alias Bootleg.{UI, Config}
use Bootleg.DSL
# Configure the following roles to match your environment.
# `build` defines what remote server your distillery release should be built on.
#
# Some available options are:
# - `user`: ssh username to use for SSH authentication to the role's hosts
# - `password`: password to be used for SSH authentication
# - `identity`: local path to an identity file that will be used for SSH authentication instead of a password
FROM ubuntu:16.04
# Avoid error messages from apt during image build
ARG DEBIAN_FRONTEND=noninteractive
RUN \
apt-get update && \
apt-get install -y wget curl gnupg
//-----types.graphql
type Post {
id: Int
user_id: Int
title: String
description: String
created_at: Date
updated_at: Date
}
//當你需要依照作者列出個人所有的文章時:
query Users{
users {
id
username
posts {
title
description
}
}
const DataLoader = require('dataloader')
/**
* Creates a dataloader for a supplied model.
*
* @param {String} model e.g. 'App/Models/User'
* @param {String} ref_id e.g. 'order_id'
* @returns {DataLoader}
*/
function createLoader(model, ref_id = 'id', has = 'one') {
const createLoader = require('../Helpers/loaders/createLoader')
/**
* Define your loaders here.
* Each key should be a valid
* instance of DataLoader.
*/
const loaders = () => ({
user_group: createLoader('App/Models/UserGroup'),
user_personal_data: createLoader('App/Models/PersonalData', 'user_id'),
// app/data/resolvers.js
const resolvers = {
Query: {
...
async users() {
const users = await User.all()
return users.toJSON()
},
...