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 / virtualbox_4_1.rb.patch
Created September 8, 2012 17:45
Added `:both` support for forward_port protocol configuration
--- virtualbox_4_1.rb.orig 2012-09-09 01:24:56.000000000 +0800
+++ virtualbox_4_1.rb 2012-09-09 01:39:32.000000000 +0800
@@ -135,15 +135,22 @@
def forward_ports(ports)
args = []
ports.each do |options|
- pf_builder = [options[:name],
- options[:protocol] || "tcp",
- "",
- options[:hostport],
@Leechael
Leechael / pjson.py
Created November 10, 2012 07:21
Pretty print for JSON, in Python
#!/usr/bin/env python
# -*- coding: utf8 -*-
from simplejson import loads
from simplejson.decoder import JSONDecodeError
from betterprint import pprint
from os import path
if __name__ == '__main__':
@Leechael
Leechael / gist:4074485
Created November 14, 2012 20:17
vmlive and vmstart: my handy commands for VirtualBox Instance Management
alias vmlive="VBoxManage list runningvms"
function vmstart () {
if [ -e $1 ]; then
echo 'No VirualMachine specified. All available machines:'
VBoxManage list vms | cut -d'"' -f2 | sed -E 's/(.*)/> \1/'
return
fi
local _EXISTS=`VBoxManage list vms | grep $1 | wc -l | awk '{print $1}'`
if [ ! $_EXISTS -eq 1 ]; then
@Leechael
Leechael / proc.py
Last active December 10, 2015 11:29
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from itertools import imap
from functools import partial
import types
"""
Usage:
@Leechael
Leechael / build_lightpng.sh
Created April 17, 2013 19:11
Small script that build lightpng on Mac OS X (with Homebrew installed).
#!/usr/bin/env bash
git clone -q git://github.com/shibukawa/lightpng.git
pushd lightpng
wget -nv "http://nchc.dl.sourceforge.net/project/boost/boost/1.53.0/boost_1_53_0.tar.bz2"
tar xjf boost_1_53_0.tar.bz2
git submodule update --init
which scons || sudo brew install scons
./build.sh
@Leechael
Leechael / example.py
Created June 9, 2013 08:28
Graceful shutdown handler for Tornado.
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import sys
import logging
logging.basicConfig(level=logging.DEBUG,
stream=sys.stdout)
@Leechael
Leechael / benchmarks.py
Created July 26, 2013 09:34
Concurrency HTTP request benchmark
#!/usr/bin/env python
# encoding: utf-8
from contextlib import contextmanager
#
# Helpers
#
#!/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
@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
# -*- 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