Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
you-n-g committed Feb 29, 2016
2 parents b3fb7f3 + 275f621 commit 1133935
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 12 deletions.
63 changes: 63 additions & 0 deletions code_to_copy/backend/cplusplus/stl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// common
using namespace std;

auto f = [](int x) -> int {return x;} // 返回值可以为空,然后它会自动判定返回值的类型。

// vector
#include<vector>
Expand All @@ -15,6 +16,8 @@ for (vector<int>::iterator it = nums.begin(); it != nums.end(); it++) {
}
nums.push_back(STH);

cout << vector<int>({1,2}).back() << endl; // 使用匿名对象


// map
#include<map>
Expand Down Expand Up @@ -44,3 +47,63 @@ min(VALA, VALB);

lower_bound(v.begin(), v.end(), VAL); // first iterator with val >= VAL, otherwith return the position that means v.end()
upper_bound(v.begin(), v.end(), VAL); // first iterator with val > VAL,
equal_bound(v.begin(), v.end(), VAL); // 直接求出等于VAL的阈值,返回upper_bound和 lower_bound

sort(v.begin(), v.end()); // 有快排的效率

v.erase(unique(v.begin(), v.end()), v.end()); // 可以把数组中连续的重复数字都去除,数值网前移动,最后用erase 删除掉其他数值

//string
#include<string>
str = to_string(INT|FLOAT);

// stoi是C++11支持的标准, 必须加上 -std=c++11 才行
std::string::size_type sz;
int I_DEC = stoi(STR_DEC, &sz, 10);

// 这个版本不需要 C++11的支持
#include<stdlib.h>
INT = atoi(STRING_OBJ.c_str());


// 如何split string, 以','为例
#include<string>
#include<iostream>
#include<sstream> // for stringstream
string s, item;
cin >> s;
stringstream ss(s);
while (getline(ss, item, ',')) {
cout << item << endl;
}

// sub striing
str.substr(INDEX, LENGTH);

// find sub string
std::size_t found = str.find(str2);
if (found != std::string::npos) // 如果找到了
// 一般来说, 如果返回值是iterator, 那找没找到看 object.end(); 如果返回值是位置, 找没找到看 class::npos;


// useful numbers
#include <climits>
INT_MAX // (2147483647)
INT_MIN // (-2147483648)

// 对象有哪些方法 http://www.cplusplus.com/reference/string/string/





// iostream 输出格式设置
// 设置小数格式
cout.precision(5);
cout << fixed << f << endl;
cout << scientific << f << endl;

// 整数
cout.width(10);
cout.fill('0');
cout << dec << 20 << endl;
2 changes: 2 additions & 0 deletions code_to_copy/backend/etc/network/interfaces
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# auto XXX means this interface will start automatically on boot

# The loopback network interface
auto lo
iface lo inet loopback
Expand Down
17 changes: 13 additions & 4 deletions code_to_copy/backend/etc/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ endfunc
map <F9>p :call CompilePython()<cr>
func! CompilePython()
exec "w"
exec "!echo -e '\033[1;34m-----------here\ is\ the\ ans\ of\ %----------\033[0m';python %"
exec "!echo -e '\033[1;34m-----------here\ is\ the\ ans\ of\ %----------\033[0m';python \"%\""
endfunc

map <F9>s :call RunShell()<cr>
func! RunShell()
exec "w"
exec "!echo -e '\033[1;34m-----------here\ is\ the\ ans\ of\ %----------\033[0m';bash %"
exec "!echo -e '\033[1;34m-----------here\ is\ the\ ans\ of\ %----------\033[0m';bash \"%\""
endfunc

map <F9>c :call CompileRunCpp()<CR>
func! CompileRunCpp()
exec "w"
exec "!echo -e '\033[1;32mcompiling.....\033[0m';g++ % -o %:r.exe;echo -e '\033[1;34m-----------here_is_the_ans_of_%----------\033[0m';./%:r.exe;echo -e '\033[1;33mend...\033[0m';rm %:r.exe"
exec "!echo -e '\033[1;32mcompiling.....\033[0m';g++ -std=c++11 \"%\" -o \"%:r.exe\";echo -e '\033[1;34m-----------here_is_the_ans_of_%----------\033[0m';./\"%:r.exe\";echo -e '\033[1;33mend...\033[0m';rm \"%:r.exe\""
"exec "!./%:r.exe"
endfunc

Expand Down Expand Up @@ -204,7 +204,7 @@ autocmd FileType python map <buffer> <F12> :call Flake8()<CR>
" <leader>d 是默认用于Diagnostic display的, 而且是用于C-family
" 需要用 :YcmGenerateConfig 项目根目录在根目录下生成 .ycm_extra_conf.py
" 如果生成失败,则用
" ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py
" ~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py
" 需要自己修改一下前面的flags, 可以make的时候ps grep 一下看看 -I 都有些啥
" 典型的可以加上
" '-I../../include',
Expand Down Expand Up @@ -243,3 +243,12 @@ au FileType go nmap <Leader>gd <Plug>(go-doc)
" TComment
" https://github.com/tomtom/tcomment_vim
" gc 确定一切


