-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
865 lines (673 loc) · 308 KB
/
atom.xml
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Hm's Blog</title>
<subtitle>I am here</subtitle>
<link href="/atom.xml" rel="self"/>
<link href="http://huangming.github.io/"/>
<updated>2016-12-27T02:11:22.000Z</updated>
<id>http://huangming.github.io/</id>
<author>
<name>Mingo</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>Oracle无法登陆:ORA-00020</title>
<link href="http://huangming.github.io/2016-12-27-oracle-ora00020.html"/>
<id>http://huangming.github.io/2016-12-27-oracle-ora00020.html</id>
<published>2016-12-27T04:03:57.000Z</published>
<updated>2016-12-27T02:11:22.000Z</updated>
<content type="html"><![CDATA[<p>转自:<a href="http://blog.itpub.net/22621861/viewspace-1280235/" target="_blank" rel="external">http://blog.itpub.net/22621861/viewspace-1280235/</a></p>
<p>登录Oracle数据库,结果报ORA-00020: maximum number of processes (%s) exceeded错误。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="operator"><span class="keyword">select</span> username,<span class="keyword">count</span>(sid) <span class="keyword">from</span> v$<span class="keyword">session</span> <span class="keyword">group</span> <span class="keyword">by</span> username;</span></span><br><span class="line">USERNAME COUNT(SID)</span><br><span class="line"><span class="comment">------------------------------ ----------</span></span><br><span class="line"> 21</span><br><span class="line">SYSMAN 124</span><br><span class="line">SYS 1</span><br></pre></td></tr></table></figure>
<p>发现SYSMAN用户有大量会话数,后发现SYSMAN主要用的PROGRAM是OMS。</p>
<p>查阅OMS相关信息,得知其是由Enterprise Management产生的。</p>
<p>关闭EM,CMD下执行:</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">emctl stop dbconsole</span><br></pre></td></tr></table></figure>
<p>确保下次启动默认不启动EM,需要在Windows服务中关闭OracleDBConsoleORCL服务的自动启动。</p>
]]></content>
<summary type="html">
<p>转自:<a href="http://blog.itpub.net/22621861/viewspace-1280235/" target="_blank" rel="external">http://blog.itpub.net/22621861/viewspace-12
</summary>
<category term="oracle" scheme="http://huangming.github.io/tags/oracle/"/>
</entry>
<entry>
<title>Windows下用Nginx部署DokuWiki</title>
<link href="http://huangming.github.io/2016-12-17-dokuwiki-nginx.html"/>
<id>http://huangming.github.io/2016-12-17-dokuwiki-nginx.html</id>
<published>2016-12-17T12:56:06.000Z</published>
<updated>2017-01-07T04:53:33.569Z</updated>
<content type="html"><![CDATA[<p><a href="https://www.dokuwiki.org/dokuwiki#" target="_blank" rel="external">DokuWiki</a> 是一个使用,用途多样的开源 Wiki 软件,并且不需要数据库。部署Dokuwiki需要一个支持PHP的Webserver。通过nginx+php可以简单部署使用。<br><a href="http://nginx.org/en/" target="_blank" rel="external">Nginx</a> (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。<br>本文环境:<code>windows10 64位</code>+<code>nginx1.11.7</code>+<code>php-5.6.29-Win32-VC11-x64</code></p>
<h2 id="下载解压软件">下载解压软件</h2><p>用到的软件均是绿色版,不用安装解压即可使用: </p>
<ul>
<li><a href="http://windows.php.net/downloads/releases/php-5.6.29-Win32-VC11-x64.zip" target="_blank" rel="external">php-5.6.29-Win32-VC11-x64.zip</a> 解压到 <code>E:\OneDrive\www\php</code></li>
<li><a href="http://nginx.org/download/nginx-1.11.7.zip" target="_blank" rel="external">nginx-1.11.7.zip</a> 解压到 <code>E:\OneDrive\www\nginx-1.11.7</code></li>
<li><a href="https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz" target="_blank" rel="external">DokuWiki</a> 解压到 <code>E:\OneDrive\www\dokuwiki</code></li>
<li><a href="http://redmine.lighttpd.net/attachments/660/RunHiddenConsole.zip" target="_blank" rel="external">RunHiddenConsole</a>(此程序用于隐藏nginx运行的窗口) 解压到 <code>E:\OneDrive\www\RunHiddenConsole.exe</code></li>
</ul>
<a id="more"></a>
<h2 id="修改PHP配置">修改PHP配置</h2><p>将php.ini-dist或php.ini-development配置文件重命名为php.ini(该文件中分号开始行为注释内容),然后做如下设置:</p>
<ol>
<li><p>extension_dir = “C:/php5/ext”</p>
</li>
<li><p>取消下列设置的注释:</p>
</li>
</ol>
<p> extension=php_curl.dll<br> extension=php_gd2.dll<br> extension=php_mbstring.dll<br> extension=php_mysql.dll<br> extension=php_pdo_mysql.dll<br> extension=php_pdo_odbc.dll<br> extension=php_xmlrpc.dll</p>
<ol>
<li><p>配置Session功能:</p>
<p> 在使用session功能时,必须配置session文件在服务器上的保存目录,否则无法使用session,在Windows 7上新建一个可读写的目录文件夹,此目录最好独立于WEB主程序目录之外,在D盘根目录上建立了phpsessiontmp目录,然后在php.ini配置文件中找到 ;session.save_path = “/tmp” 改成 session.save_path = “D:/phpsessiontmp”</p>
</li>
<li><p>配置PHP的文件上传功能</p>
<p> 同session一样,在使用PHP文件上传功能时,我们必须要指定一个临时文件夹以完成文件上传功能,否则文件上传功能会失败,我们仍然需要在Windows 7上建立一个可读写的目录文件夹,此处我在D盘根目录上建立了phpfileuploadtmp目录,然后在php.ini配置文件中找到 ;upload_tmp_dir = 改成 upload_tmp_dir = “D:/phpfileuploadtmp”</p>
</li>
<li><p>修改date.timezone</p>
</li>
</ol>
<p>;date.timezone = 改成 date.timezone = Asia/Shanghai</p>
<h2 id="修改Nginx配置">修改Nginx配置</h2><p><a href="https://www.dokuwiki.org/install:nginx" target="_blank" rel="external">DokuWiki with nginx on Windows</a> 有关于nginx的配置内容。<br>修改 <code>E:\OneDrive\www\nginx-1.11.1\conf\nginx.conf</code> 文件:<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">#E:\OneDrive\www\nginx-1.11.1\conf\nginx.conf #user nobody; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { location ~ ^/dokuwiki/.*\.php { root E:/OneDrive/www;	 fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME E:/OneDrive/www$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; include fastcgi_params; } # serve static files location ~ ^/dokuwiki/lib/ { root E:/OneDrive/www;		 expires 30d; } location ~ ^/dokuwiki/conf/ { deny all; } location ~ ^/dokuwiki/data/ { deny all; } location ~ /\.ht { deny all; } } }</span><br></pre></td></tr></table></figure></p>
<h2 id="编写启动批处理">编写启动批处理</h2><p><a href="https://www.nginx.com/resources/wiki/start/topics/examples/phpfastcgionwindows/" target="_blank" rel="external">这里</a>有关于NGINX 跟 PHP 在 Windows 平台通过 FastCGI 对接的例子,此页面也有 RunHiddenConsole 的下载</p>
<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">REM E:\OneDrive\www\php.bat</span></span><br><span class="line"><span class="keyword">ECHO</span> Starting PHP FastCGI...</span><br><span class="line"><span class="keyword">set</span> <span class="built_in">PATH</span>=E:\OneDrive\www\PHP;<span class="envvar">%PATH%</span></span><br><span class="line">RunHiddenConsole.exe E:\OneDrive\www\php\php-cgi.exe -b <span class="number">127</span>.<span class="number">0</span>.<span class="number">0</span>.<span class="number">1</span>:<span class="number">9000</span></span><br><span class="line"><span class="keyword">ECHO</span> Starting nginx...</span><br><span class="line"><span class="built_in">cd</span> /d E:\OneDrive\www\nginx-<span class="number">1</span>.<span class="number">11</span>.<span class="number">1</span> && <span class="built_in">start</span> nginx.exe</span><br></pre></td></tr></table></figure>
<h2 id="运行">运行</h2><p>双击 <code>E:\OneDrive\www\php.bat</code> 会看到命令行一闪而过。<br>打开浏览器,访问 </p>
<ul>
<li><a href="http://127.0.0.1/dokuwiki/install.php" target="_blank" rel="external">http://127.0.0.1/dokuwiki/install.php</a></li>
<li><a href="http://127.0.0.1/dokuwiki/doku.php" target="_blank" rel="external">http://127.0.0.1/dokuwiki/doku.php</a></li>
</ul>
]]></content>
<summary type="html">
<p><a href="https://www.dokuwiki.org/dokuwiki#">DokuWiki</a> 是一个使用,用途多样的开源 Wiki 软件,并且不需要数据库。部署Dokuwiki需要一个支持PHP的Webserver。通过nginx+php可以简单部署使用。<br><a href="http://nginx.org/en/">Nginx</a> (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。<br>本文环境:<code>windows10 64位</code>+<code>nginx1.11.7</code>+<code>php-5.6.29-Win32-VC11-x64</code></p>
<h2 id="下载解压软件">下载解压软件</h2><p>用到的软件均是绿色版,不用安装解压即可使用: </p>
<ul>
<li><a href="http://windows.php.net/downloads/releases/php-5.6.29-Win32-VC11-x64.zip">php-5.6.29-Win32-VC11-x64.zip</a> 解压到 <code>E:\OneDrive\www\php</code></li>
<li><a href="http://nginx.org/download/nginx-1.11.7.zip">nginx-1.11.7.zip</a> 解压到 <code>E:\OneDrive\www\nginx-1.11.7</code></li>
<li><a href="https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz">DokuWiki</a> 解压到 <code>E:\OneDrive\www\dokuwiki</code></li>
<li><a href="http://redmine.lighttpd.net/attachments/660/RunHiddenConsole.zip">RunHiddenConsole</a>(此程序用于隐藏nginx运行的窗口) 解压到 <code>E:\OneDrive\www\RunHiddenConsole.exe</code></li>
</ul>
</summary>
<category term="www" scheme="http://huangming.github.io/categories/www/"/>
<category term="dokuwiki" scheme="http://huangming.github.io/tags/dokuwiki/"/>
<category term="nginx" scheme="http://huangming.github.io/tags/nginx/"/>
<category term="wiki" scheme="http://huangming.github.io/tags/wiki/"/>
</entry>
<entry>
<title>无意翻到当年的云笔记</title>
<link href="http://huangming.github.io/2016-12-03-cloud-notes-2012.html"/>
<id>http://huangming.github.io/2016-12-03-cloud-notes-2012.html</id>
<published>2016-12-03T04:03:57.000Z</published>
<updated>2016-12-21T13:10:51.030Z</updated>
<content type="html"><![CDATA[<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>学校举办一次中国象棋比赛,有10名同学参加,比赛采用单循环赛制,每名同学都要与其他9名同学比赛一局。比赛规则,每局棋胜者得2分,负者得0分,平局两人各得1分,比赛结束后,10名同学的得分各不相同,已知:(1)比赛第一名与第二名都是一局都没有输过;(2)前两名的得分总和比第三名多20分;(3)第四名的得分与最后四名的得分和相等。那么,排名第五名的同学的得分是?<br>A.8分 B,9分 C.10分 D.11分</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>年度最爱电影。穆赫兰道影评是两个极端,抛去其他人的看法,自己坚持看完这部冗长的电影,而且还不知所云,只是强迫自己记住其中内容,等看完影评后用记忆串联起整部片子的时候,我深深地呼了一口气。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【心理技巧:如何让人喜欢你】1、出门照照镜子,给自己一个自信的微笑;2、善于发现别人优点;3、赞美;4、主动、付出,别陪着人冷场;5、接受别人递过来的零食;6、多请人帮你小忙;7、用心倾听,不打断对方的话;8、说话有力,能感受到自己声音的感染力;9、说话之前,先考虑对方的感觉。</p>
<a id="more"></a>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【艺术治疗:让这些电影治愈你】1、缺乏学习动力:《幸福终点站》、《风雨哈佛路》;2、对爱失望:《偷天情缘》、《初恋50次 》;3、自卑失落:《阿甘正传》、《肖申克的救赎》;4、失败或绝望:《铁权男人》、《迫在眉梢》、《伊丽莎白镇》;5、厌倦生活:《在世界的转角遇见爱》、《搏击俱乐部》。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【心理技巧:让你心情变好的10个小方法】1、每天拍几张照片;2、看场快乐的电影;3、在周末的清晨做白日梦;4、给朋友寄卡片;5、在水边散步;6、偶尔吃一顿大餐;7、每星期坚持做一次锻炼;8、一边喝咖啡,一边读小说;9、一边打电话,一边信手涂鸦;10、一边洗澡,一边唱歌。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【心理技巧:平息愤怒的7个方法】1、语速降低2/3,音量降低2/3;2、闭上眼睛,可以快速浇灭怒火;3、转转脖子,缓解僵硬;4、拥抱自己,用双臂紧紧拥抱一下自己;5、闻闻植物,离绿色植物10厘米左右,深呼吸5次;6、自我解嘲;7、击掌、跺脚,两三分钟即可</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>英国颁布的《儿童10大宣言》:1平安成长比成功更重要;2背心、裤衩覆盖的地方不许别人摸;3生命第一,财产第二;4小秘密要告诉妈妈;5不喝陌生人的饮料,不吃陌生人的糖果;6不与陌生人说话;7遇到危险可以打破玻璃,破坏家具;8遇到危险可以自己先跑;9不保守坏人的秘密;10坏人可以骗</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【那些简单的小幸福,你拥有过几个?】1爸妈疼你;2被人背过;3得过第1名;4笑到肚子痛;5有人为你哭过;6买到喜欢的衣服;7半夜有人短信给你;8和蜜友煲电话粥;9生病有过人照顾你;10生日凌晨有人发短信祝福;11在车站有过人接;12和心爱的一起走路到腿疼;13有好事就有人第1想到你</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【9个增加自信的小技巧】1、挑前面的位子坐; 2、练习正视别人; 3、把你走路的速度加快25%; 4、练习当众发言; 5、咧嘴大笑;6、怯场时,不妨道出真情,即能平静下来; 7、用对自己用肯定的语气,消除自卑感;8、发现自己薄弱环节并逐步提高;9、培养兴趣,做自己能做、喜欢的事。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【你经常说“随便”吗?】习惯说“随便”是一种从众的心理,这看似洒脱的通用语,但却透出漠然,甚至是忍耐的意味。人们会反感“随便”,是因为社会倡导交流沟通、各抒己见、团队合作,而常说“随便”的人让人觉得不愿意与人合作、工作不努力、没有主见,这样的形象不太受人欢迎</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【测试:你是向日葵族吗?】1善于发现微小幸福。2没有太大野心。3对负面情绪不敏感。4生活标准较低。5选择喜欢的职业。6抗压力耐打击.7.感恩的心态。8张弛有度的生活节奏。9相互赞美。10充满热情。11适当健忘。12善于自嘲。13适当的精神胜利法。14嘴角习惯性上扬15度。15拥有丰富的内涵。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【心理学家给恋爱中男女的6条建议】1、不要轻易说出“分手”两个字。2、不要因为你很生气而不接电话。3、不要相互猜忌,请彼此绝对信任。4、不要小肚鸡肠,请你能够宽容对待彼此。5、不要互揭伤疤,因为那样除了疼痛以外毫无意义。6、不要过于理智。你有哪些需要反思?</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【80后的10个小悲哀】1.每天凌晨才睡;2.觉不够睡钱不够花;3.手机24小时开机;4.平时起不来,周末睡不着;5.狂想去远方旅游,却只能在近郊瞎晃;6.怀疑自己抑郁;7.感觉自己亚健康,只能亚下去;8.想些不着边际的事;9.不知道自己是成熟还是世故;10.以前认为特鄙视的事变得能接受</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【你逼过自己吗?】逼自己经常会逼出许多意想不到的奇迹,正如背水一战,会反败为胜,奋力一搏,会出师告捷;逼过自己之后,我们可能会发现自己身上竟蕴藏着丰富的潜力,使自己脱颖而出,锋芒尽露;我们还可能在逼过自己之后,沉浸于事有所成的激动之中,面对自己的辉煌战果,俨然开天辟地的英雄。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【你有“晚睡强迫症”吗?】 无视疲惫的身体,还要继续熬夜打游戏、上网、看书、看电影、聚会……没什么事可做时却不愿睡觉,非要熬到凌晨一两点才上床,这正是“晚睡强迫症”的典型表现。这样的童鞋请举手~</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【那些我们毕业后发现的事情】1.学生时代结束了;2.就算是很多年不联系也依然想念着的人是存在的;3.好人有好报是句假话;4.做不了恋人就做陌生人原来是真的;5.爱说真话的人越来越少了;6.话越来越少,也越来越不爱笑了;7.哭是不需要理由的;8.能让我快乐的做个傻瓜的人越来越少了。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【心理成熟标准发布】 1.不再盲目跟风;2.不再犹豫不定;3.合理安排时间;4.开始关注新闻国事;5.开始养生;6.在爱情、友情、亲情之间,首先想到亲情;7.不再用哭闹来解决问题;8.重视身边的朋友;9.让周围的人快乐;10.在得失方面变得大度;11.学着尊重每个人;12.自信地生活;13.淡忘仇恨。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>你在不理我,我就成包子了,而且是天津最出名的那个</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>小李到机场接出差归来的妻子。<br>妻子见丈夫愁眉苦脸的,就说:“你看那边那对夫妻,有说有笑,多开心啊。”<br>小李叹了口气,说:“那个丈夫是来送妻子的。”</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>1.小米一家晚上回家要过一座桥,只有一根蜡烛且这根蜡烛只能燃烧30秒,<br>雷军过桥需要1秒,小米手机过桥需要3秒,小米MIUI过桥需要6秒,小米论坛过桥需要8秒,米聊过桥需要12秒。<br>一次最多只能同时两人过桥,<br>请问怎么样小米一家才能安全过桥?</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>三只母老虎各自带着自己的孩子小老虎过河(共有三只大老虎和三只小老虎,可用A、B、C代表三只大老虎、用a、b、c代表三只小老虎,并对应各自的母子关系)<br>河上只有一只船(他们只能划船过河)<br>这只船每次只能载两只老虎过河(不论大小)<br>三只大老虎都会划船,三只小老虎只有一只会划船(此处设定a会划船)<br>注意 —- 三只小老虎不能离开自己的母亲和别的大老虎在一起(或相遇),否则就会被别的大老虎吃掉<br>问 这六只老虎怎样过河<br>1.ac过去,a回来<br>2.ab过去,a回来<br>3.BC过去,Bb回来<br>4.Aa过去,Cc回来<br>5.CB过去,a回来<br>6.ab过去,a回来<br>7.ac过去</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>我空有一身泡妞的本事,可惜自己是个妞。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>火车座位靠窗<br>给正在外面漂的大家提个醒:只要是个位数 0 ,5, 4, 9的火车票全是靠近窗户的。0 5是三人座靠窗的;4 9是两人座靠窗的。个位数是2 7 3 8是靠近过道的,2 7是三人座靠过道,3 8二人座靠过道的。剩的两个数就是三人座中间的。绝对真实!</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>哥, 你是为了看起来高才带着脑袋的吗?—-秘密花园<br>如果爱需要用语言表达,那么哑巴怎么相爱—-比悲伤更悲伤的故事 权相宇<br>喜欢上你不在我的计划当中,只是刚好发生<br>找个好男人结婚吧,和你结婚不行吗?我不是好男人—-权相宇主演</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>有十二个乒乓球特征相同,其中只有一个重量异常,现在要求用一部没有砝码的天平称三次,将那个重量异常的球找出来。<br>分3份ABC称,每份4个:<br>a.此时AB两边平衡,那么AB正常,异类在第三份C中。从第三份C中取两个C1C2跟正常2个的称:<br> a.1如果平衡,那么异类在第三份剩下的C3C4中,再取C3跟正常的称,如平衡那么异类就是C4,如不平衡,异类就是C3.<br> a.2如果C1C2偏下/偏上,再取C1跟正常的称,如果平衡那么C2是异类,如不平衡,那么异类就是C2.<br>b.此时A下B上,那么C正常。再取A1A2B1B2跟A3B3C1C2称:<br> b1如果平衡,那么异类在A4B4中,简单;<br> b2若A1A2B1B2偏上,则异类在A3B1B2中,再取A3B1跟C1C2测,平衡则异类是B2,A3B1上异类是B1,A3B1下异类是A3;<br> b3若A1A2B1B2偏下,异类在A1A2B3中,再取A1B3跟C1C2称如果A1B3偏上那么异类B3如果偏下异类A1<br>c.此时A上B下,与步骤b同理可测。</p>
<p>Create: Tue Dec 04 2012 00:14:41 GMT+0800 (中国标准时间)Link<br>李广射石,弓虽强,石更硬。 楼主自宫,七刀切,土里埋</p>
]]></content>
<summary type="html">
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>学校举办一次中国象棋比赛,有10名同学参加,比赛采用单循环赛制,每名同学都要与其他9名同学比赛一局。比赛规则,每局棋胜者得2分,负者得0分,平局两人各得1分,比赛结束后,10名同学的得分各不相同,已知:(1)比赛第一名与第二名都是一局都没有输过;(2)前两名的得分总和比第三名多20分;(3)第四名的得分与最后四名的得分和相等。那么,排名第五名的同学的得分是?<br>A.8分 B,9分 C.10分 D.11分</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>年度最爱电影。穆赫兰道影评是两个极端,抛去其他人的看法,自己坚持看完这部冗长的电影,而且还不知所云,只是强迫自己记住其中内容,等看完影评后用记忆串联起整部片子的时候,我深深地呼了一口气。</p>
<p>Create: Sat Nov 24 2012 07:09:37 GMT+0800 (中国标准时间)Link<br>【心理技巧:如何让人喜欢你】1、出门照照镜子,给自己一个自信的微笑;2、善于发现别人优点;3、赞美;4、主动、付出,别陪着人冷场;5、接受别人递过来的零食;6、多请人帮你小忙;7、用心倾听,不打断对方的话;8、说话有力,能感受到自己声音的感染力;9、说话之前,先考虑对方的感觉。</p>
</summary>
<category term="云笔记" scheme="http://huangming.github.io/tags/%E4%BA%91%E7%AC%94%E8%AE%B0/"/>
</entry>
<entry>
<title>oracle自动备份同步</title>
<link href="http://huangming.github.io/2016-08-18-oracle-auto-backup-and-restore.html"/>
<id>http://huangming.github.io/2016-08-18-oracle-auto-backup-and-restore.html</id>
<published>2016-08-18T10:41:36.000Z</published>
<updated>2016-12-20T01:14:12.000Z</updated>
<content type="html"><![CDATA[<p>oracle的简单导入导出工具一般有 <code>exp/imp</code> 跟 <code>expdp/impdp</code>。</p>
<ul>
<li>exp无法导出空表结构</li>
<li>exp可以导出long类型的数据,expdp不可以。long类型现在在慢慢被淘汰中。</li>
<li>exp是客户端工具,expdp是服务器端工具,expdp还可以并发,exp不可以</li>
</ul>
<p>使用exp导出而不是expdp的情况是无法直接访问数据库主机,也无法在建立dblink,这个时候只能使用exp导出。大部分情况还是用 expdp/impdp。exp无法导出空表不注意的话是很麻烦的,曾经做同步就因为这个原因导致应用无法使用,虽然网上也有一些解决办法,但是都需要对源库做一些变更,这对生产服务器来说还是很麻烦的,毕竟操作了就有风险要负责任。下面是用expdp/impdp自动同步生产跟测试库的范例。</p>
<h2 id="环境">环境</h2><p>源库跟目的库的Oracle大版本要一致,并且数据库SID要一样。<br>本文测试环境:</p>
<ul>
<li>源库操作系统 <code>windows server 2008 R2 x64</code><br>源库数据库版本 <code>11g Enterprise Edition Release 11.2.0.1.0 - 64bit</code></li>
<li>目的库操作系统 <code>win7 x64</code> <code>win10 x64</code> <code>windows server 2008 R2 x64</code> 均测试成功<br>目的库数据库版本 <code>11g Enterprise Edition Release 11.2.0.1.0 - 64bit</code></li>
</ul>
<p>查看版本:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="operator"><span class="keyword">select</span> banner <span class="keyword">from</span> sys.v_$<span class="keyword">version</span>;</span></span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h2 id="源库导出">源库导出</h2><p>在源库机器(假定SID名为ORCL)执行以下操作:</p>
<h3 id="1-_打开CMD,用sysdba登录数据库。">1. 打开CMD,用sysdba登录数据库。</h3><p>有些操作系统安装了不止一个数据库实例,为了确保操作的是源库,在CMD命令行中先执行一次<code>set ORACLE_SID=ORCL</code>:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">set</span> ORACLE_SID=ORCL</span><br><span class="line">sqlplus / as sysdba</span><br></pre></td></tr></table></figure></p>
<p>先检查一下登录的数据库:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">SQL> select instance_name from v<span class="variable">$instance</span>;</span><br><span class="line">INSTANCE_NAME</span><br><span class="line">----------------</span><br><span class="line">orcl</span><br></pre></td></tr></table></figure></p>
<h3 id="2-_新建directory(首次导出才要)。">2. 新建directory(首次导出才要)。</h3><pre><code><span class="comment"><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">SQL> create directory dump_dir as <span class="string">'D:\dump'</span>; </span><br><span class="line">SQL> grant all on directory dump_dir to <span class="built_in">test</span>; </span><br><span class="line">SQL> select * from dba_directories;</span><br></pre></td></tr></table></figure></span>
</code></pre><h3 id="3-_执行导出操作。">3. 执行导出操作。</h3><p>此操作再CMD中执行,不是登录到SQLPLUS里面。可用<code>Ctrl+C</code>退出SQLPLUS。<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">expdp system/manager@ORCL directory=dump_dir dumpfile=expdp_orcl_full.dmp logfile=expdp_orcl_full.log FULL=y;</span><br></pre></td></tr></table></figure></p>
<p>导出完成后,在<code>D:\dump</code>里面就能看到文件了,然后拷贝到目标机器的<code>director</code>路径里面。</p>
<h2 id="目的库导入">目的库导入</h2><p>首次导入同源库导出1、2步骤操作,这里省略。<br>因为目的库已经有各种用户对象了,不确定这些已存在对象会不会影响导入结果,所以这边先进行删除对象操作,然后再进行导入操作,最后重新编译一下一些存储过程等。</p>
<h3 id="1-删除对象">1.删除对象</h3><p>先创建删除对象的脚本,CMD下执行:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sqlplus system/manager@ORCL @d:\orcl_build_drop_sql.sql</span><br></pre></td></tr></table></figure></p>
<p>其中,<code>orcl_build_drop_sql.sql</code> 如下:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">-- d:\orcl_build_drop_sql.sql</span><br><span class="line"><span class="built_in">set</span> feedback off heading off verify off trimspool off </span><br><span class="line"><span class="built_in">set</span> pagesize <span class="number">0</span> linesize <span class="number">100</span> </span><br><span class="line">define v_spool =<span class="string">'d:\orcl_drop_objects.sql'</span> </span><br><span class="line">spool &v_spool </span><br><span class="line"> SELECT <span class="string">'DROP PACKAGE BODY '</span>|| OWNER ||<span class="string">'.'</span>|| OBJECT_NAME ||<span class="string">';'</span> FROM ALL_OBJECTS WHERE OBJECT_TYPE=<span class="string">'PACKAGE BODY'</span> AND OWNER IN ((<span class="string">'DBUSER1'</span>,<span class="string">'DBUSER2'</span>))</span><br><span class="line"> union all</span><br><span class="line"> SELECT <span class="string">'DROP PACKAGE '</span>|| OWNER ||<span class="string">'.'</span>|| OBJECT_NAME ||<span class="string">';'</span> FROM ALL_OBJECTS WHERE OBJECT_TYPE=<span class="string">'PACKAGE'</span> AND OWNER IN ((<span class="string">'DBUSER1'</span>,<span class="string">'DBUSER2'</span>))</span><br><span class="line"> union all</span><br><span class="line"> SELECT <span class="string">'DROP PROCEDURE '</span>|| OWNER ||<span class="string">'.'</span>|| OBJECT_NAME ||<span class="string">';'</span> FROM ALL_OBJECTS WHERE OBJECT_TYPE=<span class="string">'PROCEDURE'</span> AND OWNER IN ((<span class="string">'DBUSER1'</span>,<span class="string">'DBUSER2'</span>))</span><br><span class="line"> union all</span><br><span class="line"> SELECT <span class="string">'DROP FUNCTION '</span>|| OWNER ||<span class="string">'.'</span>|| OBJECT_NAME ||<span class="string">';'</span> FROM ALL_OBJECTS WHERE OBJECT_TYPE=<span class="string">'FUNCTION'</span> AND OWNER IN ((<span class="string">'DBUSER1'</span>,<span class="string">'DBUSER2'</span>))</span><br><span class="line"> union all</span><br><span class="line"> SELECT <span class="string">'DROP SEQUENCE '</span>|| SEQUENCE_OWNER ||<span class="string">'.'</span>|| SEQUENCE_NAME ||<span class="string">';'</span> FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER IN ((<span class="string">'DBUSER1'</span>,<span class="string">'DBUSER2'</span>))</span><br><span class="line"> union all</span><br><span class="line"> SELECT <span class="string">'DROP VIEW '</span>|| OWNER ||<span class="string">'.'</span>|| VIEW_NAME ||<span class="string">';'</span> FROM ALL_VIEWS WHERE OWNER IN ((<span class="string">'DBUSER1'</span>,<span class="string">'DBUSER2'</span>))</span><br><span class="line"> union all</span><br><span class="line"> SELECT <span class="string">'DROP TABLE '</span>|| OWNER ||<span class="string">'.'</span>|| TABLE_NAME ||<span class="string">' CASCADE CONSTRAINTS PURGE;'</span> FROM ALL_TABLES WHERE OWNER IN ((<span class="string">'DBUSER1'</span>,<span class="string">'DBUSER2'</span>))</span><br><span class="line"> union all</span><br><span class="line"> SELECT <span class="string">'exit '</span> from dual;</span><br><span class="line"></span><br><span class="line">spool off </span><br><span class="line"></span><br><span class="line"><span class="built_in">exit</span></span><br></pre></td></tr></table></figure></p>
<p>创建的删除脚本在 <code>d:\orcl_build_drop_sql.sql</code>,在CMD中执行脚本删除对象:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sqlplus system/krcs@KRCS @d:\krcs_drop_objects.sql</span><br></pre></td></tr></table></figure></p>
<h3 id="2-导入操作">2.导入操作</h3><p>执行导入操作:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">impdp system/manager@ORCL directory=dump_dir dumpfile=expdp_orcl_full.dmp logfile=impdp_orcl_full.log FULL=y;</span><br></pre></td></tr></table></figure></p>
<h3 id="3-重新编译无效对象">3.重新编译无效对象</h3><p>oracle自带脚本<code>$ORACLE_HOME/rdbms/admin/utlrp.sql</code>可重新编译无效对象。<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sqlplus system/krcs@KRCS @D:\app\Administrator\product\<span class="number">11.2</span>.<span class="number">0</span>\dbhome_1\RDBMS\ADMIN\utlrp.sql</span><br></pre></td></tr></table></figure></p>
<h2 id="汇总所有操作写成批处理自动执行">汇总所有操作写成批处理自动执行</h2><h3 id="1-源库定时导出并发送">1.源库定时导出并发送</h3><p>在源库机器新建一个任务计划,每天执行以下批处理。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off </span><br><span class="line">color <span class="number">0</span>b & cls </span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 设置备份文件存放文件夹... </span><br><span class="line">echo.</span><br><span class="line"><span class="built_in">set</span> <span class="string">"localexpdpdir=d:\dump"</span> </span><br><span class="line">:: 备份服务器</span><br><span class="line"><span class="built_in">set</span> <span class="string">"bk_server=\\192.168.1.1\g$"</span> </span><br><span class="line"><span class="built_in">set</span> <span class="string">"bk_server_full=\\192.168.1.1\g$\数据"</span></span><br><span class="line">:: 测试服务器<span class="number">1</span></span><br><span class="line"><span class="built_in">set</span> <span class="string">"bk_server2=\\192.168.1.2\e$\data"</span></span><br><span class="line">:: 测试服务器<span class="number">2</span></span><br><span class="line"><span class="built_in">set</span> <span class="string">"bk_server3=\\192.168.1.3\c$\temp"</span></span><br><span class="line"> </span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 是否存在<span class="number">2</span>天前备份文件,若存在则删除... </span><br><span class="line">echo.</span><br><span class="line">forfiles /p %localexpdpdir% /d -<span class="number">2</span> /c <span class="string">"cmd /c echo deleting @file ... && del /f /q /a @path"</span></span><br><span class="line"> </span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 设置备份文件名</span><br><span class="line">echo.</span><br><span class="line"><span class="built_in">set</span> name=%date:~<span class="number">0</span>,<span class="number">4</span>%%date:~<span class="number">5</span>,<span class="number">2</span>%%date:~<span class="number">8</span>,<span class="number">2</span>%</span><br><span class="line"><span class="built_in">set</span> name=%name%</span><br><span class="line">::<span class="built_in">set</span> name=<span class="number">20161210</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 是否存在同名文件,若存在则删除同名文件... </span><br><span class="line">echo.</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] ===========================================================</span><br><span class="line">echo.</span><br><span class="line"><span class="keyword">if</span> exist %localexpdpdir%\orcl_full_%name%.dmp del %localexpdpdir%\orcl_full_%name%.dmp</span><br><span class="line"><span class="keyword">if</span> exist %localexpdpdir%\orcl_%name%.dmp del %localexpdpdir%\orcl_%name%.dmp</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 开始备份..... </span><br><span class="line">echo.</span><br><span class="line">::select * from dba_directories;</span><br><span class="line">:: 备份两种,一种全库,一种按部分用户</span><br><span class="line">expdp system/manager@orcl directory=dump_dir dumpfile=orcl_%name%.dmp logfile=orcl_%name%.log schemas=dbuser1,dbuser2</span><br><span class="line">expdp system/manager@orcl directory=dump_dir dumpfile=orcl_full_%name%.dmp logfile=orcl_full_%name%.log FULL=y</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 备份完毕!</span><br><span class="line">echo.</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] ===========================================================</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 拷贝备份到<span class="number">192.168</span>.<span class="number">1.1</span></span><br><span class="line">echo.</span><br><span class="line">net use O: /del</span><br><span class="line">net use O: \\<span class="number">192.168</span>.<span class="number">1.1</span>\g$ <span class="string">"psw****"</span> /user:<span class="string">"Administrator"</span></span><br><span class="line"></span><br><span class="line">:: 每周二拷贝全量备份,其余日期拷贝选定用户的备份,减少备份服务器的空间压力</span><br><span class="line"><span class="keyword">if</span> <span class="string">"%date:~13%"</span>==<span class="string">"二"</span> (</span><br><span class="line">copy %localexpdpdir%\orcl_full_%name%.dmp %bk_server_full%\orcl_full_%name%.dmp /y</span><br><span class="line">) <span class="keyword">else</span> (</span><br><span class="line">copy %localexpdpdir%\orcl_%name%.dmp %bk_server%\orcl_%name%.dmp /y</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 删除备份服务器上<span class="number">31</span>天前的全量备份</span><br><span class="line">echo.</span><br><span class="line">forfiles /p <span class="string">"o:"</span> /d -<span class="number">31</span> /c <span class="string">"cmd /c echo deleting @file ... && del /f /q /a @path"</span></span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 删除备份服务器上<span class="number">7</span>天前的选定用户数据的备份</span><br><span class="line">echo.</span><br><span class="line">forfiles /p <span class="string">"o:\数据"</span> /d -<span class="number">7</span> /c <span class="string">"cmd /c echo deleting @file ... && del /f /q /a @path"</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] ===========================================================</span><br><span class="line"></span><br><span class="line">::<span class="built_in">echo</span> 拷贝备份到<span class="number">192.168</span>.<span class="number">1.2</span></span><br><span class="line">::net use O: /del</span><br><span class="line">::net use O: \\<span class="number">192.101</span>.<span class="number">1.2</span>\e$\data <span class="string">"psw****"</span> /user:<span class="string">"Administrator"</span></span><br><span class="line">::</span><br><span class="line">::copy %localexpdpdir%\orcl_full_%name%.dmp %bk_server2%\orcl_full_%name%.dmp /y</span><br><span class="line">::<span class="built_in">echo</span> 删除备份服务器上<span class="number">2</span>天前的备份</span><br><span class="line">::forfiles /p <span class="string">"o:\" /d -2 /c "</span>cmd /c <span class="built_in">echo</span> deleting @file ... && del /f /q /a @path<span class="string">"</span><br><span class="line"></span><br><span class="line">echo [%date:~0,10% %time%] ===========================================================</span><br><span class="line"></span><br><span class="line">echo [%date:~0,10% %time%] 拷贝备份到192.168.1.3</span><br><span class="line">echo.</span><br><span class="line">net use O: /del</span><br><span class="line">net use O: \\192.168.1.3\c$\temp "</span>psw****<span class="string">" /user:"</span>Administrator<span class="string">"</span><br><span class="line"></span><br><span class="line">echo [%date:~0,10% %time%] 删除备份服务器192.168.1.3上2天前的备份</span><br><span class="line">echo.</span><br><span class="line">forfiles /p "</span>o:\<span class="string">" /d -2 /c "</span>cmd /c <span class="built_in">echo</span> deleting @file ... && del /f /q /a @path<span class="string">"</span><br><span class="line">copy %localexpdpdir%\orcl_full_%name%.dmp %bk_server3%\orcl_full_%name%.dmp /y</span><br><span class="line">echo [%date:~0,10% %time%] 拷贝备份到192.168.1.3完成</span><br><span class="line">echo.</span><br><span class="line">echo [%date:~0,10% %time%] ===========================================================</span><br><span class="line">echo [%date:~0,10% %time%] 结束</span><br><span class="line"></span><br><span class="line">goto :eof</span><br><span class="line"></span><br><span class="line">::rem 计算指定天数之前的日期</span><br><span class="line">::set DaysAgo=5</span><br><span class="line">::rem 假设系统日期的格式为yyyy-mm-dd</span><br><span class="line">::call :DateToDays %date:~0,4% %date:~5,2% %date:~8,2% PassDays</span><br><span class="line">::set /a PassDays-=%DaysAgo%</span><br><span class="line">::call :DaysToDate %PassDays% DstYear DstMonth DstDay</span><br><span class="line">::set DstDate=%DstYear%%DstMonth%%DstDay%</span><br><span class="line">::echo %DaysAgo%天的日期是%DstDate%</span><br><span class="line">::pause</span><br><span class="line">::goto :eof</span><br><span class="line"></span><br><span class="line">:DateToDays %yy% %mm% %dd% days</span><br><span class="line">setlocal ENABLEEXTENSIONS</span><br><span class="line">set yy=%1&set mm=%2&set dd=%3</span><br><span class="line">if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)</span><br><span class="line">set /a dd=100%dd%%%100,mm=100%mm%%%100</span><br><span class="line">set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2</span><br><span class="line">set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633</span><br><span class="line">endlocal&set %4=%j%&goto :EOF</span><br><span class="line"></span><br><span class="line">:DaysToDate %days% yy mm dd</span><br><span class="line">setlocal ENABLEEXTENSIONS</span><br><span class="line">set /a a=%1+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a</span><br><span class="line">set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5</span><br><span class="line">set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10</span><br><span class="line">(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)</span><br><span class="line">endlocal&set %2=%yy%&set %3=%mm%&set %4=%dd%&goto :EOF</span></span><br></pre></td></tr></table></figure>
<h3 id="2-目的库定时导入">2.目的库定时导入</h3><p>在目的库机器新建一个任务计划,每天执行以下批处理(执行时间在源库的定时时间延后2小时)。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off </span><br><span class="line">color <span class="number">0</span>b & cls </span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 设置导入路径... </span><br><span class="line">echo.</span><br><span class="line"><span class="built_in">set</span> <span class="string">"localexpdpdir=c:\temp"</span></span><br><span class="line"><span class="built_in">echo</span> %localexpdpdir%</span><br><span class="line">echo.</span><br><span class="line"></span><br><span class="line">::<span class="built_in">set</span> <span class="string">"localexpdpdir=Z:\orcl系统备份\data"</span></span><br><span class="line">::<span class="built_in">set</span> <span class="string">"localexpdpdir=Y:"</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 设置导入文件名</span><br><span class="line">echo.</span><br><span class="line"><span class="built_in">set</span> name=%date:~<span class="number">0</span>,<span class="number">4</span>%%date:~<span class="number">5</span>,<span class="number">2</span>%%date:~<span class="number">8</span>,<span class="number">2</span>%</span><br><span class="line"><span class="built_in">set</span> name=%name%</span><br><span class="line">::<span class="built_in">set</span> name=<span class="number">20161215</span></span><br><span class="line"></span><br><span class="line">:: 前一日</span><br><span class="line">::call :DateToDays %date:~<span class="number">0</span>,<span class="number">4</span>% %date:~<span class="number">5</span>,<span class="number">2</span>% %date:~<span class="number">8</span>,<span class="number">2</span>% PassDays</span><br><span class="line">::<span class="built_in">set</span> /a PassDays-=<span class="number">1</span></span><br><span class="line">::call :DaysToDate %PassDays% DstYear DstMonth DstDay</span><br><span class="line">::<span class="built_in">set</span> name=%DstYear%%DstMonth%%DstDay%</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> %name%</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] work begin......</span><br><span class="line">echo.</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> exist %localexpdpdir%\orcl_full_%name%.dmp (</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 存在%localexpdpdir%\orcl_full_%name%.dmp</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 创建删除对象脚本.....</span><br><span class="line">echo.</span><br><span class="line">sqlplus system/manager@orcl @d:\orcl_build_drop_sql.sql</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 开始删除对象.....</span><br><span class="line">echo.</span><br><span class="line">sqlplus system/manager@orcl @d:\orcl_drop_objects.sql</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 开始导入.....</span><br><span class="line">impdp system/manager@orcl directory=dump_dir dumpfile=<span class="string">'orcl_full_%name%.dmp'</span> logfile=<span class="string">'orcl_full_%name%.log'</span> TABLE_EXISTS_ACTION=SKIP schemas=dbuser1,dbuser2</span><br><span class="line">echo.</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 重新编译无效对象.....</span><br><span class="line">echo.</span><br><span class="line">sqlplus system/manager@orcl @D:\app\Administrator\product\<span class="number">11.2</span>.<span class="number">0</span>\dbhome_1\RDBMS\ADMIN\utlrp.sql</span><br><span class="line">)</span><br><span class="line">::del %localexpdpdir%\sipfbak%name%.dmp)</span><br><span class="line"><span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 导入结束。</span><br><span class="line">echo.</span><br><span class="line"></span><br><span class="line">::pause</span><br><span class="line"></span><br><span class="line">:: 删除T-<span class="number">2</span>日备份</span><br><span class="line">call :DateToDays %date:~<span class="number">0</span>,<span class="number">4</span>% %date:~<span class="number">5</span>,<span class="number">2</span>% %date:~<span class="number">8</span>,<span class="number">2</span>% PassDays</span><br><span class="line"><span class="built_in">set</span> /a PassDays-=<span class="number">2</span></span><br><span class="line">call :DaysToDate %PassDays% DstYear DstMonth DstDay</span><br><span class="line"><span class="built_in">set</span> aYesDate=%DstYear%%DstMonth%%DstDay%</span><br><span class="line"><span class="keyword">if</span> exist %localexpdpdir%\orcl_full_%aYesDate%.dmp (</span><br><span class="line"> <span class="built_in">echo</span> [%date:~<span class="number">0</span>,<span class="number">10</span>% %time%] 删除过期文件orcl_full_%aYesDate%.dmp</span><br><span class="line"> del %localexpdpdir%\orcl_full_%aYesDate%.dmp</span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">:DateToDays %yy% %mm% %dd% days</span><br><span class="line">setlocal ENABLEEXTENSIONS</span><br><span class="line"><span class="built_in">set</span> yy=%<span class="number">1</span>&<span class="built_in">set</span> mm=%<span class="number">2</span>&<span class="built_in">set</span> dd=%<span class="number">3</span></span><br><span class="line"><span class="keyword">if</span> <span class="number">1</span>%yy% LSS <span class="number">200</span> <span class="keyword">if</span> <span class="number">1</span>%yy% LSS <span class="number">170</span> (<span class="built_in">set</span> yy=<span class="number">20</span>%yy%) <span class="keyword">else</span> (<span class="built_in">set</span> yy=<span class="number">19</span>%yy%)</span><br><span class="line"><span class="built_in">set</span> /a dd=<span class="number">100</span>%dd%%%<span class="number">100</span>,mm=<span class="number">100</span>%mm%%%<span class="number">100</span></span><br><span class="line"><span class="built_in">set</span> /a z=<span class="number">14</span>-mm,z/=<span class="number">12</span>,y=yy+<span class="number">4800</span>-z,m=mm+<span class="number">12</span>*z-<span class="number">3</span>,j=<span class="number">153</span>*m+<span class="number">2</span></span><br><span class="line"><span class="built_in">set</span> /a j=j/<span class="number">5</span>+dd+y*<span class="number">365</span>+y/<span class="number">4</span>-y/<span class="number">100</span>+y/<span class="number">400</span>-<span class="number">2472633</span></span><br><span class="line">endlocal&<span class="built_in">set</span> %<span class="number">4</span>=%j%&goto :EOF</span><br><span class="line"> </span><br><span class="line">:DaysToDate %days% yy mm dd</span><br><span class="line">setlocal ENABLEEXTENSIONS</span><br><span class="line"><span class="built_in">set</span> /a a=%<span class="number">1</span>+<span class="number">2472632</span>,b=<span class="number">4</span>*a+<span class="number">3</span>,b/=<span class="number">146097</span>,c=-b*<span class="number">146097</span>,c/=<span class="number">4</span>,c+=a</span><br><span class="line"><span class="built_in">set</span> /a d=<span class="number">4</span>*c+<span class="number">3</span>,d/=<span class="number">1461</span>,e=-<span class="number">1461</span>*d,e/=<span class="number">4</span>,e+=c,m=<span class="number">5</span>*e+<span class="number">2</span>,m/=<span class="number">153</span>,dd=<span class="number">153</span>*m+<span class="number">2</span>,dd/=<span class="number">5</span></span><br><span class="line"><span class="built_in">set</span> /a dd=-dd+e+<span class="number">1</span>,mm=-m/<span class="number">10</span>,mm*=<span class="number">12</span>,mm+=m+<span class="number">3</span>,yy=b*<span class="number">100</span>+d-<span class="number">4800</span>+m/<span class="number">10</span></span><br><span class="line">(<span class="keyword">if</span> %mm% LSS <span class="number">10</span> <span class="built_in">set</span> mm=<span class="number">0</span>%mm%)&(<span class="keyword">if</span> %dd% LSS <span class="number">10</span> <span class="built_in">set</span> dd=<span class="number">0</span>%dd%)</span><br><span class="line">endlocal&<span class="built_in">set</span> %<span class="number">2</span>=%yy%&<span class="built_in">set</span> %<span class="number">3</span>=%mm%&<span class="built_in">set</span> %<span class="number">4</span>=%dd%&goto :EOF</span><br></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<p>oracle的简单导入导出工具一般有 <code>exp/imp</code> 跟 <code>expdp/impdp</code>。</p>
<ul>
<li>exp无法导出空表结构</li>
<li>exp可以导出long类型的数据,expdp不可以。long类型现在在慢慢被淘汰中。</li>
<li>exp是客户端工具,expdp是服务器端工具,expdp还可以并发,exp不可以</li>
</ul>
<p>使用exp导出而不是expdp的情况是无法直接访问数据库主机,也无法在建立dblink,这个时候只能使用exp导出。大部分情况还是用 expdp/impdp。exp无法导出空表不注意的话是很麻烦的,曾经做同步就因为这个原因导致应用无法使用,虽然网上也有一些解决办法,但是都需要对源库做一些变更,这对生产服务器来说还是很麻烦的,毕竟操作了就有风险要负责任。下面是用expdp/impdp自动同步生产跟测试库的范例。</p>
<h2 id="环境">环境</h2><p>源库跟目的库的Oracle大版本要一致,并且数据库SID要一样。<br>本文测试环境:</p>
<ul>
<li>源库操作系统 <code>windows server 2008 R2 x64</code><br>源库数据库版本 <code>11g Enterprise Edition Release 11.2.0.1.0 - 64bit</code></li>
<li>目的库操作系统 <code>win7 x64</code> <code>win10 x64</code> <code>windows server 2008 R2 x64</code> 均测试成功<br>目的库数据库版本 <code>11g Enterprise Edition Release 11.2.0.1.0 - 64bit</code></li>
</ul>
<p>查看版本:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="operator"><span class="keyword">select</span> banner <span class="keyword">from</span> sys.v_$<span class="keyword">version</span>;</span></span><br></pre></td></tr></table></figure>
</summary>
<category term="database" scheme="http://huangming.github.io/categories/database/"/>
<category term="backup" scheme="http://huangming.github.io/tags/backup/"/>
<category term="expdp" scheme="http://huangming.github.io/tags/expdp/"/>
<category term="impdp" scheme="http://huangming.github.io/tags/impdp/"/>
<category term="oracle" scheme="http://huangming.github.io/tags/oracle/"/>
<category term="oracle热备" scheme="http://huangming.github.io/tags/oracle%E7%83%AD%E5%A4%87/"/>
</entry>
<entry>
<title>Python爬虫正则表达式抓取糗百笑话</title>
<link href="http://huangming.github.io/2016-08-06-python-zhengze-pachong-qiubai.html"/>
<id>http://huangming.github.io/2016-08-06-python-zhengze-pachong-qiubai.html</id>
<published>2016-08-06T08:25:54.000Z</published>
<updated>2016-08-07T14:40:58.662Z</updated>
<content type="html"><![CDATA[<p>很多人对正则表达式很头痛,其实写正则表达式是有套路的,看完这篇文章保证你会写任何html上的内容抓取的正则。<br>为确保代码的正确性,此文约定环境为python3,如果在python2运行,可能要做一些调整。</p>
<a id="more"></a>
<h2 id="从网上获取整个html">从网上获取整个html</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> urllib.parse</span><br><span class="line"><span class="keyword">import</span> urllib.request</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">QSBK</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line"> self.page = <span class="number">1</span></span><br><span class="line"> <span class="comment"># 记录访问的页码</span></span><br><span class="line"> self.user_agent = <span class="string">'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'</span></span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">get_stories</span><span class="params">(self)</span>:</span></span><br><span class="line"> url = <span class="string">"http://www.qiushibaike.com/hot/page/"</span>+str(self.page) </span><br><span class="line"> <span class="comment">#构建请求的url </span></span><br><span class="line"> req = urllib.request.Request(url)</span><br><span class="line"> req.add_header(<span class="string">'User-Agent'</span>, self.user_agent)</span><br><span class="line"> response = urllib.request.urlopen(req)</span><br><span class="line"> the_page = response.read().decode(<span class="string">"utf-8"</span>)</span><br><span class="line"> <span class="keyword">return</span> the_page</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line"> qb = QSBK()</span><br><span class="line"> <span class="comment"># print(qb.get_stories()) 此处会报一个编码错误的error,应该是在html的后面有</span></span><br><span class="line"> <span class="comment"># 个别编码不一样的原因,用下面这个可以截取前面的部分,正常看到内容</span></span><br><span class="line"> print(qb.get_stories()[:<span class="number">5000</span>])</span><br></pre></td></tr></table></figure>
<h2 id="编写正则表达式">编写正则表达式</h2><p>为了写出正则表达式,我们总结了糗百的段子规律:以<code><div\sclass="article\sblock\suntagged\smb15"\sid='qiushi_tag</code>开头,然后有好多空行啦,html的 <code><div></code> 块啦,然后<code><div\sclass="content"></code>接着可能有几行空行或者没空行,接着就是我们要的段子,再接着是空行加<code></div></code>结束段子。在匹配到开头到段子内容之间有很多内容,我们如果想要用一些正则忽略他们的内容进行匹配就必须用到<code>.*</code>的多行匹配re.S。</p>
<p>这里用到了正则表达式的 <code>re.findall(pattern, string[, flags])</code> 大家可以先去搜索一下这个东西大概浏览一下,特别注意一下 <code>flags=re.X</code> 和 <code>flags=re.S</code> 的意义,这里了利用这两个flags能写出很好看很容易理解的正则表达式:</p>
<ul>
<li>re.S:DOTALL<br>使 “.” 特殊字符完全匹配任何字符,包括换行;没有这个标志, “.” 匹配除了换行外的任何字符。</li>
<li>re.X:VERBOSE<br>该标志通过给予你更灵活的格式以便你将正则表达式写得更易于理解。当该标志被指定时,在 RE 字符串中的空白符被忽略,除非该空白符在字符类中或在反斜杠之後;这可以让你更清晰地组织和缩进 RE。它也可以允许你将注释写入 RE,这些注释会被引擎忽略;注释用 “#”号 来标识,不过该符号不能在字符串或反斜杠之後。</li>
</ul>
<p>抓取到内容后就是编写正则表达式匹配内容了,这里先另外起程序写出正确的正则表达式再加进上面代码里面。</p>
<p>先选用一段html作为范例教大家怎么写正则。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> re</span><br><span class="line">html = <span class="string">'''<div class="article block untagged mb15" id='qiushi_tag_117188488'></span><br><span class="line"></span><br><span class="line"><div class="author clearfix"></span><br><span class="line"><a href="/users/29552012/" target="_blank" rel="nofollow"></span><br><span class="line"><img src="http://pic.qiushibaike.com/system/avtnew/2955/29552012/medium/20150723232021.jpg" alt="invictusmaneo"/></span><br><span class="line"></a></span><br><span class="line"><a href="/users/29552012/" target="_blank" title="invictusmaneo"></span><br><span class="line"><h2>invictusmaneo</h2></span><br><span class="line"></a></span><br><span class="line"></div></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><div class="content"></span><br><span class="line"></span><br><span class="line">昨天在食堂打菜 给人碰了一下 菜汤泼裤子上了 当时愁的 心说油渍多难洗啊 吃完饭 看了眼裤子 连个印子都没了 菜里根本就没油啊!!! 是我想太多了..</span><br><span class="line"></span><br><span class="line"></div></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><div class="stats"></span><br><span class="line"><span class="stats-vote"><i class="number">7152</i> 好笑</span></span><br><span class="line"><span class="stats-comments">'''</span></span><br><span class="line">pattern = <span class="string">'''<div class="article block untagged mb15" id='qiushi_tag_117192587'>'''</span></span><br><span class="line">myItems = re.findall(pattern,html,re.S|re.X)</span><br><span class="line">print(myItems)</span><br></pre></td></tr></table></figure>
<h3 id="1-空格">1.空格</h3><p>我们先拿一小段试试能不能匹配,发现匹配不了。匹配不了的时候不用慌,我们把匹配内容再缩小: <code>pattern='''<div'''</code> 发现是能匹配的,而 <code>pattern='''<div class'''</code> 匹配不了,这时候稍微想一下就知道,这个空格出问题了,然后再浏览一下python正则的博文或者直接百度搜索,就知道空格应该用 <code>\s</code>,然后我们把整行的空格全替换掉:<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="article\sblock\suntagged\smb15"\sid='qiushi_tag_117192587'>'''</span></span><br></pre></td></tr></table></figure></p>
<p>运行后,结果能匹配到。然后我们继续研究关于多行匹配的</p>
<h3 id="2-多行">2.多行</h3><p>先试试匹配两行连续的。记得先把空格替换成 <code>\s</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="author\sclearfix"></span><br><span class="line"><a\shref="/users/27990908/"\starget="_blank"\srel="nofollow">'''</span></span><br></pre></td></tr></table></figure>
<p>发现是匹配不了的,这时候就要想了,有可能换行要特殊处理的,搜一下百度,我们试试 <code>\n</code> 代替换行。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="author\sclearfix">\n<a\shref="/users/27990908/"\starget="_blank"\srel="nofollow">'''</span></span><br></pre></td></tr></table></figure>
<p>试了下,结果空的,说明不对,然后再试一下写两行的:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="author\sclearfix">\n</span><br><span class="line"><a\shref="/users/27990908/"\starget="_blank"\srel="nofollow">'''</span></span><br></pre></td></tr></table></figure>
<p>结果还是空的,说明这个换行是匹配失败了,因为单独两行的分别去匹配是可以匹配到的,加个换行就不行了。此时再想一想,还有什么地方关于这个<code>\n</code>容易出问题的?很容易想到<code>\</code>可能会出问题。我们再试试<code>\\n</code>:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="author\sclearfix">\\n<a\shref="/users/27990908/"\starget="_blank"\srel="nofollow">'''</span></span><br></pre></td></tr></table></figure>
<p>发现是能匹配到结果的。因为用了<code>re.X</code>,我们再试试换写成两行的:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="author\sclearfix">\\n</span><br><span class="line"> <a\shref="/users/27990908/"\starget="_blank"\srel="nofollow">'''</span></span><br></pre></td></tr></table></figure>
<p>这个也是能匹配的。证明用了<code>re.X</code>确实对于空格和换行等于没效果的。</p>
<h3 id="3-分组">3.分组</h3><p>上面所有匹配到的都是在 <code>pattern</code> 的全部内容,我们最终要的只是笑话的部分,所以必然会有一个筛选的东西。通过大概的搜索浏览 <code>python正则</code> 可以知道括号分组能从匹配结果中只返回分组内容。例如:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="author\sclearfix">\\n</span><br><span class="line"> <a\shref="/users/27990908/"\starget="_blank"\srel="(nofollow)">'''</span></span><br></pre></td></tr></table></figure>
<p>运行后得到 <code>nofollow</code>。所以我们只要把<code>pattern</code>一直写下去,写到笑话那里,然后把内容用括号括起来就可以得到笑话内容了。另外,因为每段笑话前后结构大体相同,但是还是有细节是不一样的,所以还要处理一些不一样的东西。不然像上面的<code>pattern</code>就只能匹配到一个结果,也就是说如果是笑话也只能匹配到一个。很容易,我们就能观察到时那串数字<code>27990908</code>不一样。此时我们可以用<code>\d+</code>代替,以匹配所有的数字。</p>
<h3 id="4-贪婪、非贪婪匹配">4.贪婪、非贪婪匹配</h3><p>我们继续写开始的<code>pattern</code>:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="article\sblock\suntagged\smb15"\sid='qiushi_tag_\d+'>'''</span></span><br></pre></td></tr></table></figure>
<p>此时,能匹配到开头了,但是接下来有一大段内容,我们不想关注他是什么,我们只想关注到段子那里。我们尝试用 <code>.*</code>、<code>\w*</code>之类的写法: </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="article\sblock\suntagged\smb15"\sid='qiushi_tag_\d+'>.*<div\sclass="content">'''</span></span><br></pre></td></tr></table></figure>
<p>运行发现,只有一段笑话的话是可以匹配到的,但是整个html有很多段的时候,他直接匹配到最后一个笑话的<code><div\sclass="content"></code>!为了解决问题,我们搜索一下<code>python正则 尽可能少匹配</code>,很容易得到<code>贪婪</code>、<code>非贪婪</code>这两个词:</p>
<figure class="highlight 1c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">Python里数量词默认是贪婪的(在少数语言里也可能是默认非贪婪),总是尝试匹配尽可能多的字符;</span><br><span class="line">非贪婪则相反,总是尝试匹配尽可能少的字符。在<span class="string">"*"</span>,<span class="string">"?"</span>,<span class="string">"+"</span>,<span class="string">"{m,n}"</span>后面加上?,使贪婪变成非贪婪</span><br></pre></td></tr></table></figure>
<p>然后我们得到新的pattern:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="article\sblock\suntagged\smb15"\sid='qiushi_tag_\d+'>.*?<div\sclass="content">\\n*(.*?)\\n*</div>'''</span></span><br></pre></td></tr></table></figure>
<p>此时运行后发现已经能抓到大部分段子了,但是依然存在一些垃圾信息抓多了的。然后观察一下html会发现,这些垃圾信息是属于带图片的段子的文本部分,因为少了图片看起来就很奇怪。所以我们要继续改进pattern,使其不匹配带图片的段子。要想实现这个就必须找出文本跟图片段子的区别。</p>
<p>很容易我们就能发现,在文本段子后面,只有文本的段子是直接就<code><div class="stats"></code>,然后几行后是有<code><div class="single-clear"></div></code> 的,而有图片的段子在到达<code><div class="stats"></code>之前是多了好几个html标记的,其中一个是<code><img></code>标记。我们只要把pattrtn继续写下去,就能只匹配文本的段子了:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="article\sblock\suntagged\smb15"\sid='qiushi_tag_\d+'>.*?<div\sclass="content">\\n*([^(?:</div>)]*?)\\n*</div>\\n*<div\sclass="stats">'''</span></span><br></pre></td></tr></table></figure>
<p>运行发现,垃圾信息依然存在</p>
<figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">['昨天在食堂打菜 给人碰了一下 菜汤泼裤子上了 当时愁的 心说油渍多难洗啊 吃完饭 看了眼裤子 连个印子都没了 菜里根本就没油啊!!! 是我想太多了..', '12345\<span class="keyword">n</span>\<span class="keyword">n</span></div>\<span class="keyword">n</span>\<span class="keyword">n</span>\<span class="keyword">n</span>\<span class="keyword">n</span><div <span class="keyword">class</span>=<span class="string">"thumb"</span>>\<span class="keyword">n</span>\<span class="keyword">n</span><a href=<span class="string">"/article/117193665"</span> target=<span class="string">"_blank"</span>>\<span class="keyword">n</span><img src=<span class="string">"http://pic.qiushibaike.com/system/pictures/11719/117193665/medium/app117193665.jpg"</span> alt=<span class="string">"糗事#117193665"</span> />\<span class="keyword">n</span></a>', '家里有个两岁的小暖男,大热天他经常问他爸爸:冷吗?然后帮他爸爸把电风扇关了,把被子盖上,每天乐此不疲。']</span><br></pre></td></tr></table></figure>
<p>仔细分析我们的pattern和那个多余的垃圾信息,发现确实是能匹配到的,那个垃圾信息完全符合pattern开头中间结尾的所有内容。关键点就在于在 <code><div class="content"></code> 跟 <code></div></code> 之间的才是真正的段子。我们虽然对段子用了<code>(.*?)</code>非贪婪匹配,但是因为加了后面结尾的条件,所以匹配会在满足结尾的条件下去用非贪婪匹配,所以得到了上面的结果。这时候非贪婪就不够用了,我们要自己给他实现非贪婪匹配。既然是段子结尾接着是<code></div></code>,那么我们只要限制段子的内容不能是<code></div></code>就能让他抓取到正确的段子了。</p>
<p>搜索一下 <code>python正则 否定</code> 就能得到<code>^</code>在python正则里边是否定的意思。但是网上的例子大部分都是只有一个字符的,我们想要实现<code>不是</div></code>要怎么写呢?答案是 <code>[^(</div>)]*</code> 至于为什么这样,写起来太啰嗦,能理解的理解,不能理解的记住规则就可以了。如果纠结于括号会想到分组,可以用<code>[^(?:</div>)]*</code>,分组括号里面用<code>?:</code>表示这个分组的内容不会被当作返回结果,分组只作为一个整体的作用。</p>
<p>最终,我们得到了能完全匹配到自己想要的段子的正则,然后可以利用<code>re.X</code>的特性,让正则更美观易懂一些:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">pattern = <span class="string">'''<div\sclass="article\sblock\suntagged\smb15"\sid='qiushi_tag_\d+'> # 这里匹配开头</span><br><span class="line"> .*? # 这里匹配开头到段子前标记之间的内容,注意要用非贪婪匹配?</span><br><span class="line"> <div\sclass="content">\\n* # 这里是段子开始的标记,包括段子前的空行</span><br><span class="line"> ([^(?:</div>)]*?) # 这里是段子内容,最外边的括号是分组,里边的只是整体作用</span><br><span class="line"> \\n*</div> # 这里是段子结束的标记,包括段子后的空行</span><br><span class="line"> \\n*</span><br><span class="line"> <div\sclass="stats"> # 只匹配不含图片的段子。</span><br><span class="line">'''</span></span><br></pre></td></tr></table></figure>
<h2 id="最终结果">最终结果</h2><p>因为糗事百科网页可能会变化,这段代码在写这篇文章的时候是能得到预期结果的,如果不能得到预期结果,请自行修正。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> urllib.parse</span><br><span class="line"><span class="keyword">import</span> urllib.request</span><br><span class="line"><span class="keyword">import</span> re</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">QSBK</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line"> self.page = <span class="number">1</span></span><br><span class="line"> <span class="comment"># 记录访问的页码</span></span><br><span class="line"> self.user_agent = <span class="string">'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'</span></span><br><span class="line"> self.stories = []</span><br><span class="line"> <span class="comment"># 存储段子</span></span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">get_stories</span><span class="params">(self)</span>:</span></span><br><span class="line"> url = <span class="string">"http://www.qiushibaike.com/hot/page/"</span>+str(self.page) </span><br><span class="line"> <span class="comment">#构建请求的url </span></span><br><span class="line"> req = urllib.request.Request(url)</span><br><span class="line"> req.add_header(<span class="string">'User-Agent'</span>, self.user_agent)</span><br><span class="line"> response = urllib.request.urlopen(req)</span><br><span class="line"> the_page = response.read().decode(<span class="string">"utf-8"</span>)</span><br><span class="line"> <span class="comment"># print(the_page)</span></span><br><span class="line"> pattern = <span class="string">'''<div\sclass="article\sblock\suntagged\smb15"\sid='qiushi_tag_\d+'> # 这里匹配开头</span><br><span class="line"> .*? # 这里匹配开头到段子前标记之间的内容,注意要用非贪婪匹配?</span><br><span class="line"> <div\sclass="content">\\n* # 这里是段子开始的标记,包括段子前的空行</span><br><span class="line"> ([^(?:</div>)]*?) # 这里是段子内容,最外边的括号是分组,里边的只是整体作用</span><br><span class="line"> \\n*</div> # 这里是段子结束的标记,包括段子后的空行</span><br><span class="line"> \\n*</span><br><span class="line"> <div\sclass="stats"> # 只匹配不含图片的段子。</span><br><span class="line"> '''</span></span><br><span class="line"> myItems = re.findall(pattern,the_page,re.S|re.X)</span><br><span class="line"> <span class="comment"># print(len(myItems))</span></span><br><span class="line"> <span class="keyword">for</span> item <span class="keyword">in</span> myItems: </span><br><span class="line"> self.stories.append(item)</span><br><span class="line"> self.page += <span class="number">1</span></span><br><span class="line"> print(self.stories)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">haha</span><span class="params">(self)</span>:</span></span><br><span class="line"> <span class="keyword">if</span> len(self.stories)<<span class="number">2</span>:</span><br><span class="line"> self.get_stories()</span><br><span class="line"> <span class="keyword">return</span> self.stories.pop()[<span class="number">1</span>]</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line"> qb = QSBK()</span><br><span class="line"> print(qb.haha())</span><br></pre></td></tr></table></figure>
<p>只要掌握了上面的1234,基本的网页正则匹配都没什么问题了。</p>
]]></content>
<summary type="html">
<p>很多人对正则表达式很头痛,其实写正则表达式是有套路的,看完这篇文章保证你会写任何html上的内容抓取的正则。<br>为确保代码的正确性,此文约定环境为python3,如果在python2运行,可能要做一些调整。</p>
</summary>
<category term="python" scheme="http://huangming.github.io/categories/python/"/>
<category term="python" scheme="http://huangming.github.io/tags/python/"/>
<category term="正则" scheme="http://huangming.github.io/tags/%E6%AD%A3%E5%88%99/"/>
<category term="爬虫" scheme="http://huangming.github.io/tags/%E7%88%AC%E8%99%AB/"/>
</entry>
<entry>
<title>SSH通过SCP命令上传文件夹到linux系统的vps</title>
<link href="http://huangming.github.io/2016-06-25-ssh-upload-dir-to-linux-vps-by-scp.html"/>
<id>http://huangming.github.io/2016-06-25-ssh-upload-dir-to-linux-vps-by-scp.html</id>
<published>2016-06-25T06:34:51.000Z</published>
<updated>2016-08-06T08:37:24.626Z</updated>
<content type="html"><![CDATA[<h2 id="环境">环境</h2><p>mingw2.0.3</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ scp -P <span class="number">26443</span> -r /E/OneDrive/GitRepository/ItChat_old root@<span class="number">23.105</span>.<span class="number">203</span>.**:~/ItChat</span><br><span class="line">root@<span class="number">23.105</span>.<span class="number">203</span>.**<span class="string">'s password:</span><br><span class="line">config 100% 397 0.4KB/s 00:00</span><br><span class="line">description 100% 73 0.1KB/s 00:00</span><br><span class="line">HEAD 100% 24 0.0KB/s 00:00</span><br><span class="line">applypatch-msg.sample 100% 478 0.5KB/s 00:00</span><br><span class="line">commit-msg.sample 100% 896 0.9KB/s 00:00</span><br><span class="line">post-update.sample 100% 189 0.2KB/s 00:00</span></span><br></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<h2 id="环境">环境</h2><p>mingw2.0.3</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span cl
</summary>
<category term="vps" scheme="http://huangming.github.io/categories/vps/"/>
<category term="linux" scheme="http://huangming.github.io/tags/linux/"/>
<category term="ssh" scheme="http://huangming.github.io/tags/ssh/"/>
<category term="vps" scheme="http://huangming.github.io/tags/vps/"/>
</entry>
<entry>
<title>Python调用dll动态链接库操作excel</title>
<link href="http://huangming.github.io/2016-05-31-python-excel.html"/>
<id>http://huangming.github.io/2016-05-31-python-excel.html</id>
<published>2016-05-31T14:56:05.000Z</published>
<updated>2016-08-07T05:58:39.494Z</updated>
<content type="html"><![CDATA[<p>这是一篇Python调用动态链接库的标准示范。</p>
<h2 id="原理">原理</h2><p>其实不管什么语言调用dll的流程都是一样的:先注册dll到操作系统,然后获取到初始化的dll对象,然后就可以调用dll的各种api接口了。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">register</span><span class="params">()</span>:</span></span><br><span class="line"> <span class="string">'''注册插件</span><br><span class="line"> '''</span></span><br><span class="line"> pythoncom.CoInitialize()</span><br><span class="line"> command = <span class="string">"regsvr32 /s atl.dll"</span></span><br><span class="line"> os.system(command)</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> lx = win32com.client.Dispatch(<span class="string">'Lazy.LxjExcel'</span>)</span><br><span class="line"> <span class="keyword">except</span> pywintypes.com_error:</span><br><span class="line"> command = <span class="string">'regsvr32 /s LazyOffice.dll'</span></span><br><span class="line"> <span class="keyword">if</span> os.system(command) == <span class="number">0</span>:</span><br><span class="line"> lx = win32com.client.Dispatch(<span class="string">'Lazy.LxjExcel'</span>)</span><br><span class="line"> <span class="keyword">return</span> lx</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> self.log.error(<span class="string">'regsver32 error'</span>)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">return</span> lx</span><br></pre></td></tr></table></figure>
<p>这段代码是python调用dll的标准代码。别的dll也可以用这个调用。其中<code>LazyOffice.dll</code>是操作excel的dll文件,<code>Lazy.LxjExcel</code>是初始化的操作excel的对象,该对象由dll的编写作者提供。</p>
<p>然后就能通过返回的lx调用这个dll内部封装的接口啦:<code>lx.ExcelOpen(path, visual)</code></p>
<a id="more"></a>
<h2 id="封装">封装</h2><p>环境:<code>win7</code> <code>python3</code> <code>python2</code>,如果操作系统注册dll插件失败,可先手动注册成功后再运行程序调用。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># Last Update:</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> win32com.client</span><br><span class="line"><span class="keyword">import</span> pywintypes</span><br><span class="line"><span class="keyword">import</span> pythoncom</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">GoodString</span><span class="params">(value)</span>:</span></span><br><span class="line"> <span class="string">"""</span><br><span class="line"> >>> GoodString(2)</span><br><span class="line"> '2'</span><br><span class="line"> """</span></span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> <span class="keyword">return</span> str(value)</span><br><span class="line"> <span class="keyword">except</span> UnicodeEncodeError:</span><br><span class="line"> <span class="keyword">return</span> value</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Lxsoft</span><span class="params">()</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, log, path=<span class="string">''</span>)</span>:</span></span><br><span class="line"> self.log = log</span><br><span class="line"> self.lx = self.__registerLxsoft()</span><br><span class="line"> self.InitExcel()</span><br><span class="line"> <span class="keyword">if</span> path:</span><br><span class="line"> self.Open(path)</span><br><span class="line"> self.SheetIndex()</span><br><span class="line"> self.SheetCount()</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__registerLxsoft</span><span class="params">(self)</span>:</span></span><br><span class="line"> <span class="string">'''注册插件</span><br><span class="line"> '''</span></span><br><span class="line"> pythoncom.CoInitialize()</span><br><span class="line"> command = <span class="string">"regsvr32 /s atl.dll"</span></span><br><span class="line"> os.system(command)</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> lx = win32com.client.Dispatch(<span class="string">'Lazy.LxjExcel'</span>)</span><br><span class="line"> <span class="keyword">except</span> pywintypes.com_error:</span><br><span class="line"> command = <span class="string">'regsvr32 /s LazyOffice.dll'</span></span><br><span class="line"> <span class="keyword">if</span> os.system(command) == <span class="number">0</span>:</span><br><span class="line"> lx = win32com.client.Dispatch(<span class="string">'Lazy.LxjExcel'</span>)</span><br><span class="line"> <span class="comment"># assert(dm.Ver == '2.1138')</span></span><br><span class="line"> <span class="keyword">return</span> lx</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> self.log.error(<span class="string">'regsver32 error'</span>)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">return</span> lx</span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">InitExcel</span><span class="params">(self)</span>:</span></span><br><span class="line"> self.path = <span class="string">''</span></span><br><span class="line"> self.maxsheet = <span class="number">1</span></span><br><span class="line"> self.index = <span class="number">1</span></span><br><span class="line"> self.sindex = <span class="number">1</span></span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__del__</span><span class="params">(self)</span>:</span></span><br><span class="line"> self.Close()</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__Trueindex</span><span class="params">(self, index)</span>:</span></span><br><span class="line"> <span class="keyword">if</span> index == <span class="string">''</span>:</span><br><span class="line"> <span class="keyword">return</span> self.index</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">return</span> index</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">Open</span><span class="params">(self, path, visual=<span class="number">0</span>)</span>:</span></span><br><span class="line"> <span class="comment"># visual:1可见,0不可见 opencd:打开密码(如果存在)</span></span><br><span class="line"> <span class="comment"># writecd:写入密码 flag:只读方式打开</span></span><br><span class="line"> self.path = path</span><br><span class="line"> self.index = self.lx.ExcelOpen(path, visual)</span><br><span class="line"> <span class="keyword">return</span> self.index</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">Close</span><span class="params">(self, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> <span class="keyword">return</span> self.lx.ExcelClose(index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">SheetIndex</span><span class="params">(self, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># 获取当前标签页序号</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.sindex = self.lx.SheetIndex(index)</span><br><span class="line"> <span class="keyword">return</span> self.sindex</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">SheetName</span><span class="params">(self, Sindex, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># 获取标签页序号(或名称)为Sindex的标签名称(或索引)</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> <span class="keyword">return</span> self.lx.SheetGetName(Sindex, index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">SheetCount</span><span class="params">(self, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># 获取标签页总数</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.maxsheet = self.lx.SheetCount(index)</span><br><span class="line"> <span class="keyword">return</span> self.maxsheet</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">SheetAdd</span><span class="params">(self, Sindex, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># 在第Sindex个标签页之前新建一个标签</span></span><br><span class="line"> <span class="comment"># 如果Sindex是字符串,则在最后新建一个名叫Sindex的标签</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.log.debug(<span class="string">u'新建标签: '</span>+GoodString(Sindex))</span><br><span class="line"> <span class="keyword">return</span> self.lx.SheetAdd(Sindex, index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">SheetRename</span><span class="params">(self, Sindex, name, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># Sindex可为序号或者名称</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> <span class="keyword">return</span> self.lx.SheetRename(Sindex, name, index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">SheetDel</span><span class="params">(self, Sindex, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.log.debug(<span class="string">u'删除标签: '</span>+GoodString(Sindex))</span><br><span class="line"> <span class="keyword">return</span> self.lx.SheetDel(Sindex, index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">Write</span><span class="params">(self, Sindex, x, y, string, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># Write(1,3,2,"内容",Index)向单元格(3,2)即'B3'写入内容</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.log.debug(<span class="string">u'向单元格(%s,%s)写入内容: %s'</span> % (GoodString(x),GoodString(y),GoodString(string)))</span><br><span class="line"> <span class="keyword">return</span> self.lx.ExcelWrite(Sindex, x, y, string, index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">Read</span><span class="params">(self, Sindex, x, y, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> string = self.lx.ExcelRead(Sindex, x, y, index)[<span class="number">0</span>]</span><br><span class="line"> self.log.debug(<span class="string">u'读取单元格(%s,%s): %s'</span> % (GoodString(x),GoodString(y),GoodString(string)))</span><br><span class="line"> <span class="keyword">return</span> string</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">differ</span><span class="params">(self, Sindex, x1, y1, x2, y2, index1=<span class="string">''</span>, index2=<span class="string">''</span>)</span>:</span></span><br><span class="line"> index1 = self.__Trueindex(index1)</span><br><span class="line"> index2 = self.__Trueindex(index2)</span><br><span class="line"> <span class="keyword">return</span> int(self.Read(Sindex, x1, y1, index1)) - int(self.Read(Sindex, x2, y2, index2))</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">Cells</span><span class="params">(self, tab1, action, tab2, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># 如设置tab2为负数,将只进行复制</span></span><br><span class="line"> <span class="comment"># 如设置tab2为0,将在所有标签页后面新建一个被复制的表</span></span><br><span class="line"> <span class="comment"># 将工作表第1个标签页整表复制到第3个标签页:self.lx.ExcelCells(1, u"复制", 3, Index)</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.log.debug(<span class="string">u'表%s %s -> %s'</span> % (GoodString(tab1),action,GoodString(tab2)))</span><br><span class="line"> <span class="keyword">return</span> self.lx.ExcelCells(tab1, action, tab2, index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">Rows</span><span class="params">(self, tab, row1, action, row2, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># 如设置row2为负数,将只进行复制</span></span><br><span class="line"> <span class="comment"># 复制第1个标签页第2行到第8行:self.lx.ExcelRows(1, 2, u"复制", 8, Index)</span></span><br><span class="line"> <span class="comment"># 第2行模糊查找1:self.lx.ExcelRows(1, 2, u"模糊查找", 1, Index)</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.log.debug(<span class="string">u'行%s %s -> %s'</span> % (GoodString(row1),action,GoodString(row2)))</span><br><span class="line"> <span class="keyword">return</span> self.lx.ExcelRows(tab, row1, action, row2, index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">Columns</span><span class="params">(self, tab, col1, action, col2, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># 如设置col2为负数,将只进行复制</span></span><br><span class="line"> <span class="comment"># 复制第1个标签页第3列到第6列:self.lx.ExcelColumns(1, 3, u"复制", 6, Index)</span></span><br><span class="line"> <span class="comment"># 第3列模糊查找1:self.lx.ExcelColumns(1,3, u"模糊查找", 1, Index)</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.log.debug(<span class="string">u'列%s %s -> %s'</span> % (GoodString(col1),action,GoodString(col2)))</span><br><span class="line"> <span class="keyword">return</span> self.lx.ExcelColumns(tab, col1, action, col2, index)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">Range</span><span class="params">(self, tab, ranges, action, destination, index=<span class="string">''</span>)</span>:</span></span><br><span class="line"> <span class="comment"># 如设置destination为负数,将只进行复制</span></span><br><span class="line"> <span class="comment"># 复制第1个标签页"B2:C5"区域:self.lx.ExcelRange(1, "B2:C5", "复制", -1, Index)</span></span><br><span class="line"> <span class="comment"># 区域C2:E5模糊查找1:self.lx.ExcelRange(1, "C2:E5",u"模糊查找", 1, Index)</span></span><br><span class="line"> index = self.__Trueindex(index)</span><br><span class="line"> self.log.debug(<span class="string">u'区域%s %s -> %s'</span> % (GoodString(tab),action,GoodString(destination)))</span><br><span class="line"> <span class="keyword">return</span> self.lx.ExcelRange(tab, ranges, action, destination, index)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line"> <span class="keyword">import</span> log</span><br><span class="line"> <span class="keyword">import</span> time</span><br><span class="line"> path = <span class="string">'F:\\test.xls'</span></span><br><span class="line"> mylog = log.Log()</span><br><span class="line"> lx = Lxsoft(mylog, path)</span><br><span class="line"> <span class="comment"># print int(lx.Read(lx.SheetCount(), 5, 7))==int(time.strftime("%Y%m%d"))</span></span><br><span class="line"> <span class="comment"># a = lx.Read(lx.maxsheet, 5, 7)</span></span><br><span class="line"> a = lx.SheetCount()</span><br><span class="line"> print(lx.Columns(a, <span class="number">7</span>, <span class="string">u"模糊查找"</span>, <span class="string">"20150722"</span>)[<span class="number">0</span>][<span class="number">0</span>])</span><br><span class="line"> <span class="comment"># lx.Cells(lx.SheetCount(), 5, u"字体颜色", 3)</span></span><br><span class="line"> <span class="comment"># print lx.differ(lx.maxsheet, 17, 7, 17, 3)</span></span><br><span class="line"> <span class="comment"># print a</span></span><br><span class="line"> <span class="comment"># lx.Write(lx.maxsheet, 5, 7, "20150709")</span></span><br><span class="line"> <span class="comment"># lx.Cells(80, u"复制", 0, index)</span></span><br><span class="line"> lx.Close()</span><br><span class="line"> <span class="comment"># lx = Lxsoft(config.log)</span></span><br><span class="line"> <span class="comment"># index = lx.Open(path, 0)</span></span><br><span class="line"> <span class="comment"># lx.Close(index)</span></span><br></pre></td></tr></table></figure>
<h2 id="其他">其他</h2><ul>
<li><p><a href="http://huangming.work/2016-05-29-python-log.html" target="_blank" rel="external">log模块</a></p>
</li>
<li><p><a href="https://github.com/huangming/python_dll_excel/blob/master/%E6%87%92%E4%BA%BA%E5%8A%9E%E5%85%AC%E6%8F%92%E4%BB%B6%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3.CHM" target="_blank" rel="external">动态链接库接口文档</a></p>
</li>
<li><p><a href="https://github.com/huangming/python_dll_excel" target="_blank" rel="external">GithubRepository</a></p>
</li>
</ul>
]]></content>
<summary type="html">
<p>这是一篇Python调用动态链接库的标准示范。</p>
<h2 id="原理">原理</h2><p>其实不管什么语言调用dll的流程都是一样的:先注册dll到操作系统,然后获取到初始化的dll对象,然后就可以调用dll的各种api接口了。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">register</span><span class="params">()</span>:</span></span><br><span class="line"> <span class="string">'''注册插件</span><br><span class="line"> '''</span></span><br><span class="line"> pythoncom.CoInitialize()</span><br><span class="line"> command = <span class="string">"regsvr32 /s atl.dll"</span></span><br><span class="line"> os.system(command)</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> lx = win32com.client.Dispatch(<span class="string">'Lazy.LxjExcel'</span>)</span><br><span class="line"> <span class="keyword">except</span> pywintypes.com_error:</span><br><span class="line"> command = <span class="string">'regsvr32 /s LazyOffice.dll'</span></span><br><span class="line"> <span class="keyword">if</span> os.system(command) == <span class="number">0</span>:</span><br><span class="line"> lx = win32com.client.Dispatch(<span class="string">'Lazy.LxjExcel'</span>)</span><br><span class="line"> <span class="keyword">return</span> lx</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> self.log.error(<span class="string">'regsver32 error'</span>)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">return</span> lx</span><br></pre></td></tr></table></figure>
<p>这段代码是python调用dll的标准代码。别的dll也可以用这个调用。其中<code>LazyOffice.dll</code>是操作excel的dll文件,<code>Lazy.LxjExcel</code>是初始化的操作excel的对象,该对象由dll的编写作者提供。</p>
<p>然后就能通过返回的lx调用这个dll内部封装的接口啦:<code>lx.ExcelOpen(path, visual)</code></p>
</summary>
<category term="python" scheme="http://huangming.github.io/categories/python/"/>
<category term="excel" scheme="http://huangming.github.io/tags/excel/"/>
<category term="python" scheme="http://huangming.github.io/tags/python/"/>
<category term="动态链接库" scheme="http://huangming.github.io/tags/%E5%8A%A8%E6%80%81%E9%93%BE%E6%8E%A5%E5%BA%93/"/>
<category term="自动化" scheme="http://huangming.github.io/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/"/>
</entry>
<entry>
<title>Python logging 模块封装</title>
<link href="http://huangming.github.io/2016-05-29-python-log.html"/>
<id>http://huangming.github.io/2016-05-29-python-log.html</id>
<published>2016-05-29T05:22:14.000Z</published>
<updated>2016-07-01T08:11:51.000Z</updated>
<content type="html"><![CDATA[<p>python自带的记录日志模块 <a href="https://docs.python.org/3/library/logging.html#module-logging" target="_blank" rel="external">logging</a> 非常强大,但是每次写程序都要写很多东西来配置使用,体验不怎么友好,花时间封装在一个文件里面,用的时候直接调用,并且提供配置接口保留其强大的功能还是非常有必要的。</p>
<h2 id="logging介绍">logging介绍</h2><p>Python的logging模块提供了通用的日志系统,可以方便第三方模块或者是应用使用。这个模块提供不同的日志级别,并可以采用不同的方式记录日志,比如文件,HTTP GET/POST,SMTP,Socket等,甚至可以自己实现具体的日志记录方式。</p>
<p>logging模块与log4j的机制是一样的,只是具体的实现细节不同。模块提供logger,handler,filter,formatter。</p>
<ul>
<li>logger:提供日志接口,供应用代码使用。</li>
<li>handler:将日志记录(log record)发送到合适的目的地(destination),比如文件,socket,cmd等。一个logger对象可以通过addHandler方法添加0到多个handler,每个handler又可以定义不同日志级别,以实现日志分级过滤显示。每个handler还可以单独设置自己的formatter格式。</li>
<li>filter:提供一种优雅的方式决定一个日志记录是否发送到handler。</li>
<li>formatter:指定日志记录输出的具体格式。</li>
</ul>
<p>与log4j类似,logger,handler和日志消息的调用可以有具体的日志级别(Level),只有在日志消息的级别大于logger和handler的级别才会呈现。</p>
<p>默认的日志级别设置为<code>WARNING</code>(日志级别等级<code>CRITICAL</code> > <code>ERROR</code> > <code>WARNING</code> > <code>INFO</code> > <code>DEBUG</code> > <code>NOTSET</code>), 小于WARNING级别的日志都不输出, 大于等于WARNING级别的日志都会输出。<br><a id="more"></a><br>更多可以自己搜索一下。</p>
<h2 id="封装成log-py">封装成log.py</h2><p>源码在github上有:<a href="https://github.com/huangming/python_log" target="_blank" rel="external">python_log</a></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#!/usr/bin/env python</span></span><br><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># Last Update: 2015/06/30 10:53:52</span></span><br><span class="line"><span class="comment"># file mylog.py</span></span><br><span class="line">__author__ = <span class="string">"Mingo <[email protected]>"</span></span><br><span class="line">__status__ = <span class="string">"Development"</span></span><br><span class="line"> </span><br><span class="line">__all__ = [<span class="string">'set_logger'</span>, <span class="string">'debug'</span>, <span class="string">'info'</span>, <span class="string">'warning'</span>, <span class="string">'error'</span>,</span><br><span class="line"> <span class="string">'critical'</span>, <span class="string">'exception'</span>]</span><br><span class="line"> </span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"><span class="keyword">import</span> traceback</span><br><span class="line"><span class="keyword">import</span> logging</span><br><span class="line"><span class="keyword">import</span> logging.handlers</span><br><span class="line"> </span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ColoredFormatter</span><span class="params">(logging.Formatter)</span>:</span></span><br><span class="line"> <span class="string">'''A colorful formatter.'''</span></span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, fmt = None, datefmt = None)</span>:</span></span><br><span class="line"> logging.Formatter.__init__(self, fmt, datefmt)</span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">format</span><span class="params">(self, record)</span>:</span></span><br><span class="line"> <span class="comment"># Color escape string</span></span><br><span class="line"> COLOR_RED=<span class="string">'\033[1;31m'</span></span><br><span class="line"> COLOR_GREEN=<span class="string">'\033[1;32m'</span></span><br><span class="line"> COLOR_YELLOW=<span class="string">'\033[1;33m'</span></span><br><span class="line"> COLOR_BLUE=<span class="string">'\033[1;34m'</span></span><br><span class="line"> COLOR_PURPLE=<span class="string">'\033[1;35m'</span></span><br><span class="line"> COLOR_CYAN=<span class="string">'\033[1;36m'</span></span><br><span class="line"> COLOR_GRAY=<span class="string">'\033[1;37m'</span></span><br><span class="line"> COLOR_WHITE=<span class="string">'\033[1;38m'</span></span><br><span class="line"> COLOR_RESET=<span class="string">'\033[1;0m'</span></span><br><span class="line"> <span class="comment"># Define log color</span></span><br><span class="line"> LOG_COLORS = {</span><br><span class="line"> <span class="string">'DEBUG'</span>: <span class="string">'%s'</span>,</span><br><span class="line"> <span class="string">'INFO'</span>: COLOR_GREEN + <span class="string">'%s'</span> + COLOR_RESET,</span><br><span class="line"> <span class="string">'WARNING'</span>: COLOR_YELLOW + <span class="string">'%s'</span> + COLOR_RESET,</span><br><span class="line"> <span class="string">'ERROR'</span>: COLOR_RED + <span class="string">'%s'</span> + COLOR_RESET,</span><br><span class="line"> <span class="string">'CRITICAL'</span>: COLOR_RED + <span class="string">'%s'</span> + COLOR_RESET,</span><br><span class="line"> <span class="string">'EXCEPTION'</span>: COLOR_RED + <span class="string">'%s'</span> + COLOR_RESET,</span><br><span class="line"> }</span><br><span class="line"> level_name = record.levelname</span><br><span class="line"> msg = logging.Formatter.format(self, record)</span><br><span class="line"> <span class="keyword">return</span> LOG_COLORS.get(level_name, <span class="string">'%s'</span>) % msg</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Log</span><span class="params">()</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, filename = None, mode = <span class="string">'a'</span>,</span><br><span class="line"> cmdlevel=<span class="string">'DEBUG'</span>,</span><br><span class="line"> filelevel=<span class="string">'INFO'</span>,</span><br><span class="line"> cmdfmt = <span class="string">'[%(asctime)s] %(filename)s line:%(lineno)d %(levelname)-8s%(message)s'</span>,</span><br><span class="line"> filefmt = <span class="string">'[%(asctime)s] %(levelname)-8s%(message)s'</span>,</span><br><span class="line"> cmddatefmt = <span class="string">'%H:%M:%S'</span>,</span><br><span class="line"> filedatefmt = <span class="string">'%Y-%m-%d %H:%M:%S'</span>,</span><br><span class="line"> backup_count = <span class="number">0</span>, limit = <span class="number">20480</span>, when = None, colorful = False)</span>:</span></span><br><span class="line"> self.filename = filename</span><br><span class="line"> <span class="keyword">if</span> self.filename <span class="keyword">is</span> <span class="keyword">None</span>:</span><br><span class="line"> self.filename = getattr(sys.modules[<span class="string">'__main__'</span>], <span class="string">'__file__'</span>, <span class="string">'log.py'</span>)</span><br><span class="line"> self.filename = os.path.basename(self.filename.replace(<span class="string">'.py'</span>, <span class="string">'.log'</span>))</span><br><span class="line"> <span class="comment">#self.filename = os.path.join('/tmp', self.filename)</span></span><br><span class="line"> self.mode = mode</span><br><span class="line"> self.cmdlevel = cmdlevel</span><br><span class="line"> self.filelevel = filelevel</span><br><span class="line"> <span class="keyword">if</span> isinstance(self.cmdlevel, str):</span><br><span class="line"> self.cmdlevel = getattr(logging, self.cmdlevel.upper(), logging.DEBUG)</span><br><span class="line"> <span class="keyword">if</span> isinstance(self.filelevel, str):</span><br><span class="line"> self.filelevel = getattr(logging, self.filelevel.upper(), logging.DEBUG)</span><br><span class="line"> self.filefmt = filefmt</span><br><span class="line"> self.cmdfmt = cmdfmt</span><br><span class="line"> self.filedatefmt = filedatefmt</span><br><span class="line"> self.cmddatefmt = cmddatefmt</span><br><span class="line"> self.backup_count = backup_count</span><br><span class="line"> self.limit = limit</span><br><span class="line"> self.when = when</span><br><span class="line"> self.colorful = colorful</span><br><span class="line"> self.logger = <span class="keyword">None</span></span><br><span class="line"> self.streamhandler = <span class="keyword">None</span></span><br><span class="line"> self.filehandler = <span class="keyword">None</span></span><br><span class="line"> <span class="keyword">if</span> self.cmdlevel > <span class="number">10</span>:</span><br><span class="line"> self.filefmt = <span class="string">'[%(asctime)s] %(levelname)-8s%(message)s'</span></span><br><span class="line"> self.cmdfmt = <span class="string">'[%(asctime)s] %(levelname)-8s%(message)s'</span></span><br><span class="line"> self.cmddatefmt = <span class="string">'%Y-%m-%d %H:%M:%S'</span></span><br><span class="line"> self.set_logger(cmdlevel = self.cmdlevel)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">init_logger</span><span class="params">(self)</span>:</span></span><br><span class="line"> <span class="string">'''Reload the logger.'''</span></span><br><span class="line"> <span class="keyword">if</span> self.logger <span class="keyword">is</span> <span class="keyword">None</span>:</span><br><span class="line"> self.logger = logging.getLogger()</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> logging.shutdown()</span><br><span class="line"> self.logger.handlers = []</span><br><span class="line"> self.streamhandler = <span class="keyword">None</span></span><br><span class="line"> self.filehandler = <span class="keyword">None</span></span><br><span class="line"> self.logger.setLevel(logging.DEBUG)</span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">add_streamhandler</span><span class="params">(self)</span>:</span></span><br><span class="line"> <span class="string">'''Add a stream handler to the logger.'''</span></span><br><span class="line"> self.streamhandler = logging.StreamHandler()</span><br><span class="line"> self.streamhandler.setLevel(self.cmdlevel)</span><br><span class="line"> <span class="keyword">if</span> self.colorful:</span><br><span class="line"> formatter = ColoredFormatter(self.cmdfmt, self.cmddatefmt)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> formatter = logging.Formatter(self.cmdfmt, self.cmddatefmt,)</span><br><span class="line"> self.streamhandler.setFormatter(formatter)</span><br><span class="line"> self.logger.addHandler(self.streamhandler)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">add_filehandler</span><span class="params">(self)</span>:</span></span><br><span class="line"> <span class="string">'''Add a file handler to the logger.'''</span></span><br><span class="line"> <span class="comment"># Choose the filehandler based on the passed arguments</span></span><br><span class="line"> <span class="keyword">if</span> self.backup_count == <span class="number">0</span>: <span class="comment"># Use FileHandler</span></span><br><span class="line"> self.filehandler = logging.FileHandler(self.filename, self.mode)</span><br><span class="line"> <span class="keyword">elif</span> self.when <span class="keyword">is</span> <span class="keyword">None</span>: <span class="comment"># Use RotatingFileHandler</span></span><br><span class="line"> self.filehandler = logging.handlers.RotatingFileHandler(self.filename,</span><br><span class="line"> self.mode, self.limit, self.backup_count)</span><br><span class="line"> <span class="keyword">else</span>: <span class="comment"># Use TimedRotatingFileHandler</span></span><br><span class="line"> self.filehandler = logging.handlers.TimedRotatingFileHandler(self.filename,</span><br><span class="line"> self.when, <span class="number">1</span>, self.backup_count)</span><br><span class="line"> self.filehandler.setLevel(self.filelevel)</span><br><span class="line"> formatter = logging.Formatter(self.filefmt, self.filedatefmt,)</span><br><span class="line"> self.filehandler.setFormatter(formatter)</span><br><span class="line"> self.logger.addHandler(self.filehandler)</span><br><span class="line"> </span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">set_logger</span><span class="params">(self, **kwargs)</span>:</span></span><br><span class="line"> <span class="string">'''Configure the logger.'''</span></span><br><span class="line"> keys = [<span class="string">'mode'</span>,<span class="string">'cmdlevel'</span>,<span class="string">'filelevel'</span>,<span class="string">'filefmt'</span>,<span class="string">'cmdfmt'</span>,\</span><br><span class="line"> <span class="string">'filedatefmt'</span>,<span class="string">'cmddatefmt'</span>,<span class="string">'backup_count'</span>,<span class="string">'limit'</span>,\</span><br><span class="line"> <span class="string">'when'</span>,<span class="string">'colorful'</span>]</span><br><span class="line"> <span class="keyword">for</span> (key, value) <span class="keyword">in</span> kwargs.items():</span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> (key <span class="keyword">in</span> keys):</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">False</span></span><br><span class="line"> setattr(self, key, value)</span><br><span class="line"> <span class="keyword">if</span> isinstance(self.cmdlevel, str):</span><br><span class="line"> self.cmdlevel = getattr(logging, self.cmdlevel.upper(), logging.DEBUG)</span><br><span class="line"> <span class="keyword">if</span> isinstance(self.filelevel, str):</span><br><span class="line"> self.filelevel = getattr(logging, self.filelevel.upper(), logging.DEBUG)</span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> <span class="string">"cmdfmt"</span> <span class="keyword">in</span> kwargs:</span><br><span class="line"> self.filefmt=<span class="string">'[%(asctime)s] %(filename)s line:%(lineno)d %(levelname)-8s%(message)s'</span></span><br><span class="line"> self.filedatefmt = <span class="string">'%Y-%m-%d %H:%M:%S'</span></span><br><span class="line"> self.cmdfmt=<span class="string">'[%(asctime)s] %(filename)s line:%(lineno)d %(levelname)-8s%(message)s'</span></span><br><span class="line"> self.cmddatefmt = <span class="string">'%H:%M:%S'</span></span><br><span class="line"> <span class="keyword">if</span> self.cmdlevel > <span class="number">10</span>:</span><br><span class="line"> self.filefmt = <span class="string">'[%(asctime)s] %(levelname)-8s%(message)s'</span></span><br><span class="line"> self.cmdfmt = <span class="string">'[%(asctime)s] %(levelname)-8s%(message)s'</span></span><br><span class="line"> self.cmddatefmt = <span class="string">'%Y-%m-%d %H:%M:%S'</span></span><br><span class="line"> self.init_logger()</span><br><span class="line"> self.add_streamhandler()</span><br><span class="line"> self.add_filehandler()</span><br><span class="line"> <span class="comment"># Import the common log functions for convenient</span></span><br><span class="line"> self.import_log_funcs()</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">True</span></span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">import_log_funcs</span><span class="params">(self)</span>:</span></span><br><span class="line"> <span class="string">'''Import the common log functions from the logger to the class'''</span></span><br><span class="line"> log_funcs = [<span class="string">'debug'</span>, <span class="string">'info'</span>, <span class="string">'warning'</span>, <span class="string">'error'</span>, <span class="string">'critical'</span>,</span><br><span class="line"> <span class="string">'exception'</span>]</span><br><span class="line"> <span class="keyword">for</span> func_name <span class="keyword">in</span> log_funcs:</span><br><span class="line"> func = getattr(self.logger, func_name)</span><br><span class="line"> setattr(self, func_name, func)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">trace</span><span class="params">(self)</span>:</span></span><br><span class="line"> info = sys.exc_info()</span><br><span class="line"> <span class="keyword">for</span> file, lineno, function, text <span class="keyword">in</span> traceback.extract_tb(info[<span class="number">2</span>]):</span><br><span class="line"> self.error(<span class="string">'%s line:%s in %s:%s'</span> % (file, lineno, function, text))</span><br><span class="line"> self.error(<span class="string">'%s: %s'</span> % info[:<span class="number">2</span>])</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line"> log = Log(cmdlevel=<span class="string">'info'</span>)</span><br><span class="line"> <span class="comment"># log = Log(cmdlevel='debug')</span></span><br><span class="line"> log.set_logger(cmdlevel=<span class="string">'debug'</span>)</span><br><span class="line"> log.debug(<span class="string">'debug'</span>)</span><br><span class="line"> log.info(<span class="string">'debug%s'</span> % <span class="string">'haha'</span>)</span><br><span class="line"> log.error((<span class="number">1</span>,<span class="number">2</span>))</span><br><span class="line"> log.error(<span class="string">'debug'</span>)</span><br><span class="line"> log.info({<span class="string">'a'</span>:<span class="number">1</span>,<span class="string">'b'</span>:<span class="number">2</span>})</span><br><span class="line"> os.system(<span class="string">"pause"</span>)</span><br><span class="line"> <span class="class"><span class="keyword">class</span> <span class="title">A</span><span class="params">()</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, log)</span>:</span></span><br><span class="line"> self.log = log</span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">a</span><span class="params">(self,a)</span>:</span></span><br><span class="line"> self.log.info(a)</span><br><span class="line"> <span class="class"><span class="keyword">class</span> <span class="title">B</span><span class="params">()</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, log)</span>:</span></span><br><span class="line"> self.log = log</span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">b</span><span class="params">(self,a)</span>:</span></span><br><span class="line"> self.log.info(a)</span><br><span class="line"> a = A(log)</span><br><span class="line"> a.a(<span class="string">"test a"</span>)</span><br><span class="line"> b = B(log)</span><br><span class="line"> b.b(<span class="number">5</span>)</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">fun</span><span class="params">(a)</span>:</span></span><br><span class="line"> <span class="keyword">return</span> <span class="number">10</span>/a</span><br><span class="line"> <span class="keyword">try</span>:</span><br><span class="line"> a = fun(<span class="number">0</span>)</span><br><span class="line"> <span class="keyword">except</span>:</span><br><span class="line"> log.trace()</span><br></pre></td></tr></table></figure>
<h2 id="例子">例子</h2><p>用的时候把log.py丢到工程目录然后import进来初始化一个Log对象即可。</p>
<p>如果全部使用默认配置(具体值请看Log类的init函数):<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># tmp.py</span></span><br><span class="line"><span class="keyword">import</span> log</span><br><span class="line">log = log.Log()</span><br><span class="line">log.debug(<span class="string">'hello, world'</span>)</span><br><span class="line">log.info(<span class="string">'hello, world'</span>)</span><br><span class="line">log.error(<span class="string">'hello, world'</span>)</span><br><span class="line">log.critical(<span class="string">'hello, world'</span>)</span><br></pre></td></tr></table></figure></p>
<p>得到结果:<br>在命令行跟文件里面分别记录运行日志,命令行呈现大于DEBUG级别的记录,文件记录大于INFO级别的记录。文件名跟主程序的py名字一样,这里是<code>tmp.log</code>。里面内容:<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">2016</span>-<span class="number">05</span>-<span class="number">29</span> <span class="number">17</span>:<span class="number">17</span>:<span class="number">05</span>] tmp.py line:<span class="number">6</span> INFO hello, world</span><br><span class="line">[<span class="number">2016</span>-<span class="number">05</span>-<span class="number">29</span> <span class="number">17</span>:<span class="number">17</span>:<span class="number">05</span>] tmp.py line:<span class="number">7</span> ERROR hello, world</span><br><span class="line">[<span class="number">2016</span>-<span class="number">05</span>-<span class="number">29</span> <span class="number">17</span>:<span class="number">17</span>:<span class="number">05</span>] tmp.py line:<span class="number">8</span> CRITICALhello, world</span><br><span class="line">[<span class="number">2016</span>-<span class="number">05</span>-<span class="number">29</span> <span class="number">17</span>:<span class="number">17</span>:<span class="number">49</span>] tmp.py line:<span class="number">6</span> INFO hello, world</span><br><span class="line">[<span class="number">2016</span>-<span class="number">05</span>-<span class="number">29</span> <span class="number">17</span>:<span class="number">17</span>:<span class="number">49</span>] tmp.py line:<span class="number">7</span> ERROR hello, world</span><br><span class="line">[<span class="number">2016</span>-<span class="number">05</span>-<span class="number">29</span> <span class="number">17</span>:<span class="number">17</span>:<span class="number">49</span>] tmp.py line:<span class="number">8</span> CRITICALhello, world</span><br></pre></td></tr></table></figure></p>
<p>cmd显示运行结果:<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">17</span>:<span class="number">17</span>:<span class="number">05</span>] tmp.py line:<span class="number">5</span> DEBUG hello, world</span><br><span class="line">[<span class="number">17</span>:<span class="number">17</span>:<span class="number">05</span>] tmp.py line:<span class="number">6</span> INFO hello, world</span><br><span class="line">[<span class="number">17</span>:<span class="number">17</span>:<span class="number">05</span>] tmp.py line:<span class="number">7</span> ERROR hello, world</span><br><span class="line">[<span class="number">17</span>:<span class="number">17</span>:<span class="number">05</span>] tmp.py line:<span class="number">8</span> CRITICALhello, world</span><br><span class="line">Hit any key to close this window...</span><br></pre></td></tr></table></figure></p>
<p>里面的内容符合对文件跟cmd的level级别筛选规则,显示的格式也分别符合<code>Log类</code>init默认初始化参数的formatter设置的规则。</p>
<p>如果要更改设置,直接调用<code>log.set_logger</code>就可以了。一般来说很少会有更改设置的情况,都是直接初始化就一直用到结束。有一种情况就是给出一个可以调整log level的级别的配置接口。这样程序运行的过程中,遇到bug用户可以调整日志级别,然后把debug日志记录获取到发给开发人员分析。</p>
<p>另外,封装的log.py比原来的logging模块多了一个trace接口。可以打印exception的详细信息。具体用法可以看封装的文件里边的例子。</p>
<h2 id="其他">其他</h2><h3 id="1-_formatter配置">1. formatter配置</h3><p>下面是formatter用到的匹配规则,其中asctime还可以进一步配置:命令行通过<code>cmddatefmt</code>、文件日志通过<code>filedatefmt</code>,具体写法可参照Log类的初始化函数。<br><figure class="highlight gherkin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">+---------------------+-----------------------------------------------------------------------------</span><br><span class="line">|<span class="string"> %(name)s </span>|<span class="string"> Logger的名字 </span><br><span class="line"></span>|<span class="string"> %(levelno)s </span>|<span class="string"> 数字形式的日志级别 </span><br><span class="line"></span>|<span class="string"> %(levelname)s </span>|<span class="string"> 文本形式的日志级别 </span><br><span class="line"></span>|<span class="string"> %(pathname)s </span>|<span class="string"> 调用日志输出函数的模块的完整路径名,可能没有 </span><br><span class="line"></span>|<span class="string"> %(filename)s </span>|<span class="string"> 调用日志输出函数的模块的文件名 </span><br><span class="line"></span>|<span class="string"> %(module)s </span>|<span class="string"> 调用日志输出函数的模块名 </span><br><span class="line"></span>|<span class="string"> %(funcName)s </span>|<span class="string"> 调用日志输出函数的函数名 </span><br><span class="line"></span>|<span class="string"> %(lineno)d </span>|<span class="string"> 调用日志输出函数的语句所在的代码行 </span><br><span class="line"></span>|<span class="string"> %(created)f </span>|<span class="string"> 当前时间,用UNIX标准的表示时间的浮 点数表示 </span><br><span class="line"></span>|<span class="string"> %(relativeCreated)d </span>|<span class="string"> 输出日志信息时的,自Logger创建以 来的毫秒数 </span><br><span class="line"></span>|<span class="string"> %(asctime)s </span>|<span class="string"> 字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒</span><br><span class="line"></span>|<span class="string"> %(thread)d </span>|<span class="string"> 线程ID。可能没有 </span><br><span class="line"></span>|<span class="string"> %(threadName)s </span>|<span class="string"> 线程名。可能没有 </span><br><span class="line"></span>|<span class="string"> %(process)d </span>|<span class="string"> 进程ID。可能没有 </span><br><span class="line"></span>|<span class="string"> %(message)s </span>|<span class="string"> 用户输出的消息 </span><br><span class="line">+---------------------+-----------------------------------------------------------------------------</span></span><br></pre></td></tr></table></figure></p>
<h3 id="2-_Use_set_logger_to_change_settings">2. Use set_logger to change settings</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Change limit size in bytes of default rotating action</span></span><br><span class="line">log.set_logger(limit = <span class="number">10240</span>) <span class="comment"># 10M</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Use time-rotated file handler, each day has a different log file, see</span></span><br><span class="line"><span class="comment"># logging.handlers.TimedRotatingFileHandler for more help about 'when'</span></span><br><span class="line">log.set_logger(when = <span class="string">'D'</span>, limit = <span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># Use normal file handler (not rotated)</span></span><br><span class="line">log.set_logger(backup_count = <span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># File log level set to INFO, and stdout log level set to DEBUG</span></span><br><span class="line">log.set_logger(cmdlevel = <span class="string">'DEBUG'</span>, filelevel = <span class="string">'INFO'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># Change default log file name and log mode</span></span><br><span class="line">log.set_logger(filename = <span class="string">'yyy.log'</span>, mode = <span class="string">'w'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># Change default log formatter</span></span><br><span class="line">log.set_logger(cmdfmt = <span class="string">'[%(levelname)s] %(message)s'</span>)</span><br></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<p>python自带的记录日志模块 <a href="https://docs.python.org/3/library/logging.html#module-logging">logging</a> 非常强大,但是每次写程序都要写很多东西来配置使用,体验不怎么友好,花时间封装在一个文件里面,用的时候直接调用,并且提供配置接口保留其强大的功能还是非常有必要的。</p>
<h2 id="logging介绍">logging介绍</h2><p>Python的logging模块提供了通用的日志系统,可以方便第三方模块或者是应用使用。这个模块提供不同的日志级别,并可以采用不同的方式记录日志,比如文件,HTTP GET/POST,SMTP,Socket等,甚至可以自己实现具体的日志记录方式。</p>
<p>logging模块与log4j的机制是一样的,只是具体的实现细节不同。模块提供logger,handler,filter,formatter。</p>
<ul>
<li>logger:提供日志接口,供应用代码使用。</li>
<li>handler:将日志记录(log record)发送到合适的目的地(destination),比如文件,socket,cmd等。一个logger对象可以通过addHandler方法添加0到多个handler,每个handler又可以定义不同日志级别,以实现日志分级过滤显示。每个handler还可以单独设置自己的formatter格式。</li>
<li>filter:提供一种优雅的方式决定一个日志记录是否发送到handler。</li>
<li>formatter:指定日志记录输出的具体格式。</li>
</ul>
<p>与log4j类似,logger,handler和日志消息的调用可以有具体的日志级别(Level),只有在日志消息的级别大于logger和handler的级别才会呈现。</p>
<p>默认的日志级别设置为<code>WARNING</code>(日志级别等级<code>CRITICAL</code> &gt; <code>ERROR</code> &gt; <code>WARNING</code> &gt; <code>INFO</code> &gt; <code>DEBUG</code> &gt; <code>NOTSET</code>), 小于WARNING级别的日志都不输出, 大于等于WARNING级别的日志都会输出。<br>
</summary>
<category term="python" scheme="http://huangming.github.io/categories/python/"/>
<category term="log" scheme="http://huangming.github.io/tags/log/"/>
<category term="python" scheme="http://huangming.github.io/tags/python/"/>
</entry>
<entry>
<title>Oracle收缩临时表空间</title>
<link href="http://huangming.github.io/2016-05-25-oracle-rebuild-temp-tablespace.html"/>
<id>http://huangming.github.io/2016-05-25-oracle-rebuild-temp-tablespace.html</id>
<published>2016-05-25T06:42:57.000Z</published>
<updated>2016-05-25T07:33:20.000Z</updated>
<content type="html"><![CDATA[<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SQL> alter tablespace temp shrink space;</span><br><span class="line">表空间已更改。</span><br></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><
</summary>
<category term="database" scheme="http://huangming.github.io/categories/database/"/>
<category term="oracle" scheme="http://huangming.github.io/tags/oracle/"/>
</entry>
<entry>
<title>Oracle冷备与恢复</title>
<link href="http://huangming.github.io/2016-05-21-oracle-cold-backup.html"/>
<id>http://huangming.github.io/2016-05-21-oracle-cold-backup.html</id>
<published>2016-05-21T12:41:46.000Z</published>
<updated>2016-05-25T14:04:53.867Z</updated>
<content type="html"><![CDATA[<p>冷备恢复是oracle最快捷方便安全的恢复、拷贝方式。他只有一个缺点:冷备的时候要关闭源库。冷备特别适合搭建跟生产一致的测试环境。</p>
<h2 id="环境">环境</h2><p>源库跟目的库的Oracle大版本要一致,并且数据库SID要一样。<br>本文测试环境:</p>
<ul>
<li>源库操作系统 <code>windows server 2008 R2 x64</code><br>源库数据库版本 <code>11g Enterprise Edition Release 11.2.0.1.0 - 64bit</code></li>
<li>目的库操作系统 <code>win7 x64</code> <code>win10 x64</code> <code>windows server 2008 R2 x64</code> 均测试成功<br>目的库数据库版本 <code>11g Enterprise Edition Release 11.2.0.1.0 - 64bit</code></li>
</ul>
<p>查看版本:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="operator"><span class="keyword">select</span> banner <span class="keyword">from</span> sys.v_$<span class="keyword">version</span>;</span></span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h2 id="冷备">冷备</h2><p>在源库(假定SID名为ORCL)执行以下操作:</p>
<h3 id="1-_打开CMD,用sysdba登录数据库。">1. 打开CMD,用sysdba登录数据库。</h3><p>有些操作系统安装了不止一个数据库实例,为了确保操作的是源库,在CMD命令行中先执行一次<code>set ORACLE_SID=ORCL</code>:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">set</span> ORACLE_SID=ORCL</span><br><span class="line">sqlplus / as sysdba</span><br></pre></td></tr></table></figure></p>
<p>先检查一下登录的数据库:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">SQL> select instance_name from v<span class="variable">$instance</span>;</span><br><span class="line">INSTANCE_NAME</span><br><span class="line">----------------</span><br><span class="line">orcl</span><br></pre></td></tr></table></figure></p>
<h3 id="2-_查找并记下各物理文件路径">2. 查找并记下各物理文件路径</h3><p>总共有控制文件、参数文件、数据文件、密码文件、redolog文件<br>可在SQL*PLUS 也可在 Pl/SQL 里边查看:</p>
<ul>
<li><p>控制文件(可不拷贝)</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">SQL> <span class="built_in">set</span> line <span class="number">200</span></span><br><span class="line">SQL> columnn NAME format a60</span><br><span class="line">SQL> select * from V<span class="variable">$CONTROLFILE</span>;</span><br><span class="line">STATUS NAME IS_ BLOCK_SIZE FILE_SIZE_BLKS</span><br><span class="line">------- ------------------------------------------------------------ --- ---------- --------------</span><br><span class="line"> D:\APP\ADMINISTRATOR\ORADATA\ORCL\CONTROL01.CTL NO <span class="number">16384</span> <span class="number">636</span></span><br><span class="line"> D:\APP\ADMINISTRATOR\FLASH_RECOVERY_AREA\ORCL\CONTROL02.CTL NO <span class="number">16384</span> <span class="number">636</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>参数文件(如果没有可不拷贝) </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">SQL> show parameter spfile</span><br><span class="line">NAME TYPE VALUE</span><br><span class="line">------------------------------------ ----------- ------------------------------</span><br><span class="line">spfile string</span><br></pre></td></tr></table></figure>
</li>
<li><p>密码文件<br>一般在如下路径,以<code>PWD+SID.ora</code>命名。可直接拷贝整个<code>database</code>文件夹(上面的参数文件一般也在这里)。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">D:\app\Administrator\product\<span class="number">11.2</span>.<span class="number">0</span>\dbhome_1\database\PWDorcl.ora</span><br></pre></td></tr></table></figure>
</li>
<li><p>重做日志文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">SQL> select * from V<span class="variable">$LOGFILE</span>;</span><br><span class="line"> GROUP<span class="comment"># STATUS TYPE MEMBER IS_</span></span><br><span class="line">---------- ------- ------- ------------------------------------------------------------ ---</span><br><span class="line"> <span class="number">2</span> ONLINE D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO02.LOG NO</span><br><span class="line"> <span class="number">1</span> ONLINE D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO01.LOG NO</span><br><span class="line"> <span class="number">3</span> ONLINE D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO03.LOG NO</span><br></pre></td></tr></table></figure>
</li>
<li><p>数据文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">SQL> select name from V<span class="variable">$DATAFILE</span>;</span><br><span class="line">NAME</span><br><span class="line">------------------------------------------------------------</span><br><span class="line">D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBF</span><br><span class="line">D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF</span><br><span class="line">D:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBF</span><br><span class="line">D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF</span><br><span class="line">D:\APP\ADMINISTRATOR\ORADATA\ORCL\ORCL.DBF</span><br><span class="line">已选择<span class="number">5</span>行。</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="3-_然后关闭数据库,并拷贝物理文件。">3. 然后关闭数据库,并拷贝物理文件。</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">SQL> shutdown immediate;</span><br><span class="line">数据库已经关闭。</span><br><span class="line">已经卸载数据库。</span><br><span class="line">ORACLE 例程已经关闭。</span><br></pre></td></tr></table></figure>
<h3 id="4-_拷贝完文件后备份重建控制文件脚本">4. 拷贝完文件后备份重建控制文件脚本</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">SQL> startup mount;</span><br><span class="line">ORACLE 例程已经启动。</span><br><span class="line">Total System Global Area <span class="number">3423965184</span> bytes</span><br><span class="line">Fixed Size <span class="number">2180544</span> bytes</span><br><span class="line">Variable Size <span class="number">1862273600</span> bytes</span><br><span class="line">Database Buffers <span class="number">1543503872</span> bytes</span><br><span class="line">Redo Buffers <span class="number">16007168</span> bytes</span><br><span class="line">数据库装载完毕。</span><br><span class="line">SQL> alter database backup controlfile to trace as <span class="string">'d:\controlfile.sql'</span>;</span><br><span class="line">数据库已更改。</span><br></pre></td></tr></table></figure>
<p><code>d:\controlfile.sql</code>为建立控制文件的脚本。</p>
<h3 id="5-_重新启动数据库">5. 重新启动数据库</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">SQL> shutdown abort;</span><br><span class="line">ORACLE 例程已经关闭。</span><br><span class="line">SQL> startup;</span><br><span class="line">ORACLE 例程已经启动。</span><br><span class="line">Total System Global Area <span class="number">3423965184</span> bytes</span><br><span class="line">Fixed Size <span class="number">2180544</span> bytes</span><br><span class="line">Variable Size <span class="number">1862273600</span> bytes</span><br><span class="line">Database Buffers <span class="number">1543503872</span> bytes</span><br><span class="line">Redo Buffers <span class="number">16007168</span> bytes</span><br><span class="line">数据库装载完毕。</span><br><span class="line">数据库已经打开。</span><br></pre></td></tr></table></figure>
<p>如果有问题可直接通过系统服务重启对应的服务</p>
<h2 id="恢复、拷贝">恢复、拷贝</h2><p>这里只讨论控制文件丢失的情况下的恢复还有拷贝搭建一模一样的测试库的情况。</p>
<p>如果目的库不存在,先新建一个同名目的库(可用<code>Database Configuration Assistant</code>)。建立的时候注意一下字符集还有存储位置(跟源库一样选所有数据库文件使用公共位置)即可。以下操作均在目的库执行:</p>
<h3 id="1-_创建参数化文件">1. 创建参数化文件</h3><p> 打开CMD并用sqlplus以sysdba身份登陆ORCL(方法如上节)<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SQL> Create pfile from spfile;</span><br><span class="line">文件已创建。</span><br></pre></td></tr></table></figure></p>
<p>创建结果在<code>product\11.2.0\dbhome_1\database\INIT+DBNAME.ORA</code> 这里是<code>INITorcl.ORA</code></p>
<h3 id="2-_关闭实例并重命名spfile">2. 关闭实例并重命名spfile</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">SQL> shutdown immediate;</span><br><span class="line">数据库已经关闭。</span><br><span class="line">已经卸载数据库。</span><br><span class="line">ORACLE 例程已经关闭。</span><br></pre></td></tr></table></figure>
<p>此处将<code>D:\app\Administrator\product\11.2.0\dbhome_1\database\SPFILEORCL.ORA</code>重命名为<br><code>D:\app\Administrator\product\11.2.0\dbhome_1\database\SPFILEORCL.ORA.20160525.bak</code></p>
<h3 id="3-_将数据文件、密码文件、redolog文件拷贝到目的库对应路径">3. 将数据文件、密码文件、redolog文件拷贝到目的库对应路径</h3><p>我实际测试的时候<code>win7</code>跟<code>win2008</code>路径是跟源库一模一样的,<code>win10</code>跟源库对比路径的磁盘位置不一样。</p>
<h3 id="4-_重建控制文件">4. 重建控制文件</h3><p>先修改备份的控制文件。备份的控制文件里边有两种重建脚本。这里选<code>NORESETLOGS case</code>。<br>什么时候用另一个不太清楚,实际测试的时候第二种失败了。应该跟源库的<code>ARCHIVELOG</code>设置有关。<br>选好后把别的都删除,<red><strong>特别是空行一定要删除</strong></red>!路径有修改的,可以改成目的库的路径,例如我测试的时候数据库在H盘,所以d全部变成h了。<br>修改后的内容如下:<br> <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">STARTUP NOMOUNT</span><br><span class="line"><span class="operator"><span class="keyword">CREATE</span> CONTROLFILE REUSE <span class="keyword">DATABASE</span> <span class="string">"ORCL"</span> NORESETLOGS NOARCHIVELOG</span><br><span class="line"> MAXLOGFILES <span class="number">16</span></span><br><span class="line"> MAXLOGMEMBERS <span class="number">3</span></span><br><span class="line"> MAXDATAFILES <span class="number">100</span></span><br><span class="line"> MAXINSTANCES <span class="number">8</span></span><br><span class="line"> MAXLOGHISTORY <span class="number">292</span></span><br><span class="line"><span class="keyword">LOGFILE</span></span><br><span class="line"> <span class="keyword">GROUP</span> <span class="number">1</span> <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO01.LOG'</span> <span class="keyword">SIZE</span> <span class="number">50</span>M BLOCKSIZE <span class="number">512</span>,</span><br><span class="line"> <span class="keyword">GROUP</span> <span class="number">2</span> <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO02.LOG'</span> <span class="keyword">SIZE</span> <span class="number">50</span>M BLOCKSIZE <span class="number">512</span>,</span><br><span class="line"> <span class="keyword">GROUP</span> <span class="number">3</span> <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\REDO03.LOG'</span> <span class="keyword">SIZE</span> <span class="number">50</span>M BLOCKSIZE <span class="number">512</span></span><br><span class="line"><span class="comment">-- STANDBY LOGFILE</span></span><br><span class="line">DATAFILE</span><br><span class="line"> <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSTEM01.DBF'</span>,</span><br><span class="line"> <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\SYSAUX01.DBF'</span>,</span><br><span class="line"> <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\UNDOTBS01.DBF'</span>,</span><br><span class="line"> <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\USERS01.DBF'</span>,</span><br><span class="line"> <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\ORCL.DBF'</span></span><br><span class="line"><span class="built_in">CHARACTER</span> <span class="keyword">SET</span> ZHS16GBK</span><br><span class="line">;</span></span><br></pre></td></tr></table></figure></p>
<p>把修改后的文件放到目的库所在系统某路径,这里测试的时候放到了<code>d:\</code>,然后在sqlplus以<code>nomount</code>模式启动数据库执行这个脚本:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">SQL> STARTUP NOMOUNT;</span><br><span class="line">ORACLE 例程已经启动。</span><br><span class="line">Total System Global Area <span class="number">3423965184</span> bytes</span><br><span class="line">Fixed Size <span class="number">2180544</span> bytes</span><br><span class="line">Variable Size <span class="number">1862273600</span> bytes</span><br><span class="line">Database Buffers <span class="number">1543503872</span> bytes</span><br><span class="line">Redo Buffers <span class="number">16007168</span> bytes</span><br><span class="line">SQL> @d:\controlfile.sql;</span><br><span class="line">SQL> @d:\CONTROLFILE_KRCS.SQL</span><br><span class="line">ORA-<span class="number">01081</span>: ????????? ORACLE - ??????</span><br><span class="line">控制文件已创建。</span><br></pre></td></tr></table></figure></p>
<p>那个<code>ora-01081</code>可以不用管他,出现的原因是本身已经<code>STARTUP NOMOUNT</code>,脚本里边又执行了一次。<br>此处报01503、01565之类的错的话检查脚本中的datafile在对应路径是否存在,路径对不上的话改对它。<br>重建控制文件后执行一次恢复:<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">SQL> recover database;</span><br><span class="line">ORA-<span class="number">00283</span>: ????????????????????</span><br><span class="line">ORA-<span class="number">00264</span>: ??????????</span><br></pre></td></tr></table></figure></p>
<p>如果弹出ORA-00264错误,表示数据库是一致的,不需要恢复</p>
<p>接着打开数据库<br> <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">SQL> alter database open;</span><br><span class="line">数据库已更改。</span><br></pre></td></tr></table></figure></p>
<p>如果无报错表示数据迁移、恢复成功。</p>
<h3 id="5-_最后把临时表空间重建一下">5. 最后把临时表空间重建一下</h3><p>重建语句可以在原来备份的重建控制文件脚本里边找。<br> <figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="operator"><span class="keyword">ALTER</span> <span class="keyword">TABLESPACE</span> TEMP <span class="keyword">ADD</span> TEMPFILE <span class="string">'D:\APP\ADMINISTRATOR\ORADATA\ORCL\TEMP01.DBF'</span> REUSE;</span></span><br></pre></td></tr></table></figure></p>
]]></content>
<summary type="html">
<p>冷备恢复是oracle最快捷方便安全的恢复、拷贝方式。他只有一个缺点:冷备的时候要关闭源库。冷备特别适合搭建跟生产一致的测试环境。</p>
<h2 id="环境">环境</h2><p>源库跟目的库的Oracle大版本要一致,并且数据库SID要一样。<br>本文测试环境:</p>
<ul>
<li>源库操作系统 <code>windows server 2008 R2 x64</code><br>源库数据库版本 <code>11g Enterprise Edition Release 11.2.0.1.0 - 64bit</code></li>
<li>目的库操作系统 <code>win7 x64</code> <code>win10 x64</code> <code>windows server 2008 R2 x64</code> 均测试成功<br>目的库数据库版本 <code>11g Enterprise Edition Release 11.2.0.1.0 - 64bit</code></li>
</ul>
<p>查看版本:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="operator"><span class="keyword">select</span> banner <span class="keyword">from</span> sys.v_$<span class="keyword">version</span>;</span></span><br></pre></td></tr></table></figure>
</summary>
<category term="database" scheme="http://huangming.github.io/categories/database/"/>
<category term="oracle" scheme="http://huangming.github.io/tags/oracle/"/>
</entry>
<entry>
<title>Hexo怎么优雅地插入图片</title>
<link href="http://huangming.github.io/2016-05-02-hexo-img-solution.html"/>
<id>http://huangming.github.io/2016-05-02-hexo-img-solution.html</id>
<published>2016-05-02T02:05:47.000Z</published>
<updated>2016-05-25T02:25:09.000Z</updated>
<content type="html"><![CDATA[<p>发现懒得更新博客的一个很大原因是,写一个图文博文实在是有点麻烦。这两天研究了下如何优雅的在写<a href="http://hexo.io" target="_blank" rel="external">hexo</a>博客的时候优雅地插入图片。</p>
<h2 id="环境">环境</h2><p>我的环境:<code>win10</code> <code>gvim7.4</code> <code>hexo3.1.1</code>, 此方案对环境无要求。 </p>
<p>用<a href="http://www.vim.org/" target="_blank" rel="external">gvim</a> 编写markdown。</p>
<h2 id="开始">开始</h2><h3 id="最终结果">最终结果</h3><ul>
<li>在执行 <code>hexo new [layout] <title></code> 后,自动在一个设定的目录创建以 <code><title></code> 命名的子目录,然后把文章用到的截图全部放到这个文件夹。通过工具自动同步到图床。图床的存储路径必须满足统一前缀。例如,我的截图是 <code>youpath/title/name.png</code> ,上传到图床后,网络路径必须是 <code>http://yoursite/title/name.png</code> 类型。</li>
<li>在gvim写作的时候,每次保存会自动转换:<ol>
<li><code>![pic4](4.png)</code> 替换为 <code>![pic4](http://yoursite/title/4.png)</code></li>
<li><code>![pic4][4]</code> 自动在文章末尾增加 <code>![4](http://yoursite/title/4.png)</code></li>
</ol>
</li>
</ul>
<a id="more"></a>
<h3 id="vim配置">vim配置</h3><p>vim配置很简单,在你的配置文件vimrc里面添加下面的内容即可(网址请改为自己的图床,这里我用的是七牛图床)。</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">autocmd! BufWritePost *.md,*.mkd,*.markdown :silent!call Insertimg()<CR></span><br><span class="line">function! Insertimg()</span><br><span class="line"> " 转换![name](num)</span><br><span class="line"> :%s#\(!\[[^\]]*\](\)\(\w\{,10}\))#\=submatch(1).'http://7xsj4f.com2.z0.glb.clouddn.com/'.expand("%:r").'/'.submatch(2).'.png)'#</span><br><span class="line"> </span><br><span class="line"> " 转换 ![name][num]</span><br><span class="line"> let lnum = 1</span><br><span class="line"> let lst = []</span><br><span class="line"> while lnum <= line("$")</span><br><span class="line"> let line = getline(lnum)</span><br><span class="line"> call substitute(line, '\(!\[[^\]]*\]\[\)\(\d\{,2}\)\]', '\=add(lst, submatch(2))', 'g')</span><br><span class="line"> let lnum += 1</span><br><span class="line"> endwhile</span><br><span class="line"> let unduplst=sort(filter(copy(lst),'index(lst, v:val, v:key+1)==-1'))</span><br><span class="line"> let line = getline(line("$"))</span><br><span class="line"> let flag = matchstr(line,'\[\d\+\]: http:')</span><br><span class="line"> :ks</span><br><span class="line"> while flag != ''</span><br><span class="line"> exe "normal G"</span><br><span class="line"> exe "normal dd"</span><br><span class="line"> let line = getline(line("$"))</span><br><span class="line"> let flag = matchstr(line,'\[\d\+\]: http:')</span><br><span class="line"> endwhile</span><br><span class="line"> exe "normal 's"</span><br><span class="line"></span><br><span class="line"> for name in unduplst</span><br><span class="line"> if len(name)>0</span><br><span class="line"> call append(line("$"), "[".name."]: http://7xsj4f.com2.z0.glb.clouddn.com/".expand("%:r")."/".name.".png")</span><br><span class="line"> endif</span><br><span class="line"> endfor</span><br><span class="line"> :w</span><br><span class="line">endfunction</span><br></pre></td></tr></table></figure>
<h3 id="hexo_配置">hexo 配置</h3><p>这个配置起来有点小麻烦,要改hexo的一个模块代码。文件路径在<code>yourpath\hexo\node_modules\hexo\lib\hexo\post.js</code> 更改内容:</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">@@ -<span class="number">63</span>,<span class="number">7</span> +<span class="number">63</span>,<span class="number">7</span> @@ Post.prototype.create = <span class="function"><span class="keyword">function</span>(<span class="params">data, replace, callback</span>) </span>{</span><br><span class="line"> <span class="comment">// Write content to file</span></span><br><span class="line"> fs.writeFile(path, content),</span><br><span class="line"> <span class="comment">// Create asset folder</span></span><br><span class="line">- createAssetFolder(path, config.post_asset_folder)</span><br><span class="line">+ createAssetFolder(pathFn.resolve(config.post_asset_folder,pathFn.basename(path)), config.post_asset_folder)</span><br><span class="line"> ]).then(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line"> ctx.emit(<span class="string">'new'</span>, result);</span><br><span class="line"> }).thenReturn(result);</span><br><span class="line">@@ -<span class="number">213</span>,<span class="number">7</span> +<span class="number">213</span>,<span class="number">7</span> @@ Post.prototype.publish = <span class="function"><span class="keyword">function</span>(<span class="params">data, replace, callback</span>) </span>{</span><br><span class="line"> <span class="comment">// Remove the original draft file</span></span><br><span class="line"> <span class="keyword">return</span> fs.unlink(src);</span><br><span class="line"> }).then(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</span><br><span class="line">- <span class="keyword">if</span> (!config.post_asset_folder) <span class="keyword">return</span>;</span><br><span class="line">+ <span class="keyword">if</span> (config.post_asset_folder !== <span class="literal">true</span>) <span class="keyword">return</span>;</span><br></pre></td></tr></table></figure>
<p>然后在 <code>yourpath\hexo\_config.yml</code> 中配置 <code>post_asset_folder</code> 路径,路径可随意:</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">post_asset_folder: .\static\images\</span><br></pre></td></tr></table></figure>
<p>当每次用 <code>hexo new [layout] <title></code> 命令的时候就会自动在配置的路径生成一个跟 <code>title</code> 同名的文件夹。并且此文件夹内的内容不会上传到github。</p>
<h3 id="自动同步到图床">自动同步到图床</h3><ul>
<li><a href="https://github.com/beyondskyway/QiniuSync" target="_blank" rel="external">QiniuSync</a></li>
<li><a href="https://github.com/tiann/markdown-img-upload" target="_blank" rel="external">markdown-img-upload</a></li>
</ul>
]]></content>
<summary type="html">
<p>发现懒得更新博客的一个很大原因是,写一个图文博文实在是有点麻烦。这两天研究了下如何优雅的在写<a href="http://hexo.io">hexo</a>博客的时候优雅地插入图片。</p>
<h2 id="环境">环境</h2><p>我的环境:<code>win10</code> <code>gvim7.4</code> <code>hexo3.1.1</code>, 此方案对环境无要求。 </p>
<p>用<a href="http://www.vim.org/">gvim</a> 编写markdown。</p>
<h2 id="开始">开始</h2><h3 id="最终结果">最终结果</h3><ul>
<li>在执行 <code>hexo new [layout] &lt;title&gt;</code> 后,自动在一个设定的目录创建以 <code>&lt;title&gt;</code> 命名的子目录,然后把文章用到的截图全部放到这个文件夹。通过工具自动同步到图床。图床的存储路径必须满足统一前缀。例如,我的截图是 <code>youpath/title/name.png</code> ,上传到图床后,网络路径必须是 <code>http://yoursite/title/name.png</code> 类型。</li>
<li>在gvim写作的时候,每次保存会自动转换:<ol>
<li><code>![pic4](4.png)</code> 替换为 <code>![pic4](http://yoursite/title/4.png)</code></li>
<li><code>![pic4][4]</code> 自动在文章末尾增加 <code>![4](http://yoursite/title/4.png)</code></li>
</ol>
</li>
</ul>
</summary>
<category term="blog" scheme="http://huangming.github.io/categories/blog/"/>
<category term="hexo" scheme="http://huangming.github.io/tags/hexo/"/>
<category term="markdown" scheme="http://huangming.github.io/tags/markdown/"/>
</entry>
<entry>
<title>羁绊</title>
<link href="http://huangming.github.io/2015-09-28-juban.html"/>
<id>http://huangming.github.io/2015-09-28-juban.html</id>
<published>2015-09-28T08:57:24.000Z</published>
<updated>2016-05-04T15:01:26.000Z</updated>
<content type="html"><![CDATA[<p>距离上一篇日志,已经间隔四年之久。当初年少轻狂的我厌恶喧嚣的QQ,乐此不疲的翻墙出去看外面的世界,听外面的人聊天。在当时看来,朋友已经成为一种羁绊,想要远离一切,独自去行走,寻找人存在更深的意义,当然更多的是——去追寻所谓的自由。于是渐渐疏离,斩断羁绊。我像是一条鼠目寸光的蛇,可怜兮兮地维护着身边看的到的友谊却又冷血地斩断上一个窝点的羁绊。<br><a id="more"></a><br>直到我静下心来发现自己力不从心没有想象中的充满战斗力的时候,我才知道,以前之所以能那么拼,是因为有你们的羁绊,即使不说话,即使不在身边,一样充满斗志,因为若有若无的感觉得到,有你们在一起。上天就是这么残酷,让人直到失去后才懂得珍惜。</p>
<p>我不停地提醒着身边的人去找朋友玩,因为我后悔了,很早开始就已经后悔了,只是没有如今这么强烈而已。</p>
<p>我知道时间是把杀猪刀,也许很多人都已经变了很多,特别是面临人到中年。也许我们已经找不到共同的话题了,也许我们都忙着各自的责任与担当,但是我还想试着找回这些羁绊,就像以前一样,即使不说话,即使不在身边,能够感觉到大家在一起。</p>
<p>感觉身上的一道枷锁打开了,也许羁绊与自由本就是一体的。</p>
]]></content>
<summary type="html">
<p>距离上一篇日志,已经间隔四年之久。当初年少轻狂的我厌恶喧嚣的QQ,乐此不疲的翻墙出去看外面的世界,听外面的人聊天。在当时看来,朋友已经成为一种羁绊,想要远离一切,独自去行走,寻找人存在更深的意义,当然更多的是——去追寻所谓的自由。于是渐渐疏离,斩断羁绊。我像是一条鼠目寸光的蛇,可怜兮兮地维护着身边看的到的友谊却又冷血地斩断上一个窝点的羁绊。<br>
</summary>
<category term="diary" scheme="http://huangming.github.io/categories/diary/"/>
</entry>
<entry>
<title>Hello World</title>
<link href="http://huangming.github.io/2015-07-10-hello-world.html"/>
<id>http://huangming.github.io/2015-07-10-hello-world.html</id>
<published>2015-07-09T16:00:00.000Z</published>
<updated>2015-09-24T10:22:35.000Z</updated>
<content type="html"><![CDATA[<p>Welcome to <a href="http://hexo.io/" target="_blank" rel="external">Hexo</a>! This is your very first post. Check <a href="http://hexo.io/docs/" target="_blank" rel="external">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="http://hexo.io/docs/troubleshooting.html" target="_blank" rel="external">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="external">GitHub</a>.</p>
<h2 id="Quick_Start">Quick Start</h2><h3 id="Create_a_new_post">Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure>
<p>More info: <a href="http://hexo.io/docs/writing.html" target="_blank" rel="external">Writing</a></p>
<h3 id="Run_server">Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>More info: <a href="http://hexo.io/docs/server.html" target="_blank" rel="external">Server</a></p>
<h3 id="Generate_static_files">Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>
<p>More info: <a href="http://hexo.io/docs/generating.html" target="_blank" rel="external">Generating</a></p>
<h3 id="Deploy_to_remote_sites">Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>
<p>More info: <a href="http://hexo.io/docs/deployment.html" target="_blank" rel="external">Deployment</a></p>
]]></content>
<summary type="html">
<p>Welcome to <a href="http://hexo.io/" target="_blank" rel="external">Hexo</a>! This is your very first post. Check <a href="http://hexo.io
</summary>
</entry>
<entry>
<title>我的vimrc</title>
<link href="http://huangming.github.io/2012-04-25-vimrc.html"/>
<id>http://huangming.github.io/2012-04-25-vimrc.html</id>
<published>2012-04-25T08:54:00.000Z</published>
<updated>2015-07-31T06:58:01.000Z</updated>
<content type="html"><![CDATA[<p> 系统:windows 7 vim版本:7.4<a id="more"></a><br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br><span class="line">625</span><br><span class="line">626</span><br><span class="line">627</span><br><span class="line">628</span><br><span class="line">629</span><br><span class="line">630</span><br><span class="line">631</span><br><span class="line">632</span><br><span class="line">633</span><br><span class="line">634</span><br><span class="line">635</span><br><span class="line">636</span><br><span class="line">637</span><br><span class="line">638</span><br><span class="line">639</span><br><span class="line">640</span><br><span class="line">641</span><br><span class="line">642</span><br><span class="line">643</span><br><span class="line">644</span><br><span class="line">645</span><br><span class="line">646</span><br><span class="line">647</span><br><span class="line">648</span><br><span class="line">649</span><br><span class="line">650</span><br><span class="line">651</span><br><span class="line">652</span><br><span class="line">653</span><br><span class="line">654</span><br><span class="line">655</span><br><span class="line">656</span><br><span class="line">657</span><br><span class="line">658</span><br><span class="line">659</span><br><span class="line">660</span><br><span class="line">661</span><br><span class="line">662</span><br><span class="line">663</span><br><span class="line">664</span><br><span class="line">665</span><br><span class="line">666</span><br><span class="line">667</span><br><span class="line">668</span><br><span class="line">669</span><br><span class="line">670</span><br><span class="line">671</span><br><span class="line">672</span><br><span class="line">673</span><br><span class="line">674</span><br><span class="line">675</span><br><span class="line">676</span><br><span class="line">677</span><br><span class="line">678</span><br><span class="line">679</span><br><span class="line">680</span><br><span class="line">681</span><br><span class="line">682</span><br><span class="line">683</span><br><span class="line">684</span><br><span class="line">685</span><br><span class="line">686</span><br><span class="line">687</span><br><span class="line">688</span><br><span class="line">689</span><br><span class="line">690</span><br><span class="line">691</span><br><span class="line">692</span><br><span class="line">693</span><br><span class="line">694</span><br><span class="line">695</span><br><span class="line">696</span><br><span class="line">697</span><br><span class="line">698</span><br><span class="line">699</span><br><span class="line">700</span><br><span class="line">701</span><br><span class="line">702</span><br><span class="line">703</span><br><span class="line">704</span><br><span class="line">705</span><br><span class="line">706</span><br><span class="line">707</span><br><span class="line">708</span><br><span class="line">709</span><br><span class="line">710</span><br><span class="line">711</span><br><span class="line">712</span><br><span class="line">713</span><br><span class="line">714</span><br><span class="line">715</span><br><span class="line">716</span><br><span class="line">717</span><br><span class="line">718</span><br><span class="line">719</span><br><span class="line">720</span><br><span class="line">721</span><br><span class="line">722</span><br><span class="line">723</span><br><span class="line">724</span><br><span class="line">725</span><br><span class="line">726</span><br><span class="line">727</span><br><span class="line">728</span><br><span class="line">729</span><br><span class="line">730</span><br><span class="line">731</span><br><span class="line">732</span><br><span class="line">733</span><br><span class="line">734</span><br><span class="line">735</span><br><span class="line">736</span><br><span class="line">737</span><br><span class="line">738</span><br><span class="line">739</span><br><span class="line">740</span><br><span class="line">741</span><br><span class="line">742</span><br><span class="line">743</span><br><span class="line">744</span><br><span class="line">745</span><br><span class="line">746</span><br><span class="line">747</span><br><span class="line">748</span><br><span class="line">749</span><br><span class="line">750</span><br><span class="line">751</span><br><span class="line">752</span><br><span class="line">753</span><br><span class="line">754</span><br><span class="line">755</span><br><span class="line">756</span><br><span class="line">757</span><br></pre></td><td class="code"><pre><span class="line">"===========================================================================</span><br><span class="line">" Filename: vimrc</span><br><span class="line">" Author: HM</span><br><span class="line">" Email: wangbandi#gmail.com</span><br><span class="line">" Homepage: http://huangming.github.io</span><br><span class="line">" Created: 2015.03.30</span><br><span class="line">"===========================================================================</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">" _________________________</span><br><span class="line">"</span><br><span class="line">" Plugin</span><br><span class="line">" _________________________</span><br><span class="line">"</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Vundle</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">set nocompatible " be iMproved, required</span><br><span class="line">filetype off " required</span><br><span class="line"></span><br><span class="line">" set the runtime path to include Vundle and initialize</span><br><span class="line">set rtp+=~/vimfiles/bundle/Vundle.vim</span><br><span class="line">" alternatively, pass a path where Vundle should install plugins</span><br><span class="line">call vundle#begin('~/vimfiles/bundle')</span><br><span class="line"></span><br><span class="line">" let Vundle manage Vundle, required</span><br><span class="line">Plugin 'gmarik/Vundle.vim'</span><br><span class="line"></span><br><span class="line">" Plugin 'Shougo/vimproc'</span><br><span class="line">" Plugin 'Shougo/vimshell.vim'</span><br><span class="line"></span><br><span class="line">Plugin 'bufexplorer.zip'</span><br><span class="line">let g:bufExplorerSplitBelow=1 </span><br><span class="line">Plugin 'scrooloose/nerdtree'</span><br><span class="line">Plugin 'jistr/vim-nerdtree-tabs'</span><br><span class="line">if executable('ctags')</span><br><span class="line"> Plugin 'majutsushi/tagbar'</span><br><span class="line">endif</span><br><span class="line">if executable('git')</span><br><span class="line"> Plugin 'tpope/vim-fugitive'</span><br><span class="line">endif</span><br><span class="line">Plugin 'tpope/vim-surround'</span><br><span class="line">Plugin 'tpope/vim-unimpaired'</span><br><span class="line">Plugin 'Align'</span><br><span class="line">Plugin 'tpope/vim-commentary'</span><br><span class="line">autocmd FileType vim set commentstring=\"\ %s</span><br><span class="line">autocmd FileType vbnet set commentstring=\'\ %s</span><br><span class="line">Plugin 'vim-scripts/VisIncr'</span><br><span class="line">Plugin 'drmingdrmer/xptemplate'</span><br><span class="line">Plugin 'Shougo/neocomplcache.vim'</span><br><span class="line"></span><br><span class="line">Plugin 'calendar.vim'</span><br><span class="line">Plugin 'Stormherz/tablify'</span><br><span class="line">Plugin 'vimwiki'</span><br><span class="line">Plugin 'yianwillis/vimcdoc'</span><br><span class="line">Plugin 'huangming/myvimplugin'</span><br><span class="line"></span><br><span class="line">Plugin 'VOoM'</span><br><span class="line">" Plugin 'vim-scripts/txt.vim--xu'</span><br><span class="line">Plugin 'ap/vim-css-color'</span><br><span class="line">Plugin 'nathanaelkane/vim-indent-guides'</span><br><span class="line"> let g:indent_guides_enable_on_vim_startup = 1</span><br><span class="line">Plugin 'michaeljsmith/vim-indent-object'</span><br><span class="line"> let g:indentobject_meaningful_indentation = ["haml", "sass", "python", "yaml", "markdown", "vbnet"]</span><br><span class="line"></span><br><span class="line">Plugin 'scrooloose/syntastic'</span><br><span class="line">" let g:syntastic_python_checkers = ['pylint']</span><br><span class="line">let g:syntastic_python_checkers = ['python']</span><br><span class="line">let g:syntastic_enable_python_checker = 1</span><br><span class="line">set statusline+=%#warningmsg#</span><br><span class="line">set statusline+=%{SyntasticStatuslineFlag()}</span><br><span class="line">set statusline+=%*</span><br><span class="line">let g:syntastic_always_populate_loc_list = 1</span><br><span class="line">let g:syntastic_auto_loc_list = 1</span><br><span class="line">let g:syntastic_check_on_open = 1</span><br><span class="line">let g:syntastic_check_on_wq = 0</span><br><span class="line"></span><br><span class="line">if has('gui_running')</span><br><span class="line"> Plugin 'Lokaltog/vim-powerline'</span><br><span class="line">endif</span><br><span class="line">Plugin 'Color-Scheme-Explorer'</span><br><span class="line">Plugin 'baskerville/bubblegum'</span><br><span class="line">Plugin 'altercation/vim-colors-solarized'</span><br><span class="line">Plugin 'chriskempson/vim-tomorrow-theme'</span><br><span class="line">Plugin 'tomasr/molokai'</span><br><span class="line"></span><br><span class="line">" Git plugin not hosted on GitHub</span><br><span class="line">" Plugin 'git://git.wincent.com/command-t.git'</span><br><span class="line"></span><br><span class="line">" git repos on your local machine ( .e. when working on your own plugin)</span><br><span class="line">" Plugin 'file:///home/gmarik/path/to/plugin'</span><br><span class="line"></span><br><span class="line">" The sparkup vim script is in a subdirectory of this repo called vim.</span><br><span class="line">" Pass the path to set the runtimepath properly.</span><br><span class="line">" Plugin 'rstacruz/sparkup', {'rtpa': 'vim/'}</span><br><span class="line"></span><br><span class="line">" Avoid a name conflict with L9</span><br><span class="line">" Plugin 'user/L9', {'name': 'newL9'}</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">" non github repos</span><br><span class="line">call vundle#end()</span><br><span class="line">filetype plugin indent on " required!</span><br><span class="line"> "</span><br><span class="line"> " Brief help</span><br><span class="line"> " :PluginList - list configured bundles</span><br><span class="line"> " :PluginInstall(!) - install(update) bundles</span><br><span class="line"> " :PluginSearch(!) foo - search(or refresh cache first) for foo</span><br><span class="line"> " :PluginClean(!) - confirm(or auto-approve) removal of unused bundles</span><br><span class="line"> "</span><br><span class="line"> " see :h vundle for more details or wiki for FAQ</span><br><span class="line"> " NOTE: comments after Plugin command are not allowed..</span><br><span class="line"></span><br><span class="line">" _________________________</span><br><span class="line">"</span><br><span class="line">" General settings</span><br><span class="line">" _________________________</span><br><span class="line">"</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => General settings</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">set fileencodings=utf-8,chinese,ucs-bom</span><br><span class="line">set encoding=utf-8</span><br><span class="line">set fileencoding=utf-8</span><br><span class="line">" set ambiwidth=double</span><br><span class="line">set termencoding=utf-8</span><br><span class="line">"vim 提示信息乱码解决方法 </span><br><span class="line">"language messages zh_CN.UTF-8 </span><br><span class="line">if has("win32") </span><br><span class="line"> set termencoding=chinese </span><br><span class="line"> language message zh_CN.UTF-8 </span><br><span class="line">endif </span><br><span class="line"></span><br><span class="line">set history=100</span><br><span class="line">syntax on</span><br><span class="line">set cursorline</span><br><span class="line">set scrolloff=5</span><br><span class="line">set cmdheight=2</span><br><span class="line">set report=0</span><br><span class="line">set helplang=cn</span><br><span class="line">"set t_Co=256</span><br><span class="line">" set background=light</span><br><span class="line">set bsdir=buffer</span><br><span class="line">set nocompatible</span><br><span class="line">set autochdir</span><br><span class="line">set listchars=tab:>\ ,eol:$,extends:>,precedes:< " Unprintable chars mapping </span><br><span class="line">set showbreak=->\ \ \ </span><br><span class="line">set wildignore=.svn,CVS,.git,.hg,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,.DS_Store,*.aux,*.out,*.toc</span><br><span class="line">set showcmd</span><br><span class="line">set shortmess=at " Avoids 'hit enter'</span><br><span class="line">au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif</span><br><span class="line">let mapleader=',' " Change the mapleader</span><br><span class="line">let maplocalleader='\' " Change the maplocalleader</span><br><span class="line"></span><br><span class="line">"--------------------------------------------------------------------------</span><br><span class="line">" => Colorscheme</span><br><span class="line">"--------------------------------------------------------------------------</span><br><span class="line">"colorscheme solarized</span><br><span class="line">exec 'colorscheme '.["bubblegum-256-light","solarized","Tomorrow","molokai","bubblegum-256-dark","molokai"][strftime("%S")%6] </span><br><span class="line"></span><br><span class="line">"--------------------------------------------------------------------------</span><br><span class="line">" => Status bar</span><br><span class="line">"--------------------------------------------------------------------------</span><br><span class="line">" Only have cursorline in current window and in normal window</span><br><span class="line">autocmd WinLeave * set nocursorline</span><br><span class="line">autocmd WinEnter * set cursorline</span><br><span class="line">auto InsertEnter * set nocursorline</span><br><span class="line">auto InsertLeave * set cursorline</span><br><span class="line">set laststatus=1</span><br><span class="line"></span><br><span class="line">"set statusline+=%{fugitive#head()}</span><br><span class="line">set ruler " bottom status bar</span><br><span class="line">" set rulerformat=%45(%=\:b%n%m%r\ %Y\ %{fugitive#head()}\ %l,%c%V\ %P%)</span><br><span class="line">set rulerformat=%25(%n%m%r:\ %Y\ [%l,%v]\ %p%%%)</span><br><span class="line">highlight StatusLine guifg=SlateBlue guibg=Yellow</span><br><span class="line">highlight StatusLineNC guifg=Gray guibg=White</span><br><span class="line">if version >= 700 " change color when enter inser motion</span><br><span class="line"> au InsertEnter * hi StatusLine guibg=#818D2d guifg=#FCFCFC gui=none</span><br><span class="line"> au InsertLeave * hi StatusLine guibg=Yellow guifg=SlateBlue gui=none</span><br><span class="line">endif</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Gui settings</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">if has("gui_running")</span><br><span class="line"> "au GUIEnter * simalt ~x " maximun window</span><br><span class="line"> set guioptions-=m " menu bar</span><br><span class="line"> set guioptions-=T " tools bar</span><br><span class="line"> "set guioptions-=L " left scroll bar</span><br><span class="line"> set guioptions-=r " right scroll bar</span><br><span class="line"> "set guioptions-=b " bottom scroll bar</span><br><span class="line"> set showtabline=0 " tab bar</span><br><span class="line">endif</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Pos and size when start</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" winpos 350 150</span><br><span class="line">" winpos 250 200</span><br><span class="line">" set lines=25</span><br><span class="line">" set columns=85</span><br><span class="line">winpos 200 150</span><br><span class="line">set lines=30</span><br><span class="line">set columns=100</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Font</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">if has('gui_running')</span><br><span class="line"> if has("win32")</span><br><span class="line"> " set guifont=Lucida\ Console:h11:cANSI</span><br><span class="line"> set guifont=Yahei_Mono:h12.5</span><br><span class="line"> endif</span><br><span class="line">endif</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Tag label</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">set guitablabel=%m%N:%t\[%{tabpagewinnr(v:lnum)}\]</span><br><span class="line">set tabline=%!MyTabLine()</span><br><span class="line">function! MyTabLine()</span><br><span class="line"> let s=''</span><br><span class="line"> let t=tabpagenr() " The index of current page</span><br><span class="line"> let i=1</span><br><span class="line"> while i<=tabpagenr('$') " From the first page</span><br><span class="line"> let buflist=tabpagebuflist(i)</span><br><span class="line"> let winnr=tabpagewinnr(i)</span><br><span class="line"> let s.=(i==t?'%#TabLineSel#':'%#TabLine#')</span><br><span class="line"> let s.='%'.i.'T'</span><br><span class="line"> let s.=' '</span><br><span class="line"> let bufnr=buflist[winnr - 1]</span><br><span class="line"> let file=bufname(bufnr)</span><br><span class="line"> let m=''</span><br><span class="line"> if getbufvar(bufnr, "&modified")</span><br><span class="line"> let m='[+]'</span><br><span class="line"> endif</span><br><span class="line"> if file=~'\/.'</span><br><span class="line"> let file=substitute(file,'.*\/\ze.','','')</span><br><span class="line"> endif</span><br><span class="line"> if file==''</span><br><span class="line"> let file='[No Name]'</span><br><span class="line"> endif</span><br><span class="line"> let s.=m</span><br><span class="line"> let s.=i.':'</span><br><span class="line"> let s.=file</span><br><span class="line"> let s.='['.winnr.']'</span><br><span class="line"> let s.=' '</span><br><span class="line"> let i=i+1</span><br><span class="line"> endwhile</span><br><span class="line"> let s.='%T%#TabLineFill#%='</span><br><span class="line"> let s.=(tabpagenr('$')>1?'%999XX':'X')</span><br><span class="line"> return s</span><br><span class="line"> endfunction</span><br><span class="line">" Set up tab tooltips with every buffer name</span><br><span class="line">set guitabtooltip=%F</span><br><span class="line"></span><br><span class="line">" Alt+n</span><br><span class="line">if has("gui_running")</span><br><span class="line"> :map <silent> <C-S> :if expand("%") == ""<CR>:browse confirm w<CR>:else<CR>:confirm w<CR>:endif<CR></span><br><span class="line"> noremap <M-1> 1gt</span><br><span class="line"> noremap <M-2> 2gt</span><br><span class="line"> noremap <M-3> 3gt</span><br><span class="line"> noremap <M-4> 4gt</span><br><span class="line"> noremap <M-5> 5gt</span><br><span class="line"> noremap <M-6> 6gt</span><br><span class="line"> noremap <M-7> 7gt</span><br><span class="line"> noremap <M-8> 8gt</span><br><span class="line"> noremap <M-9> 9gt</span><br><span class="line"> noremap <M-0> 10gt</span><br><span class="line"> noremap <C-TAB> gt</span><br><span class="line"> noremap <C-F4> <ESC>:bd<CR></span><br><span class="line"> noremap tx <ESC>:bd<CR></span><br><span class="line">endif</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => File settings</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">set confirm " confirm when quit file</span><br><span class="line">set autoread " update file when it change external</span><br><span class="line">set backspace=indent,eol,start</span><br><span class="line">"set shortmess=atI " dont display tips when start</span><br><span class="line">" Set directories</span><br><span class="line">"set noswapfile</span><br><span class="line"></span><br><span class="line">set backup " Set backup</span><br><span class="line">" set undofile " Set undo</span><br><span class="line">" Set directories</span><br><span class="line">set backupdir=~/vimfiles/tmp/backup " backups</span><br><span class="line">set directory=~/vimfiles/tmp/swap " swap files</span><br><span class="line">set viewdir=~/vimfiles/tmp/view " view files</span><br><span class="line">set undodir=~/vimfiles/tmp/undo " undo files</span><br><span class="line"></span><br><span class="line">autocmd BufWinLeave *.* silent! mkview " Make Vim save view (state)(folds,cursor,etc)</span><br><span class="line">autocmd BufWinEnter *.* silent! loadview " Make Vim load view(state)(folds,cursor,etc)</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => File format and Typesetting</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">"set nowrap</span><br><span class="line">set virtualedit=insert " help virtualedit!</span><br><span class="line">set formatoptions=tcrqn " auto format</span><br><span class="line">set textwidth=10000 " the max column,auto wrap when eceeding</span><br><span class="line">set matchtime=5 " highlights time for Maching braces</span><br><span class="line">set showmatch " highlights for maching braces</span><br><span class="line">set nolinebreak " dont break on words</span><br><span class="line">set cindent " indent on c style</span><br><span class="line">set tabstop=4</span><br><span class="line">set shiftwidth=4</span><br><span class="line">set expandtab</span><br><span class="line">set modeline " autoload indent line setting</span><br><span class="line">au BufNewFile,BufReadPost *.html setl shiftwidth=2 tabstop=2 softtabstop=2 expandtab</span><br><span class="line">"au BufRead,BufNewFile *.css set ft=css syntax=css3</span><br><span class="line">"自动插入modeline</span><br><span class="line">func! AppendModeline()</span><br><span class="line"> let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d :",</span><br><span class="line"> \ &tabstop, &shiftwidth, &textwidth)</span><br><span class="line"> let l:modeline = substitute(&commentstring, "%s", l:modeline, "")</span><br><span class="line"> call append(line("$"), l:modeline)</span><br><span class="line">endfunc</span><br><span class="line">"按\ml,自动插入modeline</span><br><span class="line">nnoremap <silent> <Leader>ml :call AppendModeline()<CR></span><br><span class="line">" au BufWritePre *.Q ks|:silent %s/^scriptstart\s*=\s*\zs\d\+$/\=submatch(1).line('.')/|'s</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Auto completion</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">inoremap <C-]> <C-X><C-]></span><br><span class="line">inoremap <C-F> <C-X><C-F></span><br><span class="line">set complete+=]</span><br><span class="line">" line CTRL-X CTRL-L</span><br><span class="line">" keyword CTRL-X CTRL-N</span><br><span class="line">" dict CTRL-X CTRL-K</span><br><span class="line">" synonyms dict CTRL-X CTRL-T</span><br><span class="line">" key words CTRL-X CTRL-I</span><br><span class="line">" tags CTRL-X CTRL-]</span><br><span class="line">" file name CTRL-X CTRL-F</span><br><span class="line">" definitions CTRL-X CTRL-D</span><br><span class="line">" vim command CTRL-X CTRL-V</span><br><span class="line">" custom CTRL-X CTRL-U</span><br><span class="line">" spelling suggestions CTRL-X CTRL-S </span><br><span class="line">set wildmenu " command line auto-complete</span><br><span class="line">set completeopt=longest,menuone </span><br><span class="line">set wildmode=list:longest,full " Use powerful wildmenu</span><br><span class="line">set ic " ignore case</span><br><span class="line">set iskeyword+=.,_,$,@,%,#,- " about dict complete</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Search and replace</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">set hlsearch</span><br><span class="line">set incsearch " enter '/b' you can find the word begin with b</span><br><span class="line">set gdefault " replace all the lines match</span><br><span class="line">set ignorecase " ignore case</span><br><span class="line"></span><br><span class="line">" Open a Quickfix window for the last search.</span><br><span class="line">nnoremap <silent> <leader>? :execute 'vimgrep /'.@/.'/g %'<CR>:copen<CR></span><br><span class="line"></span><br><span class="line">" Highlight word </span><br><span class="line">highlight InterestingWord ctermbg=yellow guibg=yellow ctermfg=black guifg=#000000</span><br><span class="line">highlight InterestingWord1 ctermbg=green guibg=green ctermfg=black guifg=#000000</span><br><span class="line">highlight InterestingWord2 ctermbg=blue guibg=blue ctermfg=black guifg=#000000</span><br><span class="line">highlight InterestingWord3 ctermbg=red guibg=red ctermfg=white guifg=#FFFFFF</span><br><span class="line">nnoremap <silent> <leader>hh :execute 'match InterestingWord1 /\<<c-r><c-w>\>/'<cr></span><br><span class="line">nnoremap <silent> <leader>h1 :execute 'match InterestingWord1 /\<<c-r><c-w>\>/'<cr></span><br><span class="line">nnoremap <silent> <leader>h2 :execute '2match InterestingWord2 /\<<c-r><c-w>\>/'<cr></span><br><span class="line">nnoremap <silent> <leader>h3 :execute '3match InterestingWord3 /\<<c-r><c-w>\>/'<cr></span><br><span class="line"></span><br><span class="line">"-------------------------------------------------</span><br><span class="line">" => Fold Related</span><br><span class="line">"-------------------------------------------------</span><br><span class="line"></span><br><span class="line">set foldenable</span><br><span class="line">"set foldopen = "all"</span><br><span class="line">set foldmethod=syntax</span><br><span class="line">set foldcolumn=0</span><br><span class="line">setlocal foldlevel=0</span><br><span class="line">set foldlevelstart=99 " dont fold when open file</span><br><span class="line"></span><br><span class="line">" Space to toggle and create folds.</span><br><span class="line">nnoremap <silent><Space> @=(foldlevel('.')?'za':"\<Space>")<CR></span><br><span class="line">vnoremap <Space> zf</span><br><span class="line"></span><br><span class="line">" Set foldtext</span><br><span class="line">function! MyFoldText()</span><br><span class="line"> let line=getline(v:foldstart)</span><br><span class="line"> let nucolwidth=&foldcolumn+&number*&numberwidth</span><br><span class="line"> let windowwidth=winwidth(0)-nucolwidth-3</span><br><span class="line"> let foldedlinecount=v:foldend-v:foldstart+1</span><br><span class="line"> let onetab=strpart(' ', 0, &tabstop)</span><br><span class="line"> let line=substitute(line, '\t', onetab, 'g')</span><br><span class="line"> let line=strpart(line, 0, windowwidth-2-len(foldedlinecount))</span><br><span class="line"> let fillcharcount=windowwidth-len(line)-len(foldedlinecount)</span><br><span class="line"> return line.'…'.repeat(" ",fillcharcount).foldedlinecount.'…'.' '</span><br><span class="line">endfunction</span><br><span class="line">set foldtext=MyFoldText()</span><br><span class="line">"--------------------------------------------------------------------------</span><br><span class="line">" => Special file style</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">au BufRead,BufNewFile {Gemfile,Rakefile,Capfile,*.rake,config.ru} set ft=ruby</span><br><span class="line">au BufRead,BufNewFile {*.md,*.mkd,*.markdown} set ft=markdown</span><br><span class="line">au BufRead,BufNewFile {*.txt} set ft=txt</span><br><span class="line">au BufRead,BufNewFile {*.tabl} set nowrap</span><br><span class="line">"function! CtagsUpdata()</span><br><span class="line">" let s:pwd = $PWD</span><br><span class="line">" call system( 'cd ' . g:projecthome . ' && ctags -R' )</span><br><span class="line">" call system( 'cd ' . s:pwd ) | execute 'cd ' . s:pwd</span><br><span class="line">" execute 'set tags=' . g:default_tag</span><br><span class="line">" execute 'set tags+=' . g:projecthome . 'tags'</span><br><span class="line">" args *.c</span><br><span class="line">" argdo set ff=unix | update</span><br><span class="line">"endfunction</span><br><span class="line">"autocmd BufNewFile *.Q 0r ~/.vim/template/skeleton.q "</span><br><span class="line">"noremap <F12> : !ctags --langdef=vbnet --langmap=Asp:*.Q.<cr></span><br><span class="line">"noremap <C-F12> : argg tags\|argdo set fenc=utf-8\|update<cr></span><br><span class="line">set tags=./tags,tags</span><br><span class="line"></span><br><span class="line">" Python section</span><br><span class="line">" Run the current buffer in python - ie. on leader+space</span><br><span class="line">autocmd FileType python set textwidth=79 " PEP-8 Friendly</span><br><span class="line">" New Python file template</span><br><span class="line">autocmd bufnewfile *.py call setline(1,'#!/usr/bin/env python') |</span><br><span class="line"> \ call setline(2,'#coding:utf-8') |</span><br><span class="line"> \ call setline(3,"#Created Time: ".strftime("%c")) |</span><br><span class="line"> \ call setline(4,'#author: Cactus') |</span><br><span class="line"> \ call setline(5,'') |</span><br><span class="line"> \ call setline(6,'') |</span><br><span class="line"> \ exe "normal G"</span><br><span class="line"></span><br><span class="line">" Markdown</span><br><span class="line">augroup ft_markdown</span><br><span class="line"> autocmd!</span><br><span class="line"> " Use <localLeader>1/2/3/4/5/6 to add headings</span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>1 I# <ESC></span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>2 I## <ESC></span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>3 I### <ESC></span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>4 I#### <ESC></span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>5 I##### <ESC></span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>6 I###### <ESC></span><br><span class="line"> " Use <LocalLeader>b to add blockquotes in normal and visual mode</span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>b I> <ESC></span><br><span class="line"> autocmd Filetype markdown vnoremap <buffer> <localLeader>b :s/^/> /<CR></span><br><span class="line"> " Use <localLeader>ul and <localLeader>ol to add list symbols in visual mode</span><br><span class="line"> autocmd Filetype markdown vnoremap <buffer> <localLeader>ul :s/^/* /<CR></span><br><span class="line"> autocmd Filetype markdown vnoremap <buffer> <LocalLeader>ol :s/^/\=(line(".")-line("'<")+1).'. '/<CR></span><br><span class="line"> " Use <localLeader>e1/2/3 to add emphasis symbols</span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>e1 I*<ESC>A*<ESC></span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>e2 I**<ESC>A**<ESC></span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <localLeader>e3 I***<ESC>A***<ESC></span><br><span class="line"> " Use <Leader>P to preview markdown file in browser</span><br><span class="line"> autocmd Filetype markdown nnoremap <buffer> <Leader>P :MarkdownPreview<CR></span><br><span class="line">augroup END</span><br><span class="line"></span><br><span class="line">"--------------------------------------------------------------------------</span><br><span class="line">" => Key map</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line"></span><br><span class="line">" clear highlight after search</span><br><span class="line">noremap <silent><Leader>/ :nohls<CR></span><br><span class="line"></span><br><span class="line">" Use sane regexes</span><br><span class="line">nnoremap / /\v</span><br><span class="line">vnoremap / /\v</span><br><span class="line">cnoremap s/ s/\v</span><br><span class="line">nnoremap ? ?\v</span><br><span class="line">vnoremap ? ?\v</span><br><span class="line">cnoremap s? s?\v</span><br><span class="line"></span><br><span class="line">" Keep search matches in the middle of the window</span><br><span class="line">nnoremap n nzzzv</span><br><span class="line">nnoremap N Nzzzv</span><br><span class="line">nnoremap * *zzzv</span><br><span class="line">nnoremap # #zzzv</span><br><span class="line">nnoremap g* g*zzzv</span><br><span class="line">nnoremap g# g#zzzv</span><br><span class="line"></span><br><span class="line">" Visual search mappings</span><br><span class="line">function! s:VSetSearch()</span><br><span class="line"> let temp=@@</span><br><span class="line"> normal! gvy</span><br><span class="line"> let @/='\V'.substitute(escape(@@, '\'), '\n', '\\n', 'g')</span><br><span class="line"> let @@=temp</span><br><span class="line">endfunction</span><br><span class="line">vnoremap * :<C-U>call <SID>VSetSearch()<CR>//<CR></span><br><span class="line">vnoremap # :<C-U>call <SID>VSetSearch()<CR>??<CR></span><br><span class="line"></span><br><span class="line">nmap wv <C-w>v " vertical spilt window</span><br><span class="line">nmap wc <C-w>c " colse the current window</span><br><span class="line">nmap ws <C-w>s " spilt window horizontally</span><br><span class="line"></span><br><span class="line">" Begining & End of line in Normal mode</span><br><span class="line">noremap H ^</span><br><span class="line">noremap L g_</span><br><span class="line"></span><br><span class="line">" Redesign moving keys in insert mode</span><br><span class="line">"inoremap <C-K> <Up></span><br><span class="line">"inoremap <C-J> <Down></span><br><span class="line">inoremap <C-H> <Left></span><br><span class="line">inoremap <C-L> <Right></span><br><span class="line"></span><br><span class="line">" Make j and k work the way you expect</span><br><span class="line">nnoremap j gj</span><br><span class="line">nnoremap k gk</span><br><span class="line">vnoremap j gj</span><br><span class="line">vnoremap k gk</span><br><span class="line"></span><br><span class="line">" Same when jumping around</span><br><span class="line">nnoremap g; g;zz</span><br><span class="line">nnoremap g, g,zz</span><br><span class="line"></span><br><span class="line">" Navigation between windows</span><br><span class="line">nnoremap <C-H> <C-W>h</span><br><span class="line">nnoremap <C-J> <C-W>j</span><br><span class="line">nnoremap <C-K> <C-W>k</span><br><span class="line">nnoremap <C-L> <C-W>l</span><br><span class="line">nnoremap <C-O> <C-W>o</span><br><span class="line"></span><br><span class="line">" Reselect visual block after indent/outdent</span><br><span class="line">vnoremap < <gv</span><br><span class="line">vnoremap > >gv</span><br><span class="line"></span><br><span class="line">" Copy paste system clipboard</span><br><span class="line">map <leader>y "+y</span><br><span class="line">map <leader>p "+p</span><br><span class="line">map <leader>P "+P</span><br><span class="line">imap <c-v> <c-r>+</span><br><span class="line">" 把||之间的运行结果输出到剪切板</span><br><span class="line">" 把||之间的行数内容复制到剪切板</span><br><span class="line">nmap ,cn :redir @+\|\|redir END<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left></span><br><span class="line">nmap ,cm :silent redir @+\|for i in []\|echo getline(i)\|endfor\|redir END<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left></span><br><span class="line"></span><br><span class="line">" Quit help easily</span><br><span class="line">function! QuitWithQ()</span><br><span class="line"> if &buftype == 'help'</span><br><span class="line"> nnoremap <buffer> <silent> q :q<cr></span><br><span class="line"> endif</span><br><span class="line">endfunction</span><br><span class="line">autocmd FileType help exe QuitWithQ()</span><br><span class="line"></span><br><span class="line">" Easy buffer navigation</span><br><span class="line">noremap <leader>bp :bprevious<cr></span><br><span class="line">noremap <leader>bn :bnext<cr></span><br><span class="line"></span><br><span class="line">nmap gx yiw/^(def)\s+<C-R>"<CR> </span><br><span class="line"></span><br><span class="line">" Quick editing </span><br><span class="line">nnoremap <Leader>ev :tabedit $MYVIMRC<CR></span><br><span class="line">nnoremap <silent> <LocalLeader>rs :source $MYVIMRC<CR></span><br><span class="line">map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/</span><br><span class="line"></span><br><span class="line">" When vimrc is edited, reload it</span><br><span class="line">autocmd! BufWritePost _vimrc source $MYVIMRC</span><br><span class="line"></span><br><span class="line">" better ESC</span><br><span class="line">inoremap jk <Esc></span><br><span class="line">inoremap jkl <Esc>:</span><br><span class="line">nmap ; :</span><br><span class="line">" automatically leave insert mode after 4 seconds of inaction</span><br><span class="line">au CursorHoldI * stopinsert</span><br><span class="line">set ut=4000</span><br><span class="line">set nu</span><br><span class="line">nmap <leader>n :call NumberToggle()<CR></span><br><span class="line">function! NumberToggle()</span><br><span class="line"> if(&relativenumber == 1)</span><br><span class="line"> set number</span><br><span class="line"> elseif(&number == 1)</span><br><span class="line"> set nonumber</span><br><span class="line"> else</span><br><span class="line"> set relativenumber</span><br><span class="line"> endif</span><br><span class="line">endfunction </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">" Fast saving and closing current buffer without closing windows displaying the buffer</span><br><span class="line">nmap <leader>wq :w!<cr>:bdelete<cr></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Complie and run program</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" 通过log文件打印错误/调试内容 </span><br><span class="line">"function QfMakeConv()</span><br><span class="line">" let qflist = getqflist()</span><br><span class="line">" for i in qflist</span><br><span class="line">" let i.text = iconv(i.text, "cp936", "utf-8")</span><br><span class="line">" endfor</span><br><span class="line">" call setqflist(qflist)</span><br><span class="line">"endfunction</span><br><span class="line">"au QuickfixCmdPost make call QfMakeConv()</span><br><span class="line"></span><br><span class="line">" map <F9> :call CompileRunQ()<CR></span><br><span class="line">" func! CompileRunQ()</span><br><span class="line">" set errorformat=%f,第%l行:%m</span><br><span class="line">" " let &errorformat=iconv("%f第%l行%m", "utf-8", &enc)</span><br><span class="line">" exec "cexpr[]"</span><br><span class="line">" exec "caddf E:\\Dropbox\\tmp\\tmp.txt"</span><br><span class="line">" exec "copen"</span><br><span class="line">" " call QfMakeConv()</span><br><span class="line">" endfunc</span><br><span class="line"></span><br><span class="line">func! CheckPythonSyntax()</span><br><span class="line"> " w</span><br><span class="line"> let mp = &makeprg</span><br><span class="line"> let ef = &errorformat</span><br><span class="line"> let exeFile = expand("%:t")</span><br><span class="line"> setlocal makeprg=python\ -u</span><br><span class="line"> set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m</span><br><span class="line"> silent make %</span><br><span class="line"> cw</span><br><span class="line"> let &makeprg = mp</span><br><span class="line"> let &errorformat = ef</span><br><span class="line">endfunction</span><br><span class="line">au FileType python map <F5> :call CheckPythonSyntax()<CR></span><br><span class="line"></span><br><span class="line">"--------------------------------------------------</span><br><span class="line">" => Tagbar</span><br><span class="line">"--------------------------------------------------</span><br><span class="line">nnoremap <Leader>t :TagbarToggle<CR></span><br><span class="line">"let g:tagbar_ctags_bin='ctags'</span><br><span class="line">let g:tagbar_autofocus=1</span><br><span class="line">let g:tagbar_expand=1</span><br><span class="line">let g:tagbar_foldlevel=2</span><br><span class="line">let g:tagbar_ironchars=['?', '?']</span><br><span class="line">let g:tagbar_autoshowtag=1</span><br><span class="line">let g:tagbar_width = 30</span><br><span class="line"></span><br><span class="line">"--------------------------------------------------</span><br><span class="line">" => NERD_tree</span><br><span class="line">"--------------------------------------------------</span><br><span class="line">nnoremap <Leader>d :NERDTreeTabsToggle<CR></span><br><span class="line">nnoremap <Leader>f :NERDTreeFind<CR></span><br><span class="line">let NERDTreeChDirMode=2</span><br><span class="line">let NERDTreeShowBookmarks=1</span><br><span class="line">let NERDTreeShowHidden=1</span><br><span class="line">let NERDTreeShowLineNumbers=0</span><br><span class="line">let NERDTreeDirArrows=0</span><br><span class="line">let g:nerdtree_tabs_open_on_gui_startup=0 "(default: 1)Open NERDTree on gvim/macvim startup</span><br><span class="line">let g:nerdtree_tabs_open_on_console_startup=0 "(default: 0)Open NERDTree on console vim startup</span><br><span class="line"></span><br><span class="line">"--------------------------------------------------</span><br><span class="line">" => fugitive</span><br><span class="line">"--------------------------------------------------</span><br><span class="line">if executable('git')</span><br><span class="line"> nnoremap <silent> <leader>gs :Gstatus<CR></span><br><span class="line"> nnoremap <silent> <leader>gd :Gdiff<CR></span><br><span class="line"> nnoremap <silent> <leader>gc :Gcommit<CR></span><br><span class="line"> nnoremap <silent> <leader>gb :Gblame<CR></span><br><span class="line"> nnoremap <silent> <leader>gl :Glog<CR></span><br><span class="line"> nnoremap <silent> <leader>gp :Git push<CR></span><br><span class="line">" Automatically remove fugitive buffers</span><br><span class="line">autocmd BufReadPost fugitive://* set bufhidden=delete</span><br><span class="line">endif</span><br><span class="line"></span><br><span class="line">"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""</span><br><span class="line">" set jedi</span><br><span class="line">"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""</span><br><span class="line">"let g:jedi#goto_command = "<leader>d"</span><br><span class="line">let g:jedi#goto_assignments_command = "<leader>g"</span><br><span class="line">let g:jedi#goto_definitions_command = "<leader>d"</span><br><span class="line">let g:jedi#documentation_command = "K"</span><br><span class="line">let g:jedi#usages_command = "<leader>n"</span><br><span class="line">let g:jedi#completions_command = "<C-Space>"</span><br><span class="line">let g:jedi#rename_command = "<leader>rname"</span><br><span class="line"></span><br><span class="line">"--------------------------------------------------------</span><br><span class="line">" => xptemplate.vim设置</span><br><span class="line">"--------------------------------------------------------</span><br><span class="line">"let g:xptemplate_brace_complete = 1</span><br><span class="line">let g:xptemplate_brace_complete = '([''"'</span><br><span class="line">" if nothing matched in xpt, try c-p </span><br><span class="line">let g:xptemplate_fallback = '<C-p>'</span><br><span class="line"> </span><br><span class="line">" avoid key conflict</span><br><span class="line">"let g:SuperTabMappingForward = '<Plug>supertabKey'</span><br><span class="line"></span><br><span class="line">" if nothing matched in xpt, try supertab</span><br><span class="line">"let g:xptemplate_fallback = '<Plug>supertabKey'</span><br><span class="line"></span><br><span class="line">" xpt uses <Tab> as trigger key</span><br><span class="line">let g:xptemplate_key = '<Tab>'</span><br><span class="line"></span><br><span class="line">"let g:xptemplate_always_show_pum=1 </span><br><span class="line">" use <tab>/<S-tab> to navigate through popup menu //NOT necessary. </span><br><span class="line">let g:xptemplate_pum_tab_nav = 1</span><br><span class="line">let g:xptemplate_nav_cancel = '<C-c>'</span><br><span class="line">" xpt triggers only when you typed whole name of a snippet. //NOT necessary. </span><br><span class="line">let g:xptemplate_minimal_prefix = 'full'</span><br><span class="line">inoremap <expr> <CR> pumvisible() ? "\<C-Y><c-r>=XPTemplateStart(0)<cr>" : "\<CR>"</span><br><span class="line">inoremap <expr> <C-n> pumvisible() ? '<C-n>' : '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'</span><br><span class="line">snoremap <expr> <C-p> pumvisible() ? '<C-n>' : '<C-p><C-r>=pumvisible() ? "\<lt>Up>" : ""<CR>'</span><br><span class="line"></span><br><span class="line">"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""</span><br><span class="line">" => Omni complete functions</span><br><span class="line">"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""</span><br><span class="line">"autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete</span><br><span class="line">autocmd FileType css set omnifunc=csscomplete#CompleteCSS</span><br><span class="line">autocmd FileType html set omnifunc=htmlcomplete#CompleteTags</span><br><span class="line">autocmd FileType python set omnifunc=pythoncomplete#Complete</span><br><span class="line">autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags</span><br><span class="line">autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS</span><br><span class="line">"autocmd FileType vbnet set omnifunc=javascriptcomplete#CompleteJ</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => surround.vim</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">xmap <Leader>sa <Plug>Vsurround</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Calendar</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">"let g:calendar_diary='/home/cactus/dev/diary'</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => VimWiki</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">let g:vimwiki_use_mouse = 1</span><br><span class="line">let g:vimwiki_camel_case = 0</span><br><span class="line">let g:vimwiki_hl_cb_checked = 1</span><br><span class="line">let g:vimwiki_CJK_length = 1</span><br><span class="line">let g:vimwiki_ext2syntax = {'.md': 'markdown',</span><br><span class="line"> \ '.mkd': 'markdown',</span><br><span class="line"> \ '.wiki': 'media'}</span><br><span class="line">let g:vimwiki_valid_html_tags ='b,i,s,u,sub,sup,kbd,br,hr,div'</span><br><span class="line"> let wiki_1 = {}</span><br><span class="line">" let wiki_1.index = 'VimWiki-@HM'</span><br><span class="line"> let wiki_1.path = '~/vimwiki/'</span><br><span class="line"> let wiki_1.path_html = '~/vimwiki/html'</span><br><span class="line"> let wiki_1.template_path = '~/vimwiki/template/'</span><br><span class="line"> let wiki_1.template_default = 'template1'</span><br><span class="line"> let wiki_1.template_ext = '.html'</span><br><span class="line"> let wiki_1.nested_syntaxes = {'python': 'python', 'c++': 'cpp'}</span><br><span class="line">" let wiki_1.syntax = 'markdown'</span><br><span class="line">" let wiki_1.ext = '.md'</span><br><span class="line"> let g:vimwiki_list = [wiki_1]</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => Grep</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">nnoremap <silent> <F3> :Grep<CR></span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => vim-indent-guides</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">let g:indent_guides_start_level=2</span><br><span class="line">let g:indent_guides_guide_size=1</span><br><span class="line">"nmap <silent> <Leader>ig <Plug>IndentGuidesToggle</span><br><span class="line"></span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">" => vim-powerline</span><br><span class="line">"---------------------------------------------------------------------------</span><br><span class="line">"let g:Powerline_symbols = 'fancy'</span><br><span class="line">set t_Co=256</span><br><span class="line">"let g:Powerline_symbols = 'unicode'</span><br><span class="line"></span><br><span class="line">" vim: set ts=4 sw=4 tw=10000 :</span><br></pre></td></tr></table></figure></p>
]]></content>
<summary type="html">
<p> 系统:windows 7 vim版本:7.4
</summary>
<category term="Vim" scheme="http://huangming.github.io/categories/Vim/"/>
</entry>
<entry>
<title>QQ空间日记迁移声明</title>
<link href="http://huangming.github.io/2012-03-11-qq-kongjian-qianyi.html"/>
<id>http://huangming.github.io/2012-03-11-qq-kongjian-qianyi.html</id>
<published>2012-03-10T16:00:00.000Z</published>
<updated>2012-07-24T14:27:34.000Z</updated>
<content type="html"><![CDATA[<h2>关于起因</h2>
<p>近半个月了,终于将这个博客弄的差不多了。最起码文章的排版格式还有各种高亮已经设定好。因为<a href="http://403169989.qzone.qq.com/" target="_blank" rel="external">QQ空间</a>已经好久没去维护了(qq空间蛋疼的各种不给力)今天突发奇想想把自己以前写的日记弄过来,多少可以回忆下以前的单纯与青涩。<br><a id="more"></a></p>
<h2>关于评论和留言</h2>
<p>经过整理才发现,以前真的是身在福中不知福。有那么多朋友一直关心我,支持我。而我没有好好去经营这份缘分,时间这把杀猪刀终于体现出了它的残忍。不知道现在还能挽回多少呢?不管如何,记录下这些,是我铭记一生的幸福。朋友们的评论都直接记录在文章后面了,等有时间再把<a href="http://403169989.qzone.qq.com/#!app=334&url=http%3A%2F%2Fcnc.qzs.qq.com%2Fqzone%2Fmsgboard%2Fmsgbcanvas.html%23uin%3D403169989%26pfid%3D2%26qz_ver%3D6%26appcanvas%3D0%26qz_style%3Dv6%2F88%26params%3D%26canvastype%3D" target="_blank" rel="external">留言板</a>和<a href="http://403169989.qzone.qq.com/#!app=311&url=http%3A%2F%2Fcnc.qzs.qq.com%2Fqzone%2Fapp%2Fmood_v6%2Fhtml%2Fprofile.html" target="_blank" rel="external">说说</a>里面的内容搬过来。</p>
<h2>关于内容</h2>
<p>迁移日记里面最晚的是2010年8月6日的,大部分都是09年以前的(我的高中时代)。10年8月6日后到现在都没再写日记。即是说10年8月6日以前的文章都是QQ空间迁移过来的。</p>
<h2 id="最后">最后</h2><p>不得不说,高中到大学,特别是高二高三那段时间,我变化真的好大。或许是叫做成长吧。只是这成长也太令人恐惧了。我已经好久好久没像以前一样去逛别人空间博客了,也好久没占朋友口头便宜了。。。现在面临踏入社会,那心思就更加提不起来了。可能也是我性格比较保守吧,现在就继续任性一下了,希望等安稳下来的时候一切有改变吧。<br>感觉自己一直像只笼子里的鸟或者说井底的蛙。虽然有各种枷锁,但都一直小打小闹。嗯,还没找到我自己的生命的意义~~觉得我适合做个和尚,当然是好吃好睡又好色的那种<img src="/images/e120.gif" alt=""></p>
]]></content>
<summary type="html">
<h2>关于起因</h2>
<p>近半个月了,终于将这个博客弄的差不多了。最起码文章的排版格式还有各种高亮已经设定好。因为<a href="http://403169989.qzone.qq.com/">QQ空间</a>已经好久没去维护了(qq空间蛋疼的各种不给力)今天突发奇想想把自己以前写的日记弄过来,多少可以回忆下以前的单纯与青涩。<br>
</summary>
<category term="other" scheme="http://huangming.github.io/categories/other/"/>
</entry>
<entry>
<title>象棋人格</title>
<link href="http://huangming.github.io/2009-04-12-xiangqi-renge.html"/>
<id>http://huangming.github.io/2009-04-12-xiangqi-renge.html</id>
<published>2009-04-11T16:00:00.000Z</published>
<updated>2012-07-25T02:10:55.000Z</updated>
<content type="html"><![CDATA[<p>今天学院举办了一场象棋棋王争霸赛,我报名参赛了。第一轮对手有事没来弃权直接进局。第二轮跟一个人下的时候我一开始就主动进攻,很快就占据主动,死死压住对手。到中局的时候,他开始晃脚做小动作了。我知道他被我压的焦躁起来了(其实,我已经进入一个更严重的状态)。对这个我有经验,离成功不远了呢。我下棋一直是这样,喜欢一开始就主动攻击,占据有力形势。而且,下棋的时候思考很少,利用的是瞬间智慧的闪光,没走一步用的时间嘟是很少的。走完一步就开始悠闲地看对手或者周围的景物。我喜欢那种悠闲地看对手认真思考的感觉。好像真的就一切嘟掌握在我手中,好像对手被我控制牵着鼻子走。就在我吃着棒棒糖看手上的纹路的时候(对手每次嘟思考很久让我等的花儿嘟谢了),对手一招炮打堵头士让我无语。就这样,一步就让我那么好的局势白费了。认输!多么简单的一步棋,甚至初学者嘟可以看出来的一步棋!被我忽略。。<br><a id="more"></a><br>很早以前我就知道自己有这样的毛病,总是在最辉煌最悠闲的时候,摔一个菜鸟嘟不会摔得跤,然后就直接满盘皆输。多年下棋嘟是这样。从概率学的角度看,这已经足够说明一个人的性格对所做事情的影响以及一个人的性格决定了他能有多大成就。其实象棋真的能够反映一个人的人品。从而能间接反映出他的人生路程。 </p>
<p>决定棋手成才的,除了智力因素外,还有非智力因素,其中气质对棋手的成功率影响较大。心理学把人的气质分为胆汁质、多血质、粘液质和抑郁质四种类型,但纯属单一类型的人是极少的,绝大多数人都以某一类型为主又兼其他类型的混合型。 </p>
<p>胆汁质的人精力旺盛、态度直率、激动暴躁,行动敏捷但欠精确,兴奋时热情埋头工作,失望时情绪顿时沮丧。表现在下棋时则勇于进攻,大刀阔斧,敢拼敢杀,喜欢弃子入局,但决策时往往不顾防御,所以在打比赛时,胜局虽多而败局难免,总成绩往往不够理想,成绩起伏较大。棋手中王嘉良和于幼华可以说是这一类的代表(貌似我也是,只是失败的时候我不会顿时沮丧。这也是值得安慰的一个好性格)。 </p>
<p>多血质的人机智灵活,善于交际,很易适应新的环境,工作能力强。但办事重兴趣,不够耐心,注意力不够持久。下棋时应变能力强,战术机动灵活,着法精巧动人,但在互缠局势中缺乏耐心,有时分散精力而出漏着。“十连冠”胡荣华可以说是这一类的代表(我也有这点倾向)。 </p>
<p>粘液质的人处事冷静,自制力较强,工作上专心致志埋头苦干,有恒心有耐力,有条理有规律。但对新鲜事物反应慢而不够灵活,有惰性。下棋时稳健细腻,思维严密,三思而后行,擅长下残棋作持久战。但顾虑较多,冲击力不足,在比赛中输棋较少而和棋较多,虽然也会影响总成绩,但成绩总是较为稳定。许银川是这一类棋手的代表。 </p>
<p>抑郁质的人沉静、含蓄,细心谨慎,但孤僻多愁,优柔寡断。下棋时胆小慎微,缺乏进取精神,对胜负患得患失。 </p>
<p>从象棋运动的特点看,棋手应能承受较长时间紧张比赛的高强度脑力负担,沉着冷静地对待局势的起落,灵活机动地应付棋局的千变万化,巧妙应变各种难题。所以棋手的气质以粘液质、多血质等类型较理想,胆汁质次之,抑郁质则不适合下棋。 </p>
<p>有时候通过下棋从侧面还可以看出一个人的心理近况。心理平静了,下棋考虑的比较远一些;如果心情比较浮躁,考虑将欠佳。 </p>
<p>急躁的人,往往不假思索,便急于出招。稳重的人,往往全盘敲定,步步紧逼显得阵法齐整,从容不度。性格孤傲的人,大都大刀阔斧,奉长驱直入之术。 性格刚毅的人,往往临危不慌,效于迂回挺进之功。暴戾的人,则不讲求战略战术,囿于硬拼死磨,有兑子险进之虞。自信的人,以持久耐战著称,系坚守寡进这策。</p>
<p>我的性格真的不是很好呢。只是要改变一个人真的不容易呢。已经20年了呢。经过这么多年的沉淀,已经根深蒂固了。也许,只有在生死考验下,人才能彻底的改变人格。以前听过好多大难不死然后整个人性格变的完全不一样的例子。所以,我也喜欢看恐怖片。既然现实中找不到或者不敢找机会经历生死考验,那么让恐怖片吓吓也可能改变性格呢~</p>
<p>既然知道不要就要彻底的改变它。我要从每个细节开始,只要在生活中注意没个瞬间,我相信我能改变自己。</p>
<p>讨厌需要长时间的耐力才能看出效果的事,这也是我的性格弱点呢。每次学点什么学了一会儿没什么进步就放弃。很多东西嘟是要经过长时间的积累,就像性格。我相信,我会成功,也许要经过很长很长时间。</p>
<p>但是,值得。 </p>
]]></content>
<summary type="html">
下象棋能反映一个人的人格!通过这次象棋比赛反省自己
</summary>
<category term="diary" scheme="http://huangming.github.io/categories/diary/"/>
</entry>
<entry>
<title>天秤座</title>
<link href="http://huangming.github.io/2009-02-21-tian-cheng-zuo.html"/>
<id>http://huangming.github.io/2009-02-21-tian-cheng-zuo.html</id>
<published>2009-02-20T16:00:00.000Z</published>
<updated>2012-07-25T02:10:32.000Z</updated>
<content type="html"><![CDATA[<p><strong>天平座的爱情</strong> 天平在爱情方面是一个为别人而活的星座。天平的被动更是让很多天平们错过了自己的真爱。天平不懂得拒绝,天平面对一个自己明明不喜欢的人,只要那人能主动积极一点,那天平是不会拒绝的,因为天平觉得拒绝会伤害你。为了不伤害你,天平只有牺牲自己。或者,天平会为你对他哪怕是一句关心的话而感动,就为了感谢你这句关心的话而和你在一起,因为天平永远都是追求平衡的,他认为你付出了哪怕是一句关心的话他就应该回报你,而不是真的因为爱你才和你在一起。(感动不等于爱)而且天平将“责任“二字看得太重,却又未认识到“责任“的真正精髓所在,以至于用了一种对自己极其残酷的方式给“责任“下着定义。天平不爱对方,却要坚持对对方不离不弃。这是一个力求公平的天平的善良抉择,更是一个近乎愚蠢的抉择。这是天平的悲哀。只能说天平懂得负责任,却真的不理解“责任“。可是懂得负责也变成了一种错误吗?天平认为责任比爱情重要,却未想过幸福也同样重要。你完全有理由责备天平,但是在你责备天平的同时可曾想过其实最可悲的正是天平。天平的要求真的不高,只是需要有人理解自己而已。但是,谁又能理解天平呢?<br><a id="more"></a><br>还有一点,天平在爱情方面确实是比较优柔寡断犹豫不决,这点必须承认。但是天平为什么会这样?因为天平想的事很多想的很远,天平觉得如果要爱一个人就要让对方快乐。这里说的“快乐“包括很多,比如说有没有足够的经济能力来维持平时和你在一起时的花销,能不能让你每天都开心,自己的朋友和父母会接受你吗?你的父母朋友能接受自己吗?甚至可能会想到结婚以后你们孩子的模样漂亮吗?。。。。。等等,还有许多问题!你说天平能不犹豫吗?天平是出了名的12个星座最懒的,如果不是因为爱你天平根本懒的考虑那么多!如果天平一旦确定你就是他深爱的人并且确定了你们的恋爱关系以后,那么这时候天平追求完美的一面就展现出来了。</p>
<p>这时的天平满脑子就是想如何做到最好让你觉得自己是世界上最幸福的人。和天平恋爱过的人应该都知道这一点吧,刚和天平恋爱时的感觉简直太完美了,一些只有在电影和小说里面出现的情景会经常出现在你们身上,你会感觉现在的你真的就是世界上最幸福的人。这时的天平只要每天能看到深爱的人开心一笑就算付出在大的代价也愿意!由于刚恋爱时的天平表现的太完美了,以至于对方已经习惯了天平的这种完美表现,这在对方的心理已经是对天平的一种标准,所以天平只要稍稍表现的不够以前好,对方就会不习惯,就会觉得天平不爱她了!可是,这个世界上谁也不可能永远都做的这么好,天平也不能,虽然这时天平依然深爱着对方!对方的抱怨让天平觉得自己很委屈,自己付出了那么多对方却还不满足,还说自己不够好,所以天平就会觉得自己的付出不值得,到最后当然就只剩下分手!</p>
<p>在这里给所有天平朋友一个忠告,细水常流,平平淡淡才是真,不可能每一天都是完美的!烟花确实绚烂,但是注定短暂!这里在特别说一下天平男。天平男花心吗?也许吧。但是所谓天平男的花心又和其他人不同,最原则性的不同在于天平男的花心跟爱情本身不关。所谓天平男的花心应该理解为是一种博爱。天平男认为世界上一切事物都是美好的,而女人更是这个美丽世界中的一个个艺术品。所以女人是要用来好好呵护的,与爱无关!这是天平男一种怜香惜玉的本质。这种本质是天平与生俱来的,是根深蒂固的。天平真正意义上爱一个人时是和那种怜香惜玉的爱是有本质上的区别的。天平真正爱上一个人时,天平在心中会把爱人奉为自己的女神,不仅有爱,更多的是一种尊敬甚至崇拜!反过来说,天平面对自己真正深爱的人时内心会有那么一点小小的自卑。这里的自卑不是平时大家所说的因某种缺陷自卑,这种自卑是相对于“完美“二字来说的。大家也许会怀疑,自信又自恋的天平也会自卑?是的,因为天平面对爱人的时候总希望自己做到完美,但是天平不明白完美只是一种传说一种境界,世界上没有人是完美的,天平也不能,所以这时天平就会产生自卑感。要求完美的天平对自己的不完美很不满意,觉得自己配不上心爱的人,所以很多天平宁愿选择放弃(其实天平在对方心目中天平已经很好了,只是当天平深爱一个人时鲜前昱=羌?。但是放弃不等于不爱。天平对自己深爱的人是一辈子都不会忘的。放弃对天平来说另一种爱,天平会永远把深爱的人深深埋在心里的某个角落默默的为对方祈祷祝福!天平不是因为寂寞才会爱上一个人,天平是因为爱上一个人才寂寞! </p>
<p>天平对于自己内心真正的想法很少对人倾诉,因为天平深知沉默才能坚强。所以,除了天平自己之外没有人能真正了解天平,除非你来生有幸作为一个天平时用生命来体会一次。。。。。。不管是谁对谁错,一切的过错都由天平背负着,任由人们误会,任由人们无端的指责甚至漫骂,天平只是轻描淡写的一笑而过,在人前永远保持着优雅的微笑。一切是命中注定,无需多言,我们即然是天秤,太懂得去分析事情的轻与重,善与恶,真与假了。所以说对于本身也是一种负罪吧。因为都看透了。对于真不真心,懂的人自然了解,不懂的人也不想再多说,因为我们是天秤,骄傲的天平!传说中有位骑士名叫天平,英俊,迷人,优雅,高贵。。。。。。黑夜中,西风吹过; 白马上,骑士仰望星空; 手中有剑,心中有爱,骑士正在为他心爱的人祈祷平安幸福!夜,还是那么黑。路,还有那么远。人,还那么寂寞!拍拍身上的灰尘,振作疲惫的精神,抚平疼痛的伤口,远方也许尽是坎坷路,骑士却仍然微笑着上路了—- 虽然心碎了无痕,依旧白马啸西风!</p>
<p><strong>关于天平的友情和人际关系</strong> “朋友“二字对于天平有多重要是一般人不能理解的。这么说吧,天平把友情看的重要。因为天平是一个特别害怕孤独的星座,天平不会享受孤独。每个天平都有轻微的抑郁症,孤独就是诱发天平抑郁症的罪魁祸首!而抑郁症的最大特点就是厌世,这绝不是危言耸听,孤独就是能让天平产生厌世的感觉。天平是活在人群中的人,只有在人群中天平才能找到自我的位置发挥自我的价值。所以天平总是希望自己的朋友多些在多些。对于自己不喜欢的人,天平虽不愿把他当做朋友但还是希望对方能把自己当成朋友,但凡是天平认识的人天平绝不会轻易得罪。为了维持这种和谐的关系,天平不的不圆滑一点虚伪一点,见人说人话见鬼说鬼话。其实天平真的很累的。绝大多数的时候,天平的朋友受到伤害和委屈了,天平总是第一时间出现在朋友旁边安慰和关心朋友,给朋友以最大的鼓励,但是当天平受伤时却很少得到这样的待遇。换句话说,天平的朋友看上去虽然很多,但是知心朋友却很少,能了解天平内心的更始微乎其微。天平对每个朋友都很好,而且都是一样的好,以至于大家都不知道天平对谁是真心真意对谁是虚情假意。天平一生都致力于创造一个自己心目中理想的和谐的美丽新世界,在那个世界中没有明争暗斗,没有尔虞我诈,大家都是好朋友,所有人都互相关心,互相照顾。总之,天平对朋友是最无私的,宁愿天下人负我,我不负天下人是天平对于与朋友关系的最好的一句话概括。如果你有朋友是天平的话,那么你应该感到幸运!</p>
<h2 id="评论:">评论:</h2><ul>
<li><a href="http://user.qzone.qq.com/710137381" target="_blank" rel="external">难为水</a><time>2009-03-17 21:53:56</time> </li>
<li>奈吾是天平痤…你信不信命的.?..有时真的很难说…</li>
<li><a href="http://user.qzone.qq.com/869308831" target="_blank" rel="external">西西</a><time>2009-05-02 09:01:49</time> </li>
<li>是天平座的?我在想那我是不是应该感到幸运呢?好吧,勉强算是吧!<img src="/images/e120.gif" alt=""></li>
<li><a href="http://user.qzone.qq.com/403169989" target="_blank" rel="external">仙人掌</a>(博主)<time>2009-05-02 23:11:00</time></li>
<li>嗯~很典型的天平。不过也有说天平很虚伪的<del>各有优缺点啦</del>大家嘟很幸运啦 十二分之一得几率嘛~~ 神是很公平哒。</li>
<li><a href="http://user.qzone.qq.com/869308831" target="_blank" rel="external">西西</a><time>2009-05-03 00:13:00</time> </li>
<li>其实我只看了最后几句而已,没研究过这些东西,不懂<img src="/images/e120.gif" alt=""></li>
<li><a href="http://user.qzone.qq.com/260136976" target="_blank" rel="external">‘守望者</a><time>2009-10-22 07:16:10</time> </li>
<li>嗯,我赞同。真有这么傻,这么好。</li>
</ul>
]]></content>
<summary type="html">
关于天秤座的一切,真实的让你无法相信!
</summary>
<category term="diary" scheme="http://huangming.github.io/categories/diary/"/>
</entry>
<entry>
<title>我的十年感言</title>
<link href="http://huangming.github.io/2008-12-01-10-nian-ganyan.html"/>
<id>http://huangming.github.io/2008-12-01-10-nian-ganyan.html</id>
<published>2008-11-30T16:00:00.000Z</published>
<updated>2012-07-22T19:40:49.000Z</updated>
<content type="html"><![CDATA[<p><code>回忆1998年</code><br> 今年我十岁了,终于到了二位数年龄~好感动~~</p>
<p><code>回忆1999年</code><br> 今年11岁,11代表着光棍,孤独的岁月开始~~</p>
<p><code>回忆2000年</code><br> 今年是龙年,属龙的我注定飞黄腾达哈~~骗你的…小学数学竞赛拿奖了呗</p>
<p><code>回忆2001年</code><br> 今年?不知道有什么了,好像开始学会乐观吧~~</p>
<p><code>回忆2002年</code><br> 貌似我入团了呢 ~ 跟一大帮朋友瞎混~ 最开心的是那次野炊了~自己做的饭菜好好吃 ~</p>
<p><code>回忆2003年</code><br> 初二了吧,貌似是,额,貌似没什么。。。想想看。有了,玩封神榜的游戏通关了~~~哈哈,那纣王挺难打的</p>
<p><code>回忆2004年</code><br> 初三了呢,最开心的事是特招考试成功了,不用再去参加中考~~呵呵。。不过快中考的时候出水豆了~555,刚开始没去看医生,结果挺严重的~~~虽然快中考了,同学还是抽空来看我,好感动~</p>
<p><code>回忆2005年</code><br> 今年是高一呢,在城里读书,些许兴奋~~~最开心的是101宿舍里的打打闹闹啦 ~ 遗憾的是拍的同学的几张裸照曝光了,冲洗不了~~~还记得中段或期终后整个宿舍的在网吧通宵~那时候好可爱耶~让人暴汗的是那次随便在班群上找个人来骂,他也跟我斗嘴,结果后来知道是老师来的,瀑布汗~~嘿嘿,还记得一次跟粉仔通宵上网再回来数学竞赛,结果还拿奖了~</p>
<p><code>回忆2006年</code><br> 高二,额。。。开始T毽球~~让人气愤的是技术一直很烂~不是运动的料,不过经常去玩轮滑,觉得还不错~~心情不好就去轮滑~还学会了折很多纸东西~~貌似高二的成绩也一直很好~开始喜欢看书了~~</p>
<p><code>回忆2007年</code><br> 高三,是最郁闷的一年,整天混混沌沌,幻想,还是看小说好~~~放学后很多同学一起跑步,放松自己,还有T毽球,虽然技术不好,老被当同学的笑料,还是感觉蛮开心的~高考没考好,考外省了,决定重读~~</p>
<p><code>回忆2008年</code><br> 考中大了呗~~~来到中大,开阔了眼界啊~自己真的很渺小耶~就拿轮滑来说,走到这里简直就是菜鸟~~他们的技术真的不错~还有很多要学习的~~~很多很多东西都要自己找条件去学习~</p>
<h2 id="评论:">评论:</h2><ul>
<li><a href="http://user.qzone.qq.com/552311925" target="_blank" rel="external">D.E.M</a><time>2008-12-02 20:31:12</time> </li>
<li>呵呵。你的十年经历就被你几句话说完啦?不过你说的有些事我也知道耶。五年级数学竞赛第一名,初三特招考试成功,出水痘,但后来还有来上课。高一数学竞赛得奖。有一次我去一中看到那里贴的通知。高三结束后考了个外省重点,但你把通知书撕啦,去重读。最后考出了对你来说还不错的成绩。进入中大。之后关于你的事,我这个朋友就不知道啦。因为你呀,肯定重学习,重色轻友。害我伤肝伤心伤肺伤脾伤肾呀。 </li>
</ul>
]]></content>
<summary type="html">
我在1998-2008的主要大事记!
</summary>
<category term="diary" scheme="http://huangming.github.io/categories/diary/"/>
</entry>
<entry>
<title>o(∩_∩)o</title>
<link href="http://huangming.github.io/2008-10-03-jintian-tianqi-bucuo.html"/>
<id>http://huangming.github.io/2008-10-03-jintian-tianqi-bucuo.html</id>
<published>2008-10-02T16:00:00.000Z</published>
<updated>2012-07-19T14:47:28.000Z</updated>
<content type="html"><![CDATA[<p>今天天气真的不错~!~~~!!! </p>
]]></content>
<summary type="html">
天气不错
</summary>
<category term="diary" scheme="http://huangming.github.io/categories/diary/"/>
</entry>
<entry>
<title>有个脑筋急转弯的题目,给大家震荡一下大脑</title>
<link href="http://huangming.github.io/2008-09-27-naojing-jizhuanwan.html"/>
<id>http://huangming.github.io/2008-09-27-naojing-jizhuanwan.html</id>
<published>2008-09-26T16:00:00.000Z</published>
<updated>2012-07-19T14:47:28.000Z</updated>
<content type="html"><![CDATA[<p>一天有个年轻人来到王老板的店里买了一件礼物这件礼物成本是18元,标价是21元。结果是这个年轻人掏出100元要买这 件礼物。 王老板当时没有零钱,用那100元向街坊换了100元的零钱,找给年轻人79元。但是街坊後来发现那100元是假钞 ,王老板无奈还了街坊100元。王老板在这次交易中到底损失了多少钱 ?</p>
<h2 id="评论:">评论:</h2><ul>
<li><a href="http://user.qzone.qq.com/415116400" target="_blank" rel="external">柔情♂丘比特</a><time>2008-11-04 21:44:11</time></li>
<li>197</li>
<li><a href="http://user.qzone.qq.com/403169989" target="_blank" rel="external">仙人掌</a>(博主)<time>2008-11-25 00:16:08</time></li>
<li>不知道是你打错还是算错的……太像答案了。。。。 </li>
<li><a href="http://user.qzone.qq.com/415116400" target="_blank" rel="external">柔情♂丘比特</a><time>2009-03-19 15:32:20</time></li>
<li>靠,真实答案到底是多少?</li>
<li><a href="http://user.qzone.qq.com/403169989" target="_blank" rel="external">仙人掌</a>(博主)<time>2009-3-21 00:00:21</time></li>
<li>街坊没损失也没赚,买家赚了79+21的商品=100但是3元是利润来的,所以按照推理店家损失97</li>
<li>或者,算现金,店家进货-18+街坊100-买家79-街坊100=97</li>
</ul>
]]></content>
<summary type="html">
数学计算题
</summary>
<category term="diary" scheme="http://huangming.github.io/categories/diary/"/>
</entry>
</feed>