Skip to content

Instantly share code, notes, and snippets.

@jon-uw
jon-uw / docker-enter
Created October 29, 2014 08:22
使用nsenter进入Docker容器http://www.hjue.me/post/docker-nsenter
if [ -e $(dirname "$0")/nsenter ]; then
# with boot2docker, nsenter is not in the PATH but it is in the same folder
NSENTER=$(dirname "$0")/nsenter
else
NSENTER=nsenter
fi
if [ -z "$1" ]; then
echo "Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]"
echo ""
import os
"""
as bash command: du -sb dir
+4906: add 4096bytes for the top dir
"""
def du_sb(dir):
return sum(os.path.getsize(f) for f in reduce(lambda x,y:x+y, [[os.path.join(w[0], fe) for fe in w[1] + w[2]] for w in os.walk(dir)])) + 4096;
def get_total_file_size(dir):
return sum(os.path.getsize(f) for f in reduce(lambda x,y:x+y, [[os.path.join(w[0], fe) for fe in w[1] + w[2]] for w in os.walk(dir)]) if os.path.isfile(f))
@jon-uw
jon-uw / win_key.rb
Created November 5, 2013 09:04
stimulate windows key stroking from oschina.net
require 'win32api'
class KeyBoardHelper
attr_reader :ctrl, :shift, :alt, :win
def initialize
@ctrl, @shift, @alt, @win = 0x11, 0x10, 0x12, 0x5b
@bScan, @downFlag, @upFlag, @extraInfo = 0x45, 1, 3, 0
@ke = Win32API.new('User32.dll', 'keybd_event', 'IIII')
require 'net/http'
require 'rubygems'
require 'json'
require 'uri'
topicId='DOubanTA'
maxCount = 50
# get topic count
#response = Net::HTTP.get_response('www.baidu.com', "/index.html");
@jon-uw
jon-uw / cd_mark
Last active December 21, 2015 22:19
linux directory mark utils to change dir fast. copy from: http://www.ccvita.com/520.html
#!/bin/bash
# mark dir
# add this line to ~/.bashrc:
# if [ -f cd_mark ]; then ./cd_mark; fi
# usage: func $mark
# mls: list all the mark