git server on ubuntu

ubuntu 14.04 LTS

1
2
3
# sudo add-apt-repository ppa:git-core/ppa && sudo apt-get update #如果要安裝最新版就要先裝ppa
sudo apt-get install git git-core
git --version

on server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#建立git server所使用的路徑。/opt/git也可以。
cd /var
sudo mkdir git

sudo groupadd git #這裡使用群組的方式控制存取git server的權限
sudo usermod -a -G git useraccount # useraccount要改成要存取git server的帳號。每次有新的使用者要加入時也要做一次。

cd /var/git
sudo mkdir new_project.git
cd new_project.git
sudo git init --bare --shared
#修改專案路徑的owner和權限,每次建新專案的路徑時都要做。
sudo chgrp -R git /var/git
sudo chmod g+rwx -R /var/git

on client

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#第一次使用git時會被強制要求提做識別資訊。雖然之後要改也不是不是,可是git log裡會是舊的資訊。
git config --global user.email "useraccount@gmail.com"
git config --global user.name "useraccount"

#建立local的專案路徑並關連到git server
cd ~
mkdir new_project
cd new_project
git init
git remote add origin ssh://useraccount@serverhost/var/git/new_project.git/

#push到git server
git status
git add .
git commit -m 'first commit'
git push origin master

#若發生error: src refspec master does not match any. 那是因為不允許push空目錄。隨便加個檔案就好。
touch README.md
git status
git add README.md
git commit -m 'add README.md'
git push origin master
git log

#有時git server上的專案已有內容時,push會出錯。必需先pull下來。
git pull origin master
git log

d3

hbar

test embeded d3

postgresql

install postgresql 9.5 on ubuntu14.04

1
2
3
4
sudo sh -c ‘echo “deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main” >> /etc/apt/sources.list.d/pgdg.list’
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O – | sudo apt-key add –
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

login and create table

sudo su – postgres
psql

1
2
3
4
5
6
7
8
\conninfo
create table test (name char(12));
select * from test;
insert into test select 'aaa';
insert into test select 'aaabbb';
insert into test select 'aaabbbccc';
select * from test;
\q

exit

install pgadmin3

sudo apt-get install pgadmin3

instal postgresql 9.5 via rpm on CentOS/RHEL/Fendora

CentOS/RHEL 7
rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm

CentOS/RHEL 6
rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

CentOS/RHEL 5
rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-5-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

Fedora 23
rpm -Uvh http://yum.postgresql.org/9.5/fedora/fedora-23-x86_64/pgdg-fedora95-9.5-3.noarch.rpm

Fedora 22
rpm -Uvh http://yum.postgresql.org/9.5/fedora/fedora-22-x86_64/pgdg-fedora95-9.5-3.noarch.rpm

Fedora 21
rpm -Uvh http://yum.postgresql.org/9.5/fedora/fedora-21-x86_64/pgdg-fedora95-9.5-2.noarch.rpm

yum install postgresql95-server postgresql95
/usr/pgsql-9.5/bin/postgresql95-setup initdb

start/enable

CentOS/RHEL 7 and Fedora 23
systemctl start postgresql-9.5
systemctl enable postgresql-9.5

CentOS/RHEL 6/5 and Fedora 22/21
service postgresql-9.5 start
chkconfig postgresql-9.5 on

login

su - postgres
psql

password

1
\password postgres

sudo su postgres -c psql postgres

1
2
alter user postgres with password 'assignednewpassword';
\q

sudo passwd -d postgres
sudo su postgres -c passwd

configure postgresql

sudo vi /etc/postgresql/9.0/main/postgresql.conf

1
2
3
4
#listen_addresses = ‘localhost’
listen_addresses = ‘*’
#password_encryption = on
password_encryption = on

