Skip to content

Instantly share code, notes, and snippets.

@ImSingee
ImSingee / wanmen.py
Last active March 31, 2018 06:24
万门大学课程目录生成(可读性 txt 与可导入至 Omni Focus 的 Task Paper 文件)
#!/usr/bin/env python
import sys
import json
import subprocess
import os
from urllib.parse import urlparse
import requests
def request(url):
@ImSingee
ImSingee / jack.py
Created April 15, 2018 10:53
「加减大师」游戏攻略
import re
import json
from mitmproxy import ctx
from urllib.parse import quote
from pprint import pformat
def response(flow):
path = flow.request.path
if path == '/index/index_one_nine_two/make_question':
ctx.log.info('Start')
@ImSingee
ImSingee / parse_second.py
Created May 7, 2018 04:11
「秒」转「时:分:秒」的格式
def parse_second(second):
m, s = divmod(second, 60)
h, m = divmod(m, 60)
return "%02d:%02d:%02d" % (h, m, s)
@ImSingee
ImSingee / get_video_time.py
Created May 7, 2018 04:43
获取视频长度
import subprocess
def parse_second(second):
# https://gist.github.com/ImSingee/f1272ab376066749c2e0141d2f57c320
m, s = divmod(second, 60)
h, m = divmod(m, 60)
return "%02d:%02d:%02d" % (h, m, s)
def get_video_time(file_path, t=False):
# ffmpeg (ffprobe) required
@ImSingee
ImSingee / get_random.py
Created May 8, 2018 06:16
取 [start, end) 间的随机数,保留 accuracy 位小数
def get_random(start=0, end=1, accuracy=0):
rnd = random.random() # [0, 1)
rnd = (end - start) * rnd + start # [start, end)
if accuracy == 0:
return int(rnd)
else:
return round(rnd, accuracy)
@ImSingee
ImSingee / get_head_number.py
Created May 8, 2018 06:17
取出一段字符串前端的数字
def get_head_number(s):
m = ''
for i in s:
if i.isdigit():
m += i
else:
break
if m == '':
return None
else:
@ImSingee
ImSingee / get_random_str.py
Last active May 31, 2018 09:01
获取定长随机字符串;可自定义分割方式
SEEDS = (
(0, '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'),
(1, '1234567890'),
(2, '1234567890abcdefghijklmnopqrstuvwxyz'),
(3, '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
(4, 'abcdefghijklmnopqrstuvwxyz'),
(5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
(6, '!@\\#$%^&*()/_+=-\'\"'), # 特殊符号:!@\#$%^&*()/_+=-'"
(7, ''),
(8, ''),
@ImSingee
ImSingee / get_distance.py
Created June 13, 2018 16:08
计算经纬度距离差
def get_distance(latitude_start, latitude_end, longitude_start, longitude_end):
"""
计算经纬度距离差
:param latitude_start: 纬度1
:param latitude_end: 纬度2
:param longitude_start: 经度1
:param longitude_end: 经度2
:return:
"""
import math
@ImSingee
ImSingee / OmniFocus-打开动作网址.scpt
Created August 26, 2019 11:01
OmniFocus-打开动作网址,可以自动从父任务/父项目获取网址打开,可以设定 NEED_CONFIRM 来选择是否在打开网址前询问
global NEED_CONFIRM
on run {}
set NEED_CONFIRM to true
set theSelecteditems to my selectedActions()
if (count of theSelecteditems) is equal to 0 then
display alert "请选择一个有效的动作" as critical
return
@ImSingee
ImSingee / OmniFocus-清除截止时间.scpt
Created August 26, 2019 11:11
OmniFocus-清除截止时间,将选中的项目/动作的截止时间删除
on run {}
set i to 1
repeat with _action in my selectedActions()
my processAction(_action, i)
set i to i + 1
end repeat
tell application "OmniFocus"
tell default document
compact
end tell