eRic eric Nov. 18, 2015, 11:45 a.m. Asynchronous HTTP requests in Python 3.5 Nov. 9, 2015, 4:32 a.m. asynchronous-http-requests-in-Python-3-5 eric <p>Just a snippet with aiohttp.</p> <pre><code class="lang-python">import aiohttp import asyncio async def get_status(url, id): r = await aiohttp.get(url) print(r.status, id) r.close() tasks = [] for i in range(100): tasks.append(asyncio.ensure_future(get_status(&#39;https://api.github.com/events&#39;, id=i))) if...</code></pre> How to Watermark A Video with Python Oct. 18, 2015, 2:23 a.m. how-to-watermark-a-video-withpython eric <h2>Why Watermarking?</h2> <p>Preventing people from saving video contents from your web site is never possible, because, firstly, video contents are always streamed to users' device, users just cannot watch the video without retrieving it, secondly, people can always do a screen recording to save content. </p> ... A Python Web Crawler Helper Oct. 9, 2015, 7:45 p.m. a-python-web-crawler-helper eric <p>I was tired of writing the similar bit of code every time I wanted to craw something from the web. So, I wrote this helper to save the boring part of the work. </p> <p>I call it a helper because it's definitely not a framework and it's so simple that I don't want to call it a library. It's also the firs...</p> A new editor Oct. 9, 2015, 5:21 a.m. a-new-editor eric <p>Before adding this editor I would usually use some third party markdown editor and then copy-paste the code to Django's admin, which worked fine, until I finally can't tolerant the user experience. </p> <p>Django's admin is fine, for content management, but is bad to actual writing and editing. I was re...</p> Solve Proftpd 503 error when shell set to /bin/false Aug. 1, 2015, 10:48 p.m. proftpd-503-error-when-shell-set-to-bin-false eric <p>This issue is caused by the directive <code>RequireValidShell</code>. When set to on (which is the default), Proftpd will not allow users who do not have a shell binary listed in <code>/etc/shells</code> to login. To solve this problem, either add <code>/bin/false</code> to <code>/etc/shells</code> OR set <code>RequireValidShell</code> to <code>off</code> in <code>/etc/proftpd/p...</code></p> Flask-mongoengine pagination performance issue April 19, 2015, 6:48 a.m. Flask-mongoengine-pagination-performance-issue eric <p>So I'm using flask-mongoengine as my ORM in many projects.</p> <p>The pagination comes with it is very useful and easy to use, especially the <code>iter_pages()</code> function. </p> <p>However, there's a problem with flask-mongoengine's pagination that can cause a huge performance lag. The <code>count()</code> function used to calcula...</p> Being caught cheating dose not make one victim Oct. 14, 2014, 4:02 a.m. Being-caught-cheating-dose-not-make-one-victim eric <p>Recently, GitHub's student's pack has made Digitalocean and it's free $100 promo the headlines again.</p> <p>As an university student, I'm happy with such an offer from GitHub and it's partners.</p> <p>I knew people who are not students will falsely claim the special offer only for students, but I didn't see t...</p> How to Get an 8 in IELTS Without Preparation Sept. 25, 2014, 12:46 a.m. how-to-get-an-8-in-IELTS-without-preparation eric <ol> <li>Study English hard for years until one 1 month before the test</li> <li>Make sure you don't know anything about the test</li> <li>Spend the month before test without anything about English</li> <li>Go to the test and get your 8</li> <li>People will think you're some sort of god</li> </ol> Vultr, better than DigitalOcean Sept. 12, 2014, 8:19 p.m. vultr-better-than-digitalocean eric <p><a href="http://www.vultr.com/?ref=6811092">Vultr</a> is a cloud hosting provider which was usually recognized as a copy of digitalocean.</p> <p>I was not optimistic about it. Because the first time I visited their site, it was like a cheap VPS povider who will set up 120 VMs in a E3 powered CPU with 120GB RAM. Besides, at that time ,there was a prom...</p> how to make a base64 image downloadable Aug. 27, 2014, 2:42 a.m. how-to-make-a-base64-image-downloadable eric <p>Using Base64 code to present a image in web pages can be of a lot of benefit, especially when you use Javascript to process a image file and give the result, because this cost no bandwidth and no server-side CPU usage.</p> <p>However, in some browsers, especially mobile browsers, the Base64 encoded file...</p> FairyBBS SAE新版本发布,部署更方便 July 26, 2014, 1:24 a.m. fairybbs-sae-update-to-004 eric <p>SAE版本更新到了和github上的版本一样的功能,而且有加强的地方,部署也更加方便了。</p> <p>首先,下载地址:</p> <p><a href="http://pan.baidu.com/s/1i3ggHq1">http://pan.baidu.com/s/1i3ggHq1</a></p> <p>然后,部署方式:</p> <ol> <li>在SAE创建一个应用,上传代码包</li> <li>开启mysql, kvdb服务</li> <li>分别创建domain名为avatar和upload的strorage bucket,用于储存上传的头像和图片文件</li> <li>访问应用(可能需要刷新两次)</li> <li>注册的第一个用户为超级用户</li> </ol> <p>比普通版增加的东西:</p> <ol> <li>采用simditor编辑器,含有图片上传功能</li> <li>/panel里面可以修改标题和导航处的文字和友情链接</li> </ol> <p>说明:</p> <ol> <li>有2个后台,一个是/pan...</li></ol> 这个博客代码放到了github上 July 14, 2014, 10:22 a.m. source-code-is-available-on-github eric <p>地址 <a href="https://github.com/ericls/djanblog">https://github.com/ericls/djanblog</a></p> <p>这个博客的代码简单 (我觉得还可以更简单,但是我水平有限。。)</p> <p>除了jquery, fontawesome就没几行东西了</p> <p>模板是抄的farbox的default</p> <p>使用django框架 1.7版本</p> <p>一共有5个view 2个function 和 3个class</p> <p>没有category 只有 tag</p> <p>模版里面使用regroup来做的archive</p> mysql设置二进制日志保存天数 June 15, 2014, 2:50 p.m. set-mysql-bin-log-expire eric <p>只需要在<code>/etc/my.cnf</code>加入</p> <pre><code>expire_logs_days = 10 </code></pre> <p>再重启mysql服务就可</p> 把博客用Django1.7 beta重写了 May 22, 2014, 12:47 a.m. rewrite-with-django-17beta eric <p>听闻Django1.7是一个令人激动的版本,测试之后确实如此。特别是原生的migration功能,相当好用。它不仅比south方便,而且更智能,而且方便。还能探测是否是对field的重命名和为之前没有记录migration的model创建migration。</p> <p>这次重写还尝试了Class Based View,感觉在一些典型的场景下应用还是相当方便和舒适的。 然后呢,把整个project的目录优化了,尽力达到了一种reusable的境界。同时也发现之前写的东西至少在reusability方面是一坨翔。</p> <p>对了对了,模板是用的Farbox现在的default</p> 一个我想记得的故事 May 9, 2014, 11:48 a.m. a-story-i-want-to-remember eric <p>第一人称说</p> <p>在医院排队 前面的前面是一对很老的夫妇</p> <p>老太太生病了 老爷爷来陪她看病</p> <p>医生说是情况很严重 要马上做手术</p> <p>老爷爷问 多少钱</p> <p>医生说 反正要很多很多钱</p> <p>老太太说 我们还是回去吧</p> <p>于是他们就相互搀扶着走了</p> <p>我也就走了</p> FairyBBS,VPS部署实例 April 23, 2014, 11:47 a.m. FairyBBS-vps-deployment-example eric <p><strong>给大家的部署说明</strong></p> <p>因为很多同学的VPS已经装了LNMP或者nginx等环境或软件</p> <p>这个帖子就尽量详细说一下如何在这样的VPS上面部署一个django应用(fairybbs为例)</p> <p>(这里采用supervisor配合nginx+uwsgi的方式)</p> <h3>1.配置Django</h3> <p>首先,登陆到你的VPS上(暂时不说安全性,全程root账户)</p> <p>然后,cd到一个拿来放网站的目录,比如<code>/data/www/</code></p> <p>在这里 我们先使用virtualenv创建一个虚拟环境名为fairyenv</p> <p>执行<code>virtualenv fairyenv</code></p> <p><em>(virtualenv的安装各个distro各个版本都不一样 就不在这里说了)</em></p> <p>再来 ...</p> 一条命令解决EnvironmentError: mysql_config not found March 21, 2014, 11:46 a.m. sovle-mysql_config-not-found eric <p>找不到mysql_config一般是由于通过lnmp.org或者其他方式安装mysql以后mysql_config是在<code>/usr/local/mysql/bin/</code>里面,这里面的文件不是在任意位置都可以访问的</p> <p><strong>解决方法:</strong></p> <p>执行</p> <pre><code>ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/mysql_config </code></pre> <p>将mysql_config链接到<code>/usr/local/bin</code>目录下</p> FairyBBS开源 March 14, 2014, 11:44 a.m. FairyBBS-is-now-opensource eric <p>FairyBBS是一套用Django开发的简洁论坛程序</p> <ul> <li>下载:<a href="https://github.com/ericls/FairyBBS">Github</a></li> <li><p>演示:<a href="http://fairybbs.com/">FairyBBS</a></p> </li> <li><p>手机界面:</p> </li> </ul> <p><img src="http://eric-cdn.u.qiniudn.com/FkfUVQTWaJRat1CV-dZKhT4GwjTl" alt="FairyBBS Mobile"></p> 全球未被注册的3位不含v的.pw域名 Dec. 16, 2013, 11:44 a.m. available-3-character-pw-domain-without-v eric <p>扫描了10多小时 api还有不准的地方,需要手动验证,最后一共发现有<code>19</code>个</p> <ul> <li>lma.pw</li> <li>lni.pw</li> <li>lxd.pw</li> <li>luq.pw</li> <li>ltu.pw</li> <li>lti.pw</li> <li>lsu.pw</li> <li>lsi.pw</li> <li>lra.pw</li> <li>lqu.pw</li> <li>lqo.pw</li> <li>lqi.pw</li> <li>lpu.pw</li> <li>lpa.pw</li> <li>loz.pw</li> <li>loj.pw</li> <li>mje.pw</li> <li>mli.pw</li> <li>ule.pw</li> </ul> <p>恩 如果有中意的可以尽快注册哦,拿来做私人短网址什么的</p> <p>而且.pw最近活动16RMB 一年到处都是哦</p> <p>另外,短网址程序开发中,最近期末考试进度可能有点慢,回尽快跟大家见面</p> 自动备份数据库到百度云 Dec. 10, 2013, 11:42 a.m. backup-sql-automatically-to-bcs eric <h3>使用步骤</h3> <ol> <li>准备工作:脚本文件获取 <a href="http://eric-cdn.u.qiniudn.com/back_Sql.py">点击这里</a>(PS:之前在loc下载的需要在首行加入<code># -*- coding: utf-8 -*-</code>),百度开发者申请</li> <li>下载安装百度官方sdk(<a href="http://bcs.duapp.com/cplat-01/bcs/Baidu-BCS-SDK-Python-1.3.2.zip">点击下载</a>,进入解压后的目录,执行<code>python setup.py install</code>)</li> <li>编辑脚本文件,里面有注释,就不多说了,ak sk在自己的百度开发者中心获取(<a href="http://developer.baidu.com/wiki/index.php?title=docs/cplat/stor/console">详情</a>)。</li> <li>执行<code>python backup_sql.py</code>测试是否成功,不成功请检查报错原因</li> </ol> <h3>crontab自动执行</h3> <p>例子</p> <ol> <li><p><code>crontab -e</code></p> </li> <li><p>加入<code>0 1* * * python /root/backup_sql.py</code> 表示每天1点0分开始执行备份</p> </li> <li><p>没了</p> </li> </ol> 不做站长了 Dec. 8, 2013, 11:41 a.m. do-not-want-to-be-a-webmaster-anymore eric <p>做个人站长真的是一个费力费神的事情,</p> <p>操着卖白粉的心,也只能够服务器和域名的开销</p> <p>今后只保留开发网站的兴趣,不再去经营网站</p> 我喜欢平凡的人 Dec. 3, 2013, 11:40 a.m. i-admire-ordinary-people eric <p>我喜欢平凡的人</p> <p>因为平凡才感觉真实</p> <p>每一个人身上都闪耀着人性和生命的光芒</p> <p>人们会开心、会难过、会笑、会哭、会爱、会恨</p> <p>他们坚强,他们脆弱,他们会做出自己的选择,对的或是错的</p> <p>我也钦佩那些伟大的人</p> <p>但我钦佩他们也是因为发现他们是真正的有血友肉的人,不是神</p> <p>他们会让我看到我和他们之间没有什么区别,他会是我,我会是他</p> <p>平凡或伟大,我们都是活生生的人</p> <p>历史的车轮,在我们每一个人的脚下</p> <p>我清楚</p> <p>从来就没有什么救世主,也没有神仙皇帝</p> <p>所以,这个世界上 我只关心三个东西</p> <p>我自己、身边的人、全人类</p> <p>这三个东西 就是我存在的目的</p> 推荐目前用的VPS Nov. 29, 2013, 11:39 a.m. acrosvm-that-im-currently-using eric <p><img src="http://eric-cdn.u.qiniudn.com/FqIbWXiERNekz-VUJj-EMLNYafHr" alt="AcrosVM" title="AcrosVM"></p> <h3>AcrosVM</h3> <p>这家用了一个月了,也该发发软文了</p> <p>这是一家hostigation旗下的VPS服务器提供商,主要面向国内用户</p> <p>我在这家持有两个vps,一个128M,也就是现在用的这个 节点是03</p> <p>还有一个1G的,节点是01</p> <p>用了一个月了 感觉不错 没有出现过任何问题 虽然是openVZ但是超收不严重</p> <p>这一点从上新node的频率和内存使用率上很容易看出来。</p> <p>暂时没有发现跑路风险,而且hostigation这么大的业务,应该也不会有太大风险</p> <p>但是以防万一,我还是做了每日数据库异地备份。</p> <p>CPU是E3-1230的,其他硬盘、带宽、流量之类的 反正对我来说,美国的服务器都满足要求</p> <p><a href="http://126.am/acrosvm" title="acrosvm">可以点击这里了...</a></p> 脱离SAE,目前部署在某128M VPS Nov. 25, 2013, 11:37 a.m. runs-on-a-128m-ram-vps eric <p>再也不想用SAE了,虽然能绑定域名但是那个在线率不是一般的低,每周都只有70%多,即使在线也几乎进不去。</p> <p>刚好hostigation旗下品牌正在促销,128M的VPS只要60RMB一年(OPENVZ),非常爽。</p> <p>这个博客程序本来就没几行代码,在这上面跑还是毫无压力的。</p> <p>跑这博客大概用了这些东西:</p> <ol> <li>python</li> <li>uwsgi</li> <li>supervisord</li> <li>sqlite</li> <li>还有django,virtualenv等,不知道是不是算'在服务器上跑'</li> </ol> <p>用17ce.com测试的时候,内存占用大概在30%左右,负载无变化</p> <p>恩,还是挺划算的~</p> Where to host a Website Targeted at China Nov. 25, 2013, 11:34 a.m. choose-where-to-host-a-website-targetted-at-china- eric <p><img class="alignnone" alt="Flag of China" src="http://eric-cdn.u.qiniudn.com/FgsjvmYQvD2fz57Bnqvv2-ZowuP0" width="200" height="133" /></p> <p>As we know,an ICP license is required before your domain names are accessible if pointed to a server in  Mainland China.Namely,you have to get the license , if you want host your sites within China Mainland.Unfortunately,it's extremely hard for individuals who's not Chinese to get an ICP license...</p> 我要战胜拖延症 Nov. 25, 2013, 11:30 a.m. i-want-to-get-rid-of-procrastination eric <p><img src="http://eric-cdn.u.qiniudn.com/FtuqIOy_ctehLqK-1m4TPKlI1hVD" alt="Procrastination" title="Procrastination"> 最近越来越意识到拖延症对我的负面影响,让我养成把所有事情都放在deadline前一个合适的时间才开始做的习惯(如上图,图片来自网络)。</p> <p>这种习惯性的拖延已经让我产生了习惯性的自责和焦虑等等负面情绪。这个很容易理解吧,比如本来准备7点去上自习,但是我总会在寝室里面拖到8点才去。当我发现我这一个小时无非是坐在电脑面前瞎点鼠标的时候,会产生一种强烈的自责感。而当这种情况长期发生,便会成为一种习惯,会使我更加地自责甚至丧失自信、焦虑。更恶劣的情况是为自己找一个借口,然后堂而皇之地放弃。</p> <p>我真的很希望像《搏击俱乐部》里说的一样有一个人能拿枪指着我的头,逼着我做我自己想做的事情,如果我不做我自己想...</p> My View on Academic Plagiarism Nov. 25, 2013, 11:29 a.m. My-View-on-Academic-Plagiarism eric <p>It’s increasingly common to see that people use other’s words, ideas, computer programs, or other academic work in their own work or essays as if they were their own, without giving proper credit. This dishonesty is considered as academic plagiarisms. With the help of the Internet, in today’s Chi...</p> The basic functions are finished Nov. 25, 2013, 11:27 a.m. the-basic-functions-are-finished eric <p>Todos:</p> <ol> <li>file uploading(&radic;)</li> <li>comment function(&radic;)</li> <li>markdown support(&radic;)</li> <li>a customized admin panel(&radic;)</li> </ol>