Skip to content

Instantly share code, notes, and snippets.

View fy0's full-sized avatar
🎲
thinking

fy fy0

🎲
thinking
View GitHub Profile
export function getSvgPositionFromToEl(stage, el) {
var point = stage.createSVGPoint();
let matrix = stage.getScreenCTM().inverse().multiply(el.getScreenCTM());
return point.matrixTransform(matrix);
}
// 程序启动器[win32]
// 一个小玩意,作用就是读取与 exe 同名的 .config 文件,并逐条并行执行,不显示窗口
// 以 # 打头的行忽略
// 用于开机挂载一些自带 cmd 窗口的程序
// 自用 vs2017 编译测试通过
// ver 1.1
// 一个新语法:@命令 可以等待此命令结束后再继续运行
// 例如 @ping 127.1 -n 3 等待3秒
@fy0
fy0 / PIL文本生成图片.py
Last active May 7, 2017 13:26
PIL文本生成图片
from PIL import Image, ImageFont, ImageDraw
text = '立行跃击'
font = ImageFont.truetype('../font/SourceHanSansCN-Regular.otf', 80)
for i in text:
img = Image.new('RGBA', (100, 100))
brush = ImageDraw.Draw(img)
brush.text((10,0), i, fill='#000', font=font)
import struct
from PIL import Image
fp = open('myshot.raw', 'rb')
size = struct.unpack('II', fp.read(8))
img = Image.frombytes('RGBA', size, fp.read())
img.save('out.bmp')
# 基于 peewee,需要传入 model 类和查询条件
def parse_query(sheet_model, statements):
"""
statements:
['and',
['==', 'col1', val1],
['!=', 'col2', val2],
['and',
@fy0
fy0 / 24点.py
Last active October 8, 2016 13:58
import re
import itertools
t = input('输入四个数:')
nums = list(map(int, re.split('\s+', t)))
div = lambda x, y : x // y
signs = [int.__add__, int.__sub__, int.__mul__, div]
signs_txt = {signs[0]: '+', signs[1]: '-', signs[2]: '*', signs[3]: '/'}
signs_to_txt = lambda x: signs_txt[x]
@fy0
fy0 / test.py
Last active September 21, 2016 06:38
class A(dict):
def __new__(cls):
ret = dict.__new__(cls)
ret.a = 1
return ret
class B(A):
def __new__(cls, a):
# coding: utf-8
# 更新于2017/10/02,python3测试通过
import re
import requests
# 领取 X 铜币
# 每日登录奖励已领取
base_headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.57 Safari/537.36 OPR/40.0.2308.15 (Edition beta)', 'Referer': 'https://www.v2ex.com/signin', 'Origin': 'https://www.v2ex.com'}