-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.xml
253 lines (180 loc) · 10.9 KB
/
index.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
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>rookiebulls on rookiebulls</title>
<link>/</link>
<description>Recent content in rookiebulls on rookiebulls</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<lastBuildDate>Sat, 23 Feb 2019 10:37:06 +0800</lastBuildDate>
<atom:link href="/" rel="self" type="application/rss+xml" />
<item>
<title>Generate website with Hugo and deploy it with Travis CI</title>
<link>/2019/generate-blog-with-hugo/</link>
<pubDate>Sat, 23 Feb 2019 10:37:06 +0800</pubDate>
<guid>/2019/generate-blog-with-hugo/</guid>
<description>
<h2 id="why-hugo">Why Hugo</h2>
<p>I used to use <a href="https://blog.getpelican.com" rel="nofollow noreferrer" target="_blank">Pelican</a> to generate my website, it works petty well. But in some way, it&rsquo;s just not that perfect, such as, no hot reload, small community, lots of dependencies, not that fast. Hugo, in other way, is fast, nearly no dependencies, better writing experience with hot reloading, so it&rsquo;s clearly a better choice for me.</p>
<h2 id="install-hugo">Install Hugo</h2>
<p>If you are on Mac OS, you can install Hugo with Homebrew <code>brew install hugo</code>, for other platforms, check this <a href="https://gohugo.io/getting-started/installing" rel="nofollow noreferrer" target="_blank">link</a>, you can find your answers here.</p>
<h2 id="generate-website">Generate website</h2>
<p>Use command <code>hugo new site sitename</code> to generate a website.</p>
<h2 id="install-a-theme">Install a theme</h2>
<pre><code class="language-bash">cd blog/themes
git clone https://github.com/liuzc/LeaveIt.git
</code></pre>
<h2 id="customize-your-configuration">Customize your configuration</h2>
<p>Open <code>config.toml</code> and set the <code>theme</code> property to your theme.</p>
<pre><code class="language-conf">baseURL = &quot;/&quot;
languageCode = &quot;en-us&quot;
title = &quot;rookiebulls&quot;
theme = &quot;LeaveIt&quot;
...
</code></pre>
<p>For more configurations, check your theme&rsquo;s example site.</p>
<h2 id="add-a-new-post">Add a new post</h2>
<p>Run command <code>hugo new posts/new-post-title.md</code> to add a new post in the <code>content/posts</code> directory. Hugo supports <code>Markdown</code> out of box, if you are not familiar with it, here&rsquo;s a <a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" rel="nofollow noreferrer" target="_blank">cheatsheet</a> about it.</p>
<h2 id="build-you-website">Build you website</h2>
<p>Just type <code>hugo</code>, your website will be generated automatically in the <code>public</code> directory.</p>
<h2 id="deploy-your-website">Deploy your website</h2>
<p>The content in the <code>pubic</code> directory is static, you can host it with Nginx, Apache&hellip; any web server will be fine, but you need to have a VPS first. I choose Github Pages to host my website, because it&rsquo;s free and perfectly suitable for static site.</p>
<ol>
<li>Create a new repository
<img src="https://ws4.sinaimg.cn/large/006tKfTcgy1g0gabrlfurj31dz0u07b9.jpg" alt="" /></li>
<li>Push your content to master branch
<img src="https://ws2.sinaimg.cn/large/006tKfTcgy1g0gaf36divj314l0u0to5.jpg" alt="" /></li>
</ol>
<h2 id="auto-deploy-your-website-with-travis-ci">Auto deploy your website with Travis CI</h2>
<p>Doing build, copy, paste and push operations all the time is really annoying, so I decide to do it in an automatic way. Travis CI is a perfect solution for this, it works perfectly with Github, you just need to push your source content to Github, and let Travis CI do the rest.</p>
<ol>
<li>Sign up with your Github account.
<img src="https://ws1.sinaimg.cn/large/006tKfTcgy1g0garjc1wcj31o20u0dlr.jpg" alt="" /></li>
<li>Add your repository
<img src="https://ws4.sinaimg.cn/large/006tKfTcgy1g0gay5l3zkj31se0pejvc.jpg" alt="" />
<img src="https://ws2.sinaimg.cn/large/006tKfTcgy1g0gb01jd37j318g0nsad2.jpg" alt="" /></li>
<li>Create a new personal access token
<img src="https://ws4.sinaimg.cn/large/006tKfTcgy1g0gb3t3fy1j31ns0h443a.jpg" alt="" /></li>
<li>Set up your repository settings in Travis, add a new environment variable named GITHUB_TOKEN with the token you created in step 3
<img src="https://ws3.sinaimg.cn/large/006tKfTcgy1g0gb6dbo4yj31q10u0gsn.jpg" alt="" /></li>
<li><p>Add .travis.yml to your website root directory</p>
<pre><code class="language-yaml">language: go
go:
- '1.11' # Use Golang 1.11
# Specify which branches to build using a safelist
branches:
only:
- source
install:
# install hugo
- go get github.com/gohugoio/hugo
script:
# build website
- hugo
deploy:
provider: pages # Important, it means using github pages to deploy
skip-cleanup: true # Important, keep it to true
local-dir: public # Your content direcotry after building
target-branch: master # Which branch to push to
github-token: $GITHUB_TOKEN # Your github access token for travis
keep-history: true # keep the target-branch history
on:
branch: source # source content branch
</code></pre></li>
<li><p>Push your source content to <code>source</code> branch</p></li>
</ol>
<p>With all this done, next time your update your source content, Travis CI will deploy it automatically.
<img src="https://ws1.sinaimg.cn/large/006tKfTcgy1g0gbm1z0psj322c0bomzp.jpg" alt="" /></p>
</description>
</item>
<item>
<title>Python call dll library</title>
<link>/2016/python-call-cdll/</link>
<pubDate>Thu, 08 Sep 2016 00:00:00 +0000</pubDate>
<guid>/2016/python-call-cdll/</guid>
<description>
<h2 id="install-minggw-and-gcc">Install MingGW and gcc</h2>
<p>Install MingGW if you are using Windows, which I am. After intalling MingGW, you need to install gcc compiler. With all this done, you need to add your MingGW Bin directory to your PATH environment. Lauch cmd.exe, type &ldquo;gcc -v&rdquo;, you will see some information if you installed gcc successfully.</p>
<h2 id="write-some-code-in-c">Write some code in C</h2>
<p>A simple c file.</p>
<pre><code class="language-c">__declspec( dllexport ) int add2(int a, int b)
{
return a+b;
}
</code></pre>
<p>Do not add extern &ldquo;C&rdquo;, unless you are writing this in c++, otherwise there would be an error.</p>
<p><code>&quot;error: expected identifier or '(' before string constant extern C&quot;</code></p>
<h2 id="compile-your-c-file">Compile your C file</h2>
<p>Compile your c file with gcc.</p>
<p><code>gcc -shared -o mytest.dll test.c</code></p>
<p>&rdquo;-shared&rdquo; means making this a dll file.</p>
<h2 id="call-dll-in-python">Call DLL in python</h2>
<p>Using module <code>ctypes</code> to load a dll file.</p>
<pre><code class="language-python">import ctypes
dllPath = r'C:\Users\Administrator\Desktop\mylib.dll'
dll = ctypes.CDLL(dllPath)
#Change your c argument type to ctypes type
dll.add2.argtypes=[ctypes.c_int,ctypes.c_int]
print dll.add2(1,2)
</code></pre>
<p>If you want to load your dll by using ctype.windll.LoadLibrary(), you have to change your C code to</p>
<pre><code class="language-c">__declspec( dllexport ) int __stdcall add2(int a, int b)
{
return a+b;
}
</code></pre>
<p>otherwise, there would be an error.</p>
<p><code>&quot;ValueError: Procedure probably called with too many arguments (8 bytes in excess)&quot;</code></p>
</description>
</item>
<item>
<title>Control serial port with pyserial</title>
<link>/2016/pyserial/</link>
<pubDate>Sun, 21 Aug 2016 00:00:00 +0000</pubDate>
<guid>/2016/pyserial/</guid>
<description>
<h2 id="install-pyserail">Install pyserail</h2>
<p>Use pip to install pyserail module.</p>
<p><code>pip install pyserial</code></p>
<h2 id="open-serail-port">Open serail port</h2>
<p>First of all, import pyserial module.</p>
<p><code>import pyserial</code></p>
<p>Secondly, open your serial port. If you don&rsquo;t know which port you are using, you can do it like this.</p>
<pre><code class="language-python">def open_serialport():
PORT_NUM = 1
while True:
SERIAL_PORT = 'COM%d' % PORT_NUM
try:
ser = serial.Serial(port=SERIAL_PORT,baudrate=1048576,parity='N',bytesize=8,stopbits=1,timeout=0)
print &quot;OPEN SERIAL PORT ON %s&quot; % SERIAL_PORT
return ser
except Exception,e:
PORT_NUM = PORT_NUM + 1
</code></pre>
<h2 id="send-data-package">Send data package</h2>
<p>In my case, I need to send binary data to a device through serail port. I use the <code>struct</code> module to do this.</p>
<pre><code class="language-python">import struct
senddata = &quot;0015FEFF01FFFFFF0100010000020500&quot;
str2 = &quot;&quot;
while True:
if senddata:
str1 = senddata[0:2]
s = int(str1,16)
str2 += struct.pack('B',s)
senddata = senddata[2:]
else:
ser.write(str2)
print repr(str2)
time.sleep(2)
ack = ser.read(100)
print repr(ack)
</code></pre>
<h2 id="unpack-binary-data">Unpack binary data</h2>
<pre><code class="language-python">for bdata in ack:
ddata, = struct.unpack('B',bdata)
print &quot;%02x&quot; % ddata
</code></pre>
</description>
</item>
</channel>
</rss>