-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.xml
More file actions
225 lines (188 loc) · 31.2 KB
/
feed.xml
File metadata and controls
225 lines (188 loc) · 31.2 KB
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
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.8.5">Jekyll</generator><link href="http://zoubuzao.com/feed.xml" rel="self" type="application/atom+xml" /><link href="http://zoubuzao.com/" rel="alternate" type="text/html" /><updated>2019-07-25T10:30:43+08:00</updated><id>http://zoubuzao.com/feed.xml</id><title type="html">邹鱼 一个全干工程师</title><subtitle>这是邹鱼的个人网站,主要和Ruby、Ruby on Rails、前端、java有关</subtitle><entry><title type="html">focus event in DevTools</title><link href="http://zoubuzao.com/frontend/2019/07/25/focus-event-in-devtools.html" rel="alternate" type="text/html" title="focus event in DevTools" /><published>2019-07-25T00:00:00+08:00</published><updated>2019-07-25T00:00:00+08:00</updated><id>http://zoubuzao.com/frontend/2019/07/25/focus-event-in-devtools</id><content type="html" xml:base="http://zoubuzao.com/frontend/2019/07/25/focus-event-in-devtools.html"><p>在Chrome DevTools中测试触发focus事件,结果不起作用。经过一番查找,发现原因如下:<br />
其实可以把DevTools当做页面的一部分,当输入完代码时focus在你输入完成的位置,所以光标不在期望位置。</p>
<blockquote>
<p>You will realize that when clicking on the Chrome console, it will steal focus from any input or textarea control on the current page, and vice versa. That’s because the Chrome console actually is implemented using the same HTML controls as any other HTML page, just with special properties which, for instance, prevent Chrome from inspecting the Chrome console recursively.</p>
</blockquote>
<blockquote>
<p>When you type a command in the Chrome console, i.e. in the input control that is part of the Chrome console, it will keep the focus. The Chrome engineers might have chosen to implement it differently, but in most cases the user will want to continue typing in the Chrome console after firing a command, so no command will release focus from the console.</p>
</blockquote>
<h3 id="reference">Reference:</h3>
<ol>
<li><a href="https://stackoverflow.com/questions/14783585/jquery-focus-command-doesnt-work-from-chrome-command-line" target="_blank">jquery focus command doesn’t work from chrome command line</a></li>
</ol></content><author><name></name></author><summary type="html">在Chrome DevTools中测试触发focus事件,结果不起作用。经过一番查找,发现原因如下: 其实可以把DevTools当做页面的一部分,当输入完代码时focus在你输入完成的位置,所以光标不在期望位置。</summary></entry><entry><title type="html">rails Testing 功能测试 集成测试 系统测试</title><link href="http://zoubuzao.com/rails/2019/07/13/test.html" rel="alternate" type="text/html" title="rails Testing 功能测试 集成测试 系统测试" /><published>2019-07-13T00:00:00+08:00</published><updated>2019-07-13T00:00:00+08:00</updated><id>http://zoubuzao.com/rails/2019/07/13/test</id><content type="html" xml:base="http://zoubuzao.com/rails/2019/07/13/test.html"><h1 id="功能测试functional-testing-集成测试integration-testing-系统测试system-testing">功能测试(Functional Testing) 集成测试(Integration Testing) 系统测试(System Testing)</h1>
<p>第一次看这三个概念很模糊,尤其是理解集成测试和系统测试的区别上,最后在rails的源代码中找到一丝端倪,所以记录下自己的一些见解。</p>
<ol>
<li>功能测试,主要用来测试单个action</li>
<li>集成测试,可能跨越多个controller、action,用来测试重要的工作流程</li>
<li>系统测试,在rails的源码中发现它是集成自集成测试的,它运行浏览器环境中,能够很方便的测试你的js代码。End-to-end 测试</li>
</ol>
<hr />
<p>在浏览器环境中运行是系统测试和集成测试最主要的区别,系统测试通过近似人的方式来测试代码准确性,突入<strong>人</strong></p>
<hr />
<p>集成测试通过一系列的输入和对输出的检查来验证代码的准确性。</p>
<hr />
<p>集成测试</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">test</span> <span class="s2">"can create an article"</span> <span class="k">do</span>
<span class="n">get</span> <span class="s2">"/articles/new"</span>
<span class="n">assert_response</span> <span class="ss">:success</span>
<span class="n">post</span> <span class="s2">"/articles"</span><span class="p">,</span>
<span class="ss">params: </span><span class="p">{</span> <span class="ss">article: </span><span class="p">{</span> <span class="ss">title: </span><span class="s2">"can create"</span><span class="p">,</span> <span class="ss">body: </span><span class="s2">"article successfully."</span> <span class="p">}</span> <span class="p">}</span>
<span class="n">assert_response</span> <span class="ss">:redirect</span>
<span class="n">follow_redirect!</span>
<span class="n">assert_response</span> <span class="ss">:success</span>
<span class="n">assert_select</span> <span class="s2">"p"</span><span class="p">,</span> <span class="s2">"Title:</span><span class="se">\n</span><span class="s2"> can create"</span>
<span class="k">end</span>
</code></pre></div></div>
<p>系统测试</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">test</span> <span class="s2">"creating an article"</span> <span class="k">do</span>
<span class="n">visit</span> <span class="n">articles_path</span>
<span class="n">click_on</span> <span class="s2">"New Article"</span>
<span class="n">fill_in</span> <span class="s2">"Title"</span><span class="p">,</span> <span class="ss">with: </span><span class="s2">"Creating an Article"</span>
<span class="n">fill_in</span> <span class="s2">"Body"</span><span class="p">,</span> <span class="ss">with: </span><span class="s2">"Created this article successfully!"</span>
<span class="n">click_on</span> <span class="s2">"Create Article"</span>
<span class="n">assert_text</span> <span class="s2">"Creating an Article"</span>
<span class="k">end</span>
</code></pre></div></div></content><author><name></name></author><summary type="html">功能测试(Functional Testing) 集成测试(Integration Testing) 系统测试(System Testing)</summary></entry><entry><title type="html">Ruby write a configuration module or class</title><link href="http://zoubuzao.com/ruby/2019/05/05/make-a-config-module.html" rel="alternate" type="text/html" title="Ruby write a configuration module or class" /><published>2019-05-05T00:00:00+08:00</published><updated>2019-05-05T00:00:00+08:00</updated><id>http://zoubuzao.com/ruby/2019/05/05/make-a-config-module</id><content type="html" xml:base="http://zoubuzao.com/ruby/2019/05/05/make-a-config-module.html"><div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="k">module</span> <span class="nn">Mailer</span>
<span class="k">class</span> <span class="o">&lt;&lt;</span> <span class="nb">self</span>
<span class="nb">attr_accessor</span> <span class="ss">:configuration</span>
<span class="k">def</span> <span class="nf">configure</span>
<span class="nb">self</span><span class="p">.</span><span class="nf">configuration</span> <span class="o">||=</span> <span class="no">Configuration</span><span class="p">.</span><span class="nf">new</span>
<span class="k">yield</span><span class="p">(</span><span class="n">configuration</span><span class="p">)</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">class</span> <span class="nc">Configuration</span>
<span class="nb">attr_accessor</span> <span class="ss">:sender_mailer</span>
<span class="k">def</span> <span class="nf">def</span> <span class="n">initialize</span>
<span class="vi">@sender_mailer</span> <span class="o">=</span> <span class="s1">'example@example.com'</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="no">Mailer</span><span class="p">.</span><span class="nf">configure</span> <span class="k">do</span> <span class="o">|</span><span class="n">config</span><span class="o">|</span>
<span class="n">config</span><span class="p">.</span><span class="nf">sender_mailer</span> <span class="o">=</span> <span class="s1">'yu@example.com'</span>
<span class="k">end</span>
<span class="no">Mailer</span><span class="p">.</span><span class="nf">configuration</span><span class="p">.</span><span class="nf">sender_mailer</span> <span class="o">=&gt;</span> <span class="s1">'yu@example.com'</span>
</code></pre></div></div>
<h3 id="reference">Reference:</h3>
<ol>
<li><a href="https://www.skcript.com/svr/the-easiest-configuration-block-for-your-ruby-gems/" target="_blank">The easiest configuration block for your Ruby gems</a></li>
<li><a href="https://thoughtbot.com/blog/mygem-configure-block" target="_blank">MyGem.configure Block</a></li>
</ol></content><author><name></name></author><summary type="html">```ruby module Mailer class « self attr_accessor :configuration def configure self.configuration ||= Configuration.new yield(configuration) end end class Configuration attr_accessor :sender_mailer def def initialize @sender_mailer = 'example@example.com' end end end</summary></entry><entry><title type="html">Ruby socket simple server</title><link href="http://zoubuzao.com/ruby/2019/04/18/ruby-socket-1.html" rel="alternate" type="text/html" title="Ruby socket simple server" /><published>2019-04-18T00:00:00+08:00</published><updated>2019-04-18T00:00:00+08:00</updated><id>http://zoubuzao.com/ruby/2019/04/18/ruby-socket-1</id><content type="html" xml:base="http://zoubuzao.com/ruby/2019/04/18/ruby-socket-1.html"><div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">require</span> <span class="s1">'socket'</span>
<span class="c1"># 创建</span>
<span class="n">server</span> <span class="o">=</span> <span class="no">Socket</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="ss">:INET</span><span class="p">,</span> <span class="ss">:STREAM</span><span class="p">)</span>
<span class="n">addr</span> <span class="o">=</span> <span class="no">Socket</span><span class="p">.</span><span class="nf">pack_sockaddr_in</span><span class="p">(</span><span class="mi">4444</span><span class="p">,</span> <span class="s1">'0.0.0.0'</span><span class="p">)</span>
<span class="c1"># 绑定</span>
<span class="n">server</span><span class="p">.</span><span class="nf">bind</span><span class="p">(</span><span class="n">addr</span><span class="p">)</span>
<span class="c1"># 监听</span>
<span class="n">server</span><span class="p">.</span><span class="nf">listen</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="c1"># 接受</span>
<span class="kp">loop</span> <span class="k">do</span>
<span class="n">connection</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">server</span><span class="p">.</span><span class="nf">accept</span>
<span class="c1"># 处理连接</span>
<span class="c1"># 读取数据</span>
<span class="nb">p</span> <span class="n">connection</span><span class="p">.</span><span class="nf">read</span>
<span class="c1"># 发送数据</span>
<span class="n">connection</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="s1">'ACK'</span><span class="p">)</span>
<span class="c1"># 关闭</span>
<span class="n">connection</span><span class="p">.</span><span class="nf">close</span>
<span class="k">end</span>
<span class="c1"># 关闭server</span>
<span class="n">server</span><span class="p">.</span><span class="nf">close</span>
<span class="c1"># 以上代码可以使用如下语法糖</span>
<span class="no">Socket</span><span class="p">.</span><span class="nf">tcp_server_loop</span><span class="p">(</span><span class="mi">4444</span><span class="p">,</span> <span class="s1">'0.0.0.0'</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">connection</span><span class="o">|</span>
<span class="nb">p</span> <span class="n">connection</span><span class="p">.</span><span class="nf">read</span>
<span class="c1"># 发送数据</span>
<span class="n">connection</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="s1">'ACK'</span><span class="p">)</span>
<span class="n">connection</span><span class="p">.</span><span class="nf">close</span>
<span class="k">end</span>
</code></pre></div></div></content><author><name></name></author><summary type="html">```ruby require ‘socket’</summary></entry><entry><title type="html">Ruby method arguments 方法参数</title><link href="http://zoubuzao.com/ruby/2019/04/18/ruby-method-argument.html" rel="alternate" type="text/html" title="Ruby method arguments 方法参数" /><published>2019-04-18T00:00:00+08:00</published><updated>2019-04-18T00:00:00+08:00</updated><id>http://zoubuzao.com/ruby/2019/04/18/ruby-method-argument</id><content type="html" xml:base="http://zoubuzao.com/ruby/2019/04/18/ruby-method-argument.html"><p>可使用的参数:</p>
<ol>
<li>必须参数 args</li>
<li>可选参数 args=4</li>
<li>变长参数 **args</li>
<li>关键字参数 args: args: 4</li>
<li>block参数(将传入的block装换为一个Proc对象)
<blockquote>
<p>这些参数推荐的顺序为 必选参数-&gt; 可选参数-&gt; 变长参数 -&gt; 关键词参数 -&gt; 变长关键词参数 -&gt; block参数</p>
</blockquote>
</li>
</ol>
<p>注意:</p>
<ol>
<li>block参数必需为最后一个参数</li>
<li>关键词参数放于普通参数之后</li>
<li>变长关键词参数放于关键词参数之后</li>
<li>变长参数放于可选参数之后</li>
<li>变长参数可以放于必选参数前中后</li>
</ol>
<p>以下为一个例子:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">def</span> <span class="nf">method</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="o">*</span><span class="n">c</span><span class="p">,</span> <span class="n">d</span><span class="p">:,</span> <span class="ss">e: </span><span class="mi">5</span><span class="p">,</span> <span class="o">**</span><span class="n">f</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">block</span><span class="p">)</span>
<span class="nb">p</span> <span class="n">a</span>
<span class="nb">p</span> <span class="n">b</span>
<span class="nb">p</span> <span class="n">c</span>
<span class="nb">p</span> <span class="n">d</span>
<span class="nb">p</span> <span class="n">e</span>
<span class="nb">p</span> <span class="n">f</span>
<span class="nb">p</span> <span class="n">block</span>
<span class="k">end</span>
</code></pre></div></div></content><author><name></name></author><summary type="html">可使用的参数: 必须参数 args 可选参数 args=4 变长参数 **args 关键字参数 args: args: 4 block参数(将传入的block装换为一个Proc对象) 这些参数推荐的顺序为 必选参数-&gt; 可选参数-&gt; 变长参数 -&gt; 关键词参数 -&gt; 变长关键词参数 -&gt; block参数</summary></entry><entry><title type="html">转载 Ruby block</title><link href="http://zoubuzao.com/ruby/2019/04/18/ruby-block.html" rel="alternate" type="text/html" title="转载 Ruby block" /><published>2019-04-18T00:00:00+08:00</published><updated>2019-04-18T00:00:00+08:00</updated><id>http://zoubuzao.com/ruby/2019/04/18/ruby-block</id><content type="html" xml:base="http://zoubuzao.com/ruby/2019/04/18/ruby-block.html"><p>一篇比较容易理解的讲述ruby block
<a href="https://mixandgo.com/learn/mastering-ruby-blocks-in-less-than-5-minutes" target="_blank">转载</a></p></content><author><name></name></author><summary type="html">一篇比较容易理解的讲述ruby block 转载</summary></entry><entry><title type="html">JavaScript 正则表达式</title><link href="http://zoubuzao.com/frontend/2019/04/11/regular-expression.html" rel="alternate" type="text/html" title="JavaScript 正则表达式" /><published>2019-04-11T00:00:00+08:00</published><updated>2019-04-11T00:00:00+08:00</updated><id>http://zoubuzao.com/frontend/2019/04/11/regular-expression</id><content type="html" xml:base="http://zoubuzao.com/frontend/2019/04/11/regular-expression.html"><p>JavaScript中的正则表达式对象在执行全局搜索时,其lastIndex属性会记录对同一字符串下次的搜索位置,此时对同一字符串执行两次搜索结果会出现不符合直觉上预期的方式。</p>
<p>解决办法:1. 使用字符串的match方法 2. 手动设置lastIndex为0</p>
<p class="codepen" data-height="265" data-theme-id="0" data-default-tab="js,result" data-user="zouyu" data-slug-hash="LvyZrR" style="height: 265px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid black; margin: 1em 0; padding: 1em;" data-pen-title="regular expression">
<span>See the Pen <a href="https://codepen.io/zouyu/pen/LvyZrR/">
regular expression</a> by Xiu (<a href="https://codepen.io/zouyu">@zouyu</a>)
on <a href="https://codepen.io">CodePen</a>.</span>
</p>
<script async="" src="https://static.codepen.io/assets/embed/ei.js"></script>
<h3 id="reference">Reference:</h3>
<ol>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex" target="_blank">lastIndex</a></li>
</ol></content><author><name></name></author><summary type="html">JavaScript中的正则表达式对象在执行全局搜索时,其lastIndex属性会记录对同一字符串下次的搜索位置,此时对同一字符串执行两次搜索结果会出现不符合直觉上预期的方式。</summary></entry><entry><title type="html">rails CSRF</title><link href="http://zoubuzao.com/rails/2019/04/05/csrf.html" rel="alternate" type="text/html" title="rails CSRF" /><published>2019-04-05T00:00:00+08:00</published><updated>2019-04-05T00:00:00+08:00</updated><id>http://zoubuzao.com/rails/2019/04/05/csrf</id><content type="html" xml:base="http://zoubuzao.com/rails/2019/04/05/csrf.html"><h1 id="rails中的csrf">Rails中的CSRF</h1>
<blockquote>
<p>rails的ActionController::RequestForgeryProtection,处理CSRF</p>
</blockquote>
<ol>
<li>至少从rails 4.1.7开始,只对XMLHttpRequest的get请求不做验证。对于跨源的script的src造成的请求默认阻止。
<a href="https://api.rubyonrails.org/v4.1.7/classes/ActionController/RequestForgeryProtection.html">RequestForgeryProtection.html</a></li>
<li>在Rails5中<strong>protect_from_forgery</strong>默认启用。</li>
</ol>
<iframe src="https://api.rubyonrails.org/v4.1.7/classes/ActionController/RequestForgeryProtection.html" style="width:100%;height: 50vh;"></iframe></content><author><name></name></author><summary type="html">Rails中的CSRF rails的ActionController::RequestForgeryProtection,处理CSRF</summary></entry><entry><title type="html">rails 根据ActiveRecord动态创建路由</title><link href="http://zoubuzao.com/rails/2019/04/02/view-render.html" rel="alternate" type="text/html" title="rails 根据ActiveRecord动态创建路由" /><published>2019-04-02T00:00:00+08:00</published><updated>2019-04-02T00:00:00+08:00</updated><id>http://zoubuzao.com/rails/2019/04/02/view-render</id><content type="html" xml:base="http://zoubuzao.com/rails/2019/04/02/view-render.html"><p>使用ActionDispatch::Routing::PolymorphicRoutes中提供的方法根据AR动态创建路由,以下为官方文档:</p>
<p>
Polymorphic URL helpers are methods for smart resolution to a named route call when given an Active Record model instance. They are to be used in combination with ActionController::Resources.
</p>
<p>
These methods are useful when you want to generate the correct URL or path to a RESTful resource without having to know the exact type of the record in question.
</p>
<hr />
<p>以上的前提:</p>
<ol>
<li>RESTful resource</li>
</ol>
<hr />
<p>提供的方法</p>
<ol>
<li>polymorphic_url/polymorphic_path</li>
<li>edit_polymorphic_url/edit_polymorphic_path</li>
<li>new_polymorphic_url/new_polymorphic_url</li>
</ol>
<hr />
<p>例子</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="mi">1</span><span class="p">.</span> <span class="nf">polymorphic_path</span> <span class="no">User</span> <span class="o">=&gt;</span> <span class="sr">/users
2. polymorphic_path @user =&gt; /use</span><span class="n">rs</span><span class="o">/</span><span class="mi">1</span>
<span class="mi">3</span><span class="p">.</span> <span class="nf">new_polymorphic_path</span> <span class="no">User</span> <span class="o">=&gt;</span> <span class="sr">/users/ne</span><span class="n">w</span>
<span class="mi">3</span><span class="p">.</span> <span class="nf">edit_polymorphic_path</span> <span class="no">User</span> <span class="o">=&gt;</span> <span class="sr">/users/</span><span class="mi">1</span><span class="o">/</span><span class="n">edit</span>
</code></pre></div></div></content><author><name></name></author><summary type="html">使用ActionDispatch::Routing::PolymorphicRoutes中提供的方法根据AR动态创建路由,以下为官方文档:</summary></entry><entry><title type="html">JavaScript Event</title><link href="http://zoubuzao.com/frontend/2019/03/28/event.html" rel="alternate" type="text/html" title="JavaScript Event" /><published>2019-03-28T00:00:00+08:00</published><updated>2019-03-28T00:00:00+08:00</updated><id>http://zoubuzao.com/frontend/2019/03/28/event</id><content type="html" xml:base="http://zoubuzao.com/frontend/2019/03/28/event.html"><p>Event表示了一个在DOM发生的一个事件</p>
<p>在事件处理函数中有个默认的参数即为event。事件处理函数中的this表示事件被注册的DOM对象,
event.target表示触发事件的对象,event.currentTarget表示事件注册的DOM对象和this相等。
由于冒泡机制event.target和event.currentTarget不一定相等。
示例代码:</p>
<p class="codepen" data-height="265" data-theme-id="0" data-default-tab="js,result" data-user="zouyu" data-slug-hash="ywdEPB" style="height: 265px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid black; margin: 1em 0; padding: 1em;" data-pen-title="show event target currentTarget">
<span>See the Pen <a href="https://codepen.io/zouyu/pen/ywdEPB/">
show event target currentTarget</a> by Xiu (<a href="https://codepen.io/zouyu">@zouyu</a>)
on <a href="https://codepen.io">CodePen</a>.</span>
</p>
<script async="" src="https://static.codepen.io/assets/embed/ei.js"></script>
<h3 id="reference">Reference:</h3>
<ol>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Event" target="_blank">Event</a></li>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Event_handlers" target="_blank">DOM on-event handlers</a></li>
</ol></content><author><name></name></author><summary type="html">Event表示了一个在DOM发生的一个事件</summary></entry></feed>