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

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

其实后来看了微信开发者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等等。


- 阅读剩余部分 -

用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

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

github上的原文:sed command with -i option failing on Mac, but works on Linux

不是最佳方案,但比较好,-i''可以直接覆盖,不用创建备份。

This works with both GNU and BSD versions of sed:

sed -i'' -e 's/old_link/new_link/g' *

or with backup:

sed -i'.bak' -e 's/old_link/new_link/g' *

原文是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 %}