sudo vi /etc/postgresql/9.0/main/pg_hba.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
#"local" is for Unix domain socket connections only
#開放本地端同資料庫使用者帳號的 linux 使用者可以不用密碼從本機登入系統
local all all ident sameuser
#IPv4 local connections: IPV4本地端
host all all 127.0.0.1/32 ident sameuser
#IPv6 local connections: IPV6本地端
host all all ::1/128 ident sameuser

#IPv4 local connections:
#可以透過 tcp/ip 從 127.0.0.1/32 及 110.111.69.0/24 登入
host all all 127.0.0.1/32 md5
host all all 110.111.69.0/24 md5

#本地端的使用者使用 Unix domain socket及 md5 密碼登入
local all all md5

create user and database

1
2
3
4
5
create user testuser with password 'password4testuser';
alter role testuser with superuser;
create database testdb
GRANT ALL PRIVILEGES ON DATABASE testdatabase to testuser;
\q

check alive on socket

netstat -an | grep 5432

use postgresql

install postgresql 9.5 on ubuntu14.04

1
2
3
4
sudo sh -c ‘echo “deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main” >> /etc/apt/sources.list.d/pgdg.list’
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O – | sudo apt-key add –
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib

login and create table

sudo su – postgres
psql

1
2
3
4
5
6
7
8
\conninfo
create table test (name char(12));
select * from test;
insert into test select 'aaa';
insert into test select 'aaabbb';
insert into test select 'aaabbbccc';
select * from test;
\q

exit

install pgadmin3

sudo apt-get install pgadmin3

instal postgresql 9.5 via rpm on CentOS/RHEL/Fendora

CentOS/RHEL 7
rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm

CentOS/RHEL 6
rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

CentOS/RHEL 5
rpm -Uvh http://yum.postgresql.org/9.5/redhat/rhel-5-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

Fedora 23
rpm -Uvh http://yum.postgresql.org/9.5/fedora/fedora-23-x86_64/pgdg-fedora95-9.5-3.noarch.rpm

Fedora 22
rpm -Uvh http://yum.postgresql.org/9.5/fedora/fedora-22-x86_64/pgdg-fedora95-9.5-3.noarch.rpm

Fedora 21
rpm -Uvh http://yum.postgresql.org/9.5/fedora/fedora-21-x86_64/pgdg-fedora95-9.5-2.noarch.rpm

yum install postgresql95-server postgresql95
/usr/pgsql-9.5/bin/postgresql95-setup initdb

start/enable

CentOS/RHEL 7 and Fedora 23
systemctl start postgresql-9.5
systemctl enable postgresql-9.5

CentOS/RHEL 6/5 and Fedora 22/21
service postgresql-9.5 start
chkconfig postgresql-9.5 on

login

su - postgres
psql

password

1
\password postgres

sudo su postgres -c psql postgres

1
2
alter user postgres with password 'assignednewpassword';
\q

sudo passwd -d postgres
sudo su postgres -c passwd

configure postgresql

sudo vi /etc/postgresql/9.0/main/postgresql.conf

1
2
3
4
#listen_addresses = ‘localhost’
listen_addresses = ‘*’
#password_encryption = on
password_encryption = on

sudo vi /etc/postgresql/9.0/main/pg_hba.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
#"local" is for Unix domain socket connections only
#開放本地端同資料庫使用者帳號的 linux 使用者可以不用密碼從本機登入系統
local all all ident sameuser
#IPv4 local connections: IPV4本地端
host all all 127.0.0.1/32 ident sameuser
#IPv6 local connections: IPV6本地端
host all all ::1/128 ident sameuser

#IPv4 local connections:
#可以透過 tcp/ip 從 127.0.0.1/32 及 110.111.69.0/24 登入
host all all 127.0.0.1/32 md5
host all all 110.111.69.0/24 md5

#本地端的使用者使用 Unix domain socket及 md5 密碼登入
local all all md5

create user and database

1
2
3
4
5
create user testuser with password 'password4testuser';
alter role testuser with superuser;
create database testdb
GRANT ALL PRIVILEGES ON DATABASE testdatabase to testuser;
\q

