Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am ma233 on github.
* I am ma233 (https://keybase.io/ma233) on keybase.
* I have a public key ASC7oq0hBzwv4Q1YUTwBqN8jdNaYUS8ubBYgaRq6QrZ98Qo
To claim this, I am signing this object:
async fn test_croath() -> Result<()> {
let croath = Did::from_str("0xf7fea1722f9b27b0666919a5664bab486a4b18d3")?;
let no_41d = Did::from_str("0x0298ba2b72ef040bbd99398f96594e8d8c0d0607")?;
let vnode = Did::from_str("0xec472b3b5e00a33cd3b8ce91159e4d43350c3098")?;
let croath_dht = PeerRing::new(croath).await?;
{
let mut successors = croath_dht.lock_successor()?;
successors.update(no_41d);
@Ma233
Ma233 / model_query.py
Created October 12, 2018 03:31
sqlalchemy query
from sqlalchemy.orm import load_only
def model_query(M, *, select_=None, order_by_=None, conditions_=None, **kwargs):
q = M.query
if select_:
q = q.options(load_only(*select_))
if conditions_:
@Ma233
Ma233 / parse_nginx_access_log.py
Created September 28, 2016 10:07
分析 nginx 的 access log
#!/usr/bin/env python
# encoding: utf-8
import re
LOG = '''\
192.168.20.16 - - [28/Sep/2016:15:55:43 +0800] "GET /v2/dae-rasha/manifests/dc26e9e9873baf1af7dc0169496f4de373e4fc01__1d374a6a93125b5bddc57b0b1c34243a5cdcd9586c19ad0b432133b7d81ef123 HTTP/1.1" 200 2008 "-" "docker/1.10.3 go/go1.5.3 git-commit/20f81dd kernel/3.18.10-gentoo os/linux arch/amd64" "-" 0.011
192.168.20.16 - - [28/Sep/2016:15:55:43 +0800] "GET /v2/dae-lunar/manifests/3137109cad460d22d6585ebbe90f3f31b6db5c77__9046a5f27c39cb2f8c110f7c6599f945648e55acf4979c3e6af42f92ad67143a HTTP/1.1" 200 2007 "-" "docker/1.10.3 go/go1.5.3 git-commit/20f81dd kernel/3.18.10-gentoo os/linux arch/amd64" "-" 0.011
192.168.20.16 - - [28/Sep/2016:15:55:43 +0800] "GET /v2/dae-lunar/blobs/sha256:fb781d214197779f45d002c20ff3f5084b817389889c6f9057ca02e9ef34dc85 HTTP/1.1" 200 2839 "-" "docker/1.10.3 go/go1.5.3 git-commit/20f81dd kernel/3.18.10-gentoo os/linux arch/amd64" "-" 0.010
192.168.20.16 - - [28/Sep/2016:15:55:43 +0800] "GET /v2/dae-rasha/blobs/sha256:b80ae88db4
@Ma233
Ma233 / daemonize.py
Last active October 13, 2024 17:35
double fork in python
# encoding: utf-8
import os
import sys
import time
import atexit
from signal import SIGTERM
'''
A daemon class referred from
`http://www.jejik.com/files/examples/daemon.py`
#!/usr/bin/env python
# encoding: utf-8
from functools import partial
import requests
class URLAgent(object):
def __init__(self, host, handler=None, actions=set()):
self._host = host
@Ma233
Ma233 / open_repo
Last active December 5, 2016 07:40
chmod a+x open_repo && cp ./open_repo $HOME/bin && git config --global alias.open '!open_repo'
#!/usr/bin/env python
# encoding: utf-8
import sys
import subprocess
def convert_git_url(git_url):
if git_url.startswith('git@'):
git_url = 'http://' + '/'.join(git_url[4:].split(':'))
return git_url
@Ma233
Ma233 / dict.py
Created January 20, 2016 06:43
pip install pyobjc-framework-DictionaryServices && ln -s ./dict.py /usr/bin/dict
#!/usr/bin/python
import re
import sys
from DictionaryServices import DCSCopyTextDefinition
split_re = re.compile(r"\s+(?=[A-Z]\.\s)")
_split_re = re.compile(r"(?=" + u"[\u2460-\u2473]" + r")")
def search(word):