get请求
r = requests.get('https://api.github.com/events')
post请求
AppCompat-v7:21 provides a very useful way of dealing with pressed/focused/activated states maintaining backwards compatibility downto API-7, but there's a small issue (big for some) with the default selectableItemBackground: It uses some PNGs and/or default values for API<21. | |
The main reason is that android drawable resource definitions (prior API 21) CANNOT use theme attributes at all, so there's no way of making something like: | |
<shape android:shape="rectangle"> | |
<solid android:color="?attr/colorControlHighlight" /> | |
</shape> | |
For this, I've put this simple mockup on how to give your app better drawables that the appcompat defaults. |
public class MyParcelable implements Parcelable { | |
private int mData; | |
public int describeContents() { | |
return 0; | |
} | |
public void writeToParcel(Parcel out, int flags) { | |
out.writeInt(mData); | |
} |
/** | |
* @param originalColor color, without alpha | |
* @param alpha from 0.0 to 1.0 | |
* @return | |
*/ | |
public static String addAlpha(String originalColor, double alpha) { | |
long alphaFixed = Math.round(alpha * 255); | |
String alphaHex = Long.toHexString(alphaFixed); | |
if (alphaHex.length() == 1) { | |
alphaHex = "0" + alphaHex; |
# 2016-10-30T14:02:48.269Z | |
from datetime import datetime, timedelta | |
def generate_timestamp(self): | |
# now = arrow.now() | |
# now.to('GMT') | |
# now.format("YYYY-MM-dd'T'HH:mm:ss.SSSZZ") | |
date_format = "%Y-%m-%dT%H:%M:%S.%f" | |
now = datetime.utcnow().strftime(date_format) | |
now = str(now)[0:-3] | |
return now + "Z" |
import base64 | |
import json | |
from Crypto import Random | |
from Crypto.Cipher import AES | |
from star_site import settings | |
class AESCrypt: |
class TestPickle(unittest.TestCase): | |
def test_pickle_unpickle(self): | |
cache_key = 'just_test_pickle' | |
_redis = redis.StrictRedis(host='localhost', port=6379, db=0) | |
session = Session() | |
session.cookies['Heee'] = 'adc' | |
session.cookies.update({ |
# 将byte转换成str | |
# byte_sample = b'xxxxxxxxxxx' -----> 'xxxxxxxxxxxxxx' | |
byte_sample = b'abcde' | |
byte2str = byte_sample.decode("utf-8") | |
print(byte2str) #abcde |
from tornado.httpclient import AsyncHTTPClient | |
from tornado.testing import AsyncTestCase, gen_test | |
URL = 'http://www.tornadoweb.org' | |
class MyTestCase(AsyncTestCase): | |
@gen_test | |
def test_http_fetch(self): | |
client = AsyncHTTPClient(self.io_loop) |