280篇 Default中的文章

自媒体视频相关常用的几个工具

##1 VideoScribe: 可以录制模拟人手在绘图写字的视频。可以试用。
Screen Shot 2019-06-21 at 01.44.42.png
https://www.videoscribe.co/

##2 typemonkey: After Effects的脚本。抖音上经常看到那种文字旋转动画,适合朗读配音完
类似的App有<字说>等
Screen Shot 2019-06-21 at 01.53.08.png
https://aescripts.com/typemonkey/

##3 Final Cut Pro 或者 Adobe Premiere Pro

##4 Adobe After Effects 后期特效工具,常见影视拍摄时用绿布做背景,然后用此软件添加飞人特效

##5 ArcTime 字幕工具,一大亮点就是选择音频时间轴就可以搞定字幕
http://arctime.cn/index.html

More ~

docker-compose 指定文件

完整的文档在这里https://docs.docker.com/compose/reference/overview/

这里有个坑,不注意看可能和我一样会碰到,

docker-compose -f xxx.yml up -d, 这里 -f必须前置,否则执行一堆提示

More ~

容器化之路 - 网站迁移记录

从事云计算有几个年头了,但是上层容器化的应用还是用的少,以往经验就是买个虚拟机(VM),然后安装wordpress之类的应用,安装相应所需的环境,如php5.x, mysql 5.x, apache2.x, nginx1.x等等, 或者用那种一链安装脚本安装完环境,再把本地开发的网站通过sftp上传到vm, 配好域名就OK了。

这但这个有个问题,单机部署的网站或工具类型多了,比如装个python环境,有python2.7, 有python3等,即使可以用virtualenv,但周边的应用如mongodb、redis一堆,显得这个节点非常臃肿,如果要迁移上面的某个网站就很麻烦了,有了容器可以很好的隔离应用,俗称微服务或者服务治理。

接触docker是在华为工作期间升级minios, 修改裸金属所需的minios中的Dockerfile,变更基础镜像和安装底层所需的lib. 调试时经常会在生成的docker窗器与host之间共享lib,

最近因为频繁面试,大多数公司都要求做PaaS平台,很少公司做IaaS层面的,所以密集自学了Docker,Kubernetes. 深切体会到使用docker或k8s部署的便利。所以就小试牛刀来迁移下自己的网站,之所以迁移,一是因为这个vm年底就到期了,到时如果续费比较贵就想能够很快的迁移。

当前的情况是在腾讯云我有两个VM, 一个在上海,一个在香港。上海的就是搞个网站备案后用的,上面写点研发日志或跑些爬虫之类的。腾讯云的kubernetes可以托管,好处是省了硬件资源的开销和k8s环境的维护,不过还是计时收费的,好在每小时不算贵,一年下来不到200. 当然你如果不差钱也可以搞几台,他们说最低要3台,2核8G的配置。

docker-compose学完docker就紧接着想怎么部署一个网站,按行话叫容器编排,可以用docker swarm,类似于k8s,可以对应用节点扩容,比较方便。但是我就一个vm,差钱,也不整这么复杂,直接用docker-compose来组合web前后台和数据库。
web这边用Dockerfile来编译,用的基础镜像FROM php:7.2-apache,内容参考的wordpress,这个可以在github和dockerhub上找到。重要的地方就是docker-compose里将数据挂载在Host的目录上。当然如果有云硬盘也可以考虑专门放数据,这样迁移就更方便了。

More ~

MySQL的主从配置

主从配置常用作考虑在主服务器上做读写操作,从服务器相当于备用节点。但也有主服务只写,slave只读这种达到读写分离。如果有多个从服务器,那其实每个从服务器可以单独来读,如数据分析、远程调用等而不暴露主库。

记得面试时问我MySQL的主从是怎样的,虽然使用过MySQL,但都是单机部署经验,随口一说结果被面试官问住了,回头亲自实践了下作个记录。

More ~

微信刷票分析

现在但凡商家或者一些媒体、公司有什么活动都会在比赛竞选阶段设置投票环节,一方面可能是认为这样让公众参与更有公平感、另一方面可能是想让更多人知道了解活动背后的商业目的和价值,提升品牌的公众知名度等。

这不,就连所谓的程序员大赛也设置了投票环节,而且这个环节还是前置于评委专家。本文不想对此评论过多,只是在刷票分析后的吐槽一下。下面就来简单分析下这个『第二届全球程序员节解放号杯程序员大赛』是如何来刷票的。

