Skip to content

Instantly share code, notes, and snippets.

View lhwork's full-sized avatar

李焕 lhwork

  • 热酷
  • http://www.gravatar.com/avatar/14cdd9dd97899e09d30ee7b012a73117.png
View GitHub Profile
@cooldaemon
cooldaemon / udp_server.erl
Created July 23, 2008 01:53
This is udp server framework for Erlang.
%% @author Masahito Ikuta <cooldaemon@gmail.com> [http://d.hatena.ne.jp/cooldaemon/]
%% @copyright Masahito Ikuta 2008
%% @doc UDP Server Behaviour.
%% Copyright 2008 Masahito Ikuta
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
#!/usr/local/bin/python
import rrdtool
def create_rrd(fname):
DSs = ['DS:in:GAUGE:600:U:U','DS:out:GAUGE:600:U:U']
RRAs = [
'RRA:AVERAGE:0.5:1:603',
'RRA:AVERAGE:0.5:6:603',
'RRA:AVERAGE:0.5:24:603',
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
@micktwomey
micktwomey / client.py
Created October 1, 2010 13:03
python multiprocessing socket server example
import socket
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("localhost", 9000))
data = "some data"
sock.sendall(data)
result = sock.recv(1024)
print result
sock.close()
@andymccurdy
andymccurdy / crier.py
Created December 11, 2010 01:09
Crier: simple introspection for long-running Python processes
import pprint
import os
import sys
import threading
import time
import traceback
_crier = None
def init_crier(temp_dir='/tmp'):
"Initialzies Crier, ensuring it's only created once in the process"
@tmc
tmc / gist:777085
Created January 12, 2011 23:08
multiprocessing gevent chat example
import sys
import gevent
from gevent.monkey import patch_all; patch_all()
from gevent import server, event, socket
from multiprocessing import Process, current_process, cpu_count
"""
Simple multiprocess StreamServer that proxies messages between clients.
Avoids using a multiprocessing.Event since it blocks on a semaphore.
@btompkins
btompkins / Fabric-UserSetup.py
Created February 7, 2011 18:15
Simple fabric function to create a new user
def new_user(admin_username, admin_password):
env.user = 'root'
# Create the admin group and add it to the sudoers file
admin_group = 'admin'
runcmd('addgroup {group}'.format(group=admin_group))
runcmd('echo "%{group} ALL=(ALL) ALL" >> /etc/sudoers'.format(
group=admin_group))
# Create the new admin user (default group=username); add to admin group
@coopernurse
coopernurse / gist:904526
Created April 5, 2011 20:53
gevent - limit example
#!/usr/bin/env python
import sys
from gevent import Greenlet
from gevent.pool import Pool
from gevent.server import StreamServer
from gevent.socket import create_connection
bind_addr = '127.0.0.1'
port = 32392
@ouyangzhiping
ouyangzhiping / gist.rb
Created July 8, 2011 15:24
github库修改之后的gist.rb文件
# Copyright 2008 Chris Wanstrath
# Taken from defunkt's gist repository: http://github.com/defunkt/gist/tree/master
require 'open-uri'
require 'net/http'
require 'net/https'
module Gist
extend self
@fwolf
fwolf / mt-mon.sh
Created August 24, 2011 09:04
Monitor system mem and load, if too high, restart some service.
#! /bin/bash
#====================================================================
# mt-mon.sh
#
# Copyright (c) 2011, Fwolf <fwolf.aide+fwolfbin@gmail.com>
# All rights reserved.
# Distributed under the GNU General Public License, version 3.0.
#
# Monitor system mem and load, if too high, restart some service.