"
" vim-slime
" https://github.com/jpalardy/vim-slime
" ":i.j" means the ith window, jth pane
" C-c, C-c --- the same as slime
" C-c, v --- mnemonic: "variables"
let g:slime_target = "tmux"
16 changes: 16 additions & 0 deletions code_to_copy/backend/java/OftenUsed.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,26 @@ public void listFilesForFolder(final File folder) {
public static void main(String[] args) {
}

// 算法相关
// 排序
Arrays.sort(nums); // int[] nums


// 常用语法
for(char c: new char[]{'g', 'h', 'i'}) ///
char[][] a = {{}, {}, {'g', 'h'}} // 每个长度还可以不一样吗???

// 坑!!!!!!!
// ArrayList 转 Array居然要这样, 而不是直接 toArray
List<String> list = ..;
String[] array = list.toArray(new String[list.size()]);


// 字符串处理
String str;
str.indexOf(strB);
String.valueOf(STH); // 转换成字符串
// 基础中的基础
str.length(); //是一个method ,区别于普通数组的 length是属性
str.charAt(); //你不能对string直接用[], 因为java中没有运算符重载
}
46 changes: 46 additions & 0 deletions code_to_copy/backend/mysql/often_used.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


-- 下面的都是从 HIVE 中学会的, 自己慢慢领悟。
drop table if exists XXX_table;


CREATE TABLE XXX_table (uid string, mid string, action_sum bigint);


insert overwrite table weibo_rd_2_submit
XXXX_select;
-- insert into `XXX_table` (a ,b) values (1,1), (2,2);
-- hive 不支持 insert into table这种格式



select DISTINCT XXX
from XXXX
where XXXX like "prefix%"
ORDER BY XXXX DESC|ASC;



delete from XXX_TABLE
where XXXX
limit XXXX;


ALTER TABLE XXXX_TABLE CHANGE OLD_COLUMN_NAME NEW_COLUMN_NAME XXX_TYPE;


-- 一些函数的用法
select (rank() over (PARTITION BY uid,XXX ORDER BY blog_time,XXXX DESC)) as rank from XXXXX;
select
case
when COL_NAME is NULL then 0
else COL_NAME_OR_VALUE
end
as action_sum
from XXXXX;


-- 常用需求的思路
-- 选择每组最高分:先group by 计算最高分, 然后再做表链接


5 changes: 4 additions & 1 deletion code_to_copy/backend/openstack/shell.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

#
nova hypervisor-[list|servers|show|stats|uptime]
# 用于看具体的compute节点上的hypervisor 的各种详细信息

# boot the vm
nova boot <vm_name> --image <image_name> --flavor <flavor_id>
Expand All @@ -12,5 +15,5 @@ glance image-create --name <image_name> --disk-format=<same_as_image-list> --con


# restart all the openstack service
for svc in api conductor scheduler compute network cert ; do service openstack-nova-$svc restart; done
for svc in api conductor scheduler compute network cert; do service openstack-nova-$svc restart; done

1 change: 1 addition & 0 deletions code_to_copy/backend/python_apps/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# 将字符串转化为datetime对象
import datetime
print(datetime.datetime.strptime('2011-03-07', '%Y-%m-%d'))
print datetime.datetime.now().isoformat()
2 changes: 1 addition & 1 deletion code_to_copy/backend/python_apps/often_used.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# 或者直接这样也行 : export PYTHONIOENCODING=UTF-8

# 模仿这个就能得到相对当前脚本的一个绝对路径
DIRNAME = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
DIRNAME = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) # 注意这得到的是上级目录的绝对路径
17 changes: 17 additions & 0 deletions code_to_copy/backend/python_apps/python_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

pdb.set_trace()
(Pdb) p a # 即打印a

# TODO 优化的版本是 ipdb, 把上面的 pdb都换成ipdb
# END PDB


Expand All @@ -19,9 +21,24 @@
for line in traceback.format_stack():
print line
# 可以配合 os.getpid() 来得到当前进程的pid 看看在哪里运行

# 如果是想输出抓住的异常的traceback
try:
raise Exception
except Exception:
ex_type, ex, tb = sys.exc_info()
traceback.print_tb(tb)
finally:
del tb

# END traceback


# 查看将要调用的方法到底来自哪里
import inspect
inspect.getmodule(XXX_FUNC)
inspect.getsourcelines(XXX_FUNC)


# BEGIN trace what your script is doing

Expand Down
15 changes: 13 additions & 2 deletions code_to_copy/backend/sa/get_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,22 @@ iotop: TODO 看IO怎么实现



# BEGIN 查看进程相关
sudo lsof -i :XXX_PORT # 看XXX_PORT被哪个进程占用了
# END 查看进程相关




