Skip to content

Instantly share code, notes, and snippets.

View MikeLing's full-sized avatar
:octocat:
Busy

Tiramisu 1993 MikeLing

:octocat:
Busy
View GitHub Profile
@MikeLing
MikeLing / question1.py
Last active March 5, 2019 06:33
question from sun
from collections import OrderedDict
RED_WORDS = ['help', 'asp', 'urgent']
def check_red_words(word):
# deal with the word
# remove_duplicate = "".join(OrderedDict.fromkeys(word))
temp = []
for i in word:

Performance of Flask, Tornado, GEvent, and their combinations

Wensheng Wang, 10/1/11

Source: http://blog.wensheng.org/2011/10/performance-of-flask-tornado-gevent-and.html

When choosing a web framework, I pretty much have eyes set on Tornado. But I heard good things about Flask and Gevent. So I tested the performance of each and combinations of the three. I chose something just a little more advanced than a "Hello World" program to write - one that use templates. Here are the codes:

1, Pure Flask (pure_flask.py)

@MikeLing
MikeLing / mutiple_request.py
Last active October 18, 2018 09:06
mutiple request version for snapper.
import requests
import json
import time
import csv
import asyncio
import aiohttp
data = []
tasks = []
@MikeLing
MikeLing / test.py
Last active August 31, 2018 01:04
test script for photo-grader
import requests
import json
import csv
if __name__ == '__main__':
data = []
with open("sample-image-links.csv") as f:
reader = csv.reader(f)
for row in reader:
data.append(row[0])

问题1: 如果需要重构hero,需要修改哪些代码,有没有更好的方式? 问题2: 如果需要增加一个hero或者cards,应该怎么做到最小修改?


我认为两个问题都可以视为设计模式的问题,即如何设计可复用的hero和card类。首先我认为可以定义 HeroCard 这两个抽象类,所有的英雄和卡片实现这两个抽象类的方法,这样当需要添加一个新英雄或卡片的时候可以随时扩充,只需要实现虚基类定义的接口即可。

其次,在调用类内部方法时候可以采用传递虚基类(接口)而不是传递具体类型的方式,这样在修改了某几个具体类型之后也不需要对调用函数进行修改。比如在执行英雄技能和卡牌效果时,实质上都是一种影响自己或者是其他英雄状态的方式,因此英雄的技能(Skill)和 卡片的效果(Effect)都可以继承与同一个抽象接口(magic),这样在执行英雄技能和卡片效果的时候可以调用同一套接口函数,加强了可重用性。

what's this file about?

This file is used to invite new member to this organization.

How could I get invitation?

if you are GSoC student from China already

  • Please just create a pr to this file which contain a link to your GSoC project page [e.g mine is https://summerofcode.withgoogle.com/projects/#6008675886956544]

  • If you don't want other people know which project you are working on, that's fine. Please ask someone you already know in GSoC-CN vote (create a pr) for you to prove you are GSoC student. And then you can get the invitation.

#include <iostream>
#include <random>
int main()
{
std::mt19937_64 rng(100);
std::uniform_int_distribution<int32_t > d(1,100);
for(int32_t i=0 ; i<15; i++)
{
std::cout << d(rng) << std::endl;
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/random:3647:21: error: no matching function for call to
object of type 'const std::__1::mersenne_twister_engine<unsigned long long, 64, 312, 156, 31, 13043109905998158313, 29, 6148914691236517205, 17,
8202884508482404352, 37, 18444473444759240704, 43, 6364136223846793005>'
_RealType _Sp = __g() - _URNG::min();
^~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/random:3774:18: note: in instantiation of function template
specialization 'std::__1::generate_canonical<double, 53, const std::__1::mersenne_twister_engine<unsigned long long, 64, 312, 156, 31, 13043109905998158313,
29, 6148914691236517205, 17, 8202884508482404352, 37, 18444473444759240704, 43, 6364136223846793005> >' requested here
* _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g)
^
#ifdef SWIGPYTHON
%{
#include <shogun/base/init.h>
extern template <class T = std::mt1993> T get_prng();
%}
%template(get_mt1993_rng) get_prng<std::mt19937>;
#endif
MacBook-Pro-2:build mikeling$ lldb ./bin/shogun-unit-test
(lldb) target create "./bin/shogun-unit-test"
Current executable set to './bin/shogun-unit-test' (x86_64).
(lldb) b QuadraticTimeMMD_unittest.cc:364
Breakpoint 1: where = shogun-unit-test`QuadraticTimeMMD_perform_test_permutation_unbiased_full_Test::TestBody() + 36 at QuadraticTimeMMD_unittest.cc:365, address = 0x000000010073c104
(lldb) r --gtest_filter=QuadraticTimeMMD.perform_test_permutation_unbiased_full
Process 17168 launched: './bin/shogun-unit-test' (x86_64)
Note: Google Test filter = QuadraticTimeMMD.perform_test_permutation_unbiased_full
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.