This file contains hidden or 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
| ;(function (window) { | |
| function Template(str) { | |
| this.str = str; | |
| } | |
| Template.prototype.format = function () { | |
| var arg = arguments[0] instanceof Array ? arguments[0] : arguments; | |
| return this.str.replace(/\{(\d+)\}/g, function (a, b) { | |
| return arg[b] || ''; | |
| }); | |
| } |
This file contains hidden or 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
| /* | |
| 使用方法: | |
| 1. 将XML转为JS对象: | |
| JXParser.xml2Json(xml); | |
| 2. 将JS对象或JSON字符串转为XML: | |
| JXParser.xml2Json(xml); | |
| */ |
This file contains hidden or 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
| (function() { | |
| const INITIAL = 0; | |
| const RUNNING = 1; | |
| var inDebugMode = false; | |
| function JTPool(maxThread) { | |
| this.status = INITIAL; | |
| this.workQueue = []; // workQueue = [{id: xx, task: xx}] | |
| this.max = (undefined == maxThread) ? 3 : maxThread; |
This file contains hidden or 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
| /** | |
| * Manxisuo's Test! | |
| */ | |
| background: linear-gradient(45deg, #f06, yellow); | |
| background: #fff; | |
| min-height: 100%; |
This file contains hidden or 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
| def fibonacci(): | |
| a = b = 1 | |
| yield a | |
| yield b | |
| while True: | |
| a, b = b, a + b | |
| yield b |
This file contains hidden or 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
| # 使用iter函数 | |
| with open('a.txt', 'r') as file: | |
| for l in iter(file.readline, ''): | |
| print(l) | |
| # file对象是iterable | |
| with open('a.txt', 'r') as file: | |
| for l in file: | |
| print(l) |
This file contains hidden or 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
| #coding:utf-8 | |
| import requests | |
| import json | |
| import os.path | |
| def create_gist(file_path, name = None, desc = '', public = True): | |
| TOKEN = '[your token]' | |
| URL = 'https://api.github.com/gists' | |
| headers = {'Authorization': 'token {0}'.format(TOKEN)} |
This file contains hidden or 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
| # encoding: UTF-8 | |
| import _thread as thread, time | |
| import threading | |
| # 一个用于在线程中执行的函数 | |
| def func(): | |
| for i in range(5): | |
| print('func') | |
| time.sleep(1) |
This file contains hidden or 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
| arr = [3, 8, 4, 2, 6, 7, 9, 1, 5] | |
| length = len(arr) | |
| i = 1 #[1, length - 1] 表示第几趟遍历 | |
| j = 0 #[0, length - 1 - i] 表示某一趟遍历中,待比较的两个数中前一个数的位置 | |
| while i < length: | |
| j = 0 | |
| while j < length - i: | |
| if arr[j] > arr[j + 1]: |
This file contains hidden or 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
| /* 引用样式 */ | |
| blockquote { | |
| background: #f9f9f9; | |
| border-left: 10px solid #ccc; | |
| margin: 1.5em 10px; | |
| padding: .5em 10px; | |
| quotes: "\201C""\201D""\2018""\2019"; | |
| } | |
| blockquote:before { |