Skip to content

Instantly share code, notes, and snippets.

Dive into Elixir

Takanori Ishikawa ishikawa

Dive into Elixir
View GitHub Profile
ishikawa / map_helpers.ex
Last active Jul 27, 2020
submap?/3 for Elixir's map. It's useful for testing API response (see submap_usage_test.exs).
View map_helpers.ex
defmodule MapHelpers do
@doc """
Checks if `map1`'s entries are all contained in `map2`.
## Options
- `:recursive` - Recursively checks if a value is map (Default: `false`)
## Examples
ishikawa / gist:3f340f1274b3eb384156355665559ed7
Created Jun 25, 2020
Login with the shell into the first matching pod returned from kubectl get pod
View gist:3f340f1274b3eb384156355665559ed7
kubectl get pod | awk '{ print $1 }' | grep '^gateway-' | head -1 | xargs -o -I {} kubectl exec -it {} -- /bin/bash
ishikawa / parameterized_test.exs
Last active Dec 10, 2019
My preferred way to write parameterized tests in Elixir.
View parameterized_test.exs
# The helper functions for the test module. To make it possible to import
# this helper module in the test module, define this module outside the context that uses it.
defmodule MyTest.Helpers do
@spec fake_params(Enumrable.t()) :: map
def fake_params(override \\ %{}) do
country: "jp",
phone_number: Faker.phone_number(),
locale: "ja",
company: "My Company",
ishikawa / function_options.ex
Last active Oct 3, 2019
Passing in options: Maps vs. Keyword lists
View function_options.ex
@doc """
do foo operation
## Options
- `:option1` - option 1
- `:option2` - option 2
ishikawa / my_module.ex
Last active Sep 22, 2019
Compile different function on Mix env and test
View my_module.ex
defmodule MyModule do
@moduledoc false
if Mix.env() == :prod do
@foo Application.fetch_env!(:myapp, :foo)
def foo, do: @foo
def foo, do: Application.fetch_env!(:myapp, :foo)
ishikawa /
Last active Jul 12, 2019
Convert phrase to kebab-case
# Type your phrase then ^D
perl -pe 'chop;s/([a-z]+)/lc($1)/ige' | perl -lpe 's/[^a-z0-9]+/-/ig'
ishikawa /
Created Mar 11, 2019
mi: 選択範囲の JSON を整形
echo -n "$2" | /usr/local/bin/jq .
View docs_before_closing_head_tag.ex
defp docs_before_closing_head_tag(:html) do
~s{<link rel="stylesheet" href="assets/doc.css">}
defp docs_before_closing_head_tag(_), do: ""
View mix.exs
def project do
apps_path: "apps",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps(),
# Docs
name: "MyProject",
ishikawa / frontmatter.toml
Created Jan 13, 2018
How to print Japanese weekdays in Hugo frontmatter.
View frontmatter.toml
date = {{ .Date }}
title = "{{ $t := now }}{{ $t.Format "1月2日"}}{{ if eq ($t.Weekday) 0 }}(日){{ end }}{{ if eq ($t.Weekday) 1 }}(月){{ end }}{{ if eq ($t.Weekday) 2 }}(火){{ end }}{{ if eq ($t.Weekday) 3 }}(水){{ end }}{{ if eq ($t.Weekday) 4 }}(木){{ end }}{{ if eq ($t.Weekday) 5 }}(金){{ end }}{{ if eq ($t.Weekday) 6 }}(土){{ end }}"
You can’t perform that action at this time.