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 / last_friday.py
Last active March 16, 2016 13:35
Pythonで直近の前の金曜日の日付を調べる
#!/usr/bin/env python
import datetime, calendar
def find_last_friday():
# output: 2013-12-06
last_friday = datetime.date.today()
# output: 1 day, 0:00:00
@wang-zhijun
wang-zhijun / python_zipfile.py
Last active March 16, 2016 13:47
Python zip file
#!/usr/bin/env python
import zipfile
z = zipfile.ZipFile("/home/wzj/Downloads/7za920.zip", "r")
for filename in z.namelist():
print 'File: ', filename
@wang-zhijun
wang-zhijun / random_password.py
Last active March 16, 2016 13:37
Pythonでランダムに8桁のパスワードを生成
#!/usr/bin/env python
from random import choice
import string
def GetPasswd(length=8, chars = string.letters+string.digits):
return ''.join([choice(chars) for i in range(length) ])
@wang-zhijun
wang-zhijun / gcd.py
Last active March 16, 2016 13:49
Pythonでgcdを計算
#!/usr/bin/env python
def gcd(a, b):
"""Calculate the Greatest Common Divisor of a and b.
Unless b==0, the result will have the same sign as b (so that when
b is divided by it, the result comes out positive).
"""
while b:
a, b = b, a%b
@wang-zhijun
wang-zhijun / split_web_page_vertically.html
Last active March 16, 2016 13:32
Split web page vertically in HMTL
<html>
<head>
<style>
#column1 {
float:left;
width: 33%;
}
#column2 {
float:left;
@wang-zhijun
wang-zhijun / my-erlang-mode.md
Last active March 16, 2016 13:42
Emacsにerlang-modeを使う方法

EmacsとErlangがインストールされています。

$HOME.emacsファイルが作成して、下のようなコードを入れます。

(setq load-path (cons "/usr/local/Cellar/erlang/17.1/lib/erlang/lib/tools-2.6.15/emacs" load-path))
(setq erlang-root-dir "/usr/local/Cellar/erlang/17.1/lib/erlang/lib/")
(setq exec-path (cons "/usr/local/Cellar/erlang/17.1/lib/erlang/bin/" exec-path))
(require 'erlang-start)
@wang-zhijun
wang-zhijun / priem_list.erl
Last active March 16, 2016 13:50
Erlangで1000以内の素数を生成する
#!/usr/bin/env escript
main(_) ->
Res = prime_list(1000).
%% io:format("~p~n", [length(Res)]).
prime_list(Num)->
prime_list(Num, 3, [2]).
prime_list(Num, PP, PS) when PP >= Num ->
@wang-zhijun
wang-zhijun / binary_search.erl
Last active January 20, 2019 09:16
ErlangでBinary search インデックスを返す
-module(binary_search).
-export([binary_search/2]).
-include_lib("eunit/include/eunit.hrl").
%% > c(binary_search).
%% 5> binary_search:binary_search([], -1).
%% -1
%% 6> binary_search:binary_search([], 0).
%% -1
-module(fifo_types).
-compile(export_all).
%% 概要
%% キューをシミュレートするためにはスタックとして2つのリストを使います。
%% 片方のリストに新しい要素を保存し、もう片方を使ってキューから要素を
%% 削除します。削除するリストが空の時に要素追加するほうのリストを逆順
%% にして、そちらを削除するリストとします。
%% 2> c(fifo_types).
%% 1> T1 = tree:insert("Jim Woodland", "jim.woodland@gmail.com", tree:empty()).
%% {node,{"Jim Woodland","jim.woodland@gmail.com",
%% {node,nil},
%% {node,nil}}}
%% 2> T2 = tree:insert("Mark Anderson", "i.am.a@hotmail.com", T1).
%% {node,{"Jim Woodland","jim.woodland@gmail.com",
%% {node,nil},
%% {node,{"Mark Anderson","i.am.a@hotmail.com",
%% {node,nil},