Skip to content

Instantly share code, notes, and snippets.

@yszou
yszou / deriv-middle-parentheses.scm
Created Jul 30, 2019
符号求异,中缀,处理了括号优化级
View deriv-middle-parentheses.scm
(define (=number? a v) (and (number? a) (= a v)))
(define (variable? e) (symbol? e))
(define (sum? e)
(and (pair? e) (eq? (cadr e) '+)))
(define (sum-a e) (car e))
(define (sum-b e)
(if (= (length e) 3) (caddr e) (cdr (cdr e))))
(define (make-sum a b)
(cond ((=number? a 0) b)
@yszou
yszou / deriv.scm
Created Jul 29, 2019
符号求导
View deriv.scm
(define (variable? x) (symbol? x))
(define (same-variable? a b) (and (variable? a) (variable? b) (eq? a b)))
(define (sum? e) (and (pair? e) (eq? (car e) '+)))
(define (added e) (cadr e))
(define (augend e)
(if (= (length e) 3) (caddr e) (append '(+) (cdr (cdr e)))))
(define (product? e) (and (pair? e) (eq? (car e) '*)))
(define (multiplier e) (cadr e))
@yszou
yszou / fib.scm
Last active Jul 28, 2019
斐波那契数列
View fib.scm
(define (vector+vector a b)
(define (vector+vector-iter a b value)
(if (null? a) (reverse value)
(vector+vector-iter (cdr a) (cdr b) (cons (+ (car a) (car b)) value) )))
(vector+vector-iter a b '()))
(display "vector+vector: ")
(display (vector+vector '(1 2 3) '(4 5 6)))
(display "\n")
@yszou
yszou / queen.scm
Created Jul 28, 2019
八皇后问题
View queen.scm
(define (range a b)
(define (iter v current)
(if (< v a) current
(iter (- v 1) (cons v current))))
(iter (- b 1) '()))
(define (accmulate f init seq)
(if (null? seq) init
(accmulate f (f (car seq) init) (cdr seq))))
@yszou
yszou / alipay_mobile.py
Created Jun 20, 2014
支付宝移动网页支付的实现
View alipay_mobile.py
# -*- coding: utf-8 -*-
from hashlib import md5
from urllib import urlencode
#网关
GATEWAY = 'http://wappaygw.alipay.com/service/rest.htm'
class Alipay(object):
'支付宝移动服务网关'
@yszou
yszou / sina_sso.py
Created Dec 9, 2013
新浪的SSO授权登录
View sina_sso.py
# -*- coding: utf-8 -*-
import rsa
import re
import time
import json
import traceback
from urllib import urlencode, unquote, quote
from Cookie import SimpleCookie
import tornado
@yszou
yszou / sendmail.py
Created Dec 9, 2013
发出信息的工具
View sendmail.py
# -*- coding: utf-8 -*-
import sys, os, re
from lib.eml_parse import parse
from lib.smtpclient import SMTPClient
import tempfile
import email.utils
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
@yszou
yszou / smtpclient.py
Created Dec 9, 2013
Tornado实现的SMTP客户端
View smtpclient.py
# -*- coding: utf-8 -*-
'参考smtplib,以tornado的IOStream实现的SMTP客户端'
import socket
import re
import email.utils
import tornado.ioloop
import tornado.iostream
import tornado.gen
View eml_parse.py
# -*- coding: utf-8 -*-
import uuid
import base64
import datetime
import email
import email.Header
from email.utils import getaddresses, parsedate_tz, mktime_tz
from StringIO import StringIO
@yszou
yszou / clean.py
Created Dec 9, 2013
邮件内容过滤
View clean.py
# -*- coding: utf-8 -*-
import re
EMAIL_PATTERN = re.compile(u'[a-z0-9_\-\+\.]+@[a-z0-9_\-\.]+\.[a-z]+', re.I)
from lxml.html.clean import Cleaner
from lxml.html import defs
frozenset = set
defs.safe_attrs = frozenset([