Skip to content

Instantly share code, notes, and snippets.

Avatar

Fabian Zitter Ninigi

  • Tokyo, Japan
View GitHub Profile
View credential.ex
defmodule DripperExample.Accounts.Credential do
use Ecto.Schema
import Ecto.Changeset
alias DripperExample.Accounts
schema "credentials" do
field :email, :string
belongs_to :user, Accounts.User
timestamps()
View accounts_test.exs
describe "credentials" do
alias DripperExample.Accounts.Credential
@valid_attrs %{email: "some email"}
@update_attrs %{email: "some updated email"}
@invalid_attrs %{email: nil}
def build_valid_attrs(attrs \\ %{}) do
{:ok, user} = Accounts.create_user(%{name: "some name", username: "some username"})
View find_user_test.exs
defmodule DripperExample.FindUserTest do
use DripperExample.DataCase
alias DripperExample.{
Accounts,
AccountUsers
}
describe "find_user/1" do
test "finds a user for given username" do
View account_users.ex
defmodule DripperExample.AccountUsers do
alias DripperExample.{
Repo,
Accounts,
UserQuery
}
def find_user(args) do
Accounts.User
|> UserQuery.query_username(args)
View find_user_test.exs
defmodule DripperExample.FindUserTest do
use DripperExample.DataCase
alias DripperExample.{
Accounts,
AccountUsers
}
describe "find_user/1" do
test "finds a user for given username" do
View account_users.ex
defmodule DripperExample.AccountUsers do
alias DripperExample.{
Repo,
Accounts,
UserQuery
}
def find_user(args) do
Accounts.User
|> UserQuery.query_username(args)
View fall_through_ecto_query.ex
# Without EctoDripper
defmodule QueryModule do
def query_status(query, args)
def query_status(query, %{username: username}) do
# Create query when username key is in args
# Since we have the key already in the function name,
# I find this quite pointless in terms of readability
from(
thing in query,
where: thing.username == ^username
View mix.exs
defmodule Useless.Mixfile do
# ...
# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.3.0"},
{:phoenix_pubsub, "~> 1.0"},
@Ninigi
Ninigi / select_default_shipping.js
Last active Jul 6, 2018
Force a default value for the shipping methods in shopify checkout to be selected on page load.
View select_default_shipping.js
var preferedShipping = "EMS"; // This has to be the exact name of the shipping method you want to be preselected
function waitForFetch(tries, callback) {
if (tries > 40000) {return} // stop waiting after ~ 40 seconds
if (document.querySelector(".blank-slate")) {
setTimeout(function() { waitForFetch(tries + 1, callback) }, 10);
} else {
callback();
}
View new.html.eex
<h2>New Shop</h2>
<%= render "signup_form.html", Map.put(assigns, :action, shop_path(@conn, :signup)) %>
You can’t perform that action at this time.