<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Web on Blog - uTIcARdI</title><link>https://blog.gainskills.top/tags/web/</link><description>Recent content in Web on Blog - uTIcARdI</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 04 Aug 2025 18:51:32 +1200</lastBuildDate><atom:link href="https://blog.gainskills.top/tags/web/index.xml" rel="self" type="application/rss+xml"/><item><title>VSCode as an IDLE for Django</title><link>https://blog.gainskills.top/2019/11/15/vscode-as-idle-for-Django/</link><pubDate>Fri, 15 Nov 2019 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2019/11/15/vscode-as-idle-for-Django/</guid><description>&lt;p&gt;This blog is about using MS VSCode as Django IDLE (OS: Mac OX, the steps are referenceable on Linux, Windows).&lt;/p&gt;
&lt;h5 id="1-download-installation-files-and-install-ms-vscode-python-from-following-links"&gt;1. Download installation files and install MS VScode, Python from following links:&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://code.visualstudio.com/download"&gt;MS VSCode&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://www.python.org/downloads/"&gt;Python3&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Optional:&lt;/strong&gt; On Mac OS, I recommend &lt;a href="https://brew.sh/"&gt;homebrew&lt;/a&gt; for Python Installation because third party libraries&amp;rsquo; dependency will be processed smoothly.&lt;/p&gt;
&lt;p&gt;Install &lt;code&gt;homebrew&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/usr/bin/ruby -e &lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;&lt;span style="color:#66d9ef"&gt;$(&lt;/span&gt;curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install&lt;span style="color:#66d9ef"&gt;)&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Install &lt;code&gt;Python3&lt;/code&gt;:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-shell" data-lang="shell"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;brew install python@3
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;h5 id="2-python-extension"&gt;2. Python Extension&lt;/h5&gt;
&lt;p&gt;Launch VSCode and install the Extension: &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-python.python"&gt;Python&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Post a file to Flask by Curl via API</title><link>https://blog.gainskills.top/2019/02/20/post-file-by-curl-to-flask-via-api/</link><pubDate>Wed, 20 Feb 2019 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2019/02/20/post-file-by-curl-to-flask-via-api/</guid><description>&lt;p&gt;&lt;a href="https://curl.haxx.se/docs/manpage.html"&gt;Curl&lt;/a&gt; is widely used in command lines or scripts to transfer data.&lt;br&gt;
Different ways to use curl to post a file to a web server with samples (from both client-side and server: &lt;a href="http://flask.pocoo.org/"&gt;Python-Flask&lt;/a&gt; side) will be discussed because it took me a while on the server-side to receiving the data from client.&lt;br&gt;
I would like to add samples of &lt;a href="http://docs.python-requests.org/en/master/"&gt;Python-requests&lt;/a&gt;, &lt;a href="https://www.getpostman.com/"&gt;Postman&lt;/a&gt; later.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;h5 id="started-with"&gt;Started with&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;macOS Mojave&lt;/li&gt;
&lt;li&gt;Python 3.7.2&lt;/li&gt;
&lt;li&gt;Flask 1.0.2&lt;/li&gt;
&lt;li&gt;Flask-RESTful 0.3.7&lt;/li&gt;
&lt;li&gt;curl 7.54.0 (x86_64-apple-darwin18.0)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The Flask code:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-Python" data-lang="Python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Py file name: simple.py&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;from&lt;/span&gt; flask &lt;span style="color:#f92672"&gt;import&lt;/span&gt; Flask, request
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;from&lt;/span&gt; flask_restful &lt;span style="color:#f92672"&gt;import&lt;/span&gt; Api, Resource, reqparse
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; werkzeug
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;app &lt;span style="color:#f92672"&gt;=&lt;/span&gt; Flask(__name__)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;api &lt;span style="color:#f92672"&gt;=&lt;/span&gt; Api(app)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;class&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;kzwebfile&lt;/span&gt;(Resource):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;post&lt;/span&gt;(self, filename):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;pass&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;api&lt;span style="color:#f92672"&gt;.&lt;/span&gt;add_resource(kzwebfile, &lt;span style="color:#e6db74"&gt;&amp;#39;/&amp;lt;string:filename&amp;gt;&amp;#39;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; __name__ &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;__main__&amp;#34;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; app&lt;span style="color:#f92672"&gt;.&lt;/span&gt;run()&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;</description></item><item><title>Hugo-Customization</title><link>https://blog.gainskills.top/2019/02/06/hugo-customization/</link><pubDate>Wed, 06 Feb 2019 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2019/02/06/hugo-customization/</guid><description>&lt;p&gt;A list about how I customize Hugo and why I did the change, the post will be updated continuously.&lt;/p&gt;
&lt;h3 id="1-fractions"&gt;1. &lt;a href="https://gohugo.io/getting-started/configuration/"&gt;fractions&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Network Engineer should care about this, because it shows wrong &lt;em&gt;IP/mask&lt;/em&gt; format with default value:















&lt;div align="center"&gt;
 &lt;figure style="padding: 0.8rem; margin: 2rem 0; border: thin #c0c0c0 solid; border-radius: 10px; width: 310px; max-width: 88%; "&gt;
 &lt;a href="https://blog.gainskills.top/img/postimgs/2019/02/01-opt_hu_197622209dbd8d69.png" data-fancybox data-caption=fractions&amp;#32;with&amp;#32;default&amp;#32;value &gt;
 &lt;img data-src="https://blog.gainskills.top/img/postimgs/2019/02/01-opt_hu_32e1677037f5416.png" class="img-responsive img-lazyload" alt=fractions&amp;#32;with&amp;#32;default&amp;#32;value style="height: 140px;"/&gt;
 &lt;/a&gt;
 &lt;figcaption class="text-capitalize"&gt;
 &lt;small&gt;fractions with default value&lt;/small&gt;
 &lt;/figcaption&gt;
 &lt;/figure&gt;
&lt;/div&gt;

Disable it in config.toml:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-toml" data-lang="toml"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[&lt;span style="color:#a6e22e"&gt;blackfriday&lt;/span&gt;]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;fractions&lt;/span&gt; = &lt;span style="color:#66d9ef"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;
&lt;h3 id="2-hreftargetblank"&gt;2. hrefTargetBlank&lt;/h3&gt;
&lt;p&gt;This default value of the option is &lt;code&gt;false&lt;/code&gt; which means external links(The wording was corrected to &amp;ldquo;absolute&amp;rdquo; from &amp;rsquo;external&amp;rsquo; on Hugo official doc).
I prefer to change the value to &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Hugo-Versioning</title><link>https://blog.gainskills.top/2019/01/27/hugo-versioning/</link><pubDate>Sun, 27 Jan 2019 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2019/01/27/hugo-versioning/</guid><description>&lt;p&gt;Hugo provides the detail &lt;a href="https://gohugo.io/hosting-and-deployment/"&gt;instructions&lt;/a&gt; about how to deploy it on different environment.&lt;/p&gt;
&lt;p&gt;At first, I followed &lt;a href="https://gohugo.io/hosting-and-deployment/hosting-on-github/#deployment-of-project-pages-from-docs-folder-on-master-branch"&gt;Deployment of Project Pages from /docs folder on master branch&lt;/a&gt;, and put all files in one repository.&lt;/p&gt;
&lt;p&gt;I continue to check &lt;a href="https://gohugo.io/hosting-and-deployment/hosting-on-github/#deployment-of-project-pages-from-your-gh-pages-branch"&gt;Deployment of Project Pages From Your gh-pages branch&lt;/a&gt; after I did some customization on &lt;a href="https://themes.gohugo.io/hugo-theme-cleanwhite/"&gt;hugo-theme-cleanwhite&lt;/a&gt; and want to publish the change to the &lt;a href="https://github.com/gainskills/hugo-theme-cleanwhite"&gt;forked branch&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Instead of the follow Hugo guide, I did some try myself. I searched &amp;ldquo;change a subfolder to another repository and found the article: &lt;a href="http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/"&gt;Moving Files from one Git Repository to Another, Preserving History&lt;/a&gt; but its case is:&lt;/p&gt;</description></item><item><title>Hugo-Images management</title><link>https://blog.gainskills.top/2019/01/25/post-img-mgmt-hugo/</link><pubDate>Fri, 25 Jan 2019 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2019/01/25/post-img-mgmt-hugo/</guid><description>&lt;p&gt;I introduced &lt;a href="2019/01/01/hello-world/"&gt;why&lt;/a&gt; I migrate my blog to github and Hugo here. Most of articles have been moved to here in 30 days. Next, I just want to talk about something about &lt;a href="https://blog.gainskills.top/2019/01/25/post-img-mgmt-hugo/"&gt;posts&amp;rsquo; images management&lt;/a&gt;, &lt;a href="https://blog.gainskills.top/2019/01/27/hugo-versioning/"&gt;versioning&lt;/a&gt;, &lt;a href="https://blog.gainskills.top/2019/02/07/hugo-customization/"&gt;theme customization/something about SEO&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id="before-start"&gt;Before start&lt;/h3&gt;
&lt;p&gt;All images will be compressed before I upload them for the post. Many tools that could do this, such as &lt;a href="https://tinypng.com/"&gt;tinypng&lt;/a&gt;, &lt;a href="http://upng.photopea.com/"&gt;UPNG&lt;/a&gt;. My choice is Tinypng because it supports variety formats and its &lt;a href="https://tinypng.com/developers/reference#%7Btpath(%22/developers%22)%7D"&gt;API&lt;/a&gt;.&lt;/p&gt;















&lt;div align="center"&gt;
 &lt;figure style="padding: 0.8rem; margin: 2rem 0; border: thin #c0c0c0 solid; border-radius: 10px; width: 1362px; max-width: 88%; "&gt;
 &lt;a href="https://blog.gainskills.top/img/postimgs/2019/01/01-opt_hu_7d302392f7ee3c76.png" data-fancybox data-caption=img&amp;#32;compression&amp;#32;(20M&amp;#32;to&amp;#32;5.1M) &gt;
 &lt;img data-src="https://blog.gainskills.top/img/postimgs/2019/01/01-opt_hu_e75b43c94fbfd0e8.png" class="img-responsive img-lazyload" alt=img&amp;#32;compression&amp;#32;(20M&amp;#32;to&amp;#32;5.1M) style="height: 400px;"/&gt;
 &lt;/a&gt;
 &lt;figcaption class="text-capitalize"&gt;
 &lt;small&gt;img compression (20M to 5.1M)&lt;/small&gt;
 &lt;/figcaption&gt;
 &lt;/figure&gt;
&lt;/div&gt;

&lt;p&gt;Tinypng&amp;rsquo;s APIs can be called by &lt;a href="http://docs.python-requests.org/en/master/"&gt;Python-Requests&lt;/a&gt; in this way:
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; os
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;from&lt;/span&gt; os &lt;span style="color:#f92672"&gt;import&lt;/span&gt; path
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; requests
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;from&lt;/span&gt; requests.auth &lt;span style="color:#f92672"&gt;import&lt;/span&gt; HTTPBasicAuth
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;picopt&lt;/span&gt;(root_path, apikey):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; f &lt;span style="color:#f92672"&gt;in&lt;/span&gt; os&lt;span style="color:#f92672"&gt;.&lt;/span&gt;listdir(root_path):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; fullurl &lt;span style="color:#f92672"&gt;=&lt;/span&gt; os&lt;span style="color:#f92672"&gt;.&lt;/span&gt;sep&lt;span style="color:#f92672"&gt;.&lt;/span&gt;join([root_path, f])
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; path&lt;span style="color:#f92672"&gt;.&lt;/span&gt;isdir(fullurl):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; picopt(fullurl, apikey)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;else&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; fullurl&lt;span style="color:#f92672"&gt;.&lt;/span&gt;endswith((&lt;span style="color:#e6db74"&gt;&amp;#39;.DS_Store&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;-opt.png&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;-opt.jpg&amp;#39;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#39;-opt.jpeg&amp;#39;&lt;/span&gt;)):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; print(&lt;span style="color:#e6db74"&gt;&amp;#39;ignore &amp;#39;&lt;/span&gt; &lt;span style="color:#f92672"&gt;+&lt;/span&gt; fullurl)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;continue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; print(&lt;span style="color:#e6db74"&gt;&amp;#39;processing &amp;#39;&lt;/span&gt; &lt;span style="color:#f92672"&gt;+&lt;/span&gt; fullurl)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;with&lt;/span&gt; open(fullurl, &lt;span style="color:#e6db74"&gt;&amp;#39;rb&amp;#39;&lt;/span&gt;) &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; imgf:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; content &lt;span style="color:#f92672"&gt;=&lt;/span&gt; imgf&lt;span style="color:#f92672"&gt;.&lt;/span&gt;read()
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; res &lt;span style="color:#f92672"&gt;=&lt;/span&gt; requests&lt;span style="color:#f92672"&gt;.&lt;/span&gt;post(
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; auth&lt;span style="color:#f92672"&gt;=&lt;/span&gt;HTTPBasicAuth(&lt;span style="color:#e6db74"&gt;&amp;#34;api:&lt;/span&gt;&lt;span style="color:#e6db74"&gt;%s&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; &lt;span style="color:#f92672"&gt;%&lt;/span&gt;(apikey), &lt;span style="color:#e6db74"&gt;&amp;#39;&amp;#39;&lt;/span&gt;), url&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#39;https://api.tinify.com/shrink&amp;#39;&lt;/span&gt;, data&lt;span style="color:#f92672"&gt;=&lt;/span&gt;content)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; print(res&lt;span style="color:#f92672"&gt;.&lt;/span&gt;json())
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; optimgurl &lt;span style="color:#f92672"&gt;=&lt;/span&gt; res&lt;span style="color:#f92672"&gt;.&lt;/span&gt;json()[&lt;span style="color:#e6db74"&gt;&amp;#39;output&amp;#39;&lt;/span&gt;][&lt;span style="color:#e6db74"&gt;&amp;#39;url&amp;#39;&lt;/span&gt;]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;# print(optimgurl)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; res &lt;span style="color:#f92672"&gt;=&lt;/span&gt; requests&lt;span style="color:#f92672"&gt;.&lt;/span&gt;get(
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; auth&lt;span style="color:#f92672"&gt;=&lt;/span&gt;HTTPBasicAuth(&lt;span style="color:#e6db74"&gt;&amp;#34;api:&lt;/span&gt;&lt;span style="color:#e6db74"&gt;%s&lt;/span&gt;&lt;span style="color:#e6db74"&gt;&amp;#34;&lt;/span&gt; &lt;span style="color:#f92672"&gt;%&lt;/span&gt;(apikey), &lt;span style="color:#e6db74"&gt;&amp;#39;&amp;#39;&lt;/span&gt;), url&lt;span style="color:#f92672"&gt;=&lt;/span&gt;optimgurl)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; filename, filetypestr &lt;span style="color:#f92672"&gt;=&lt;/span&gt; fullurl&lt;span style="color:#f92672"&gt;.&lt;/span&gt;rsplit(&lt;span style="color:#e6db74"&gt;&amp;#39;.&amp;#39;&lt;/span&gt;, &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; optfullurl &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;-opt.&amp;#39;&lt;/span&gt;&lt;span style="color:#f92672"&gt;.&lt;/span&gt;join([filename, filetypestr])
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;with&lt;/span&gt; open(optfullurl, &lt;span style="color:#e6db74"&gt;&amp;#39;wb&amp;#39;&lt;/span&gt;) &lt;span style="color:#66d9ef"&gt;as&lt;/span&gt; fd:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; chunk &lt;span style="color:#f92672"&gt;in&lt;/span&gt; res&lt;span style="color:#f92672"&gt;.&lt;/span&gt;iter_content(chunk_size&lt;span style="color:#f92672"&gt;=&lt;/span&gt;&lt;span style="color:#ae81ff"&gt;128&lt;/span&gt;):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; fd&lt;span style="color:#f92672"&gt;.&lt;/span&gt;write(chunk)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; print(&lt;span style="color:#e6db74"&gt;&amp;#39;optimized img file: &amp;#39;&lt;/span&gt; &lt;span style="color:#f92672"&gt;+&lt;/span&gt; fullurl)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; __name__ &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;__main__&amp;#34;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; devkey &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; postimgsfolder &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; picopt(postimgsfolder, devkey)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;</description></item><item><title>aiohttp/aiodns-Resolving using custom nameservers</title><link>https://blog.gainskills.top/2019/01/23/try-aiohttp/</link><pubDate>Wed, 23 Jan 2019 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2019/01/23/try-aiohttp/</guid><description>&lt;p&gt;&lt;a href="https://github.com/aio-libs/aiohttp"&gt;aiohttp&lt;/a&gt; is an Asynchronous HTTP client/server framework for asyncio and Python&lt;/p&gt;
&lt;p&gt;I tried it because of the features:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aiohttp.readthedocs.io/en/stable/client_advanced.html#tuning-the-dns-cache"&gt;Tuning the DNS cache&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aiohttp.readthedocs.io/en/stable/client_advanced.html#resolving-using-custom-nameservers"&gt;Resolving using custom nameservers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;With this, verifying the CDN&amp;rsquo;s POPs with different ISPs&amp;rsquo; DNS on single a point should be possible.&lt;/p&gt;
&lt;p&gt;Since the code on the official document is simple:&lt;/p&gt;
&lt;blockquote&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/blockquote&gt;
&lt;p&gt;from aiohttp.resolver import AsyncResolver&lt;/p&gt;
&lt;p&gt;resolver = AsyncResolver(nameservers=[&amp;ldquo;8.8.8.8&amp;rdquo;, &amp;ldquo;8.8.4.4&amp;rdquo;])
conn = aiohttp.TCPConnector(resolver=resolver)&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;
I tried it with following code:

~~~python
import aiohttp
import asyncio
from aiohttp.resolver import AsyncResolver

resolver = AsyncResolver(nameservers=[&amp;#34;114.114.114.114&amp;#34;])

async def dnstesting():
 async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False, use_dns_cache=False, resolver=resolver)) as session:
 r = await session.get(&amp;#34;http://google.com&amp;#34;)
 print(r.text)

asyncio.run(dnstesting())
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Run with following error:&lt;/p&gt;</description></item><item><title>Hello World</title><link>https://blog.gainskills.top/2019/01/01/hello-world/</link><pubDate>Tue, 01 Jan 2019 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2019/01/01/hello-world/</guid><description>&lt;p&gt;Hello World!&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gohugo.io/"&gt;Hugo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pages.github.com/"&gt;Git Page&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/zhaohuabing/hugo-theme-cleanwhite"&gt;hugo-theme-cleanwhite&lt;/a&gt;
I did some changes on the theme, will share it after testing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I spend days and finally get this Blog runs up. In the next days, will move the posts from WordPress: &lt;a href="http://hanbaobao2005.WordPress.com"&gt;hanbaobao2005.WordPress.com&lt;/a&gt; to here.&lt;/p&gt;
&lt;p&gt;Happy Holidays :-)&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Update at Jan-26-2019:&lt;/p&gt;
&lt;p&gt;I have been running blogs for years, started at &lt;a href="https://blog.163.com/excellent_2008"&gt;NetEase&lt;/a&gt;(NetEase shut down its blog service at Nov-30-2018), then to &lt;a href="http://69444091.blogspot.com/"&gt;Blogger&lt;/a&gt;(The blog was closed), and &lt;a href="http://hanbaobao2005.WordPress.com"&gt;WordPress&lt;/a&gt; after Blogger was blocked within China. I setup the blog on &lt;a href="https://pages.github.com/"&gt;Git Page&lt;/a&gt; and &lt;a href="https://gohugo.io/"&gt;Hugo&lt;/a&gt; because I still unable to get used to the WordPress editor even I have used it for more than 2 years.&lt;/p&gt;</description></item><item><title>Flask, Flask-WTF, Flask-Bootstrap, Select2, jinja2 integration</title><link>https://blog.gainskills.top/2018/04/16/flask-flask-wtf-flask-bootstrap-select2-jinja2-integration/</link><pubDate>Mon, 16 Apr 2018 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2018/04/16/flask-flask-wtf-flask-bootstrap-select2-jinja2-integration/</guid><description>&lt;p&gt;I intend to acquire the Python skill on web after years&amp;rsquo; work on data processing, so I started with &lt;a href="http://flask.pocoo.org/"&gt;Flask&lt;/a&gt; by the following Miguel &lt;a href="https://blog.miguelgrinberg.com/author/Miguel%20Grinberg"&gt;Grinberg&amp;rsquo;s instruction&lt;/a&gt;: &lt;a href="https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world"&gt;The Flask Mega&lt;/a&gt;, you can learn how to integrate bootstrap with your project from it.&lt;/p&gt;
&lt;p&gt;After that, you can learn how to integrate select2 with your project by reading &lt;a href="https://blog.csdn.net/zheng_integer/article/details/59507942"&gt;Flask Web开发:用Select2实现类似知乎的标签系统&lt;/a&gt; as a guide.&lt;/p&gt;</description></item><item><title>30分钟上手Python网络爬虫</title><link>https://blog.gainskills.top/2018/01/30/30min-python-web-scrapper/</link><pubDate>Tue, 30 Jan 2018 00:00:00 +0000</pubDate><guid>https://blog.gainskills.top/2018/01/30/30min-python-web-scrapper/</guid><description>&lt;p&gt;原文链接: &lt;a href="https://hackernoon.com/30-minute-python-web-scraper-39d6d038e5da"&gt;https://hackernoon.com/30-minute-python-web-scraper-39d6d038e5da&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;此翻译已经获得作者许可。对原文、本文任何形式的转载、引用，必须知会作者&lt;/p&gt;
&lt;p&gt;我想用Python和&lt;a href="http://www.seleniumhq.org/"&gt;Selenium&lt;/a&gt;做网络爬虫有一会了，但是一直没有实施。几天之前，我决定小试一下。看起来令人望而却步，但实现代码从&lt;a href="https://unsplash.com/"&gt;Unsplash&lt;/a&gt;抓取一些漂亮的图片却是相当容易的。&lt;/p&gt;
&lt;h4 id="简易图片爬虫的食材"&gt;简易图片爬虫的食材&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.python.org/downloads/"&gt;Python&lt;/a&gt;(3.6.3或更新的版本)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jetbrains.com/pycharm/download/#section=windows"&gt;Pycharm&lt;/a&gt;(社区版就够了)&lt;/li&gt;
&lt;li&gt;pip install &lt;a href="http://docs.python-requests.org/en/master/user/install/#install"&gt;requests&lt;/a&gt; &lt;a href="https://pillow.readthedocs.io/en/latest/installation.html#basic-installation"&gt;Pillow&lt;/a&gt; &lt;a href="http://selenium-python.readthedocs.io/installation.html#downloading-python-bindings-for-selenium"&gt;selenium&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/mozilla/geckodriver/releases/latest"&gt;geckodriver&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.mozilla.org/en-US/firefox/new/"&gt;Mozlla Firefox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;互联网&lt;/li&gt;
&lt;li&gt;30分钟(或更少）&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;*译者注：&lt;/p&gt;</description></item></channel></rss>