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 / open_binary_file.erl
Last active March 16, 2016 13:48
Erlangでフィアルをバイナリコードで開く
-module(open_binary_file).
-compile(export_all).
% read_file(Filename) -> {ok, Binary} | {error, Reason}
% 4> c(open_binary_file).
% {ok,open_binary_file}
% 5> open_binary_file:read_file("prime.erl").
% [<<"#!/usr/bin/env escript">>,<<>>,<<"main(_) ->">>,
% <<" Res = prime_list(1000),">>,
% <<" io:format(\"~p~n\", [length(Res)]).">>,<<>>,<<"prime_list(Num)->">>,
@wang-zhijun
wang-zhijun / .bash_profile
Created August 21, 2015 00:06
自分のBash Prompt
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "[${BRANCH}${STAT}]"
else
echo ""
fi
@wang-zhijun
wang-zhijun / .tmux.conf
Last active October 21, 2015 13:52
自分の.tmux.confファイル
# Our .tmux.conf file
# Setting the prefix from C-b to C-a
# START:prefix
set -g prefix C-a
# END:prefix
# Free the original Ctrl-b prefix keybinding
# START:unbind
unbind C-b
@wang-zhijun
wang-zhijun / selet_gc_bucket.erl
Last active March 16, 2016 13:46
RiakCS select gc bucket
%% #!/usr/bin/env escript
%% ---------------------------------------------------------------------
%%
%% Copyright (c) 2015 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
@wang-zhijun
wang-zhijun / offline_delete.erl
Last active March 16, 2016 13:45
RiakCS offline delete
#!/usr/bin/env escript
%% ---------------------------------------------------------------------
%%
%% Copyright (c) 2015 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
@wang-zhijun
wang-zhijun / create_vm.sh
Last active January 12, 2016 00:36
IDCFクラウドで自動的にVM作成、CentOS 6.5 64-bit限定、事前にプライベート鍵の登録が必要
#!/usr/bin/env bash
# VM名を入力、Enter押して、Ctrl-dを押す
echo -n "VM名を入力: "
read VM_NAME
# Portを入力、Enter押して、Ctrl-dを押す
echo -n "SSHでログインするためのパブリックポートを入力: "
read PUBLIC_PORT
@wang-zhijun
wang-zhijun / ssh-router.exs
Created January 29, 2016 02:40 — forked from fredhsu/ssh-router.exs
SSH to router using Elixir
:ssh.start
{:ok, cref} = :ssh.connect('10.55.3.1', 22, [{:user, 'user'}, {:password, 'password'}])
{:ok, cid} = :ssh_connection.session_channel(cref, 5000)
:ssh_connection.exec(cref, cid, String.to_char_list("show ver | xml | no-more"), 3000)
#:ssh_connection.exec(cref, cid, String.to_char_list("show core"), 3000)
# need to do a receive on the cref(pid)
#flush() -- useful to find out what the result will look like
receive do
{:ssh_cm, _, {:data, _, _, d}} -> IO.puts d
end
@wang-zhijun
wang-zhijun / install-vim74-centos
Last active February 10, 2016 04:14 — forked from juxtin/vim74centos
Compile Vim 7.4 on Centos and install my vimrc
#!/bin/bash
yum groupinstall 'Development tools' -y
yum install ncurses ncurses-devel wget git -y
cd /usr/local/src
wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
tar -xjf vim-7.4.tar.bz2
cd vim74
./configure --prefix=/usr --with-features=huge --enable-rubyinterp --enable-pythoninterp
make && make install
@wang-zhijun
wang-zhijun / observer.md
Created March 9, 2016 05:33 — forked from pnc/observer.md
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
@wang-zhijun
wang-zhijun / erlang_elixir_binary.md
Last active March 9, 2016 08:26
Erlang and Elixir Binary

Erlangのバイナリは一つの要素が255を越えると切断とされます。つまり8bitしか取らない。

11> Bin11 = <<1, 255>>.
<<1,255>>
12> erlang:binary_to_list(Bin11).
[1,255]
13> f().
ok
14> Bin11 = <<1, 256>>.