Skip to content

Instantly share code, notes, and snippets.

View zhaocai's full-sized avatar
🤨
I may be slow to respond.

Zhao Cai zhaocai

🤨
I may be slow to respond.
View GitHub Profile
@zhaocai
zhaocai / Everything in XYplorer.xys
Created October 10, 2016 06:46
Everything in XYplorer
/* CUSTOMIZATIONS
-------------------------------------------------------------------------------------------------
$path: the path of the folder containing the es.exe executable, with a final
slash.
$paper: the base name of the paper folder containing the search results, without
extension;
$mode: controls how the minus sign, which introduces switches in es.exe, is
treated/escaped. Three modes are available.
@zhaocai
zhaocai / Liberal Regex Pattern for URLs
Created October 16, 2016 23:07 — forked from winzig/Liberal Regex Pattern for URLs
Updated @gruber's regex with a modified version that looks for 2-13 letters rather than trying to look for specific TLDs. Given the recent addition of ~1400 gTLDs, it may be time to give up on that front.
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:[a-z]{2,13})(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.](?:[a-z]{2,13})\b/?(?!@)))
# Commented multi-line version:
(?xi)
\b
( # Capture 1: entire matched URL
(?:
@zhaocai
zhaocai / utf16toascii.py
Last active October 19, 2016 01:14
decode utf16
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import codecs
encoded_text = open(sys.argv[-1], 'rb').read()
bom= codecs.BOM_UTF16_LE
assert encoded_text.startswith(bom)
encoded_text= encoded_text[len(bom):]