其实后来看了微信开发者wiki后才知道现在好多都是用的静默授权认证。相关wiki可以看这里https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842

当微信打开链接http://1024.jfh.com/mvote/detail?proId=1453 时会先向微信接口发起oauth验证,获取code。链接如下
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7e3e7526c38cebb5&redirect_uri=https%3A%2F%2Fwww.jfh.com%2Fjfm%2Fwx%2Fmenu%2Fgame%2Fv1%2FauthOpenid%3Fbackurl%3Dhttp%3A%2F%2F1024.jfh.com%2Fmvote%2Fmobile%2Fdetail%3FproId%3D1453%26from%3Dtimeline&response_type=code&scope=snsapi_base&state=MESG

其中传的appid好理解,scope=snsapi_base其实就是静默授权,即微信上不会提示获取用户基本信息,所以可以知道他调这个接口就只是想取到open id。还有回调地址redirect_uri,这个拿到code后会在解放号的服务端做各种处理,首先肯定是调用接口拿code换access_token,其实在返回值里已经拿到open id。存数据库或者session、redis等等。

More ~

Could not fetch URL https://pypi.python.org/simple/pyecharts/

用virtual env后 pip安装一些个库可能会报这个

Could not fetch URL https://pypi.python.org/simple/*/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping

原因在于pip版本过低了,我的python2.7 用env后就是8.0,可以用下面的方法更新再重试pip install

curl https://bootstrap.pypa.io/get-pip.py | python

More ~

libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID

XCode debug启动时报这个:

libMobileGestalt MobileGestaltSupport.m:153: xxx does not have sandbox access for frZQaeyWLUvLjeuEK43hmg and IS NOT appropriately entitled

libMobileGestalt MobileGestalt.c:550: no access to InverseDeviceID (see )

解决方法 Edit Scheme-> Run -> Arguments, 在Environment Variables里边添加

OS_ACTIVITY_MODE = Disable

More ~

Define global function using in jinja templates

原文是Call a python function from jinja2, 原文中点赞数量最高的并不是完美的答案,我采用的下面的方案。

Variables can easily be created:

@app.context_processor
def example():
    return dict(myexample='This is an example')

The above can be used in a Jinja2 template with Flask like so:

{{ myexample }}

(Which outputs This is an example)

As well as full fledged functions:

@app.context_processor
def utility_processor():
    def format_price(amount, currency=u'€'):
        return u'{0:.2f}{1}'.format(amount, currency)
    return dict(format_price=format_price)

The above when used like so:

{{ format_price(0.33) }}

(Which outputs the input price with the currency symbol)

Alternatively, you can use jinja filters, baked into Flask. E.g. using decorators:

@app.template_filter('reverse')
def reverse_filter(s):
    return s[::-1]

Or, without decorators, and manually registering the function:

def reverse_filter(s):
    return s[::-1]
app.jinja_env.filters['reverse'] = reverse_filter

Filters applied with the above two methods can be used like this:

{% for x in mylist | reverse %}
{% endfor %}
More ~

Python: 使用requests下载图片

来自最佳答案(推荐下面第一个):
You can either use the response.raw file object, or iterate over the response.

To use the response.raw file-like object will not, by default, decode compressed responses (with GZIP or deflate). You can force it to decompress for you anyway by setting the decode_content attribute to True (requests sets it to False to control decoding itself). You can then use shutil.copyfileobj() to have Python stream the data to a file object:

import requests
import shutil

r = requests.get(settings.STATICMAP_URL.format(**data), stream=True)
if r.status_code == 200:
    with open(path, 'wb') as f:
        r.raw.decode_content = True
        shutil.copyfileobj(r.raw, f)       

To iterate over the response use a loop; iterating like this ensures that data is decompressed by this stage:

r = requests.get(settings.STATICMAP_URL.format(**data), stream=True)
if r.status_code == 200:
    with open(path, 'wb') as f:
        for chunk in r:
            f.write(chunk)

This'll read the data in 128 byte chunks; if you feel another chunk size works better, use the Response.iter_content() method with a custom chunk size:

r = requests.get(settings.STATICMAP_URL.format(**data), stream=True)
if r.status_code == 200:
    with open(path, 'wb') as f:
        for chunk in r.iter_content(1024):
            f.write(chunk)

Note that you need to open the destination file in binary mode to ensure python doesn't try and translate newlines for you. We also set stream=True so that requests doesn't download the whole image into memory first.

More ~