-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
202,578 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"6" | ||
] | ||
}, | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# https://leetcode-cn.com/problems/qiu-12n-lcof\n", | ||
"class Solution:\n", | ||
" def __init__(self):\n", | ||
" self.res = 0\n", | ||
" def sumNums(self, n: int) -> int:\n", | ||
" n > 1 and self.sumNums(n - 1)\n", | ||
" self.res += n\n", | ||
" return self.res\n", | ||
"\n", | ||
"s = Solution()\n", | ||
"s.sumNums(3)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"45" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"s = Solution()\n", | ||
"s.sumNums(9)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class Solution:\n", | ||
" def __init__(self):\n", | ||
" self.res = 0\n", | ||
" def sumNums(self, n: int) -> int:\n", | ||
" n > 1 and self.sumNums(n - 1)\n", | ||
" self.res += n\n", | ||
" return self.res" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"12" | ||
] | ||
}, | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"6 << 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"3" | ||
] | ||
}, | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"6 >> 1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 90, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"[('AccessKeyId', 'testid'),\n", | ||
" ('Action', 'AssumeRole'),\n", | ||
" ('Format', 'JSON'),\n", | ||
" ('RoleArn', 'acs:ram::1234567890123:role/firstrole'),\n", | ||
" ('RoleSessionName', 'client'),\n", | ||
" ('SignatureMethod', 'HMAC-SHA1'),\n", | ||
" ('SignatureNonce', '571f8fb8-506e-11e5-8e12-b8e8563dc8d2'),\n", | ||
" ('SignatureVersion', '1.0'),\n", | ||
" ('Timestamp', '2015-09-01T05:57:34Z'),\n", | ||
" ('Version', '2015-04-01')]" | ||
] | ||
}, | ||
"execution_count": 90, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# Python Version: 3.7\n", | ||
"# 计算签名\n", | ||
"# https://help.aliyun.com/document_detail/28761.html?spm=a2c4g.11186623.6.791.66725328JBIR5G\n", | ||
"\n", | ||
"\n", | ||
"#https://sts.aliyuncs.com/?&AccessKeyId=testid&SignatureMethod=HMAC-SHA1&Version=2015-04-01&Action=AssumeRole&SignatureNonce=571f8fb8-506e-11e5-8e12-b8e8563dc8d2\n", | ||
"params = {\n", | ||
" \"Action\": \"AssumeRole\",\n", | ||
" \"Format\": \"JSON\",\n", | ||
" \"Version\": \"2015-04-01\",\n", | ||
" \"SignatureMethod\": \"HMAC-SHA1\",\n", | ||
" \"SignatureNonce\": \"571f8fb8-506e-11e5-8e12-b8e8563dc8d2\",\n", | ||
" \"SignatureVersion\": \"1.0\",\n", | ||
" \"AccessKeyId\": \"testid\",\n", | ||
" \"Timestamp\": \"2015-09-01T05:57:34Z\",\n", | ||
" \"RoleArn\": \"acs:ram::1234567890123:role/firstrole\",\n", | ||
" \"RoleSessionName\": \"client\"\n", | ||
"}\n", | ||
"\n", | ||
"# 按照首字母排序\n", | ||
"params_arr = list(params.items())\n", | ||
"params_arr.sort(key=lambda x: x[0])\n", | ||
"params_arr\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 91, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'GET&%2F&AccessKeyId%3Dtestid%26Action%3DAssumeRole%26Format%3DJSON%26RoleArn%3Dacs%253Aram%253A%253A1234567890123%253Arole%252Ffirstrole%26RoleSessionName%3Dclient%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D571f8fb8-506e-11e5-8e12-b8e8563dc8d2%26SignatureVersion%3D1.0%26Timestamp%3D2015-09-01T05%253A57%253A34Z%26Version%3D2015-04-01'" | ||
] | ||
}, | ||
"execution_count": 91, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from collections import OrderedDict\n", | ||
"import urllib.parse\n", | ||
"\n", | ||
"# 拼接 sign_str\n", | ||
"sign_str = \"GET&%2F&\"\n", | ||
"sign_dict = OrderedDict(params_arr)\n", | ||
"params_str = urllib.parse.urlencode(sign_dict)\n", | ||
"params_str = urllib.parse.quote(params_str)\n", | ||
"\n", | ||
"sign_str += params_str\n", | ||
"sign_str" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 87, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 验证签名用的 str 是否正确\n", | ||
"eg = \"GET&%2F&AccessKeyId%3Dtestid%26Action%3DAssumeRole%26Format%3DJSON%26RoleArn%3Dacs%253Aram%253A%253A1234567890123%253Arole%252Ffirstrole%26RoleSessionName%3Dclient%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D571f8fb8-506e-11e5-8e12-b8e8563dc8d2%26SignatureVersion%3D1.0%26Timestamp%3D2015-09-01T05%253A57%253A34Z%26Version%3D2015-04-01\"\n", | ||
"assert sign_str == eg" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 82, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'gNI7b0AyKZHxDgjBGPDgJ1Ce3L4='" | ||
] | ||
}, | ||
"execution_count": 82, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import hashlib\n", | ||
"import hmac\n", | ||
"import base64\n", | ||
"h = hmac.new('testsecret&'.encode('utf-8'), sign_str.encode('utf-8'), hashlib.sha1)\n", | ||
"sign = h.digest()\n", | ||
"sign = base64.b64encode(sign).decode()\n", | ||
"sign" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 89, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 验证签名值\n", | ||
"assert sign == 'gNI7b0AyKZHxDgjBGPDgJ1Ce3L4='" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python | ||
# -*- coding:utf-8 -*- | ||
# Author: wxnacy([email protected]) | ||
# Description: | ||
|
||
DATABASE_URL = 'mysql://root:[email protected]:3306/study?charset=utf8mb4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
# Author: wxnacy([email protected]) | ||
# Description: | ||
|
||
ipynb_files=`find . -name "*.ipynb" | grep -v checkpoints` | ||
for file in $ipynb_files | ||
do | ||
outdir=`python -c "import os;print(os.path.dirname('${file}'.replace('./', './static/')))"` | ||
jupyter nbconvert $file --output-dir $outdir | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
# -*- coding:utf-8 -*- | ||
# Author: wxnacy([email protected]) | ||
# Description: | ||
|
||
HTML = """\ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | ||
"http://www.w3.org/TR/html4/strict.dtd"> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | ||
<title>Error response</title> | ||
</head> | ||
<body> | ||
<h1>Directory listing for {}</h1> | ||
<hr> | ||
{} | ||
<hr> | ||
</body> | ||
</html> | ||
""" | ||
|
||
|
||
import os | ||
import urllib.parse | ||
|
||
def main(dirname): | ||
for dirname, subdirs, files in os.walk(dirname): | ||
lines = '' | ||
for subdir in subdirs: | ||
url = urllib.parse.quote(subdir) | ||
lines = f'{lines}<li><a href="{url}/">{subdir}/</a></li>' | ||
for f in files: | ||
url = urllib.parse.quote(f) | ||
lines = f'{lines}<li><a href="{url}">{f}</a></li>' | ||
index = f'{dirname}/index.html' | ||
os.remove(index) | ||
with open(index, 'w') as f: | ||
f.write(HTML.format(dirname.replace(f'{dirname}/', './'), f"<ul>{lines}</ul>")) | ||
|
||
if __name__ == "__main__": | ||
main('./static') |
Oops, something went wrong.