Posts

Showing posts from February, 2018

Master docker for developing

#### 0. Read This ``` FROM ubuntu:17.10 ENV LANG C.UTF-8 RUN apt-get update RUN apt-get install -y python3 RUN apt-get install -y python3-pip RUN apt-get install -y python3.6-dev COPY ./requirements.txt /usr/src/Local_Show/requirements.txt RUN pip3 install --no-cache-dir -r /usr/src/Local_Show/requirements.txt COPY . /usr/src/Local_Show/ RUN chmod +x /usr/src/Local_Show/tool.sh RUN mkdir -p /usr/src/Local_Show/files EXPOSE 2018 CMD ["bash", "/usr/src/Local_Show/tool.sh", "docker_run"] ``` #### 1. Basic Things `FROM` indicates what image you are based on. `ENV LANG C.UTF-8` sets what encoding your system will use, something will wrong in Chinese Showing without it `RUN` represents every stage you are going, docker will store that stage every time after that line is executed `COPY` is like `cp` The important thing is: **`CMD` is always the final line of your docker file, that command should be running forever as long as dock

Sanic could take the place of Flask

#### Why Sanic? 1. Faster and More stable 2. `async` request handler 3. `WebSockets` support #### For static files servering ``` app.static('/static', './static') ``` #### For jinja2 template rendering ``` from jinja2 import Template from sanic import Sanic from sanic.response import text template = Template('Hello {{ name }}!') app = Sanic() @app.route("/") async def test(request):         data = request.json         return text(template.render(name=data["name"])) app.run(host="0.0.0.0", port=8000) ``` ``` from jinja2 import Template import os from sanic import Sanic from sanic.response import html def render_template(html_name, **args):     with open(os.path.join(os.path.dirname(__file__), 'templates', html_name), 'r') as f:         html_text = f.read()     template = Template(html_text)     return html(template.render(args)) app = Sanic() @app.route("/") async d

一个小目标

音频算法工程师 1. 克服学历障碍,拥有自信人生; 2. 熟悉数字音频信号处理,熟悉模式识别和深度学习开源框架; 3. 音效算法开发或移动、音频内容分析、听歌识曲和哼唱识别实际项目经验者优先; 4. 编程基础扎实,熟悉算法和数据结构,熟练运用c\c++、python等开发语言; 5. 喜欢音乐,对音乐和音频技术的结合感兴趣者优先。 —————— 一年后评价: 这个真是有点难,1、2、5好做,4只有python比较熟

Use Apache to set a file server

``` <VirtualHost>         ServerName file.yingshaoxo.xyz         DocumentRoot "/var/www/html"                                                                   <Directory "/var/www">                                                                            Options Indexes FollowSymLinks MultiViews                                                    AllowOverride None                                                                          Order allow,deny                                                                            allow from all                                                                          </Directory> </VirtualHost> ``` ``` systemctl restart apache2 ``` When you finished doing this, you could remove `/var/www/html/index.html`, then add some folder or file into `/var/www/html/` In the end, you will find your file right in `file.yingshaoxo.xyz`

Apache virtualhost setting for web-sockets

##### Environment 1. A records in DNS manager | Type | Name | Value | | A | blog | your_server_ip | | A | math | your_server_ip | 2. Set up apache2 with this https://certbot.eff.org/ 3. Add necessary module ``` a2enmod proxy proxy_http proxy_wstunnel proxy_balancer lbmethod_byrequests systemctl restart apache2 ``` ##### HTML Codes ```         var ws_link = 'ws://' + location.hostname + "/ws/";         if (window.location.protocol === 'https:') {             ws_link = 'wss://' + location.hostname + "/wss/";         }         var ws = new WebSocket(ws_link); ``` ##### Apache Codes (at /etc/apache2/sites-available/000-default.conf) ``` <VirtualHost *:80>         ServerName blog.yingshaoxo.xyz         ProxyRequests Off         ProxyPreserveHost On         ProxyPass        "/" "http://127.0.0.1:2018/"         ProxyPassReverse "/" "http://127.0.0.1:2018/" </VirtualHost