Skip to content

Instantly share code, notes, and snippets.

View Leechael's full-sized avatar
🐹
Working from home

Leechael Leechael

🐹
Working from home
View GitHub Profile
@Leechael
Leechael / result.py
Last active January 16, 2019 23:10
Thanks Rust!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import copy
PY2 = sys.version_info[0] == 2
class Result(object):
@Leechael
Leechael / _.js
Created August 29, 2018 08:03
Resolving Promises Sequentially: Kefir.js version
// https://hackernoon.com/functional-javascript-resolving-promises-sequentially-7aac18c4431e
// Kefir.js version.
// Just a demo.
var ids = [1, 2, 3, 4];
var thenables = ids.map(i => {
let thenable = fetch(`https://httpbin.org/anything?id=${i}`)
.then(r => r.json())
.then(obj => obj.args.id);
return Kefir.fromPromise(thenable);
})
@Leechael
Leechael / Setup Let's Encrypt with Dehydrated.md
Last active March 15, 2018 13:35
Setup Let's Encrypt with Dehydrated

Letsencrypt SSL cert 设置笔记

Step 1: 下载 dehydrated

wget https://raw.githubusercontent.com/lukas2511/dehydrated/116386486b3749e4c5e1b4da35904f30f8b2749b/dehydrated

UPDATE: 下载最新版本:

wget https://raw.githubusercontent.com/lukas2511/dehydrated/master/dehydrated
@Leechael
Leechael / setup-fluentd-initscript.sh
Created September 8, 2012 04:35
Fluentd init script setup for Debian
#!/usr/bin/env bash
#if [ `whoami` != 'root' ]; then
#echo "Please run as root."
#exit 1
#fi
cat << 'EOF' > /etc/init.d/fluentd
#! /bin/sh
@Leechael
Leechael / maybe.py
Last active December 29, 2016 04:34 — forked from zvyn/maybe.py
# maybe.py - a Pythonic implementation of the Maybe monad
# Copyright (C) 2014. Milan Oberkirch <milan.py@oberkirch.org>
# Copyright (C) 2014. Senko Rasic <senko.rasic@goodcode.io>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@Leechael
Leechael / fputils.py
Created November 30, 2016 10:32
Buggy: inspect.iscoroutinefunction and inspect.isfunction :(
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import inspect
def iscoroutinefunction(fn):
if inspect.iscoroutinefunction(fn):
return True
if inspect.iscoroutinefunction(getattr(fn, "__call__", None)):
return True
@Leechael
Leechael / timing.py
Created July 31, 2016 16:35
Poorman's mitmproxy based request timing
from time import time
def start(context):
context.log("Format: [send data timing] [waitting timing] [receive data timing] Request URL")
def request(context, flow):
context.started_at = time()
def response(context, flow):
sending = flow.request.timestamp_end - flow.request.timestamp_start
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from os import environ, path, makedirs
import imghdr
from datetime import datetime, timedelta
from concurrent.futures import ThreadPoolExecutor
from tornado import gen
from tornado.concurrent import run_on_executor
@Leechael
Leechael / ssl-cert-info.sh
Last active February 20, 2016 15:20
Added `-servername` option to get correct info for sub-domain. Original: http://giantdorks.org/alain/shell-script-to-check-ssl-certificate-info-like-expiration-date-and-subject/
#!/bin/bash
usage()
{
cat <<EOF
Usage: $(basename $0) [options]
This shell script is a simple wrapper around the openssl binary. It uses
s_client to get certificate information from remote hosts, or x509 for local
certificate files. It can parse out some of the openssl output or just dump all
#!/usr/bin/env python
# encoding: utf-8
def retriable(retry_counts=3, before_retry=None, final=None, noexc=False):
is_callable = lambda x: x is not None and hasattr(x, "__call__")
if not is_callable(before_retry):
before_retry = lambda err, c: c
if not is_callable(final):
final = lambda err, c: c