Skip to content

Instantly share code, notes, and snippets.

View ishikawa's full-sized avatar
🏠
Working from home

Takanori Ishikawa ishikawa

🏠
Working from home
View GitHub Profile
@ishikawa
ishikawa / parameterized_test.exs
Last active December 10, 2019 12:18
My preferred way to write parameterized tests in Elixir.
# 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
ishikawa / function_options.ex
Last active October 3, 2019 06:45
Passing in options: Maps vs. Keyword lists
# https://elixirforum.com/t/passing-in-options-maps-vs-keyword-lists/1963
@doc """
do foo operation
## Options
- `:option1` - option 1
- `:option2` - option 2
"""
@ishikawa
ishikawa / my_module.ex
Last active September 22, 2019 15:06
Compile different function on Mix env and test
defmodule MyModule do
@moduledoc false
if Mix.env() == :prod do
@foo Application.fetch_env!(:myapp, :foo)
def foo, do: @foo
else
def foo, do: Application.fetch_env!(:myapp, :foo)
end
end
@ishikawa
ishikawa / kebab.sh
Last active July 12, 2019 07:12
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
ishikawa / format_json.sh
Created March 11, 2019 03:23
mi: 選択範囲の JSON を整形
#!/bin/bash
#replace_selected
echo -n "$2" | /usr/local/bin/jq .
defp docs_before_closing_head_tag(:html) do
~s{<link rel="stylesheet" href="assets/doc.css">}
end
defp docs_before_closing_head_tag(_), do: ""
def project do
[
apps_path: "apps",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps(),
# Docs
name: "MyProject",
@ishikawa
ishikawa / frontmatter.toml
Created January 13, 2018 15:32
How to print Japanese weekdays in Hugo frontmatter.
+++
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 }}"
+++
@ishikawa
ishikawa / gist:c15be01833123ce8c742677896ed73e9
Created August 23, 2017 01:21
Create public/private key pair by openssl
# Create a private key
$ openssl genrsa -out private-key.pem 2048
# and public key
$ openssl rsa -in private-key.pem -pubout -out public-key.pem
@ishikawa
ishikawa / gist:9d76b4cefb9049a2dcf80dc9b3db0895
Last active September 7, 2017 04:26
Delete local branches except master/deployment/current
git branch | grep -v -e 'master' -e 'deployment/' -e 'develop' -e '*' | xargs git branch -D