# 查看硬件信息
dmidecode
# 常用的有
System Information -> Serial Number: GWPCZY1
# dmidecode列出的信息常用的有
System Information -> Serial Number: GWPCZY1 # 查看序列号用于售后服务
Product Name: ThinkServer RD640 # 查看机器型号
Memory Device # 查看内存信息

# 查看网卡信息
lspci | grep Ethernet



Expand Down
3 changes: 2 additions & 1 deletion code_to_copy/backend/sa/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ sudo apt-get install bash-completion dialog memcached python-memcache mercurial
sudo yum groupinstall 'Development Tools' # 相当于安装build-essential



# 中文显示不完整
[中文显示不完整](http://liangxu.wang/867/)



Expand Down
18 changes: 17 additions & 1 deletion code_to_copy/backend/sa/network_related.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ route del/add -net CIDR gw 192.168.1.1
route del/add -host IP gw 192.168.1.1
route del/add default gw 192.168.1.1

ifup eth0 # ifup is a script, include check config and using DHCP
# 重启网卡,在ubuntu上会读取 /etc/network/interfaces, 所以修改后用这个命令生效比较好
sudo ifdown eth0 && sudo ifup eth0 # ifup is a script, include check config and using DHCP

dhclient eth0 # 如果上面有问题,则用这个获取ip地址

# 给网络起别名
Expand Down Expand Up @@ -133,3 +135,17 @@ ssh -L LOCAL_ADDRESS:LOCAL_PORT:REMOTE_ADDRESS:REMOTE_PORT XXX_USER@XXX_HOST

# 所以配合polipo也可以在远方开一个http_proxy(本来只有那边本地访问), 然后再ssh -L 转到本地来



# BEGIN nmap VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
nmap -v target.com :: 扫描开了哪些端口
nmap -sP '10.0.0.*' :: 扫描这个网段的ip
nmap -sT targetHost :: 好处是很少有系统会把这种半tcp连接記入日志
# 详情参见 http://dev.firnow.com/course/6_system/linux/Linuxxl/2007211/14170.html
# BEGIN nmap ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


# config DHCP server
# [DHCP server](http://www.tuicool.com/articles/AzEbii)
sudo apt-get install isc-dhcp-server -y

22 changes: 22 additions & 0 deletions code_to_copy/backend/sa/often_used.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mount -t tmpfs -o size=1024m tmpfs /mnt/ram
set -x # 设置允许的时候会把命令写出来, 而且会在命令前面输出+
DIR="$( cd "$(dirname "$0")" ; pwd -P )"

DATETIME=`date +%Y-%m-%d:%H:%M:%S`



Expand Down Expand Up @@ -65,3 +66,24 @@ while IFS=';' read -ra XXX_ARR; do
# process "$i"
done
done <<< "$IN"




# 管理服务
service --status-all # 查看所有服务的状态




# 修改hostname
# 先改 /etc/hosts /etc/hostname, 然后
hostname -F /etc/hostname



# ubuntu server 中文乱码问题, 照着 http://www.cnblogs.com/top5/archive/2011/02/23/1962390.html 的前半部分做


# 类似于git 的格式查看两个文件夹下的代码区别
diff -bur folder1/ folder2/
3 changes: 3 additions & 0 deletions code_to_copy/backend/sa/process_text.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ sed -i '/LINE_XXX_PATTERN/a XXX_CONTENT' XXX_FILE
sed -i '1d' # 删除第一行

# sed 每次处理一行,先选择, 后接命令


XXX | sort -k N # 按第n列排序, 比如看日志时按时间排序!!!
6 changes: 4 additions & 2 deletions code_to_copy/backend/sa/version_management.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ git config --global color.ui auto # 配置自动颜色
# 配置merge
git config --global merge.tool vimdiff
git config --global mergetool.prompt false
# 看看已经配置了哪些config
git config --list


#patch的导入导出
Expand Down Expand Up @@ -44,11 +46,11 @@ git reset HEAD filename # 效果是 将 index中文件恢复到 HEAD状态(即t
# 合并
git reset --merge # merge 失败
git cherry-pick --abort # cherry-pick 失败
git mergtool # merge失败之后呼唤mergetool来合并
git mergetool # 当发生分支冲突的时候merge失败之后呼唤mergetool来合并
# TODO 如何Backport到以前的分支
# 根据django的案例来说,直接提交到master就行,之后会有人backport到以前的分支
# backport使用cherry-pick
git mergetool # 当发生分支冲突的时候使用这个命令来合并分支
git mergetool # 使用这个命令来合并分支

# git pull -u 时不能将未提交的修改自动和分支合并, 所以需要先用stash将已经修改的内容存储起来
git stash # 可以把当前工作目录的 状态储存起来,然后去别的分支工作, 通过加参数 还可以直接创建分支。
Expand Down
Loading

0 comments on commit 1133935

Please sign in to comment.