Skip to content

Instantly share code, notes, and snippets.

View wang-zhijun's full-sized avatar

WANG ZHIJUN wang-zhijun

  • Tokyo
View GitHub Profile
@wang-zhijun
wang-zhijun / capistrano.md
Last active February 18, 2020 11:14
Capistranoメモ

Capistranoを使うメモ

$ bundle init

GemfileにCapistranoを入れる

 # A sample Gemfile
 source "https://rubygems.org"
@wang-zhijun
wang-zhijun / elixir_anonymous_function.ex
Last active March 15, 2016 10:07
Elixirの関数に無名関数を定義して、List.foldlに使う例
defmodule Hhfuns do
def a(o, p, q) do
fn(num, acc) ->
IO.puts "#{inspect o}, #{inspect p} #{inspect q}"
num + acc
end
end
end
x = Hhfuns.a("ooo", "ppp", "qqq")
IO.puts "x = #{inspect x}" ## x = #Function<0.111962536/2 in Hhfuns.a/3>
@wang-zhijun
wang-zhijun / erlang_elixir_conversion.md
Last active March 16, 2016 14:00
ElixirとErlangの間の変換

Erlang, Elixir間の変換

Erlang

1> element(2, {a, b, c}). %% インデックスは1ベース
b

Elixir

iex(1)&gt; elem({:a,:b,:c}, 1) ## インデックスは0ベース
@wang-zhijun
wang-zhijun / riak_usage.md
Last active August 24, 2016 00:42
riak-erlang-clientの使い方

Riakにコネクションを貼る

iex(1)> {:ok, pid} = :riakc_pb_socket.start_link('*.*.*.*', 8087)
{:ok, #PID<0.191.0>}
iex(2)> :riakc_pb_socket.ping(pid)
:pong

Riakオブジェクトを作成して,Riakに保存する

@wang-zhijun
wang-zhijun / elixir_exrm_rpc.md
Created March 25, 2016 08:40
ElixirのexrmライブラリのRPC機能を使う
$ rel/riakcscalc/bin/riakcscalc rpc Elixir.RiakcsCalc.StorageConsole batch "['1']."
options is  :"1"
options is atom true

$ rel/riakcscalc/bin/riakcscalc rpc Elixir.RiakcsCalc.StorageConsole batch "[\"1\"]."
options is  '1'
options is list true
@wang-zhijun
wang-zhijun / io_fwrite_format.md
Created April 6, 2016 02:29
Erlangのioモジュールのformat

Erlangのioモジュールの出力フォーマットの一部をチェックしてみる

数字97を2桁で出力

54> io:fwrite("|~2b|~n", [97]).
|97|
ok

数字97を3桁で出力

@wang-zhijun
wang-zhijun / emacs_lisp_snippets.md
Last active July 11, 2016 12:26
Emacs Lisp Snippet

my-hello-emacs関数を定義して,呼び出す

(defun my-hello-emacs()
  (message "hello emacs"))
(my-hello-emacs) ; my-hello-emacs関数を呼び出す

文字列FOOを変数fooに代入.'quote関数の略称

@wang-zhijun
wang-zhijun / rebar3_cowoby_echo_get.md
Last active April 9, 2016 17:09
rebar3を使ってcowboyのアプリケーションを作成

rebar3を使ってcowboyのアプリケーションを作成,ソースコード

$ rebar3 new release echo_get
$ cd echo_get

echo_getrebar.configファイルのdeps部分をcowobyを入れる

{deps, [
@wang-zhijun
wang-zhijun / emacs.md
Last active March 10, 2024 10:34
Emacs使い方

CentosにEmacs のinstall

yum remove emacs-nox emacs-filesystem emacs-common
yum install gcc ncurses-devel
cd /opt
wget http://ftp.gnu.org/pub/gnu/emacs/emacs-25.3.tar.gz
tar zxvf emacs-25.3.tar.gz
cd /opt/emacs-25.3
./configure --without-x
make
@wang-zhijun
wang-zhijun / ets.md
Last active June 27, 2016 02:59
ETSテーブル
  • ETSのgive_away関数の使い方
1> Pid = spawn(fun () -> receive foo -> ok end end). %% Erlang Shellから一個のプロセスを作成
<0.35.0>

2> Tab = ets:new(x, [public]). %% 新規作成したETSテーブルのownerはErlang Shell 
16400

3> self().