http://golang.org/doc/GoCourseDay1.pdf
vi fib.go
package main
import "fmt"
func fib(n int) int {
if n < 2 { return n }
return fib(n-2) + fib(n-1)
}
func main() {
n := 39;
fmt.Printf("%d\n", fib(n))
}
$ 8g fib.go
$ 8l -o fib fib.8
$ ./fib
63245986
package main
import "fmt"
func fib(n int) int {
if n < 2 { return n }
return fib(n-2) + fib(n-1)
}
func main() {
n := 39;
fmt.Printf("%d\n", fib(n))
}
define ('FTP_HOST', 'hostname:21');
import web
import datetime
from google.appengine.ext import db
urls = (
'/', 'index',
'/add', 'add',
'/update', 'update',
'/delete', 'delete',
)
render = web.template.render('templates/')
class Todo(db.Model):
body = db.StringProperty(required=True)
create_date = db.DateTimeProperty()
update_date = db.DateTimeProperty()
class index:
def GET(self):
todoes = Todo.all()
return render.index(todoes)
class add:
def POST(self):
i = web.input("body")
todo = Todo(body=i.body)
todo.create_date = datetime.datetime.now()
todo.update_date = datetime.datetime.now()
todo.put()
web.seeother("/")
class update:
def POST(self):
i = web.input()
todo = Todo.get(i.key)
todo.body = i.body
todo.update_date = datetime.datetime.now()
todo.put()
web.seeother("/")
class delete:
def POST(self):
i = web.input('key')
q = Todo.get(i.key)
#q = Todo.get('agl3ZWJweXRvZG9yCgsSBFRvZG8YBgw')
q.delete()
web.seeother("/")
if __name__ == '__main__':
app = web.application(urls, globals())
main = app.cgirun()
application: webpytodo
version: 2
runtime: python
api_version: 1
handlers:
- url: .*
script: main.py
def cgirun(self, *middleware):
"""
Return a CGI handler. This is mostly useful with Google App Engine.
There you can just do:
main = app.cgirun()
"""
wsgiapp = self.wsgifunc(*middleware)
try:
from google.appengine.ext.webapp.util import run_wsgi_app
return run_wsgi_app(wsgiapp)
except ImportError:
# we're not running from within Google App Engine
return wsgiref.handlers.CGIHandler().run(wsgiapp)
render = web.template.render('templates/')
python web/template.py --compile templates/
#!/bin/sh
while test -n "$1"; do
case "$1" in
-H)
HOST=$2
;;
-u)
USER=$2
;;
-p)
PASS=$2
;;
esac
shift
done
MYSQL="/usr/bin/mysql"
QUERY="show slave status\G"
DIR="/usr/lib/nagios/plugins"
. $DIR/utils.sh
IO_CHECK=`echo $QUERY | $MYSQL -u$USER -p$PASS -h $HOST | grep Slave_IO_Running | awk '{print $2}' `
SQL_CHECK=`echo $QUERY | $MYSQL -u$USER -p$PASS -h $HOST | grep Slave_SQL_Running | awk '{print $2}' `
#echo $IO_CHECK
#echo $SQL_CHECK
if test $IO_CHECK = "Yes" -a $SQL_CHECK = "Yes"; then
exitstatus=$STATE_OK
#exitstatus=$STATE_CRITICAL
else
exitstatus=$STATE_CRITICAL
#exitstatus=$STATE_OK
fi
$ECHO "IO_STATUS: $IO_CHECK, SQL_STATUS: $SQL_CHECK"
exit $exitstatus
#!/usr/bin/python -Wignore::FutureWarning
# -*- encoding: utf-8 -*-
import urllib, re, sys, md5, time
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-H', type='string')
parser.add_option('-u', type='string')
parser.add_option('-w', type='int')
parser.add_option('-c', type='int')
(options, args) = parser.parse_args()
## 定数
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
##
comp=re.compile("(.*)")
def genmd5(str): return md5.new(str).hexdigest()
def check_url(url, str):
check = None
pre = time.time()
res = urllib.urlopen(url)
post = time.time()
exec_time = post-pre
if options.c > exec_time:
for i in res:
line = i.rstrip('\n')
#print line
if comp.match(line):
check = comp.split(line)[1]
#print check
if check == str:
return ("OK", check, exec_time, STATE_OK)
#return ("CRITICAL", check, exec_time, STATE_CRITICAL)
return ("CRITICAL", "mismatch", exec_time, STATE_CRITICAL)
else: return ("CRITICAL", "TIMEOUT", exec_time, STATE_CRITICAL)
def main():
scheme = "http://"
uri = options.u
host = options.H
url = scheme + host + uri
genstr = genmd5(host)
try:
(state, str, exec_time, flag) = check_url(url, genstr)
except:
state = "HTTP_ERROR"
exec_time = None
str = None
flag = STATE_WARNING
print "URL %s %s %s %s %s" % (state, exec_time, str, genstr, url)
sys.exit(flag)
if __name__ == '__main__':
main()
#!/usr/bin/python
import md5, socket
def genmd5(str): return md5.new(str).hexdigest()
host = socket.gethostbyname(socket.gethostname())
print "Content-type: text/html\n\n";
print "%s" % genmd5(host)