check alive on socket

netstat -an | grep 5432

ubuntu installation and setup.md

ubuntu 14.04.2 desktop i386

sudo apt-get update
sudo apt-get install git

改用gnome做為desktop manager

sudo apt-get install gnome-session-fallback -> relogin and select “Gnome Flashback”

sudo shutdown -h now
sudo reboot

uname -m &&lsb_release -a && cat /etc/issue &&cat /etc/release

i386 沒法裝 chrome…

官網最新ubuntu-14.04.4-desktop-amd64

http://www.ubuntu-tw.org/modules/tinyd0/

Universal-USB-Installer,用usb安裝ubuntu

1.開啟Universal-USB-Installer
1.選ubuntu
1.選iso檔
1.選usb碟(空間要足夠)
1.按create建立

enable ssh

sudo apt-get install ssh
sudo apt-get install openssh-server
sudo service ssh status
sudo service ssh restart

adjust timezone

date
sudo vi /etc/default/rcS
UTC=no
sudo tzselect
sudo cp /usr/share/zoneinfo/Aisa/Taipei /etc/localtime
sudo vi /etc/timezone
Asia/Taipei

ntp

sudo apt-get isntall ntpdate
sudo ntpdate time.stdtime.gov.tw
sudo hwclock -w
date
sudo crontab -e
@daily /usr/sbin/ntpdate -u time.stdtime.gov.tw > /dev/null

sudo apt-get install ntp
service ntp status

ubuntu scripts

network and loading tools

sudo apt-get install htop iftop iotop atop iptraf monit nethogs bmon nmon glances sysstat tcptrack vnstat pktstat ifstat iostat monitorix netwatch trafshow
sudo apt-get install traceroute
sudo apt-get install net-snmp
sudo apt-get install rsync iotop p7zip-full tree hardinfo

haproxy

sudo add-apt-repository ppa:vbernat/haproxy-1.5
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install haproxy
vi /etc/haproxy/haproxy.cfg
default
option forwardfor
option http-server-close
frontend http-frontend
bind public_ip:80
reqadd X-Forwarded-Proto:\ http
default_backend wwwbackend
backend wwwbackend
server 1-www private_ip_1:80 check
server 2-www private_ip_2:80 check
server 3-www private_ip_3:80 check
sudo service haproxy restart

nginx

sudo apt-get install nginx
haproxy -v
vi /etc/default/haproxy
ENABLED=1
sudo service haproxy
sudo service haproxy restart
sudo sh -c “echo \Hostname: webserver01 (192.168.205.16)\<\/h1> >> /var/www/index.html”
sudo sh -c “echo \Hostname: webserver02 (192.168.205.17)\<\/h1> >> /var/www/index.html”
http://192.168.205.15/haproxy?stats

websocket server,client,android

websocket server/client/android

https://github.com/elabs/mobile-websocket-example/blob/master/android/WebsocketExampleClientProject/WebsocketExampleClient/src/main/java/se/elabs/websocketexampleclient/MainActivity.java
http://www.elabs.se/blog/66-using-websockets-in-native-ios-and-android-apps
https://developer.kaazing.com/documentation/5.0/dev-android/p_dev_android_client.html
http://www.kevinhoyt.com/2015/09/16/websocket-on-android/

https://kheresy.wordpress.com/2013/04/02/html5-websocket-client/
https://kheresy.wordpress.com/2014/03/06/websocketpp-client/

cassandra disable bloomfilter

http://grokbase.com/t/cassandra/user/119g2qczmt/how-to-reduce-disk-read-and-bloom-filter-performance
https://docs.datastax.com/en/cassandra/1.2/cassandra/operations/ops_tuning_bloom_filters_c.html
https://grockdoc.com/cassandra/2.1/articles/tuning-reads-via-the-bloom-filter_88c8f57a-71d0-41ee-b77f-617c64ad4739

haproxy

nginx

ipython notebook

env

