Skip to content

Instantly share code, notes, and snippets.

@socrateslee
socrateslee / wsl-proxychains.sh
Created December 23, 2023 11:47
Use proxychains in wsl
#!/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
@socrateslee
socrateslee / jd_union_api.py
Last active November 1, 2023 03:31
京东联盟开放平台API的一个通用的Client封装
'''
京东联盟开放平台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())
@socrateslee
socrateslee / robotparserpatched.py
Last active September 29, 2023 13:16
A monkey patch for urllib.robotparser to support * and $ in robots.txt
'''
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 = '.*?'
@socrateslee
socrateslee / SimpleDTW.cs
Created March 3, 2012 14:06
Simple DTW(Dynamic Time Wrapping) in C#
//http://data-matters.blogspot.com/2008/07/simple-implementation-of-dtwdynamic.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace DTW
{
@socrateslee
socrateslee / stack_trace.py
Created November 4, 2012 11:24
A Stack Trace Decorator of Python Functions
import sys
import functools
'''
Usage:
consider following functions
import stack_trace
def foo():
pass
def bar():
@socrateslee
socrateslee / winpath.py
Created May 28, 2013 13:44
A simple command line tool for managing windows PATH variable in Windows Registry. Get help by `python winpath.py help`.
'''
A simple command line tool for managing windows PATH variable.
'''
import _winreg as winreg
import os
import sys
def choose_key(scope, write=False):
'''
@socrateslee
socrateslee / static-serve.go
Created June 18, 2014 14:56
Serving static files in current directory with golang. Simply a "python -m SimpleHTTPServer [PORT]" replacement written in golang. Use it as "static-serve [PORT]"
package main
import (
"net/http"
"os"
"fmt")
func main() {
port := "8080"
if len(os.Args) >= 2 {
@socrateslee
socrateslee / get_word_list.py
Created May 21, 2020 04:17
Get a word list from local man file
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
@socrateslee
socrateslee / wider-yuque.js
Last active January 9, 2020 11:23
Wider Yuque
// ==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==
@socrateslee
socrateslee / traced_obj.py
Created May 23, 2019 07:20
An object stores the change history of its attributes, the object can be use to store the hierarchies of different levels of configurations.
'''
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()