Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
from xml.etree import ElementTree
from pathlib import Path
import io
import datetime
import email.utils
__author__ = 'chrono-meter@gmx.net'
__version__ = '1.0.0'
__license__ = 'Python Software Foundation License'
#!/usr/bin/env python3
import requests
from urlpath import URL # https://pypi.org/project/urlpath/
import argparse
import logging
logger = logging.getLogger(__name__)
# https://www.peterbe.com/plog/best-practice-with-retries-with-requests
def Session(*args, **kwargs):
@chrono-meter
chrono-meter / RemoteAssistanceComparison.md
Last active May 13, 2017 04:59
Remote Assistance Comparison
App TeamViewer Windows Remote Assistance Chrome Remote Desktop Quick Assist
Platform Windows, macOS, Linux Windows 7 or later Windows, macOS, Linux Windows 10
Prerequisite Download execution file. Enable in system properties (default: enabled). Install Chro
@chrono-meter
chrono-meter / common_prefix.py
Created January 26, 2017 07:01
Python: Common prefix of pathlib.Path
import collections
import pathlib
def common_prefix(*paths):
"""Common prefix of given paths"""
counter = collections.Counter()
for path in paths:
assert isinstance(path, pathlib.Path)
counter.update([path])
@chrono-meter
chrono-meter / read_utf_with_bom.py
Created January 26, 2017 07:00
Python: UTF with BOM sample
import codecs
def read_utf_with_bom(fp, errors='strict', remove_bom: bool=True) -> str:
chunk = fp.read(4)
if chunk.startswith(codecs.BOM_UTF8):
encoding = 'utf_8_sig'
bom = codecs.BOM_UTF8
elif chunk.startswith(codecs.BOM_UTF32_BE):
@chrono-meter
chrono-meter / cdodict.py
Created January 26, 2017 06:58
Python: Caseless and Default and Ordered Dict
import collections
class CDODict(collections.UserDict):
"""Caseless and Default and Ordered Dict"""
def __init__(self, default_factory, name_normalize=str.lower):
self.default_factory = default_factory
self.name_normalize = name_normalize
self._normalized_names = {} # {normalized: original, ...}
@chrono-meter
chrono-meter / openssl-enc-compat.py
Created November 26, 2016 03:00
OpenSSL enc compatible script by Python.
#!python3
"""OpenSSL enc compatible script by Python.
"""
import sys
import os
import io
import hashlib
import binascii
import argparse
import logging
@chrono-meter
chrono-meter / jp-disable-photon.php
Created October 4, 2016 20:09
Disable Jetpack's Photon completely.
<?php
/**
* Disable Jetpack's Photon completely.
*
* Jetpack uses Photon API internally even Photon is inactivated. (ex. Related posts)
* When you disable Photon API with hooking `jetpack_photon_skip_for_url`, there is
* problem that ignore size for getting image url.
*
* compatiblity: WordPress v4.6.1, Jetpack v4.3.1
@chrono-meter
chrono-meter / wp-get-image-sizes.php
Last active October 4, 2016 09:11 — forked from eduardozulian/wp-get-image-sizes.php
Get all the registered image sizes along with their dimensions
<?php
/**
* Get all the registered image sizes along with their dimensions
*
* @global array $_wp_additional_image_sizes
*
* @link http://core.trac.wordpress.org/ticket/18947 Reference ticket
* @return array $image_sizes The image sizes
*/
function _get_all_image_sizes() {
@chrono-meter
chrono-meter / console.csh
Created July 10, 2016 08:45
さくらインターネット レンタルサーバーに Python 3.5 をインストールする
% wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
% tar xJf Python-3.5.2.tar.xz
% cd Python-3.5.2
% ./configure --prefix=$HOME/python-3.5/
% make
% make install
% ~/python-3.5/bin/python3 -c "import bz2, ctypes, decimal, hashlib, lzma, sqlite3, ssl, xml.etree.ElementTree"
% mkdir ~/bin
% ln -s ~/python-3.5/bin/python3.5 ~/bin/python3
% ln -s ~/python-3.5/bin/idle3.5 ~/bin/idle3