格式测试模板
text
Copyright:: 2011, Opscode, Inc
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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
python
import tarfile
import optparse
import subprocess
from distutils import log
try:
from site import USER_SITE
except ImportError:
USER_SITE = None
DEFAULT_VERSION = "0.8"
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
def _python_cmd(*args):
args = (sys.executable,) + args
return subprocess.call(args) == 0
html
<html>
<head>
<meta charset="utf-8">
<title>GitHub System Status</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" href="/assets/application.css" type="text/css"/>
<link rel='icon' type='image/png' href='/images/status-icon-green.png'>
<script src="/assets/application.js"></script>
</head>
<body class="graph-page">
<div id="header" class="wrap">
<h1 class="logo"><a href="/"><img src="/images/logo-good.png" alt="github:status" /></a></h1>
<h2 id="last_updated">
Updated <abbr class="timeago" title="2013-11-24T04:25:18Z">2013-11-24T04:25:18Z</abbr>
</h2>
</div>
<div id="footer" class="wrap">
<div id="legal">
<ul>
<li><a href="http://github.com/blog">The GitHub Blog</a></li>
<li><a href="mailto:support@github.com">Support</a></li>
<li><a href="/api">API</a></li>
</ul>
<p>© 2013 GitHub Inc. All rights reserved.</p>
</div>
<div class="github">
<a href="http://github.com"><img src="/images/invertocat.png" alt="GitHub.com" /></a>
</div>
</div>
</body>
</html>
bash
# sumalg 可选值有 "cksum" "md5sum" "sha1sum" 等哈希算法程序
sumalg=md5sum
# 需加密的字符串的格式为:"UserName:IDentify@NakedDomain%LenthOfPwd"
if [ "$1" != "" ]; then exit; fi
read -p "input > " s;
n="`echo -n $s |awk -F '%' '{print $2}'`" # n值是指密码的长度
if [ "$n" -lt 1 ]; then echo "The Lenth Of the Password Is Too Lack !"; exit 2; fi
if [ "$n" -gt 99 ]; then echo "The Lenth Of the Password Is Too Long !"; exit 3; fi
e="`echo -n $s |$sumalg |awk '{print $1}' |tr a-z A-Z`" # e值是用哈希算法加密s字符串,所生成的值
while [ $(expr length $e) -lt $n ]; do e=$e$e; done # 若所需要的密码长度大于e值长度,则将e值长度乘以2
p="`expr $(expr length $e) % $n`" # p值:e值与n值进行取模运算后所得的数
if [ "$p" == "0" ]; then p=1; fi # 若p值为0则令p值为1,防止无法进行下面的字符串e值的截取
e="`echo $e |cut -b $p-$(($p+$n-1))`" # e值的新值:从e值的p值所在字符开始截取,长度为n值
echo "output:" ${e} # 密码
nginx
user nginx;
worker_processes 8;
pid /var/run/nginx.pid;
#error_log /data/log/nginx/error.log;
#error_log /data/log/nginx/error.log notice;
error_log /data/log/nginx/error.log warn;
events {
use epoll;
worker_connections 30000;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /data/log/nginx/access.log main;
gzip on;
sendfile on;
#tcp_nopush on;
keepalive_timeout 60;
client_max_body_size 256k;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_connect_timeout 300;
fastcgi_buffers 4 256k;
fastcgi_buffer_size 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include /etc/nginx/conf.d/*.conf;
}
c
/* 问题: 使用goto语句是很不好的 */
int foo(int bar)
{
if (!do_something( bar ))
{
goto error;
}
if (!init_stuff( bar ))
{
goto error;
}
if (!prepare_stuff( bar ))
{
goto error;
}
return do_the_thing( bar );
error:
return 0;
}
/* 问题:太多的if嵌套了,无法阅读 */
int foo(int bar)
{
int return_value = 0;
if (do_something( bar ))
{
if (init_stuff( bar ))
{
if (prepare_stuff( bar ))
{
return_value = do_the_thing( bar );
}
}
}
return return_value;
}