Skip to content

Instantly share code, notes, and snippets.

Avatar

Fabian Zitter Ninigi

  • Tokyo, Japan
View GitHub Profile
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 / hide_and_show.js
Last active Mar 23, 2020
How to hide and show payment gateways in shopify checkout (COD)
View hide_and_show.js
// The Payment Gateway / Shippnig Method can be internationalized,
// if the shop does not use this internationalization, use ["Cash on Delivery (COD)"]
var CODGatewayNames = ["代金引換", "Cash on Delivery (COD)"],
CODShippingNames = ["代金引換", "Cash on Delivery"],
radioButtonSelector = ".radio__input .input-radio";
function toggleCODPayment(shippingElement) {
var isCOD = function(el) {
var label = el.querySelectorAll(".radio__label__primary")[0];
var labelText = label ? label.textContent.trim().toLowerCase() : "";
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 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 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 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 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()
You can’t perform that action at this time.