Skip to content

Instantly share code, notes, and snippets.

@yszou
yszou / report.py
Created April 29, 2022 16:27
py code can run as micropython
# -*- coding: utf-8 -*-
import random
import json
import js
class RandomData():
def __init__(self, rows=5, dimensions=1, metrics=2):
self.data = []
# -*- coding: utf-8 -*-
todo = [
{"a": 1, "b": 1},
{"a": 2, "b": 2},
{"a": 1, "b": 1},
{"a": 0, "b": 1},
{"a": 2, "b": 2},
{"a": 0, "b": 2},
{"a": 2, "b": 2},
@yszou
yszou / deriv-middle-parentheses.scm
Created July 30, 2019 18:34
符号求异,中缀,处理了括号优化级
(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 July 29, 2019 17:23
符号求导
(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 July 28, 2019 06:40
斐波那契数列
(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 July 28, 2019 06:32
八皇后问题
(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 / angularjs
Last active August 29, 2015 14:05
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>angularjs</title>
<script src="http://cdn.staticfile.org/jquery/2.1.0/jquery.min.js" type="text/javascript"></script>
<script src="http://cdn.staticfile.org/angular.js/1.0.8/angular.min.js" type="text/javascript"></script>
</head>
<body>
<form name="test_form" ng-controller="TestCtrl" ng-init="o=[0,1,2,3]; a=o[1];">
@yszou
yszou / alipay_mobile.py
Created June 20, 2014 04:51
支付宝移动网页支付的实现
# -*- coding: utf-8 -*-
from hashlib import md5
from urllib import urlencode
#网关
GATEWAY = 'http://wappaygw.alipay.com/service/rest.htm'
class Alipay(object):
'支付宝移动服务网关'
@yszou
yszou / sendmail.py
Created December 9, 2013 12:00
发出信息的工具
# -*- 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 / sina_sso.py
Created December 9, 2013 11:56
新浪的SSO授权登录
# -*- 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