set PYTHONHOME=c:\Python27
set PYTHONPATH=c:\Python27\Lib
set PATH=%PYTHONHOME%;%PYTHONHOME%\Scripts;%PATH%

install ipython notebook

python ez_setup.py

rem ### wget https://bootstrap.pypa.io/get-pip.py —no-check-certificate
python get-pip.py
pip install “ipython[notebook]”
pip install ipython[all]

rem ### @see https://gist.github.com/fyears/7601881
pip install -U setuptools
pip install -U pip

pip install numpy
pip install scipy
pip install matplotlib
pip install pandas
pip install ipython[all]

rem ### you may lack of visual c compiler for python
error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it from http://aka.ms/vcpython27
just download and install it.

rem ### get pydata-book
git clone http://github.com/pydata/pydata-book

windows下安裝Anaconda比較省事

wget https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda2-2.4.1-Windows-x86_64.exe —no-check-certificate

安裝完Anaconda後就可以執行 ipython noteook ,開啟 http://localhost:8888/ 就可看到 jupyter 的 web 介面
接下來可以按靠近右上的”new”按鈕;選擇python2建立新的notebook
建立了新的notebook,可以在running tab裡看到目前正在運作的所有notebook。(每個notebook會對映到各自的.ipynb檔案)

ubuntu下直接sudo apt-get install ipython-book

keyboard shortcuts ctrl-m h

enter    enter edit mode

shift- enter run cell, select below
ctrl- enter run cell
alt- enter run cell, insert below

建立可以遠端操作的ipython notebook

create profile

ipython profile create nbserver

setup password

python -c “import IPython;print IPython.lib.passwd()”
or
IN [1]: from IPython.lib import passwd
IN [2]: passwd()
Enter password:
Verify password:
Out[2]: ‘sha1:xxxxxxxxxxxxxxxxxxxxxxxxx’

create certificate

openssl req -x509 -nodes -days 10000 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

edit ~/.ipython/profile_nbserver/ipython_notebook_config.py

c = get_config()
c.IPKernerlApp.pylab = ‘inline’
c.NotebookApp.ip = ‘*’
c.NotebookApp.open_browser = False
c.NotebookApp.password = u’sha1:xxxx your hashed password’
c.Notebook.App.port = 9999 #可設為其他端口

if necessary edit firewall /etc/sysconfig/iptables

-A RH-Firewall-1-INPUT -m state —state NEW -m tcp -p tcp —dport 9999 -j ACCEPT
-A OUTPUT -m state —state NEW -m tcp -p tcp —dport 9999 -j ACCEPT

start server

ipython notebook —profile=nbserver —certfile=/path/to/your/mycert.pem

open client

https://yourserver:9999

pet project check list

pet project check list

data
size
自動導入格式
人工輸入界面
人工檢核界面
sync,update,version-control,diff
database
schema
ORM hibernate
transaction
NoSQL?

Cache
ehcache
memcache
redis

MVC
security
fb/google/github login
access limit
shortlink
urlrewrite
filter

apache/nginx finetune

frondend
HTML
CSS
javascript
bootstrap
template
UI/UX

API
REST
entry url
json schema
security

search
solr
斷詞
near realtime

Visualization
statistic
MLDM

programming language outline

程式語言結構

基本資料型態
結構資料型態
操作,使用,轉換
字串處理
測試
尋找
替換
大小寫
encoding
unicode,utf8
建立,輸入,顯示
IO讀寫
text,binary
塊讀,行讀,流讀
buffering
壓縮
local file system
url,network
date,time
search,sorting,regularexpression
OOP
abstract,class,interface
design pattern
template
generalize
persistence,database
debug,test
process,thread,sync,lock
security
OS specific supports
GUI
XML,HTML,JSON
FTP,MIME,POP,HTTPS,IRC
Web,HTTP,HTTPS,REST,OPML,RSS
distribution
algorithm
Functional Programming
support library/ecosystem