Skip to content

Instantly share code, notes, and snippets.

View tawateer's full-sized avatar
Focusing

wateer tawateer

Focusing
  • Tencent
  • Beijing
View GitHub Profile
#!/usr/bin/env sh
### Download and install megaraidcli for Ubuntu;
FILE="megacli_8.07.14.orig.tar.gz"
LINK="http://hwraid.le-vert.net/ubuntu/sources/$FILE"
wget $LINK -O /tmp/$FILE
cd /tmp
@tawateer
tawateer / cmdtimeout.go
Created June 16, 2017 10:39 — forked from scottcagno/cmdtimeout.go
Golang exec.Command Timeout Wrapper
package main
import (
"bytes"
"fmt"
"os/exec"
"time"
)
func run(timeout int, command string, args ...string) string {
@tawateer
tawateer / 0_pw_hash.rb
Created December 14, 2016 04:23 — forked from pschyska/0_pw_hash.rb
PW hashing with puppet parser function
# lib/puppet/parser/functions/pw_hash.rb
module Puppet::Parser::Functions
newfunction(:pw_hash, type: :rvalue) do |args|
raise Puppet::ParseError, "pw_hash takes exactly two arguments, #{args.length} provided" if args.length != 2
# SHA512 ($6), default number of rounds (5000)
# rounds could be specified by prepending rounds=<n>$ parameter before the salt, i.e.
# args[0].crypt("$6$rounds=50000$#{args[1]}")
args[0].crypt("$6$#{args[1]}")
end
@tawateer
tawateer / iftop.py
Last active December 13, 2016 04:05 — forked from zhouqiang-cl/iftop.py
在机器上抓取到另一个网段的出入流量,基于 iftop,输出是 open-falcon 的数据收集格式。
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
@author: zhouqiang-cl@gmail.com
@date: 2016-12-12
抓取机器到另外一个机房的出入流量,并格式化输出. 包括到另外机房的每个ip的流量。
iftop 要使用较高的版本. centos 中建议 1.0pre4 以上.
"""
import subprocess
import socket
@tawateer
tawateer / GrabUrl2.py
Created April 7, 2016 17:02 — forked from presci/GrabUrl2.py
Semaphore example in python 2
import threading
import urllib2
import time, random
class GrabUrl(threading.Thread):
def __init__(self, arg0):
threading.Thread.__init__(self)
self.host=arg0
def run(self):
k=random.randint(10,20)
@tawateer
tawateer / client.go
Created December 22, 2015 15:40 — forked from jordanorelli/client.go
rpc server example in go
package main
import (
"bufio"
"log"
"net/rpc"
"os"
)
func main() {
@tawateer
tawateer / graceful_shutdown_tornado_web_server.py
Last active September 6, 2015 15:18 — forked from mywaiting/graceful_shutdown_tornado_web_server.py
The example to how to shutdown tornado web server gracefully...
#!/usr/bin/env python
"""
How to use it:
1. Just `kill -2 PROCESS_ID` or `kill -15 PROCESS_ID` , The Tornado Web Server Will shutdown after process all the request.
2. When you run it behind Nginx, it can graceful reboot your production server.
3. Nice Print in http://weibo.com/1682780325/zgkb7g8k7
"""
@tawateer
tawateer / futures_test.py
Last active August 29, 2015 14:27 — forked from lbolla/futures_test.py
Tornado and concurrent.futures
from concurrent.futures import ThreadPoolExecutor
from functools import partial, wraps
import time
import tornado.ioloop
import tornado.web
EXECUTOR = ThreadPoolExecutor(max_workers=4)
#!/usr/bin/env/python
#
# More of a reference of using jinaj2 without actual template files.
# This is great for a simple output transformation to standard out.
#
# Of course you will need to "sudo pip install jinja2" first!
#
# I like to refer to the following to remember how to use jinja2 :)
# http://jinja.pocoo.org/docs/templates/
#

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens