-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom.xml
819 lines (764 loc) · 61.4 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
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[luopuya's blog]]></title>
<subtitle><![CDATA[Even If You Walk and Walk]]></subtitle>
<link href="/atom.xml" rel="self"/>
<link href="http://luopuya.github.io/"/>
<updated>2015-03-20T10:49:44.000Z</updated>
<id>http://luopuya.github.io/</id>
<author>
<name><![CDATA[luopuya]]></name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title><![CDATA[KMP]]></title>
<link href="http://luopuya.github.io/2015/01/23/KMP/"/>
<id>http://luopuya.github.io/2015/01/23/KMP/</id>
<published>2015-01-23T02:34:16.000Z</published>
<updated>2015-03-20T10:49:44.000Z</updated>
<content type="html"><![CDATA[<p>朴素的字符串查找的复杂度是 O(MN) 的,显然这里有很大的优化空间,KMP 算法 (Knuth-Morris-Pratt) 可优化至 O(M+N)。 </p>
<h1 id="引入_next[]">引入 next[]</h1><p><em>注:本文使用 Python 的 slice,即 [b:e] 为左闭右开</em></p>
<p>假设比较如下字符串(上行为 S,下行为 W) </p>
<p><img src="http://ww2.sinaimg.cn/large/734b90c7jw1eoj9urz6tkj20yp030jrv.jpg" alt="CMP"></p>
<p>当发现 ‘D’ 与 ‘X’ 不符时,并不需要重新比较 ‘BCABX……’ 和 ‘ABCABD……’ ,而是根据 W 本身的性质,紧接着比较 ‘X……’ 和 ‘CABD……’ </p>
<p><strong>可视为在匹配 S 的 ‘X’ 时,比较的字符从 ‘D’(W[5]) “跳至” ‘C’(W[2])</strong><br><strong>之所以可以这样比较,是因 为 W[0:2] == W[3:5] == ‘AB’</strong> </p>
<p>对于 W 中的所有字符,都有这样的允许“跳至”的位置,不妨记录至 next[]数组,例如对于上例的 W,next[5] = 2</p>
<p>参考上文,对于 W,我们这样定义 next[] 数组 </p>
<figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">next</span>[i] = max{j | <span class="constant">W[</span><span class="number">0</span><span class="symbol">:j</span>] == <span class="constant">W[</span>i-<span class="symbol">j:</span>i] <span class="keyword">for</span> -<span class="number">1</span> <= j < i}</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h2 id="next[]_的有效性">next[] 的有效性</h2><ol>
<li>由 j 的 max 性质可保证查找不会遗漏匹配 </li>
<li>查找匹配时,当 W[i] 不符时,跳至 W[next[i]] 继续比较即可 </li>
</ol>
<h2 id="next[]_的推导">next[] 的推导</h2><p>先进行简单考察 </p>
<ol>
<li>显然 next[0] = -1 </li>
<li>当 next[i] = j 时(可知 W[0:j] == W[i-j:i]),考察 next[i+1] <ul>
<li>若 W[i] == W[j]<br> 则有 W[0:j+1] == W[i-j:i+1]<br> 猜想 next[i + 1] = j + 1 </li>
<li>若 W[i] != W[j],记next[j] = k<br> 因为 W[0:k] == W[j-k:j] == W[i-k:i]<br> 猜想问题递归为 j = k 时的小问题</li>
</ul>
</li>
</ol>
<p><img src="http://ww2.sinaimg.cn/large/734b90c7jw1eoj9vtyt9tj20y803hq3d.jpg" alt="KMP"></p>
<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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">solve_next</span><span class="params">(W)</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">_solve_next</span><span class="params">(NEXT, W, i, j, k)</span>:</span></span><br><span class="line"> <span class="comment"># 前提1:W[0:j] == W[i-j:i]</span></span><br><span class="line"> <span class="comment"># 前提2:NEXT[j] = k, 可知 W[0:k] == W[j-k:j]</span></span><br><span class="line"> <span class="comment"># j 不参与运算,仅辅助证明</span></span><br><span class="line"> <span class="keyword">if</span> (k == -<span class="number">1</span>) <span class="keyword">or</span> (W[i] == W[k]):</span><br><span class="line"> <span class="comment"># NEXT[i + 1] >= k + 1</span></span><br><span class="line"> <span class="comment"># 又 NEXT[i + 1] <= k + 1,否则可推出 NEXT[j] > k,矛盾</span></span><br><span class="line"> NEXT[i + <span class="number">1</span>] = k + <span class="number">1</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="comment"># 显然满足前提1、2。(W[0:k] == W[j-k:j] == W[i-k:i])</span></span><br><span class="line"> _solve_next(NEXT, W, i, k, NEXT[k])</span><br><span class="line"></span><br><span class="line"> n = len(W)</span><br><span class="line"> NEXT = [-<span class="number">1</span>] * n</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(n - <span class="number">1</span>):</span><br><span class="line"> _solve_next(NEXT, W, i, i, NEXT[i])</span><br><span class="line"> <span class="keyword">return</span> NEXT</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><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"><span class="function"><span class="keyword">def</span> <span class="title">solve_next</span><span class="params">(W)</span>:</span></span><br><span class="line"> n, i, j = len(W), <span class="number">0</span>, -<span class="number">1</span></span><br><span class="line"> NEXT = [-<span class="number">1</span>] * n</span><br><span class="line"> <span class="keyword">while</span> i < n - <span class="number">1</span>:</span><br><span class="line"> <span class="keyword">if</span> (j == -<span class="number">1</span>) <span class="keyword">or</span> (W[i] == W[j]):</span><br><span class="line"> NEXT[i + <span class="number">1</span>] = j + <span class="number">1</span></span><br><span class="line"> i, j = i + <span class="number">1</span>, j + <span class="number">1</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> j = NEXT[j]</span><br><span class="line"> <span class="keyword">return</span> NEXT</span><br></pre></td></tr></table></figure>
<p>利用 next[] 即可高效查找匹配 </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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">search</span><span class="params">(W, S)</span>:</span></span><br><span class="line"> NEXT = solve_next(W)</span><br><span class="line"> i, j, m, n = <span class="number">0</span>, <span class="number">0</span>, len(W), len(S)</span><br><span class="line"> <span class="keyword">while</span> i < m <span class="keyword">and</span> j < n:</span><br><span class="line"> <span class="keyword">if</span> (i == -<span class="number">1</span>) <span class="keyword">or</span> (W[i] == S[j]):</span><br><span class="line"> i, j = i + <span class="number">1</span>, j + <span class="number">1</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> i = NEXT[i]</span><br><span class="line"> <span class="keyword">return</span> (i == m)</span><br></pre></td></tr></table></figure>
<h2 id="next[]_的小优化">next[] 的小优化</h2><p>对于下图情况,当 W 中后 ‘A’ 不符时,根本无需再匹配前 ‘A’ ,即 next[1] = -1比next[1] = 0 更高效 </p>
<p><img src="http://ww3.sinaimg.cn/large/734b90c7jw1eoj9vzy2cij20q103n3yo.jpg" alt="Advance"></p>
<p>针对这样的情况,我们可以对 next[] 的定义稍稍修改 </p>
<figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">next</span>[i] = max{j | <span class="constant">W[</span><span class="number">0</span><span class="symbol">:j</span>] == <span class="constant">W[</span>i-<span class="symbol">j:</span>i] <span class="keyword">and</span> <span class="constant">W[</span>j] != <span class="constant">W[</span>i] <span class="keyword">for</span> -<span class="number">1</span> <= j < i}</span><br></pre></td></tr></table></figure>
<p>同样可先推导递归形式( max 性质同样可归纳证明,已略去) </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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">solve_next</span><span class="params">(W)</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">_solve_next</span><span class="params">(NEXT, W, i, j)</span>:</span></span><br><span class="line"> <span class="comment"># 前提:W[0:j] == W[i-j:i]</span></span><br><span class="line"> <span class="keyword">if</span> (j == -<span class="number">1</span>) <span class="keyword">or</span> (W[i] == W[j]):</span><br><span class="line"> <span class="keyword">if</span> W[i + <span class="number">1</span>] != W[j + <span class="number">1</span>]: <span class="comment"># 保证 NEXT 的性质</span></span><br><span class="line"> NEXT[i + <span class="number">1</span>] = j + <span class="number">1</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="comment"># ni, nj = i + 1, j + 1 # next_i, next_j, 已知 W[ni] == W[nj]</span></span><br><span class="line"> <span class="comment"># W[0:NEXT[nj]] == W[nj-NEXT[nj]:nj] == W[ni-NEXT[nj]:ni]</span></span><br><span class="line"> <span class="comment"># W[NEXT[nj]] != W[nj], 因此 W[NEXT[nj]] != W[ni]</span></span><br><span class="line"> NEXT[i + <span class="number">1</span>] = NEXT[j + <span class="number">1</span>]</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="comment"># 满足前提。(W[0:NEXT[j]] == W[j-NEXT[j]:j] == W[i-NEXT[j]:i])</span></span><br><span class="line"> _solve_next(NEXT, W, i, NEXT[j])</span><br><span class="line"></span><br><span class="line"> n = len(W)</span><br><span class="line"> NEXT = [-<span class="number">1</span>] * n</span><br><span class="line"> <span class="keyword">for</span> i <span class="keyword">in</span> range(n - <span class="number">1</span>):</span><br><span class="line"> _solve_next(NEXT, W, i, NEXT[i])</span><br><span class="line"> <span class="keyword">return</span> NEXT</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><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"><span class="function"><span class="keyword">def</span> <span class="title">solve_next</span><span class="params">(W)</span>:</span></span><br><span class="line"> n, i, j = len(W), <span class="number">0</span>, -<span class="number">1</span></span><br><span class="line"> NEXT = [-<span class="number">1</span>] * n</span><br><span class="line"> <span class="keyword">while</span> i < n - <span class="number">1</span>:</span><br><span class="line"> <span class="keyword">if</span> (j == -<span class="number">1</span>) <span class="keyword">or</span> (W[i] == W[j]):</span><br><span class="line"> i, j = i + <span class="number">1</span>, j + <span class="number">1</span></span><br><span class="line"> NEXT[i] = j <span class="keyword">if</span> W[i] != W[j] <span class="keyword">else</span> NEXT[j]</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> j = NEXT[j]</span><br><span class="line"> <span class="keyword">return</span> NEXT</span><br></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<![CDATA[<p>朴素的字符串查找的复杂度是 O(MN) 的,显然这里有很大的优化空间,KMP 算法 (Knuth-Morris-Pratt) 可优化至 O(M+N)。 </p>
<h1 id="引入_next[]">引入 next[]</h1><p><em>注:本文使用 Python 的 slice,即 [b:e] 为左闭右开</em></p>
<p>假设比较如下字符串(上行为 S,下行为 W) </p>
<p><img src="http://ww2.sinaimg.cn/large/734b90c7jw1eoj9urz6tkj20yp030jrv.jpg" alt="CMP"></p>
<p>当发现 ‘D’ 与 ‘X’ 不符时,并不需要重新比较 ‘BCABX……’ 和 ‘ABCABD……’ ,而是根据 W 本身的性质,紧接着比较 ‘X……’ 和 ‘CABD……’ </p>
<p><strong>可视为在匹配 S 的 ‘X’ 时,比较的字符从 ‘D’(W[5]) “跳至” ‘C’(W[2])</strong><br><strong>之所以可以这样比较,是因 为 W[0:2] == W[3:5] == ‘AB’</strong> </p>
<p>对于 W 中的所有字符,都有这样的允许“跳至”的位置,不妨记录至 next[]数组,例如对于上例的 W,next[5] = 2</p>
<p>参考上文,对于 W,我们这样定义 next[] 数组 </p>
<figure class="highlight elixir"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">next</span>[i] = max{j | <span class="constant">W[</span><span class="number">0</span><span class="symbol">:j</span>] == <span class="constant">W[</span>i-<span class="symbol">j:</span>i] <span class="keyword">for</span> -<span class="number">1</span> <= j < i}</span><br></pre></td></tr></table></figure>]]>
</summary>
<category term="Algorithm" scheme="http://luopuya.github.io/tags/Algorithm/"/>
<category term="Algorithm" scheme="http://luopuya.github.io/categories/Algorithm/"/>
</entry>
<entry>
<title><![CDATA[Alias for cmd]]></title>
<link href="http://luopuya.github.io/2015/01/09/Alias%20for%20cmd/"/>
<id>http://luopuya.github.io/2015/01/09/Alias for cmd/</id>
<published>2015-01-09T07:05:16.000Z</published>
<updated>2015-03-20T12:07:47.000Z</updated>
<content type="html"><![CDATA[<p>shell 通过修改 .bashrc 可以定制 alias,cmd 则稍稍麻烦一些 </p>
<p>cmd 中用 doskey 定义宏,可以直接定义或读取配置文件:</p>
<figure class="highlight cmd"><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"><span class="built_in">doskey</span> ls=<span class="built_in">dir</span></span><br><span class="line"><span class="built_in">doskey</span> c++<span class="number">11</span>=g++ -std=c++<span class="number">11</span> $* :: $*接收剩余的参数</span><br><span class="line"><span class="built_in">doskey</span> /macrofile=file :: 或者将 ls=<span class="built_in">dir</span> 等记录在 file 文件</span><br></pre></td></tr></table></figure>
<p>剩下的问题在于如何让 cmd 自动执行 doskey 指令 </p>
<p>shell 默认从 .bashrc 中读取设置,而在 cmd 中需要用 AutoRun 专门指定 </p>
<p>假设 C:\alias.doskey 里记录好宏定义,则将下文保存为 reg 文件并运行即可 </p>
<figure class="highlight tex"><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">Windows Registry Editor Version 5.00</span><br><span class="line"></span><br><span class="line"><span class="special">[</span>HKEY_CURRENT_USER<span class="command">\Software</span><span class="command">\Microsoft</span><span class="command">\Command</span> Processor<span class="special">]</span></span><br><span class="line">"AutoRun"="doskey /macrofile=C:<span class="command">\\</span>alias.doskey"</span><br></pre></td></tr></table></figure>
]]></content>
<summary type="html">
<![CDATA[<p>shell 通过修改 .bashrc 可以定制 alias,cmd 则稍稍麻烦一些 </p>
<p>cmd 中用 doskey 定义宏,可以直接定义或读取配置文件:</p>
<figure class="highlight cmd"><table><tr><td clas]]>
</summary>
<category term="alias" scheme="http://luopuya.github.io/tags/alias/"/>
<category term="cmd" scheme="http://luopuya.github.io/tags/cmd/"/>
<category term="Tool" scheme="http://luopuya.github.io/categories/Tool/"/>
</entry>
<entry>
<title><![CDATA[Python Subprocess with .bashrc]]></title>
<link href="http://luopuya.github.io/2014/03/29/Python%20Subprocess%20with%20.bashrc/"/>
<id>http://luopuya.github.io/2014/03/29/Python Subprocess with .bashrc/</id>
<published>2014-03-29T10:17:00.000Z</published>
<updated>2015-03-20T11:02:15.000Z</updated>
<content type="html"><![CDATA[<p>Python 调用 Shell 使用 subprocess 即可</p>
<p><em>(注意: 依照<a href="https://docs.python.org/2.7/library/subprocess.html#module-subprocess" target="_blank" rel="external">官方文档</a>,使用 subprocess 替换 os.system, os.spawn*, os.popen*, popen2.*, commands.*)</em></p>
<p>但直接执行 .bashrc 里的命令并不成功,原因没有显示指出需要读取配置 </p>
<p>bash 中的读取指令为:</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">/bin/bash -i -c</span><br></pre></td></tr></table></figure>
<p>如下为正确处理方式: </p>
<p>例如 .bashrc 里有 alias saverm=rm -i </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></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> subprocess <span class="keyword">as</span> sp</span><br><span class="line">sp.call(<span class="string">"/bin/bash -i -c saverm ./"</span>, shell=<span class="keyword">True</span>)</span><br><span class="line"><span class="comment"># or use Popen</span></span><br><span class="line"><span class="comment"># p = sp.Popen(["/bin/bash", "-i", "-c", "saverm ./"])</span></span><br><span class="line"><span class="comment"># p.communicate()</span></span><br></pre></td></tr></table></figure>
<p>简要说明一下,call 其实是封装了 Popen,是同步的(等待子进程完成),<br>可参考<a href="http://www.cnblogs.com/vamei/archive/2012/09/23/2698014.html" target="_blank" rel="external">Vamei 的博客</a></p>
<p><strong>注意:暴露 shell 是相当危险的,比如在 web 下暴露可能被执行 rm 指令</strong></p>
<p>参考并特别感谢 <a href="http://stackoverflow.com/a/6857271" target="_blank" rel="external">stackoverflow 的解答</a></p>
]]></content>
<summary type="html">
<![CDATA[<p>Python 调用 Shell 使用 subprocess 即可</p>
<p><em>(注意: 依照<a href="https://docs.python.org/2.7/library/subprocess.html#module-subprocess" target]]>
</summary>
<category term=".bashrc" scheme="http://luopuya.github.io/tags/bashrc/"/>
<category term="Python" scheme="http://luopuya.github.io/tags/Python/"/>
<category term="Issue" scheme="http://luopuya.github.io/categories/Issue/"/>
</entry>
<entry>
<title><![CDATA[Linux 压缩中文文件名乱码]]></title>
<link href="http://luopuya.github.io/2014/03/29/Linux%20%E5%8E%8B%E7%BC%A9%E4%B8%AD%E6%96%87%E6%96%87%E4%BB%B6%E5%90%8D%E4%B9%B1%E7%A0%81/"/>
<id>http://luopuya.github.io/2014/03/29/Linux 压缩中文文件名乱码/</id>
<published>2014-03-29T09:07:00.000Z</published>
<updated>2015-03-20T11:02:54.000Z</updated>
<content type="html"><![CDATA[<p>Linux 的 tar 并不保存编码集,有如下解决方式:</p>
<h2 id="使用_7zip_或_rar">使用 7zip 或 rar</h2><p>7zip 安装如无权限,修改 install.sh 里的 DEST_HOME<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">DEST_HOME=~/.local</span><br></pre></td></tr></table></figure></p>
<p><em>注:可参考笔者上篇博文</em></p>
<h2 id="人工/脚本转换文件名">人工/脚本转换文件名</h2><p>文件内容并不会乱码,因而临时人工修改,或用脚本做映射也是权宜之计 </p>
<hr>
<p>参考:<br><a href="http://gm.angeldm.com/post/202" target="_blank" rel="external">观夏 Note</a><br><a href="http://blog.sina.com.cn/s/blog_56a70c040101fxxz.html" target="_blank" rel="external">浆糊的 BLOG</a></p>
]]></content>
<summary type="html">
<![CDATA[<p>Linux 的 tar 并不保存编码集,有如下解决方式:</p>
<h2 id="使用_7zip_或_rar">使用 7zip 或 rar</h2><p>7zip 安装如无权限,修改 install.sh 里的 DEST_HOME<br><figure class="hig]]>
</summary>
<category term="Linux" scheme="http://luopuya.github.io/tags/Linux/"/>
<category term="编码" scheme="http://luopuya.github.io/tags/%E7%BC%96%E7%A0%81/"/>
<category term="Issue" scheme="http://luopuya.github.io/categories/Issue/"/>
</entry>
<entry>
<title><![CDATA[Linux 无权限安装软件]]></title>
<link href="http://luopuya.github.io/2014/03/29/Linux%20%E6%97%A0%E6%9D%83%E9%99%90%E5%AE%89%E8%A3%85%E8%BD%AF%E4%BB%B6/"/>
<id>http://luopuya.github.io/2014/03/29/Linux 无权限安装软件/</id>
<published>2014-03-29T09:04:00.000Z</published>
<updated>2015-03-20T11:04:28.000Z</updated>
<content type="html"><![CDATA[<p>Linux 软件常常默认安装在 /usr/bin 之类的目录下,没有权限的话需要指定安装路径 </p>
<p>通常有以下三种途径:</p>
<h2 id="配置时指定">配置时指定</h2><p>最常见,如 nginx<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">./configure --prefix=~/.local</span><br></pre></td></tr></table></figure></p>
<p><em>注: ./configure 其实是 shell 脚本,根据环境生成 Makefile 或其他</em></p>
<h2 id="安装时指定">安装时指定</h2><p>如 Python 的包<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">python setup.py --prefix=~/.local</span><br></pre></td></tr></table></figure></p>
<h2 id="修改安装的_shell_脚本">修改安装的 shell 脚本</h2><p>如 7zip ,修改 install.sh<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">DEST_HOME=~/.local</span><br></pre></td></tr></table></figure></p>
]]></content>
<summary type="html">
<![CDATA[<p>Linux 软件常常默认安装在 /usr/bin 之类的目录下,没有权限的话需要指定安装路径 </p>
<p>通常有以下三种途径:</p>
<h2 id="配置时指定">配置时指定</h2><p>最常见,如 nginx<br><figure class="highlight]]>
</summary>
<category term="Linux" scheme="http://luopuya.github.io/tags/Linux/"/>
<category term="Issue" scheme="http://luopuya.github.io/categories/Issue/"/>
</entry>
<entry>
<title><![CDATA[Python 判断汉字]]></title>
<link href="http://luopuya.github.io/2014/03/29/Python%20%E5%88%A4%E6%96%AD%E6%B1%89%E5%AD%97%E5%AD%97%E7%AC%A6/"/>
<id>http://luopuya.github.io/2014/03/29/Python 判断汉字字符/</id>
<published>2014-03-29T06:24:00.000Z</published>
<updated>2015-03-20T10:31:20.000Z</updated>
<content type="html"><![CDATA[<p>使用 unicode 范围 <strong>\u4e00 - \u9fff</strong> 来判别汉字</p>
<p><em>unicode 分配给汉字(中日韩越统一表意文字)的范围为 <strong>4E00-9FFF</strong> </em><br><em>(目前 unicode 6.3 的标准已定义到 9FCC )</em></p>
<p>在 Python 3 中,判断字符是否汉字的方法如下:</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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">ishan</span><span class="params">(text)</span>:</span></span><br><span class="line"> <span class="comment"># for python 3.x</span></span><br><span class="line"> <span class="comment"># sample: ishan('一') == True, ishan('我&&你') == False</span></span><br><span class="line"> <span class="keyword">return</span> all(<span class="string">'\u4e00'</span> <= char <= <span class="string">'\u9fff'</span> <span class="keyword">for</span> char <span class="keyword">in</span> text)</span><br></pre></td></tr></table></figure>
<p>而在 Python 2 中则为:</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></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">ishan</span><span class="params">(text)</span>:</span></span><br><span class="line"> <span class="comment"># for python 2.x, 3.3+</span></span><br><span class="line"> <span class="comment"># sample: ishan(u'一') == True, ishan(u'我&&你') == False</span></span><br><span class="line"> <span class="keyword">return</span> all(<span class="string">u'\u4e00'</span> <= char <= <span class="string">u'\u9fff'</span> <span class="keyword">for</span> char <span class="keyword">in</span> text)</span><br></pre></td></tr></table></figure>
<p><strong>补充说明</strong> </p>
<ol>
<li>Python 3.3+ 重新支持 Python 2 中用 u 表示 unicode 的方式 </li>
<li>\u4e00-\u9fff 不包含中文符号,如有需要可参考<a href="http://goo.gl/hyUcT7" target="_blank" rel="external">维基</a> </li>
<li>网上常见的 \u4e00-\u9fa5 写太死了,虽说目前而言后面的都是极其罕见的字 </li>
</ol>
<hr>
<p>参考:<a href="http://www.unicode.org/charts/PDF/U4E00.pdf" target="_blank" rel="external">http://www.unicode.org/charts/PDF/U4E00.pdf</a></p>
]]></content>
<summary type="html">
<![CDATA[<p>使用 unicode 范围 <strong>\u4e00 - \u9fff</strong> 来判别汉字</p>
<p><em>unicode 分配给汉字(中日韩越统一表意文字)的范围为 <strong>4E00-9FFF</strong> </em><br><em>(目前]]>
</summary>
<category term="Python" scheme="http://luopuya.github.io/tags/Python/"/>
<category term="编码" scheme="http://luopuya.github.io/tags/%E7%BC%96%E7%A0%81/"/>
<category term="Issue" scheme="http://luopuya.github.io/categories/Issue/"/>
</entry>
<entry>
<title><![CDATA[Sublime Text 3 常用快捷键]]></title>
<link href="http://luopuya.github.io/2014/03/26/Sublime%20Text%203%20%E5%B8%B8%E7%94%A8%E5%BF%AB%E6%8D%B7%E9%94%AE/"/>
<id>http://luopuya.github.io/2014/03/26/Sublime Text 3 常用快捷键/</id>
<published>2014-03-26T12:09:16.000Z</published>
<updated>2015-03-20T11:25:46.000Z</updated>
<content type="html"><![CDATA[<p>Sublime Text 3 强大的不只有插件,自带快捷键亦可圈可点,下文介绍常用快捷键 </p>
<h2 id="摘要">摘要</h2><p>Sublime Text 3 快捷键关键点: </p>
<ol>
<li>多区域编辑与行编辑的能力 </li>
<li>Go To 与 Ctrl + Shift + P </li>
<li>快捷键的管理机制 </li>
<li>功能全面:宏、折叠、多界面等 </li>
<li>可以使用历史记录的复制 </li>
</ol>
<a id="more"></a>
<p>Sublime Text 的系统自带快捷键在 Key Bindings - Default 里,<br>优先级别低于 Key Bindings - User,<br>(优先级最高的则是插件的快捷键)<br>所有的设置均在 *.sublime-keymap 文件中 </p>
<p>此外,注意 Sublime Text 光标在快捷键下可能表示<br><strong>当前位置</strong>、<strong>当前词</strong>、<strong>当前行</strong> </p>
<p><em>注:’`’表示笔者根据 eclipse 定制的,’/‘表示或者,’,’表示叠加,’()’表示有或无</em> </p>
<h2 id="Edit">Edit</h2><h3 id="基本编辑:">基本编辑:</h3><table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> Undo/Redo</td>
<td style="text-align:left">Ctrl + Z/Y </td>
</tr>
<tr>
<td style="text-align:left"> 软撤销</td>
<td style="text-align:left">Ctrl + U </td>
</tr>
<tr>
<td style="text-align:left"> Copy/Paste</td>
<td style="text-align:left">Ctrl + C/V </td>
</tr>
<tr>
<td style="text-align:left"> 选择过往复制</td>
<td style="text-align:left">Ctrl + K, Ctrl + V </td>
</tr>
<tr>
<td style="text-align:left"> 插入新上/下行并跳转</td>
<td style="text-align:left">Ctrl (+ Shift) + Enter </td>
</tr>
<tr>
<td style="text-align:left"> 删除前/后词</td>
<td style="text-align:left">Ctrl + Backspace/Delete </td>
</tr>
<tr>
<td style="text-align:left"> 删除至行首/尾</td>
<td style="text-align:left">Ctrl+ K, Ctrl + Backspace/K </td>
</tr>
<tr>
<td style="text-align:left"> 跳转至前/后词</td>
<td style="text-align:left">Ctrl/Alt + ←/→ </td>
</tr>
<tr>
<td style="text-align:left"> 补全</td>
<td style="text-align:left">Tab </td>
</tr>
<tr>
<td style="text-align:left"> 提示补全</td>
<td style="text-align:left">`Alt+/ </td>
</tr>
<tr>
<td style="text-align:left"> 删除Tab指定宽度</td>
<td style="text-align:left">Shift + Tab </td>
</tr>
<tr>
<td style="text-align:left"> 转换大/小写</td>
<td style="text-align:left">`Ctrl + Shift + X/Y </td>
</tr>
</tbody>
</table>
<h3 id="(多)行/块编辑:">(多)行/块编辑:</h3><p><em>注:这些快捷键把光标理解为当前行;此处的块指选定文本,非语句块</em> </p>
<table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> (去)行/块注释</td>
<td style="text-align:left">Ctrl + / </td>
</tr>
<tr>
<td style="text-align:left"> 选择行</td>
<td style="text-align:left">Ctrl + L </td>
</tr>
<tr>
<td style="text-align:left"> 删除行/块</td>
<td style="text-align:left">Ctrl + X </td>
</tr>
<tr>
<td style="text-align:left"> 向上/下交换行</td>
<td style="text-align:left">`Alt + ↑/↓ </td>
</tr>
<tr>
<td style="text-align:left"> 复制行</td>
<td style="text-align:left">Ctrl + Shift + D </td>
</tr>
<tr>
<td style="text-align:left"> 合并下行</td>
<td style="text-align:left">Ctrl + J </td>
</tr>
<tr>
<td style="text-align:left"> (去)缩进</td>
<td style="text-align:left">Ctrl + [/] </td>
</tr>
</tbody>
</table>
<p><em>注:Ctrl + X 和 Shift + Delete 在删除的同时复制到剪贴板</em> </p>
<h3 id="代码折叠:">代码折叠:</h3><table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> 折叠到1/2…级</td>
<td style="text-align:left">Ctrl + K, Ctrl + 1/2… </td>
</tr>
<tr>
<td style="text-align:left"> 展开全部</td>
<td style="text-align:left">Ctrl + K, Ctrl + J </td>
</tr>
<tr>
<td style="text-align:left"> 折叠/展开</td>
<td style="text-align:left">Ctrl + Shift + [/] </td>
</tr>
</tbody>
</table>
<h3 id="书签:">书签:</h3><table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> (取消)添加书签</td>
<td style="text-align:left">Ctrl + F2 </td>
</tr>
<tr>
<td style="text-align:left"> 上/下一处书签</td>
<td style="text-align:left">(Shift +) F2 </td>
</tr>
<tr>
<td style="text-align:left"> 删除所有书签</td>
<td style="text-align:left">Ctrl + Shift + F2 </td>
</tr>
</tbody>
</table>
<h2 id="Selection">Selection</h2><table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> 无限制多处选择</td>
<td style="text-align:left">Ctrl + 左键 </td>
</tr>
<tr>
<td style="text-align:left"> 同时选择上/下行同一位置</td>
<td style="text-align:left">Ctrl + Alt + ↑/↓ </td>
</tr>
<tr>
<td style="text-align:left"> 同时选择多行同一位置</td>
<td style="text-align:left">Shift + 右键 </td>
</tr>
<tr>
<td style="text-align:left"> 选择下个相同词</td>
<td style="text-align:left">Ctrl + D </td>
</tr>
<tr>
<td style="text-align:left"> 跳过当前,选择下个相同词</td>
<td style="text-align:left">Ctrl + K, Ctrl + D </td>
</tr>
<tr>
<td style="text-align:left"> 选择所有相同词</td>
<td style="text-align:left">Ctrl + F, Alt + Enter </td>
</tr>
<tr>
<td style="text-align:left"> 选择至前/后词</td>
<td style="text-align:left">Ctrl/Alt (+ Shift) + ←/→ </td>
</tr>
<tr>
<td style="text-align:left"> 选择括号内</td>
<td style="text-align:left">Ctrl + Shift + M </td>
</tr>
<tr>
<td style="text-align:left"> 选择至同一缩进</td>
<td style="text-align:left">Ctrl + Shift + J </td>
</tr>
</tbody>
</table>
<p><em>注:选中(多处)文本时:输入符号可补全头尾处;Ctrl + Shift + L 可选择多处/行末尾</em> </p>
<hr>
<h2 id="Find">Find</h2><table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> (反向)查找</td>
<td style="text-align:left">(Shift +) F3 </td>
</tr>
<tr>
<td style="text-align:left"> (所有文件)查找</td>
<td style="text-align:left">Ctrl (+ Shift) + F </td>
</tr>
<tr>
<td style="text-align:left"> 替换</td>
<td style="text-align:left">Ctrl + H </td>
</tr>
</tbody>
</table>
<hr>
<h2 id="View">View</h2><table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> 全屏</td>
<td style="text-align:left">F11 </td>
</tr>
<tr>
<td style="text-align:left"> 勿打扰模式</td>
<td style="text-align:left">Shift + F11 </td>
</tr>
<tr>
<td style="text-align:left"> 多列分屏</td>
<td style="text-align:left">Shift + Alt + 1/2/3/4 </td>
</tr>
<tr>
<td style="text-align:left"> 选择标签页</td>
<td style="text-align:left">Alt + 1/2… </td>
</tr>
</tbody>
</table>
<hr>
<h2 id="Go_To">Go To</h2><table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> Go To 文件</td>
<td style="text-align:left">Ctrl + P </td>
</tr>
<tr>
<td style="text-align:left"> Go To 行号</td>
<td style="text-align:left">Ctrl + G </td>
</tr>
<tr>
<td style="text-align:left"> Go To (所有文件)符号</td>
<td style="text-align:left">Ctrl (+ Shift) + R </td>
</tr>
<tr>
<td style="text-align:left"> Go To 对应括号</td>
<td style="text-align:left">Ctrl + M </td>
</tr>
</tbody>
</table>
<hr>
<h2 id="Tools">Tools</h2><table>
<thead>
<tr>
<th style="text-align:left">Commands</th>
<th style="text-align:left">Keys </th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"> 命令行</td>
<td style="text-align:left">Ctrl + Shift + P </td>
</tr>
<tr>
<td style="text-align:left"> 编译/运行</td>
<td style="text-align:left">Ctrl (+ Shift) + B </td>
</tr>
<tr>
<td style="text-align:left"> (停止)录制宏</td>
<td style="text-align:left">Ctrl + Q </td>
</tr>
<tr>
<td style="text-align:left"> 运行宏</td>
<td style="text-align:left">Ctrl + Shift + Q </td>
</tr>
</tbody>
</table>
<hr>
<h2 id="File,_Project,_Preference,_Help">File, Project, Preference, Help</h2><p>File 里的快捷键基本都是通用的,<br>如 Ctrl + O, Ctrl + W, Ctrl + N, Ctrl + Shift + T…,略去<br>其他三者里的快捷键不大常用,也不大通用,亦略去 </p>
<hr>
<h2 id="结语">结语</h2><p>上文提及的笔者定制的快捷键(参考 eclispe ) </p>
<pre><code>[
{ "<span class="attribute">keys</span>": <span class="value">[<span class="string">"alt+up"</span>]</span>, "<span class="attribute">command</span>": <span class="value"><span class="string">"swap_line_up"</span> </span>},
{ "<span class="attribute">keys</span>": <span class="value">[<span class="string">"alt+down"</span>]</span>, "<span class="attribute">command</span>": <span class="value"><span class="string">"swap_line_down"</span> </span>},
{ "<span class="attribute">keys</span>": <span class="value">[<span class="string">"shift+ctrl+y"</span>]</span>, "<span class="attribute">command</span>": <span class="value"><span class="string">"lower_case"</span> </span>},
{ "<span class="attribute">keys</span>": <span class="value">[<span class="string">"shift+ctrl+x"</span>]</span>, "<span class="attribute">command</span>": <span class="value"><span class="string">"upper_case"</span> </span>},
{ "<span class="attribute">keys</span>": <span class="value">[<span class="string">"alt+/"</span>]</span>, "<span class="attribute">command</span>": <span class="value"><span class="string">"auto_complete"</span> </span>},
{ "<span class="attribute">keys</span>": <span class="value">[<span class="string">"alt+/"</span>]</span>, "<span class="attribute">command</span>": <span class="value"><span class="string">"replace_completion_with_auto_complete"</span></span>, "<span class="attribute">context</span>":
<span class="value">[
{ "<span class="attribute">key</span>": <span class="value"><span class="string">"last_command"</span></span>, "<span class="attribute">operator</span>": <span class="value"><span class="string">"equal"</span></span>, "<span class="attribute">operand</span>": <span class="value"><span class="string">"insert_best_completion"</span> </span>},
{ "<span class="attribute">key</span>": <span class="value"><span class="string">"auto_complete_visible"</span></span>, "<span class="attribute">operator</span>": <span class="value"><span class="string">"equal"</span></span>, "<span class="attribute">operand</span>": <span class="value"><span class="literal">false</span> </span>},
{ "<span class="attribute">key</span>": <span class="value"><span class="string">"setting.tab_completion"</span></span>, "<span class="attribute">operator</span>": <span class="value"><span class="string">"equal"</span></span>, "<span class="attribute">operand</span>": <span class="value"><span class="literal">true</span> </span>}
]
</span>}
]
</code></pre><hr>
<p>参考和感谢:<br>Nicholas 和 Chris 在 <a href="http://scotch.io/" target="_blank" rel="external">scotch</a> 上的教程<br><a href="http://scotch.io/bar-talk/the-complete-visual-guide-to-sublime-text-3-getting-started-and-keyboard-shortcuts?utm_source=feedblitz&utm_medium=FeedBlitzRss&utm_campaign=scotch_io" target="_blank" rel="external">Nicholas</a><br><a href="http://scotch.io/bar-talk/sublime-text-keyboard-shortcuts" target="_blank" rel="external">Chris</a> </p>
]]></content>
<summary type="html">
<![CDATA[<p>Sublime Text 3 强大的不只有插件,自带快捷键亦可圈可点,下文介绍常用快捷键 </p>
<h2 id="摘要">摘要</h2><p>Sublime Text 3 快捷键关键点: </p>
<ol>
<li>多区域编辑与行编辑的能力 </li>
<li>Go To 与 Ctrl + Shift + P </li>
<li>快捷键的管理机制 </li>
<li>功能全面:宏、折叠、多界面等 </li>
<li>可以使用历史记录的复制 </li>
</ol>]]>
</summary>
<category term="Sublime Text" scheme="http://luopuya.github.io/tags/Sublime-Text/"/>
<category term="Tool" scheme="http://luopuya.github.io/categories/Tool/"/>
</entry>
<entry>
<title><![CDATA[Sublime Text as Python IDE]]></title>
<link href="http://luopuya.github.io/2014/03/21/Sublime%20Text%20as%20python%20ide/"/>
<id>http://luopuya.github.io/2014/03/21/Sublime Text as python ide/</id>
<published>2014-03-21T09:19:00.000Z</published>
<updated>2015-03-20T11:23:48.000Z</updated>
<content type="html"><![CDATA[<p>Sublime Text 是非常实用的编辑器,其中插件配置至关重要,<br>以下针对 Python 开发者推荐插件 </p>
<p>核心插件为: </p>
<ul>
<li>Anaconda </li>
<li>Git </li>
<li>Markdown Preview, MarkdownEditing </li>
</ul>
<a id="more"></a>
<h2 id="package_control">package control</h2><p><a href="https://sublime.wbond.net/installation" target="_blank" rel="external">Package Control</a> 管理插件包,下载卸载更新禁用启用一条龙服务<br>当然将插件放置包文件夹亦可安装</p>
<h2 id="colour_theme">colour theme</h2><p><a href="https://github.com/thinkpixellab/flatland" target="_blank" rel="external">Flatland</a>,基于<a href="https://github.com/buymeasoda/soda-theme" target="_blank" rel="external">Soda</a>开发<br><img src="http://ww2.sinaimg.cn/large/734b90c7jw1eewpmxikwlj21kw11x46p.jpg" alt="Flatland screenshot"></p>
<h2 id="sidebar">sidebar</h2><p><a href="https://github.com/titoBouzout/SideBarEnhancements" target="_blank" rel="external">SideBar Enhancements</a> 增强侧边栏项目树的功能:Open with(可定制)、重命名等、Copy as Text……<br><img src="http://ww4.sinaimg.cn/large/734b90c7jw1eewpmg6catj20ep0e8mz3.jpg" alt="Sidebar Enhancements overview"></p>
<h2 id="git">git</h2><p><a href="https://github.com/kemayo/sublime-text-git" target="_blank" rel="external">Git</a> 即可<br><a href="https://sublime.wbond.net/packages/GitGutter" target="_blank" rel="external">GitGutter</a> 比较前后版本差别<br><a href="https://sublime.wbond.net/packages/Gist" target="_blank" rel="external">Gist</a> 使用 Git 的代码高亮片段 </p>
<h2 id="ftp">ftp</h2><p><a href="http://wbond.net/sublime_packages/sftp" target="_blank" rel="external">SFTP</a>,但免费版实在没有 Notepad++ 的 NppFTP 好用</p>
<h2 id="python_ide">python ide</h2><p>Sublime Text 3 下最佳的 Python 插件当为 <a href="https://github.com/DamnWidget/anaconda" target="_blank" rel="external">Anaconda</a></p>
<p>Anaconda 是完整的 python 开发环境,功能包括:autocompletion, code linting, IDE features, autopep8 formating, McCabe complexity checker and Vagrant,高效而全能<br><em>(使用了 Jedi, PyFlakes, pep8, PyLint, pep257 and McCabe )</em></p>
<p>针对安装多版本 Python 的用户,亦可为工程定制 Python 路径和包路径 </p>
<p>如果是 Sublime Text 2,需要分别安装上文提及的<a href="https://github.com/srusskih/SublimeJEDI" target="_blank" rel="external">Jedi</a>, <a href="https://github.com/dreadatour/Flake8Lint" target="_blank" rel="external">Flake8</a>, <a href="https://github.com/dreadatour/Pep8Lint" target="_blank" rel="external">Pep8</a> </p>
<p>如需调试(<strong>pdb</strong>)或交互式测试(<strong>python -i</strong>),可使用<a href="https://github.com/wuub/SublimeREPL" target="_blank" rel="external">SublimeREPL</a><br>交互式测试通过定制快捷键实现,参考自<a href="http://stackoverflow.com/a/14080562" target="_blank" rel="external">Stackoverflow</a> </p>
<p>添加至 user keybindings</p>
<figure class="highlight json"><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></pre></td><td class="code"><pre><span class="line">[</span><br><span class="line"> {</span><br><span class="line"> "<span class="attribute">keys</span>": <span class="value">[<span class="string">"super+shift+r"</span>]</span>,</span><br><span class="line"> "<span class="attribute">caption</span>": <span class="value"><span class="string">"Python"</span></span>,</span><br><span class="line"> "<span class="attribute">command</span>": <span class="value"><span class="string">"repl_open"</span></span>, </span><br><span class="line"> "<span class="attribute">mnemonic</span>": <span class="value"><span class="string">"p"</span></span>,</span><br><span class="line"> "<span class="attribute">args</span>": <span class="value">{</span><br><span class="line"> "<span class="attribute">type</span>": <span class="value"><span class="string">"subprocess"</span></span>,</span><br><span class="line"> "<span class="attribute">encoding</span>": <span class="value"><span class="string">"utf8"</span></span>,</span><br><span class="line"> "<span class="attribute">cmd</span>": <span class="value">[<span class="string">"python"</span>, <span class="string">"-i"</span>, <span class="string">"-u"</span>, <span class="string">"$file"</span>]</span>,</span><br><span class="line"> "<span class="attribute">cwd</span>": <span class="value"><span class="string">"$file_path"</span></span>,</span><br><span class="line"> "<span class="attribute">syntax</span>": <span class="value"><span class="string">"Packages/Python/Python.tmLanguage"</span></span>,</span><br><span class="line"> "<span class="attribute">external_id</span>": <span class="value"><span class="string">"python"</span></span><br><span class="line"> </span>} </span><br><span class="line"> </span>}</span><br><span class="line">]</span><br></pre></td></tr></table></figure>
<p>但交互式下就没有补全功能了(相当于 Notepad++ 用 NppExec 或 PyNpp 的能力),这方面不如 IDLE 和 Ipython 。(命令行应该能改成类似的 <em>ipython -i</em> ,但暂时未研究)</p>
<p>另外仅以 Pyhton 而言,Jedi 的补全效果比 <a href="https://github.com/SublimeCodeIntel/SublimeCodeIntel" target="_blank" rel="external">SublimeCodeIntel</a> 略好,且简易性完爆之<br><img src="http://ww1.sinaimg.cn/large/734b90c7jw1eewpn9wh73g20ee03naa0.gif" alt="SublimeJEDI overview"><br><img src="http://ww1.sinaimg.cn/large/734b90c7jw1eewpnjx6umg20ee04wq2x.gif" alt="SublimeJEDI overview2"></p>
<h2 id="markdown">markdown</h2><p><a href="https://github.com/revolunet/sublimetext-markdown-preview" target="_blank" rel="external">Markdown Preview</a>,编译、预览</p>
<p><a href="https://github.com/SublimeText-Markdown/MarkdownEditing" target="_blank" rel="external">MarkdownEditing</a>,快捷键、高亮增强<br><img src="http://ww2.sinaimg.cn/large/734b90c7jw1eewpntu5hkj20k90kiwgf.jpg" alt="MarkdownEditing overview"></p>
<h2 id="todolist">todolist</h2><p><a href="https://github.com/poritsky/PlainTasksOF" target="_blank" rel="external">PlainTasks OF</a>,OmniFocus 风格的<a href="https://github.com/aziz/PlainTasks" target="_blank" rel="external">PlainTasks</a><br>功能包括:任务 + 归档,链接文件并定位<br><img src="http://ww3.sinaimg.cn/large/734b90c7jw1eewpo4wxnjj20js0itwhc.jpg" alt="PlainTasks OF overview"> </p>
<h2 id="小结">小结</h2><p>总的来说 ST3 与 ST2 相比,差别不大 </p>
<p>优点有: </p>
<ul>
<li>用户安装的包分开,便于查看管理 </li>
<li>开启速度快 </li>
</ul>
<p>不足有: </p>
<ul>
<li>默认包已压缩,修改麻烦,但可通过禁止默认语言包,选择部分安装增强版<a href="https://www.google.com.hk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCgQFjAA&url=%68%74%74%70%73%3a%2f%2f%67%69%74%68%75%62%2e%63%6f%6d%2f%66%61%63%65%6c%65%73%73%75%73%65%72%2f%73%75%62%6c%69%6d%65%2d%6c%61%6e%67%75%61%67%65%73&ei=EVYsU6WWK4PCkwWCpoH4BA&usg=AFQjCNHIuoi_n3FABhR-2mCU4r00XjWYBw" target="_blank" rel="external">Sublime Languages</a> </li>
</ul>
<p>推荐 ST3 吧,毕竟这些插件迁移不难,好东西多半还是会迁到 ST3 的吧</p>
<hr>
<p>参考并特别感谢: </p>
<ul>
<li>所有开发者 </li>
<li><a href="http://lucifr.com/tags/sublime-text/" target="_blank" rel="external">Lufir 关于 Sublime Text 的博客</a> </li>
<li><a href="http://screamingatmyscreen.com/2013/9/sublime-text-as-python-ide-jedi/" target="_blank" rel="external">Timo 的 SublimeJEDI 效果图</a></li>
</ul>
]]></content>
<summary type="html">
<![CDATA[<p>Sublime Text 是非常实用的编辑器,其中插件配置至关重要,<br>以下针对 Python 开发者推荐插件 </p>
<p>核心插件为: </p>
<ul>
<li>Anaconda </li>
<li>Git </li>
<li>Markdown Preview, MarkdownEditing </li>
</ul>]]>
</summary>
<category term="Sublime Text" scheme="http://luopuya.github.io/tags/Sublime-Text/"/>
<category term="Tool" scheme="http://luopuya.github.io/categories/Tool/"/>
</entry>
<entry>
<title><![CDATA[改造 cmd 成 shell]]></title>
<link href="http://luopuya.github.io/2014/03/21/%E6%94%B9%E9%80%A0%20cmd%20%E6%88%90%20shell/"/>
<id>http://luopuya.github.io/2014/03/21/改造 cmd 成 shell/</id>
<published>2014-03-21T06:35:00.000Z</published>
<updated>2015-03-20T11:16:57.000Z</updated>
<content type="html"><![CDATA[<p>Windows 下的 cmd 不太好用,以下将其增强部分 *nix 的 shell 功能</p>
<h2 id="摘要">摘要</h2><p>将 cmd 改造成 shell,关键点: </p>
<ul>
<li>Gow</li>
<li>Clink </li>
</ul>
<a id="more"></a>
<h2 id="Gow">Gow</h2><p><a href="https://github.com/bmatzelle/gow" target="_blank" rel="external">Gow</a> 是 Cygwin 的轻量级替代品,封装了 130 多个开源工具和 *nix 命令(编译成 exe ),常用的有: </p>
<ul>
<li>Shell : bash , zsh</li>
<li>压缩工具: gzip, zip, bzip2, compress</li>
<li>SSH: <strong>putty</strong>, psftp, pscp, pageant, plink</li>
<li>下载工具 : <strong>curl</strong>, wget</li>
<li>FTP: NcFTP</li>
<li>编辑器 :vim</li>
<li>字处理 : <strong>grep</strong>, agrep, less, <strong>cat</strong>, <strong>tail</strong>, <strong>head</strong></li>
<li>文件工具: mv, cp, du, ls, pwd, rmdir, whereis</li>
<li>开发工具: make, <strong>diff</strong>, diff3, sleep, cvs, dos2unix, unix2dos</li>
</ul>
<p>(上述列表来自<a href="http://www.oschina.net/question/12_10312" target="_blank" rel="external">oschina 的 Gow 说明</a>)<br>下载并安装即可,环境变量会自动设置,并且可往/bin添加新的exe </p>
<h2 id="Clink">Clink</h2><p><a href="http://mridgers.github.io/clink/" target="_blank" rel="external">Clink</a> 是 cmd 增强工具,功能强大: </p>
<h3 id="Tab补全">Tab补全</h3><ul>
<li>路径补全 </li>
<li>PATH 下的可执行文件 </li>
<li>环境变量 </li>
</ul>
<p>更关键的是补全形式为显示列表,而非 cmd 和 PowerShell 里的逐个蹦<br><img src="http://ww3.sinaimg.cn/large/734b90c7jw1eewphsj8l0j20ee053dgd.jpg" alt="列表补全效果示意图"> </p>
<h3 id="GNU_readline">GNU readline</h3><p><a href="http://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html" target="_blank" rel="external">GNU readline</a> 让 cmd 拥有 bash 的编辑和定制的能力: </p>
<ul>
<li>Ctrl-R, Ctrl-S (逆序)搜索历史命令</li>
<li>Ctrl-A, Ctrl-S 到行首/尾</li>
<li>Ctrl-U, Ctrl-K 删除到行首/尾</li>
<li>Ctrl-L 清屏</li>
<li>……</li>
</ul>
<h3 id="其他">其他</h3><ul>
<li>跨会话(Sessions)的保存 </li>
<li>更多快捷键<ul>
<li>Ctrl-V 复制 </li>
<li>Ctrl-Z 撤销 /Undo </li>
<li>(Alt-H 查看更多快捷键……)</li>
</ul>
</li>
<li>…… </li>
</ul>
<p>设置 cmd 的 autorun 仅需:<br><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">clink autorun -i</span><br></pre></td></tr></table></figure></p>
<h2 id="已知Bug">已知Bug</h2><ul>
<li>*nix 下 ls 默认 ascii 编码,而 Windows 文件名编码为 GBK(cp936),固 ls 时中文不显示,建议可补充使用 dir </li>
</ul>
<h2 id="小结">小结</h2><p>使用 Gow 和 Clink ,使得 cmd 最薄弱的命令、补全和编辑功能得到补充。 </p>
<hr>
<p>参考并特别感谢: </p>
<ul>
<li>开发者 bmatzelle 和 mridgers </li>
<li><a href="http://www.hanselman.com/blog/MakingABetterSomewhatPrettierButDefinitelyMoreFunctionalWindowsCommandLine.aspx" target="_blank" rel="external">Scott 的“ better cmd ”</a>及<a href="http://blogs.msdn.com/b/scott_hanselman/archive/2013/07/31/windows.aspx" target="_blank" rel="external">中文版</a></li>
</ul>
]]></content>
<summary type="html">
<![CDATA[<p>Windows 下的 cmd 不太好用,以下将其增强部分 *nix 的 shell 功能</p>
<h2 id="摘要">摘要</h2><p>将 cmd 改造成 shell,关键点: </p>
<ul>
<li>Gow</li>
<li>Clink </li>
</ul>]]>
</summary>
<category term="cmd" scheme="http://luopuya.github.io/tags/cmd/"/>
<category term="Tool" scheme="http://luopuya.github.io/categories/Tool/"/>
</entry>
<entry>
<title><![CDATA[Ubuntu 安装后的 Todolist]]></title>
<link href="http://luopuya.github.io/2013/11/29/Ubuntu%20%E5%AE%89%E8%A3%85%E5%90%8E%E7%9A%84%20Todolist/"/>
<id>http://luopuya.github.io/2013/11/29/Ubuntu 安装后的 Todolist/</id>
<published>2013-11-29T15:27:00.000Z</published>
<updated>2015-03-20T11:14:17.000Z</updated>
<content type="html"><![CDATA[<p>Ubuntu 12.04 64-bit 桌面版简单配置,以下为 todolist</p>
<h2 id="摘要">摘要</h2><p>安装 Ubuntu 后的 todolist,关键点: </p>
<ol>
<li>修改软件源,用 aptitude 统一管理软件 </li>
<li>按需设置代理 </li>
<li>配置自己的环境变量、别名 </li>
</ol>
<a id="more"></a>
<h2 id="安装虚拟机工具">安装虚拟机工具</h2><p>以 VMware 为例: </p>
<ol>
<li>点击 <strong>【虚拟机】->【安装VMware工具】</strong> </li>
<li>将压缩包拖至 ~/download,后用 tar 解压 </li>
<li>运行 vmware-install.pl,以默认配置即可(全回车) </li>
</ol>
<h2 id="设置_root_密码">设置 root 密码</h2><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">sudo passwd root</span><br></pre></td></tr></table></figure>
<h2 id="修改软件源">修改软件源</h2><p>打开 Ubuntu 软件中心,并点击 <strong>【编辑】->【软件源】</strong> </p>
<ol>
<li><p><strong>设置常规软件源</strong><br>从 <strong>下载自</strong> 中选择一个中国的服务器即可 </p>
</li>
<li><p><strong>添加额外软件源</strong><br>点击 <strong>【其它软件】->【添加】</strong><br>通常添加 deb 或 ppa:<br>如需 chrome,输入 deb <a href="http://dl.google.com/linux/chrome/deb/" target="_blank" rel="external">http://dl.google.com/linux/chrome/deb/</a> stable main<br>如需 oracle jdk,输入 ppa:webupd8team/java<br>see more[<a href="https://launchpad.net/~webupd8team/+archive/ubuntu/java" target="_blank" rel="external">https://launchpad.net/~webupd8team/+archive/ubuntu/java</a>]<br>如需 vim7.4,输入 ppa:fcwu-tw/ppa </p>
</li>
</ol>
<p>所做的修改其实均在 /etc/apt 下:<br>修改的服务器源在 /etc/apt/sources.list 文件中<br>添加的软件源在 /etc/apt/sources.list.d 文件夹里 </p>
<p>添加 ppa 也可以如下方式:<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">sudo add-apt-repository ppa:webupd8team/java</span><br></pre></td></tr></table></figure></p>
<h2 id="设置中文">设置中文</h2><p>打开系统设置,并点击 <strong>【语言支持】</strong><br>从 <strong>添加或删除语言</strong> 中选择 <strong>简体中文</strong> ,后将其拖至列表首,并点击 <strong>应用至整个系统</strong> 即可<br>依照提示安装需要的语言包</p>
<h2 id="安装_aptitude">安装 aptitude</h2><p>与 apt-get 相比,aptitude 命令统一,更友好<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">sudo apt-get install aptitude</span><br></pre></td></tr></table></figure></p>
<h2 id="设置代理">设置代理</h2><h3 id="VPN_代理">VPN 代理</h3><p>在右上方点开网络设置,点击 <strong>【VPN连接】->【配置VPN】</strong><br>添加并编辑 VPN<br>最后设置 <strong>【VPN】->【高级】->【使用点到点加密】</strong>(很重要) </p>
<h3 id="普通代理">普通代理</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">gedit ~/.bashrc</span><br></pre></td></tr></table></figure></p>
<p>添加(以 goagent 代理为例)<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"><span class="comment"># add for proxy</span></span><br><span class="line"><span class="built_in">export</span> http_proxy=http://<span class="number">127.0</span>.<span class="number">0.1</span>:<span class="number">8087</span></span><br><span class="line"><span class="built_in">export</span> https_proxy=http://<span class="number">127.0</span>.<span class="number">0.1</span>:<span class="number">8087</span></span><br><span class="line"><span class="built_in">export</span> ftp_proxy=http://<span class="number">127.0</span>.<span class="number">0.1</span>:<span class="number">8087</span></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></pre></td><td class="code"><pre><span class="line"><span class="built_in">source</span> ~/.bashrc</span><br></pre></td></tr></table></figure></p>
<p>当然也可以临时在终端输入 export 指令</p>
<hr>
<p>以上完成后,可选择升级已有软件 </p>
<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">sudo aptitude update </span><br><span class="line">sudo aptitude upgrade</span><br></pre></td></tr></table></figure>
<h2 id="总结">总结</h2><p>至此简单形成以 aptitude 统一管理软件的环境,常用指令有: </p>
<table>
<thead>
<tr>
<th style="text-align:center">功能</th>
<th style="text-align:center">指令</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">更新</td>
<td style="text-align:center"><strong>update</strong></td>
</tr>
<tr>
<td style="text-align:center">安装</td>
<td style="text-align:center"><strong>install</strong></td>
</tr>
<tr>
<td style="text-align:center">卸载</td>
<td style="text-align:center"><strong>remove</strong></td>
</tr>
<tr>
<td style="text-align:center">升级</td>
<td style="text-align:center"><strong>upgrade</strong></td>
</tr>
<tr>
<td style="text-align:center">查找</td>
<td style="text-align:center"><strong>search</strong></td>
</tr>
</tbody>
</table>
<p>自己的环境变量、别名记在 <strong>~/.bashrc</strong> : </p>
<ol>
<li>环境变量(export) </li>
<li>别名/快捷方式(alias) </li>
</ol>
]]></content>
<summary type="html">
<![CDATA[<p>Ubuntu 12.04 64-bit 桌面版简单配置,以下为 todolist</p>
<h2 id="摘要">摘要</h2><p>安装 Ubuntu 后的 todolist,关键点: </p>
<ol>
<li>修改软件源,用 aptitude 统一管理软件 </li>
<li>按需设置代理 </li>
<li>配置自己的环境变量、别名 </li>
</ol>]]>
</summary>
<category term="Ubuntu" scheme="http://luopuya.github.io/tags/Ubuntu/"/>
<category term="Tool" scheme="http://luopuya.github.io/categories/Tool/"/>
</entry>
</feed>