Skip to content

Instantly share code, notes, and snippets.

View manxisuo's full-sized avatar
🎯
Focusing

Su Yun manxisuo

🎯
Focusing
View GitHub Profile
@manxisuo
manxisuo / Template.js
Created December 9, 2013 16:37
12行代码实现简易Javascript模板引擎
;(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] || '';
});
}
@manxisuo
manxisuo / JXParser.js
Last active August 29, 2015 13:57
Convert JSON to XML & Convert XML to JSON (JSON和XML相互转化)
/*
使用方法:
1. 将XML转为JS对象:
JXParser.xml2Json(xml);
2. 将JS对象或JSON字符串转为XML:
JXParser.xml2Json(xml);
*/
@manxisuo
manxisuo / JTPool.js
Last active August 29, 2015 13:57
JTPool: A JavaScript Thread Pool (一个JavaScript线程池)
(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;
@manxisuo
manxisuo / dabblet.css
Last active August 29, 2015 14:16
Manxisuo's Test!
/**
* Manxisuo's Test!
*/
background: linear-gradient(45deg, #f06, yellow);
background: #fff;
min-height: 100%;
@manxisuo
manxisuo / fibonacci.py
Created June 4, 2015 13:50
斐波那契数列生成器
def fibonacci():
a = b = 1
yield a
yield b
while True:
a, b = b, a + b
yield b
# 使用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)
@manxisuo
manxisuo / create_a_gist.py
Created June 5, 2015 14:54
create a gist in github
#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)}
@manxisuo
manxisuo / [1]_thread.py
Last active August 29, 2015 14:22
Python Thread学习 (http://is.gd/kLyISF)
# encoding: UTF-8
import _thread as thread, time
import threading
# 一个用于在线程中执行的函数
def func():
for i in range(5):
print('func')
time.sleep(1)
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]:
@manxisuo
manxisuo / 引用内容的样式.css
Created September 9, 2015 12:18
用于blockquote(即引用)的一个比较好的样式
/* 引用样式 */
blockquote {
background: #f9f9f9;
border-left: 10px solid #ccc;
margin: 1.5em 10px;
padding: .5em 10px;
quotes: "\201C""\201D""\2018""\2019";
}
blockquote:before {