Skip to content

Instantly share code, notes, and snippets.

View yao2030's full-sized avatar

yao2030 yao2030

  • Shanghai, China
View GitHub Profile
@yao2030
yao2030 / ex02.sh
Created September 26, 2013 07:52
ex02.sh
#!/usr/bin/sh
pipe=/tmp/out
#if [[ ! -p $pipe ]]; then
# echo "Reader not running"
# exit 1
#fi
while true
do
ip=`hostname -i`
@yao2030
yao2030 / ex01(modified).sh
Created September 26, 2013 07:54
ex01.sh for ex02.sh
#!/usr/bin/sh
pipe=/tmp/out
#if [[ ! -p $pipe ]]; then
# echo "Reader not running"
# exit 1
#fi
while true
do
ip=`hostname -i`
@yao2030
yao2030 / ex01.sh
Created September 26, 2013 07:54
ex01.sh
#!/usr/bin/sh
while true
do
ip=`hostname -i`
date=`date +"%d/%b/%Y:%k:%M:%S %z"`
r=$RANDOM;
random=$(($r+10000000))
time=$[RANDOM % 200 + 10]
echo "[$ip [$date] \"$random\" time=${time}ms]";
done
@yao2030
yao2030 / ex02.sh
Created September 26, 2013 09:17
ex02.sh(new)
#!/usr/bin/sh
pipe=/tmp/out
#trap "rm -rf $pipe" EXIT
#if [[ ! -p $pipe ]]; then
# mkfifo $pipe
#fi
out=1
while true
do
@yao2030
yao2030 / conf_ini.py
Created November 1, 2013 13:45
read a configuration file
#!/usr/local/bin/python2.7
section = ""
ini_dict = {}
with open("input.txt") as f:
for l in f:
x = l.strip()
if not x:
#!/usr/local/bin/python2.7
grad = {}
stu = {}
with open("input.txt") as f:
for l in f:
name, score = l.strip().split()
if name not in grad:
grad[name] = 0
#!/usr/local/bin/python2.7
x = [
{ "a": "hoooooo",
"b": "wo",
"c": "rrrruuu",
},
{
"a": "en?",
"b": "wwwwlllllyyy",
@yao2030
yao2030 / sema.py
Created December 5, 2013 12:16
python multithreading semaphore
#!/usr/bin/env python
import threading
import urllib2
import time, random
class GrabUrl(threading.Thread):
def __init__(self, arg0):
threading.Thread.__init__(self)
self.host = arg0
@yao2030
yao2030 / Barbecue.py
Last active December 30, 2015 08:49
test
import time
import random
class Customer:
def __init__(self, id):
self.id = id
self.foods = []
self.start = time.time()
def choose_foods(self):
self.foods = random_choose(5)
# -*- coding: UTF-8 -*-
import os
import sys
from Queue import Queue
import random
import threading
import time