-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1130 lines (717 loc) · 56.7 KB
/
index.html
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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<link rel="dns-prefetch" href="http://superway117.github.io">
<title>Eason's Blog</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta property="og:type" content="website">
<meta property="og:title" content="Eason's Blog">
<meta property="og:url" content="http://superway117.github.io/index.html">
<meta property="og:site_name" content="Eason's Blog">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Eason's Blog">
<link rel="alternative" href="/atom.xml" title="Eason's Blog" type="application/atom+xml">
<link rel="icon" href="/images/favicon.png">
<link rel="stylesheet" href="/main.css?v=4.0.0.css">
<!-- baidu_tongji -->
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?d7c08ca1f1b9ed5c740dee2eb2ec85f6";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<!-- End baidu_tongji -->
</head>
<body>
<div id="container" q-class="show:isCtnShow">
<canvas id="anm-canvas" class="anm-canvas"></canvas>
<div class="left-col" q-class="show:isShow">
<div class="overlay"></div>
<div class="intrude-less">
<header id="header" class="inner">
<a href="/" class="profilepic">
<img src="/images/header.png" class="js-avatar">
</a>
<hgroup>
<h1 class="header-author"><a href="/">Eason Pan</a></h1>
</hgroup>
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/tags/python">Python</a></li>
<li><a href="/tags/angularjs">AngularJs</a></li>
<li><a href="/tags/nodejs">Nodejs</a></li>
<li><a href="/tags/es6">ES6</a></li>
<li><a href="/tags/dl">DL</a></li>
<li><a href="/tags/mongodb">MongoDB</a></li>
<li><a href="/tags/css">CSS</a></li>
<li><a href="/tags/ionic">Ionic</a></li>
<li><a href="/tags/ARM">ARM</a></li>
<li><a href="/tags/量化">量化</a></li>
</ul>
</nav>
<nav class="header-smart-menu">
<a data-idx="0" q-on="click: openSlider(e, 'innerArchive')" href="javascript:void(0)">所有文章</a>
<a data-idx="1" q-on="click: openSlider(e, 'friends')" href="javascript:void(0)">我的作品</a>
<a data-idx="2" q-on="click: openSlider(e, 'aboutme')" href="javascript:void(0)">关于我</a>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="https://github.com/superway117" title="github"><i class="icon-github"></i></a>
<a class="rss" target="_blank" href="#" title="rss"><i class="icon-rss"></i></a>
<a class="zhihu" target="_blank" href="https://www.zhihu.com/people/eason.pan" title="zhihu"><i class="icon-zhihu"></i></a>
<a class="mail" target="_blank" href="mailto:[email protected]" title="mail"><i class="icon-mail"></i></a>
<a class="linkedin" target="_blank" href="https://www.linkedin.com/in/wei-pan-bb6a5182" title="linkedin"><i class="icon-linkedin"></i></a>
</div>
</nav>
</header>
</div>
</div>
<div class="mid-col" q-class="show:isShow,hide:isShow|isFalse">
<nav id="mobile-nav">
<div class="overlay">
<div class="slider-trigger"><i class="icon-sort"></i></div>
<h1 class="header-author js-mobile-header hide">Eason Pan</h1>
</div>
<div class="intrude-less">
<header id="header" class="inner">
<div class="profilepic">
<img src="/images/header.png" class="js-avatar">
</div>
<hgroup>
<h1 class="header-author">Eason Pan</h1>
</hgroup>
<nav class="header-menu">
<ul>
<li><a href="/">主页</a></li>
<li><a href="/tags/python">Python</a></li>
<li><a href="/tags/angularjs">AngularJs</a></li>
<li><a href="/tags/nodejs">Nodejs</a></li>
<li><a href="/tags/es6">ES6</a></li>
<li><a href="/tags/dl">DL</a></li>
<li><a href="/tags/mongodb">MongoDB</a></li>
<li><a href="/tags/css">CSS</a></li>
<li><a href="/tags/ionic">Ionic</a></li>
<li><a href="/tags/ARM">ARM</a></li>
<li><a href="/tags/量化">量化</a></li>
<li><a href="/archives">所有文章</a></li>
</ul>
</nav>
<nav class="header-nav">
<div class="social">
<a class="github" target="_blank" href="https://github.com/superway117" title="github"><i class="icon-github"></i></a>
<a class="rss" target="_blank" href="#" title="rss"><i class="icon-rss"></i></a>
<a class="zhihu" target="_blank" href="https://www.zhihu.com/people/eason.pan" title="zhihu"><i class="icon-zhihu"></i></a>
<a class="mail" target="_blank" href="mailto:[email protected]" title="mail"><i class="icon-mail"></i></a>
<a class="linkedin" target="_blank" href="https://www.linkedin.com/in/wei-pan-bb6a5182" title="linkedin"><i class="icon-linkedin"></i></a>
</div>
</nav>
</header>
</div>
</nav>
<div id="wrapper" class="body-wrap">
<div class="menu-l">
<div class="canvas-wrap">
<canvas data-colors="#eaeaea" data-sectionHeight="100" data-contentId="js-content" id="myCanvas1" class="anm-canvas"></canvas>
</div>
<div id="js-content" class="content-ll">
<article id="post-findOneAndUpdate" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/03/15/findOneAndUpdate/">mongoose findOneAndUpdate</a>
</h1>
<a href="/2017/03/15/findOneAndUpdate/" class="archive-article-date">
<time datetime="2017-03-15T01:09:44.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2017-03-15</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<p><code>mongoose</code> <code>findOneAndUpdate</code>的用法</p>
<p>Mongoose supports this natively with <a href="http://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate" target="_blank" rel="external">findOneAndUpdate</a> , it calls MongoDB <a href="https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/" target="_blank" rel="external">findAndModify</a>.</p>
<h2 id="参数"><a href="#参数" class="headerlink" title="参数"></a>参数</h2><p><code>upsert</code></p>
<p>if true, it creates the object if it doesn’t exist. defaults to false.</p>
<p><code>new</code></p>
<p>if true, returns the modified document rather than the original. The findAndModify() method ignores the new option for remove operations. The default is false.</p>
<h2 id="update-操作"><a href="#update-操作" class="headerlink" title="update 操作"></a>update 操作</h2><p><a href="https://docs.mongodb.com/manual/reference/operator/update/#id1" target="_blank" rel="external">mongodb update</a></p>
<p><code>$setOnInsert</code></p>
<p>Sets the value of a field if an update results in an insert of a document. Has no effect on update operations that modify existing documents.</p>
<p>也就是说新增才会写</p>
<p><code>mongoose</code>里面用<code>setDefaultsOnInsert</code></p>
<p><a href="http://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate" target="_blank" rel="external">setDefaultsOnInsert</a>: if this and upsert are true, mongoose will apply the defaults specified in the model’s schema if a new document is created. This option only works on MongoDB >= 2.4 because it relies on MongoDB’s $setOnInsert operator.</p>
<p>如果要用这个选项的,需要的model的地方配置默认值</p>
<p><code>$set</code></p>
<p>Sets the value of a field in a document.</p>
<h2 id="Sample"><a href="#Sample" class="headerlink" title="Sample"></a>Sample</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Model.findByIdAndUpdate(id, { $set: { name: 'jason borne' }}, options, callback)</div></pre></td></tr></table></figure>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/mongodb/">mongodb</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2017/03/15/findOneAndUpdate/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-adminlte-usage" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/03/08/adminlte-usage/">Adminlte Usage</a>
</h1>
<a href="/2017/03/08/adminlte-usage/" class="archive-article-date">
<time datetime="2017-03-08T01:40:09.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2017-03-08</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<h1 id="sidebar"><a href="#sidebar" class="headerlink" title="sidebar"></a>sidebar</h1><p><code>sidebar-mini</code>: sidebar只显示图片,不设置它,就是图片文字都显示</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><body class="hold-transition skin-blue sidebar-mini"></div><div class="line"></body></div><div class="line">`</div></pre></td></tr></table></figure>
<p><code>sidebar-collapse</code>: sidebar初始是收缩状态</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><body class="hold-transition skin-blue sidebar-collapse"></div><div class="line"></body></div><div class="line">`</div></pre></td></tr></table></figure>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/css/">css</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2017/03/08/adminlte-usage/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-angular_row_4" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/03/02/angular_row_4/">如何在ng-repeat里面,每隔3个元素换行</a>
</h1>
<a href="/2017/03/02/angular_row_4/" class="archive-article-date">
<time datetime="2017-03-02T04:27:14.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2017-03-02</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<p>problem:</p>
<p>如何在ng-repeat里面,每隔3个元素换行</p>
<p>solution:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><div class="row"></div><div class="line"> <div ng-repeat="product in products"></div><div class="line"> <div class="clearfix" ng-if="$index % 3 == 0"></div></div><div class="line"> <div class="col-sm-4"></div><div class="line"> <h2>{{product.title}}</h2></div><div class="line"> </div></div><div class="line"> </div></div><div class="line"></div></div></pre></td></tr></table></figure>
<h2 id="reference"><a href="#reference" class="headerlink" title="reference"></a>reference</h2><p><a href="http://stackoverflow.com/questions/27211799/angular-ng-repeat-add-bootstrap-row-every-3-or-4-cols" target="_blank" rel="external">stackoverflow</a></p>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/angularjs/">angularjs</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2017/03/02/angular_row_4/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-flex_layout" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/02/23/flex_layout/">flex-layout</a>
</h1>
<a href="/2017/02/23/flex_layout/" class="archive-article-date">
<time datetime="2017-02-23T15:40:49.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2017-02-23</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="reference"><a href="#reference" class="headerlink" title="reference"></a>reference</h2><p>flexboxfroggy</p>
<ul>
<li><a href="https://github.com/thomaspark/flexboxfroggy" target="_blank" rel="external">github</a></li>
<li><a href="http://flexboxfroggy.com/" target="_blank" rel="external">game</a></li>
</ul>
<p>阮一峰</p>
<ul>
<li><a href="http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool" target="_blank" rel="external">Flex 布局教程:语法篇</a></li>
<li><a href="http://www.ruanyifeng.com/blog/2015/07/flex-examples.html" target="_blank" rel="external">Flex 布局教程:实例篇</a></li>
<li><a href="http://codepen.io/LandonSchropp/pen/KpzzGo" target="_blank" rel="external">demo</a></li>
</ul>
<p>张鑫旭</p>
<ul>
<li><a href="http://www.zhangxinxu.com/wordpress/2010/12/css-box-flex%E5%B1%9E%E6%80%A7%EF%BC%8C%E7%84%B6%E5%90%8E%E5%BC%B9%E6%80%A7%E7%9B%92%E5%AD%90%E6%A8%A1%E5%9E%8B%E7%AE%80%E4%BB%8B/" target="_blank" rel="external">CSS box-flex属性,然后弹性盒子模型简介</a></li>
</ul>
<p>xiaoxiangzi</p>
<ul>
<li><a href="http://www.xiaoxiangzi.com/Programme/CSS/2540.html" target="_blank" rel="external">CSS3 Flexbox可视化指南</a></li>
</ul>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/css/">css</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2017/02/23/flex_layout/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-py_numpy_index" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/01/16/py_numpy_index/">Python numpy Index</a>
</h1>
<a href="/2017/01/16/py_numpy_index/" class="archive-article-date">
<time datetime="2017-01-16T02:32:09.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2017-01-16</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<p>In Python, x[(exp1, exp2, …, expN)] is equivalent to x[exp1, exp2, …, expN]; the latter is just syntactic sugar for the former.</p>
<p>numpy.newaxis</p>
<p>The newaxis object can be used in all slicing operations to create an axis of length one. :const: newaxis is an alias for ‘None’, and ‘None’ can be used in place of this with the same result.</p>
<p><a href="https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#numpy.newaxis" target="_blank" rel="external">numpy.newaxis</a></p>
<h2 id="Basic-Slicing-and-Indexing"><a href="#Basic-Slicing-and-Indexing" class="headerlink" title="Basic Slicing and Indexing"></a>Basic Slicing and Indexing</h2><p><code>格式</code></p>
<blockquote>
<blockquote>
<blockquote>
<p>Basic slicing occurs when obj is a slice object (constructed by start:stop:step notation inside of brackets), an integer, or a tuple of slice objects and integers. </p>
</blockquote>
</blockquote>
</blockquote>
<p>也就是说<code>slice</code>,<code>integer</code>,<code>tuple of slice objects and integers</code>, 这样的index我们称为<code>Basic Slicing</code></p>
<h2 id="Advanced-Indexing"><a href="#Advanced-Indexing" class="headerlink" title="Advanced Indexing"></a>Advanced Indexing</h2>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/">python</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2017/01/16/py_numpy_index/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-py_numpy_shape" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/01/13/py_numpy_shape/">Python numpy shape</a>
</h1>
<a href="/2017/01/13/py_numpy_shape/" class="archive-article-date">
<time datetime="2017-01-13T06:32:13.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2017-01-13</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">In [52]: x3 = np.random.randint(10, size=(3, 4, 5))</div><div class="line"></div><div class="line">In [53]: x3</div><div class="line">Out[53]:</div><div class="line">array([[[1, 7, 4, 7, 5],</div><div class="line"> [3, 5, 9, 4, 3],</div><div class="line"> [6, 9, 4, 1, 4],</div><div class="line"> [2, 0, 8, 9, 4]],</div><div class="line"></div><div class="line"> [[8, 6, 8, 7, 6],</div><div class="line"> [1, 7, 8, 7, 1],</div><div class="line"> [4, 8, 6, 5, 7],</div><div class="line"> [9, 0, 2, 7, 9]],</div><div class="line"></div><div class="line"> [[6, 6, 6, 2, 1],</div><div class="line"> [6, 5, 7, 5, 9],</div><div class="line"> [5, 0, 8, 8, 1],</div><div class="line"> [4, 7, 0, 6, 1]]])</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">In [57]: x3.ndim</div><div class="line">Out[57]: 3</div><div class="line"></div><div class="line">In [58]: x3.shape</div><div class="line">Out[58]: (3L, 4L, 5L)</div><div class="line"></div><div class="line">In [59]: x3.size</div><div class="line">Out[59]: 60</div><div class="line"></div><div class="line">In [61]: x3.strides</div><div class="line">Out[61]: (80L, 20L, 4L)</div></pre></td></tr></table></figure>
<p><code>ndim</code> : the number of dimensions,也就是维度, 上面的<code>x3</code>就是一个3维数组.</p>
<p><code>shape</code>: the size of each dimension, 可以认为是数组的形状,每一维的大小.</p>
<p><code>size</code> : total size of the array, 这个<code>size</code>是指元素的个数: 3<em>4</em>5==60</p>
<p><code>strides</code>:</p>
<ul>
<li>每个轴上面相邻元素的地址差. 上面的例子(80L, 20L, 4L), 其中80==20*4,最后一个轴的元素size就是4(int).</li>
<li>numpy在数据存储上面支持C语言的方式:连续的内存存储空间,也支持Fortan的方式.默认是C语言.</li>
</ul>
<p><code>numpy.ndarray.flags</code> 描述了数组的内存layout信息. </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">In [63]: x3.flags</div><div class="line">Out[63]:</div><div class="line"> C_CONTIGUOUS : True</div><div class="line"> F_CONTIGUOUS : False</div><div class="line"> OWNDATA : True</div><div class="line"> WRITEABLE : True</div><div class="line"> ALIGNED : True</div><div class="line"> UPDATEIFCOPY : False</div></pre></td></tr></table></figure>
<ul>
<li><code>C_CONTIGUOUS</code>就是C语言的存储方式</li>
<li><code>F_CONTIGUOUS</code>就是Fortan语言的存储方式</li>
<li><code>ALIGNED</code>,C语言里面要内存对其,就存在padding的问题,这个true就表示完全follow C语言做内存对其</li>
<li><code>OWNDATA</code>, 如果是view的话,这里就是false.</li>
</ul>
<h3 id="reference"><a href="#reference" class="headerlink" title="reference"></a>reference</h3><ul>
<li><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flags.html" target="_blank" rel="external">numpy.ndarray.flags</a></li>
</ul>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/">python</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2017/01/13/py_numpy_shape/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-py_Sphinx" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/01/12/py_Sphinx/">Python Sphinx</a>
</h1>
<a href="/2017/01/12/py_Sphinx/" class="archive-article-date">
<time datetime="2017-01-12T08:52:21.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2017-01-12</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<ul>
<li>Sphinx是一个静态网站生成器,可以用来做静态网站或者写文档</li>
<li>Sphinx基于reStructuredText,markdown语法,配置文件就是py文件: conf.py</li>
<li>Sphinx支持Python 2.6+, 3.3+.</li>
</ul>
<p>For full documentation visit <a href="http://www.sphinx-doc.org/en/latest" target="_blank" rel="external">sphinx-doc</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><p>Install</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pip install Sphinx</div></pre></td></tr></table></figure>
<p>Start a new project</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sphinx-quickstart</div></pre></td></tr></table></figure>
<p>执行这个命令后,会step by step的生成一个工程,同时conf.py就生成了.同时根目录下面会生成一个make.bat文件(window下面),后面我们就可以通过这个make.bat来生成页面或者发布了.</p>
<p>make.bat支持多种格式,比如html,epub,json,latex,singlehtml. 支持列表可以敲入下面的命令查看.</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">make.bat help</div></pre></td></tr></table></figure>
<p>通过下面的命令生成网页</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">make.bat html</div></pre></td></tr></table></figure>
<p>这个命令等同于</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sphinx-build -b html sourcedir builddir</div></pre></td></tr></table></figure>
<h2 id="Theme"><a href="#Theme" class="headerlink" title="Theme"></a>Theme</h2><p>在conf.py修改theme</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">html_theme = "classic"</div><div class="line">html_theme_options = {</div><div class="line"> "rightsidebar": "true",</div><div class="line"> "relbarbgcolor": "black"</div><div class="line">}</div></pre></td></tr></table></figure>
<p>参考页面<a href="http://www.sphinx-doc.org/en/latest/theming.html" target="_blank" rel="external">theming</a></p>
<h4 id="sphinx-rtd-theme"><a href="#sphinx-rtd-theme" class="headerlink" title="sphinx_rtd_theme"></a>sphinx_rtd_theme</h4><p>scrapy和readthedocs都是采用的<code>sphinx_rtd_theme</code>,效果参考<a href="http://doc.scrapy.org/en/1.1/index.html" target="_blank" rel="external">scrapy doc页面</a>或者<a href="http://docs.readthedocs.io/en/latest/" target="_blank" rel="external">readthedocs</a></p>
<p>install</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pip install sphinx_rtd_theme</div></pre></td></tr></table></figure>
<p>usage</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">import sphinx_rtd_theme</div><div class="line"></div><div class="line">html_theme = "sphinx_rtd_theme"</div><div class="line"></div><div class="line">html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]</div></pre></td></tr></table></figure>
<h3 id="支持Markdown"><a href="#支持Markdown" class="headerlink" title="支持Markdown"></a>支持Markdown</h3><p>支持Markdown,简单说需要2步:</p>
<ol>
<li><p>安装Markdown解析工具</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pip install recommonmark.parser</div></pre></td></tr></table></figure>
</li>
<li><p>修改conf.py告诉sphinx支持Markdown</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">from recommonmark.parser import CommonMarkParser</div><div class="line"></div><div class="line">默认只支持rst后缀文件</div><div class="line">source_suffix = '.rst'</div><div class="line"> 改成</div><div class="line">source_parsers = {'.md': CommonMarkParser}</div><div class="line"> source_suffix = ['.rst', '.md']</div></pre></td></tr></table></figure>
</li>
</ol>
<h2 id="References"><a href="#References" class="headerlink" title="References"></a>References</h2><ul>
<li><p><code>scrapinghub</code> </p>
<ul>
<li>scrapinghub 文档,rst格式</li>
<li><a href="https://github.com/scrapinghub/doc.scrapinghub.com" target="_blank" rel="external">source link</a></li>
<li><a href="http://doc.scrapinghub.com/" target="_blank" rel="external">doc link</a></li>
</ul>
</li>
<li><p><code>readthedocs</code> </p>
<ul>
<li>readthedocs 文档,rst格式</li>
<li><a href="http://docs.readthedocs.io/en/latest/" target="_blank" rel="external">doc link</a></li>
</ul>
</li>
<li><p><code>scrapy</code> </p>
<ul>
<li>scrapy 文档,rst格式</li>
<li><a href="https://github.com/scrapy/scrapy/tree/master/docs" target="_blank" rel="external">source link</a></li>
<li><a href="http://doc.scrapy.org/en/1.1/" target="_blank" rel="external">doc link</a></li>
</ul>
</li>
</ul>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/">python</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2017/01/12/py_Sphinx/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-py_namedtuple" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2017/01/11/py_namedtuple/">Python namedtuple</a>
</h1>
<a href="/2017/01/11/py_namedtuple/" class="archive-article-date">
<time datetime="2017-01-10T16:43:38.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2017-01-11</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<p><code>tuple</code>只能用index来获取对应位置的值,也就是0,1,2,3 这种形式对代码可读性,可维护性都不是很好.</p>
<p>很多时候我们需要用类似<code>dict</code>的方式来取值. 这个时候就需要<code>namedtuple</code></p>
<p><code>namedtuple</code>某种意义上就是一个文本的模板,帮助你定义一个<code>tuple</code>的子类.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">Point = namedtuple(<span class="string">'Point'</span>, [<span class="string">'x'</span>, <span class="string">'y'</span>], verbose=<span class="keyword">True</span>)</div></pre></td></tr></table></figure>
<p>就相当于定义了一个类<code>Point</code></p>
<p>下面的代码关键在于 <code>__dict__ = _property(_asdict)</code>,他定义了一个<code>dict</code>,这样我们才可以实现用名字来获取值.</p>
<p>另外因为用到了<code>__slots__</code>,这个是为了节省memory, 所以大胆的用<code>namedtuple</code>,开销不是很大.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">Point</span><span class="params">(tuple)</span>:</span></div><div class="line"> <span class="string">'Point(x, y)'</span></div><div class="line"></div><div class="line"> __slots__ = ()</div><div class="line"></div><div class="line"> _fields = (<span class="string">'x'</span>, <span class="string">'y'</span>)</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__new__</span><span class="params">(_cls, x, y)</span>:</span></div><div class="line"> <span class="string">'Create new instance of Point(x, y)'</span></div><div class="line"> <span class="keyword">return</span> _tuple.__new__(_cls, (x, y))</div><div class="line"></div><div class="line"><span class="meta"> @classmethod</span></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">_make</span><span class="params">(cls, iterable, new=tuple.__new__, len=len)</span>:</span></div><div class="line"> <span class="string">'Make a new Point object from a sequence or iterable'</span></div><div class="line"> result = new(cls, iterable)</div><div class="line"> <span class="keyword">if</span> len(result) != <span class="number">2</span>:</div><div class="line"> <span class="keyword">raise</span> TypeError(<span class="string">'Expected 2 arguments, got %d'</span> % len(result))</div><div class="line"> <span class="keyword">return</span> result</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__repr__</span><span class="params">(self)</span>:</span></div><div class="line"> <span class="string">'Return a nicely formatted representation string'</span></div><div class="line"> <span class="keyword">return</span> <span class="string">'Point(x=%r, y=%r)'</span> % self</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">_asdict</span><span class="params">(self)</span>:</span></div><div class="line"> <span class="string">'Return a new OrderedDict which maps field names to their values'</span></div><div class="line"> <span class="keyword">return</span> OrderedDict(zip(self._fields, self))</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">_replace</span><span class="params">(_self, **kwds)</span>:</span></div><div class="line"> <span class="string">'Return a new Point object replacing specified fields with new values'</span></div><div class="line"> result = _self._make(map(kwds.pop, (<span class="string">'x'</span>, <span class="string">'y'</span>), _self))</div><div class="line"> <span class="keyword">if</span> kwds:</div><div class="line"> <span class="keyword">raise</span> ValueError(<span class="string">'Got unexpected field names: %r'</span> % kwds.keys())</div><div class="line"> <span class="keyword">return</span> result</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__getnewargs__</span><span class="params">(self)</span>:</span></div><div class="line"> <span class="string">'Return self as a plain tuple. Used by copy and pickle.'</span></div><div class="line"> <span class="keyword">return</span> tuple(self)</div><div class="line"></div><div class="line"> __dict__ = _property(_asdict)</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__getstate__</span><span class="params">(self)</span>:</span></div><div class="line"> <span class="string">'Exclude the OrderedDict from pickling'</span></div><div class="line"> <span class="keyword">pass</span></div><div class="line"></div><div class="line"> x = _property(_itemgetter(<span class="number">0</span>), doc=<span class="string">'Alias for field number 0'</span>)</div><div class="line"></div><div class="line"> y = _property(_itemgetter(<span class="number">1</span>), doc=<span class="string">'Alias for field number 1'</span>)</div></pre></td></tr></table></figure>
<h2 id="usage"><a href="#usage" class="headerlink" title="usage"></a>usage</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">Point = namedtuple('Point', ['x', 'y'], verbose=True)</div><div class="line"></div><div class="line">>>> p = Point(11, y=22) # instantiate with positional or keyword arguments</div><div class="line">>>> p[0] + p[1] # indexable like the plain tuple (11, 22)</div><div class="line">33</div><div class="line">>>> x, y = p # unpack like a regular tuple</div><div class="line">>>> x, y</div><div class="line">(11, 22)</div><div class="line">>>> p.x + p.y # fields also accessible by name</div><div class="line">33</div><div class="line">>>> p # readable __repr__ with a name=value style</div><div class="line">Point(x=11, y=22)</div></pre></td></tr></table></figure>
<p>另外注意<code>_fields</code>的用法,他直接返回了原始的<code>tuple</code></p>
<h2 id="reference"><a href="#reference" class="headerlink" title="reference"></a>reference</h2><ul>
<li><a href="https://docs.python.org/2/library/collections.html?highlight=namedtuple#collections.namedtuple" target="_blank" rel="external">collections.namedtuple</a></li>
<li>Python cookbook 1.18. Mapping Names to Sequence Elements</li>
</ul>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/">python</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2017/01/11/py_namedtuple/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-py_private_variables" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/12/31/py_private_variables/">Python Private Variables</a>
</h1>
<a href="/2016/12/31/py_private_variables/" class="archive-article-date">
<time datetime="2016-12-31T11:11:33.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2016-12-31</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<p>Python是不支持<code>Private</code>关键字的.Python通过2种形式来支持private.</p>
<h2 id="约定俗成"><a href="#约定俗成" class="headerlink" title="约定俗成"></a>约定俗成</h2><p>如果一个成员是以一个下划线开头(有且只有一个),这种情况是python里面约定俗成的私有变量. 但是注意 python语法上没有对他做任何处理, 这只是一个编码习惯.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span>:</span></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></div><div class="line"> self._internal = <span class="number">0</span> <span class="comment"># An internal attribute</span></div><div class="line"> self.public = <span class="number">1</span> <span class="comment"># A public attribute</span></div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">public_method</span><span class="params">(self)</span>:</span></div><div class="line"> <span class="string">'''</span></div><div class="line"> A public method</div><div class="line"> '''</div><div class="line"> ...</div><div class="line"></div><div class="line"> <span class="function"><span class="keyword">def</span> <span class="title">_internal_method</span><span class="params">(self)</span>:</span></div></pre></td></tr></table></figure>
<h2 id="name-mangling"><a href="#name-mangling" class="headerlink" title="name mangling"></a>name mangling</h2><p>如果成员是以两个下划线开头,且结尾<strong>至多</strong>一个下划线,这种类成员python是会做一个重命名的, <code>__spam</code>,python会改出: <code>_classname__spam</code>.</p>
<p>python设计这样的东西,是为了阻止继承的类<code>oeverridden</code>这样的属性.</p>
<p>下面是从python cookbook里面copy出来的.</p>
<blockquote>
<p>At this point, you might ask what purpose<br>such name mangling serves. The answer is inheritance—such attributes cannot be<br>overridden via inheritance</p>
</blockquote>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">class B:</div><div class="line"> def __init__(self):</div><div class="line"> self.__private = 0 -->相当于__B_private</div><div class="line"> def __private_method(self):</div><div class="line"> </div><div class="line"> def public_method(self):</div><div class="line"> ...</div><div class="line"></div><div class="line"> self.__private_method() -->相当于__B_private_method</div><div class="line"> ...</div><div class="line"></div><div class="line"></div><div class="line">class C(B):</div><div class="line"> def __init__(self):</div><div class="line"> super().__init__()</div><div class="line"></div><div class="line"> self.__private = 1 # Does not override B.__private</div><div class="line"></div><div class="line"> # Does not override B.__private_method()</div><div class="line"> def __private_method(self): -->相当于__C_private_method</div></pre></td></tr></table></figure>
<p>下面是<code>werkzeug\local.py</code>的code. 主要注意的是<code>object.__setattr__</code>用的是转换后的名字<code>_LocalProxy__local</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">object.__setattr__(self, <span class="string">'_LocalProxy__local'</span>, local)</div></pre></td></tr></table></figure>
<h2 id="references"><a href="#references" class="headerlink" title="references"></a>references</h2><ul>
<li><a href="https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references" target="_blank" rel="external">Private Variables and Class-local References</a></li>
<li><a href="http://blog.csdn.net/zsuguangh/article/details/6207469" target="_blank" rel="external">关于Python的class的私有变量扎压 Python的命名机制</a></li>
<li>Python Cookbook 8.5. Encapsulating Names in a Class</li>
</ul>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/">python</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2016/12/31/py_private_variables/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<article id="post-hexo_draft" class="article article-type-post article-index" itemscope itemprop="blogPost">
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2016/12/29/hexo_draft/">hexo draft</a>
</h1>
<a href="/2016/12/29/hexo_draft/" class="archive-article-date">
<time datetime="2016-12-29T08:10:57.000Z" itemprop="datePublished"><i class="icon-calendar icon"></i>2016-12-29</time>
</a>
</header>
<div class="article-entry" itemprop="articleBody">
<h2 id="如果文章写了一半-想设置成draft怎么办"><a href="#如果文章写了一半-想设置成draft怎么办" class="headerlink" title="如果文章写了一半,想设置成draft怎么办?"></a>如果文章写了一半,想设置成draft怎么办?</h2><ol>
<li>看看<code>source/_drafts</code>存在否,不存在,创建一个</li>
<li>把相关文章<code>xx.md</code>和<code>xx目录</code>扔进去就行,是mv不是cp</li>
</ol>
<h2 id="直接创建一个draft"><a href="#直接创建一个draft" class="headerlink" title="直接创建一个draft"></a>直接创建一个draft</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">hexo new draft "new draft"</div></pre></td></tr></table></figure>
<p>这个命令也就是相关文件创建在<code>source/_drafts</code>,默认是创建在<code>source/_posts</code></p>
<h2 id="强行显示draft"><a href="#强行显示draft" class="headerlink" title="强行显示draft"></a>强行显示draft</h2><p><code>__config.yml</code>里面修改:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">render_drafts: true</div></pre></td></tr></table></figure>
<p>或者启动server的时候加参数</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">hexo server --drafts</div></pre></td></tr></table></figure>
<h2 id="发布draft"><a href="#发布draft" class="headerlink" title="发布draft"></a>发布draft</h2><p>下面的命令可以发布,未验证,事实上, <code>publish</code>我从来就没用过</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">hexo publish [layout] <filename></div></pre></td></tr></table></figure>
</div>
<div class="article-info article-info-index">
<div class="article-tag tagcloud">
<i class="icon-price-tags"></i>
<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/hexo/">hexo</a></li></ul>
</div>
<p class="article-more-link">
<a class="article-more-a" href="/2016/12/29/hexo_draft/">展开全文 >></a>
</p>
<div class="clearfix"></div>
</div>
</div>
</article>
<nav id="page-nav">
<span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><a class="page-number" href="/page/3/">3</a><a class="extend next" rel="next" href="/page/2/">Next »</a>
</nav>
</div>
</div>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info">
<div class="footer-left">
© 2019 Eason Pan
</div>
<div class="footer-right">
</div>
</div>
</div>
</footer>
</div>
<script>
var yiliaConfig = {
mathjax: false,
isHome: true,
isPost: false,
isArchive: false,
isTag: false,
isCategory: false,
open_in_new: false,
root: "/",
innerArchive: true
}
</script>
<script src="/./main.js?v=4.0.0.js"></script>
<div class="tools-col" q-class="show:isShow,hide:isShow|isFalse" q-on="click:stop(e)">
<div class="tools-wrap">
<section class="tools-section tools-section-all" q-show="innerArchive">
<div class="search-wrap">
<input class="search-ipt" q-model="search" type="text" placeholder="find something…">
<i class="icon-search icon" q-show="search|isEmptyStr"></i>
<i class="icon-close icon" q-show="search|isNotEmptyStr" q-on="click:clearChose(e)"></i>
</div>
<div class="widget tagcloud search-tag">
<p class="search-tag-wording">tag:</p>
<label class="search-switch">
<input type="checkbox" q-on="click:toggleTag(e)" q-attr="checked:showTags">
</label>
<ul class="article-tag-list" q-show="showTags">
<li class="article-tag-list-item">
<a href="javascript:void(0)">python</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)">mongodb</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)">css</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)">angularjs</a>
</li>
<li class="article-tag-list-item">
<a href="javascript:void(0)">hexo</a>
</li>
<div class="clearfix"></div>
</ul>
</div>
<ul class="search-ul">
<p q-show="jsonFail" style="padding: 20px; font-size: 12px;">
缺失模块。<br/>1、在博客根目录(注意不是yilia根目录)执行以下命令:<br/> npm i hexo-generator-json-content --save<br/><br/>
2、在根目录_config.yml里添加配置:
<pre style="font-size: 12px;" q-show="jsonFail">
jsonContent:
meta: false
pages: false
posts:
title: true
date: true
path: true
text: true
raw: false
content: false
slug: false
updated: false
comments: false
link: false