This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# wsl's host ip address may change every time it reboots, | |
# this is a problem if you map your host address as proxy. | |
# Use the script to generate a new config of proxychains | |
# each time proxychains runs. | |
# put an entry | |
# http wsl-host 3128 | |
# in your /etc/proxychains.conf | |
# Copy the script as ./local/bin/wsl-proxychains.sh | |
# run your program with proxychains like |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
A monkey patch for urllib.robotparser to support * and $ in robots.txt. | |
''' | |
import re | |
import urllib.parse | |
from urllib.robotparser import RobotFileParser, Entry, RuleLine | |
def get_robots_pattern(path): | |
ending = '.*?' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import gzip | |
def get_word_list(f, pattern=None): | |
pattern = pattern if pattern else r'[a-zA-Z0-9-_]+' | |
l = re.findall(pattern, gzip.decompress(open(f, 'rb').read()).decode('utf-8')) | |
return list(set(l)) | |
# Example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
京东联盟开放平台API的一个通用的Client封装。 | |
京东联盟开放平台的文档详见 https://union.jd.com/openplatform | |
涉及到签名方法的文档见 https://union.jd.com/helpcenter/13246-13247-46301 | |
Example: | |
client = JdApiClient("<YOUR_APP_KEY>", "<YOUR_SECRET_KEY>") | |
resp = client.call("jd.union.open.goods.promotiongoodsinfo.query", | |
{'skuIds':'12072066'}) | |
print(resp.json()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Wider Yuque | |
// @namespace https://gist.github.com/socrateslee/751c6670c59d5b9cdbd8428fab493375 | |
// @version 0.1 | |
// @description Let yuque a bit wider on browser screen. | |
// @author github.com/socrateslee | |
// @include https://*.yuque.com/* | |
// @grant none | |
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
An object stores the change history of its attributes, | |
the object can be use to store the hierarchies of different | |
levels of configurations. | |
Example | |
------- | |
# Set up config object | |
config = TracedObj() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name better data.stats.gov.cn | |
// @namespace https://gist.github.com/socrateslee/69169c58be9cf2e0e3019b09b680461b | |
// @version 0.1 | |
// @description Inject css for better display of data.stats.gov.cn | |
// @author https://github.com/socrateslee | |
// @include http://data.stats.gov.cn/easyquery.htm* | |
// @grant none | |
// ==/UserScript== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import json | |
def compact_json_dumps(*sub, **kw): | |
''' | |
A wrapper of json.dumps support an optional compact_length parameter. | |
compact_length take effects when indent > 0, will return a more compact | |
indented result, i.e., pretty and compact json dumps. | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"os" | |
"fmt") | |
func main() { | |
port := "8080" | |
if len(os.Args) >= 2 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
A simple wrapper make a class become a functor, | |
the class need a __call__ function. The (*sub, | |
**kwargs) will be passed for the __init__ function, | |
and the name of class will be the name of function | |
object. | |
Example | |
------- | |
@functor(*sub, **kwargs) |
NewerOlder