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 / 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
# Checkout theirs unmerged files and continue rebase
git ls-files --unmerged | awk '{ print $4 }' | uniq | xargs git checkout --theirs --
git ls-files --unmerged | awk '{ print $4 }' | uniq | xargs git add --
git rebase --continue
@ishikawa
ishikawa / typespec_union.ex
Created October 3, 2016 12:17
Create union type from list
defmodule MyTypespec do
defmacro union_type({:"::", _, [name, types]}) when is_list(types) do
union =
types
|> Enum.reverse
|> Enum.reduce(fn x, acc ->
{:|, [], [x, acc]}
end)
quote do