Comments (11)
在docker环境下
按照docker-compose
➜ workspace docker pull
"docker pull" requires exactly 1 argument.
See 'docker pull --help'.
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST] [flags]
Pull an image or a repository from a registry
➜ workspace docker image
Usage: docker image COMMAND
Manage images
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
➜ workspace docker-compose
zsh: command not found: docker-compose
➜ workspace pip install docker-compose
Collecting docker-compose
Downloading https://files.pythonhosted.org/packages/26/d6/c2a33eb82f3bd59da803f812844e47211c353247f9dfb0938800b46af99d/docker_compose-1.21.0-py2.py3-none-any.whl (123kB)
100% |████████████████████████████████| 133kB 107kB/s
Collecting websocket-client<1.0,>=0.32.0 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/9d/fb/f51a03e232e00d6c504dfe815aed090c894ba3f8d3f7fd9612f3e227bf24/websocket_client-0.47.0-py2.py3-none-any.whl (200kB)
100% |████████████████████████████████| 204kB 306kB/s
Collecting backports.ssl-match-hostname>=3.5; python_version < "3.5" (from docker-compose)
Downloading https://files.pythonhosted.org/packages/76/21/2dc61178a2038a5cb35d14b61467c6ac632791ed05131dda72c20e7b9e23/backports.ssl_match_hostname-3.5.0.1.tar.gz
Collecting PyYAML<4,>=3.10 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/4a/85/db5a2df477072b2902b0eb892feb37d88ac635d36245a72a6a69b23b383a/PyYAML-3.12.tar.gz (253kB)
100% |████████████████████████████████| 256kB 75kB/s
Collecting dockerpty<0.5,>=0.4.1 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/8d/ee/e9ecce4c32204a6738e0a5d5883d3413794d7498fe8b06f44becc028d3ba/dockerpty-0.4.1.tar.gz
Collecting ipaddress>=1.0.16; python_version < "3.3" (from docker-compose)
Downloading https://files.pythonhosted.org/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress-1.0.22-py2.py3-none-any.whl
Collecting docopt<0.7,>=0.6.1 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-0.6.2.tar.gz
Collecting enum34<2,>=1.0.4; python_version < "3.4" (from docker-compose)
Downloading https://files.pythonhosted.org/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6-py2-none-any.whl
Collecting requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl (88kB)
100% |████████████████████████████████| 92kB 30kB/s
Collecting texttable<0.10,>=0.9.0 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/02/e1/2565e6b842de7945af0555167d33acfc8a615584ef7abd30d1eae00a4d80/texttable-0.9.1.tar.gz
Collecting cached-property<2,>=1.2.0 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/ca/21/d793828ce0bb01baa6bed307c68466829343cc93fccc055cfbc21f774959/cached_property-1.4.2-py2.py3-none-any.whl
Collecting jsonschema<3,>=2.5.1 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/77/de/47e35a97b2b05c2fadbec67d44cfcdcd09b8086951b331d82de90d2912da/jsonschema-2.6.0-py2.py3-none-any.whl
Collecting docker<4.0,>=3.2.1 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/e4/c0/ab62cdb6117c1b9824e54f707060eb63ef7e4026d9aedf2d10853ba6df98/docker-3.2.1-py2.py3-none-any.whl (123kB)
100% |████████████████████████████████| 133kB 40kB/s
Collecting six<2,>=1.3.0 (from docker-compose)
Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1->docker-compose)
Downloading https://files.pythonhosted.org/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl (150kB)
100% |████████████████████████████████| 153kB 24kB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1->docker-compose)
Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 29kB/s
Collecting idna<2.7,>=2.5 (from requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1->docker-compose)
Downloading https://files.pythonhosted.org/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 60kB/s
Collecting urllib3<1.23,>=1.21.1 (from requests!=2.11.0,!=2.12.2,!=2.18.0,<2.19,>=2.6.1->docker-compose)
Downloading https://files.pythonhosted.org/packages/63/cb/6965947c13a94236f6d4b8223e21beb4d576dc72e8130bd7880f600839b8/urllib3-1.22-py2.py3-none-any.whl (132kB)
100% |████████████████████████████████| 133kB 58kB/s
Collecting functools32; python_version == "2.7" (from jsonschema<3,>=2.5.1->docker-compose)
Downloading https://files.pythonhosted.org/packages/c5/60/6ac26ad05857c601308d8fb9e87fa36d0ebf889423f47c3502ef034365db/functools32-3.2.3-2.tar.gz
Collecting docker-pycreds>=0.2.2 (from docker<4.0,>=3.2.1->docker-compose)
Downloading https://files.pythonhosted.org/packages/1c/8b/538e392ecd02aef761390fd30f057af73679839bd2096130689d73142aea/docker_pycreds-0.2.2-py2.py3-none-any.whl
Building wheels for collected packages: backports.ssl-match-hostname, PyYAML, dockerpty, docopt, texttable, functools32
Running setup.py bdist_wheel for backports.ssl-match-hostname ... done
Stored in directory: /home/coding/.cache/pip/wheels/99/7e/f7/a88a9bcf7a3bd6b12cf6a74eee8c89746aaa02f71ab7b33939
Running setup.py bdist_wheel for PyYAML ... done
Stored in directory: /home/coding/.cache/pip/wheels/03/05/65/bdc14f2c6e09e82ae3e0f13d021e1b6b2481437ea2f207df3f
Running setup.py bdist_wheel for dockerpty ... done
Stored in directory: /home/coding/.cache/pip/wheels/e5/1e/86/bd0a97a0907c6c654af654d5875d1d4383dd1f575f77cee4aa
Running setup.py bdist_wheel for docopt ... done
Stored in directory: /home/coding/.cache/pip/wheels/9b/04/dd/7daf4150b6d9b12949298737de9431a324d4b797ffd63f526e
Running setup.py bdist_wheel for texttable ... done
Stored in directory: /home/coding/.cache/pip/wheels/99/1e/2b/8452d3a48dad98632787556a0f2f90d56703b39cdf7d142dd1
Running setup.py bdist_wheel for functools32 ... done
Stored in directory: /home/coding/.cache/pip/wheels/b5/18/32/77a1030457155606ba5e3ec3a8a57132b1a04b1c4f765177b2
Successfully built backports.ssl-match-hostname PyYAML dockerpty docopt texttable functools32
Installing collected packages: six, websocket-client, backports.ssl-match-hostname, PyYAML, dockerpty, ipaddress, docopt, enum34, certifi, chardet, idna, urllib3, requests, texttable, cached-property, functools32, jsonschema, docker-pycreds, docker, docker-compose
Successfully installed PyYAML backports.ssl-match-hostname cached-property certifi chardet docker docker-compose docker-pycreds dockerpty docopt enum34 functools32 idna ipaddress jsonschema requests six texttable urllib3 websocket-client
You are using pip version 8.1.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
from learn-es6.
nginx.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
from learn-es6.
docker-compose.yaml
version: '2'
# 定义服务 我这里nginx + php
services:
nginx:
# 依赖关系 先跑php
depends_on:
- "php"
image: "nginx:latest"
# 数据卷
volumes:
- "$PWD/conf.d:/etc/nginx/conf.d"
- "$PWD/html:/usr/share/nginx/html"
# 端口映射
ports:
- "8082:80"
# 容器名称
container_name: "compose-nginx"
php:
image: "php:fpm"
volumes:
- "$PWD/html:/var/www/html"
container_name: "compose-php"
from learn-es6.
$ docker-compose
Define and run multi-container applications with Docker.
Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
Options:
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
-p, --project-name NAME Specify an alternate project name (default: directory name)
--verbose Show more output
--no-ansi Do not print ANSI control characters
-v, --version Print version and exit
-H, --host HOST Daemon socket to connect to
--tls Use TLS; implied by --tlsverify
--tlscacert CA_PATH Trust certs signed only by this CA
--tlscert CLIENT_CERT_PATH Path to TLS certificate file
--tlskey TLS_KEY_PATH Path to TLS key file
--tlsverify Use TLS and verify the remote
--skip-hostname-check Don't check the daemon's hostname against the name specified
in the client certificate (for example if your docker host
is an IP address)
--project-directory PATH Specify an alternate working directory
(default: the path of the Compose file)
Commands:
build Build or rebuild services
bundle Generate a Docker bundle from the Compose file
config Validate and view the Compose file
create Create services
down Stop and remove containers, networks, images, and volumes
events Receive real time events from containers
exec Execute a command in a running container
help Get help on a command
images List images
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pull service images
push Push service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show the Docker-Compose version information
尝试启动服务
docker-compose start
Starting php ...
Starting nginx ... error
ERROR: for php ('Connection aborted.', error(2, 'No such file or directory'))
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
from learn-es6.
docker-compose.yml
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
redis:
image: "redis:alpine"
app.py
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host='redis', port=6379)
@app.route('/')
def hello():
count = redis.incr('hits')
return 'Hello World! 该页面已被访问 {} 次。\n'.format(count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
Dockerfile
FROM python:3.6-alpine
ADD . /code
WORKDIR /code
RUN pip install redis flask
CMD ["python", "app.py"]
from learn-es6.
docker-compose.yml
version: '2'
# 定义服务 我这里nginx + php
services:
nginx:
# 依赖关系 先跑php
depends_on:
- "php"
image: "nginx:latest"
# 数据卷
volumes:
- "$PWD/conf.d:/etc/nginx/conf.d"
- "$PWD/html:/usr/share/nginx/html"
# 端口映射
ports:
- "8082:80"
# 容器名称
container_name: "compose-nginx"
php:
image: "php:fpm"
volumes:
- "$PWD/html:/var/www/html"
container_name: "compose-php"
index.php
<?php
phpinfo();
nginx.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
from learn-es6.
coding.php
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PHP Web Demo | Cloud Studio</title>
<style>
body {
background: #fff;
padding: 0;
margin: 0;
font-family: "PingFang SC", "Helvetica Neue", "Hiragino Sans GB", "Segoe UI", "Microsoft YaHei", 微软雅黑, sans-serif;
font-size: 16px;
}
a {
color: #0066FF;
text-decoration: none;
}
a:hover {
color: #0047B1;
}
h2 {
font-size: 36px;
font-weight: 500;
}
.container {
width: 100%;
text-align: center;
}
.cover {
width: 100%;
height: 390px;
background: url("https://dn-coding-net-production-pp.qbox.me/8564b26a-9cba-4417-951a-ab0d6f735c77.png") no-repeat bottom;
background-size: 700px;
background-color: #1E1E1E;
color: #fff;
padding-top: 150px;
display: block;
}
.header {
position: absolute;
top: 0;
left: 0;
right: 0;
padding: 24px;
display: flex;
}
.header .logo {
background: url("https://webide-1255989204.cos.ap-chengdu.myqcloud.com/StudioWebResource/Images/CloudStudio-Logo-Light.svg") -10px -9px no-repeat;
height: 0px;
width: 161px;
padding-top: 20px;
overflow: hidden;
display: inline-block;
}
.header .nav {
display: flex;
flex: 1;
list-style-type: none;
list-style-image: none;
margin: 0;
padding: 0;
}
.header .nav li {
padding-left: 30px;
}
.header .nav a {
font-size: 16px;
color: #fff;
text-decoration: none;
}
@media (max-width: 400px) {
.header {
padding: 24px 12px;
}
}
@media (max-width: 350px) {
.header .nav li {
padding-left: 16px;
}
}
#global_footer {
text-align: left;
}
#global_footer .record {
background: #232f40;
color: #76808e;
}
#global_footer .record_img_info img{
position: absolute;
max-width: 353px;
width: 100%;
height: auto;
}
#global_footer .record_info {
text-align: right;
font-size: 12px;
}
#global_footer .record_info p {
margin: 0;
height: 18px;
line-height: 18px;
}
#global_footer .record_info a {
color: #76808e;
text-decoration: none;
}
#global_footer .record_info a:hover {
color: #ddd;
}
#global_footer .record_img_info {
max-width: 1020px;
margin: auto;
padding: 30px 20px;
}
@media (max-width: 840px) {
#global_footer .record_img_info img{
position: relative;
margin-bottom: 20px;
}
#global_footer .record_img_info {
text-align: center;
}
#global_footer .record_info {
text-align: center;
}
}
.cover h1 {
font-size: 60;
margin-top: 0;
margin-bottom: 20px;
}
.dynamic {
width: 100%;
background: #F7FCFF;
padding: 60px 0;
font-weight: 500;
}
.dynamic .version {
color: #0066FF;
}
.tcloud-coupon {
padding: 80px 0;
}
.tcloud-coupon h2 {
margin: 0 auto 60px;
}
.tcloud-coupon p {
color: #425063;
max-width: 340px;
margin: 0 auto 30px;
}
.full-wide {
width: 100%;
height: 400px;
}
.half-wide {
width: 50%;
height: 400px;
float: left;
color: #fff;
}
.half-wide .content {
width: 520px;
height: 400px;
margin: 0 auto;
}
.half-wide .left {
width: 188px;
float: left;
text-align: left;
}
.half-wide .right {
width: 300px;
float: right;
height: 280px;
}
.half-wide h2 {
margin: 80px 0 40px;
text-align: left;
}
.half-wide a {
background: #fff;
padding: 12px 20px;
border-radius: 2px;
}
.half-wide a:hover {
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
.coding-intro {
background: #267AF9;
}
.coding-intro a {
color: #267AF9;
}
.coding-intro .right {
background: url("https://dn-coding-net-production-pp.qbox.me/76fe0573-ef14-4670-9459-54186ca90a32.png") no-repeat;
background-size: 300px auto;
margin-top: 54px;
}
.invite-friend {
background: #F7931B;
}
.invite-friend a {
color: #F7931B;
}
.invite-friend .right {
background: url("https://dn-coding-net-production-pp.qbox.me/fa15d556-a008-4f11-8f4a-83d0fd849537.png") no-repeat;
background-size: 300px auto;
margin-top: 30px;
}
@media (min-width: 1600px) {
.half-wide .content {
width: 580px;
}
}
@media (max-width: 1140px) {
.half-wide .content {
width: 490px;
}
}
@media (max-width: 1040px) {
.full-wide {
width: 100%;
height: 800px;
}
.half-wide .content {
width: 580px;
}
.half-wide {
float: none;
width: 100%;
}
}
@media (max-width: 640px) {
.half-wide .content {
width: 490px;
}
}
@media (max-width: 520px) {
.full-wide {
height: auto;
}
.half-wide {
height: auto;
}
.half-wide .content{
height: auto;
width: 100%;
padding: 20px 0;
}
.half-wide .left {
float: none;
width: auto;
text-align: center;
padding: 40px 20px;
}
.invite-friend .left {
padding-bottom: 0;
}
.half-wide h2 {
text-align: center;
margin: 0 auto 40px;
}
.half-wide .right {
float: none;
margin: auto;
}
}
</style>
</head>
<body>
<div class="container">
<div class="cover">
<div class="header">
<a href="https://studio.coding.net" class="logo">Cloud Studio</a>
<ul class="nav">
<li>
<a href="https://studio.coding.net/intro" target="_blank" rel="noopener noreferrer">产品介绍</a>
</li>
<li>
<a href="https://coding.net/help/doc/webide" target="_blank" rel="noopener noreferrer">帮助</a>
</li>
</ul>
</div>
<h1 class="title">欢迎使用 Cloud Studio</h1>
<p class="subtitle">这是一个 PHP Web Demo</p>
</div>
<div class="dynamic">
<?php
echo '<span>当前系统的 PHP 版本为</span>
<span class="version"> v' . phpversion() . '</span>
';
?>
</div>
<div class="tcloud-coupon">
<h2>领券免费使用 Cloud Studio</h2>
<p>绑定腾讯云账号即可领取一百元腾讯云代金券,足够 Cloud Studio 使用 6 个月。</p>
<a href="https://dnspod.cloud.tencent.com/act/coding">领取腾讯云优惠券</a>
</div>
<div class="full-wide">
<div class="half-wide coding-intro">
<div class="content">
<div class="left">
<h2>面向未来的项目与代码管理工具</h2>
<a href="https://coding.net/about">了解 CODING</a>
</div>
<div class="right"></div>
</div>
</div>
<div class="half-wide invite-friend">
<div class="content">
<div class="left">
<h2>邀请好友送现金红包</h2>
<a href="https://coding.net/help/account/invitation.html">查看活动详情</a>
</div>
<div class="right"></div>
</div>
</div>
</div>
<div id="global_footer">
<div class="record">
<div class="record_img_info">
<a href="https://coding.net/index">
<img src="https://dn-coding-net-production-pp.qbox.me/0905c8a9-5b33-4819-83d4-3cd0528b0c86.png"></a>
<div class="record_info">
<p>
<a href="https://coding.net/privacy" target="_blank" rel="noopener noreferrer">隐私策略</a>
<!-- react-text: 70 -->
|
<!-- /react-text -->
<a href="https://coding.net/terms" target="_blank" rel="noopener noreferrer">服务条款</a>
<!-- react-text: 72 -->
|
<!-- /react-text -->
<a href="https://coding.net/security" target="_blank" rel="noopener noreferrer">安全策略</a>
</p>
<p>
<a href="https://coding.net/index">© 2017 Coding.net</a>
<!-- react-text: 76 -->
|
<!-- /react-text -->
<a href="http://www.miitbeian.gov.cn/" target="_blank" rel="noopener noreferrer">粤ICP备14029750号</a>
<!-- react-text: 78 -->
| 深圳市扣钉网络科技有限公司
<!-- /react-text --> </p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
from learn-es6.
hello.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import time
def get_time():
return time.strftime('%Y-%m-%d',time.localtime(time.time()))
def get_host_ip():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
print "您好,欢迎来到 Cloud Studio"
print "当前时间是:" + get_time()
print "您的IP是:" + get_host_ip()
from learn-es6.
snake.py
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
"""
Simple Snake console game for Python 3.
From https://github.com/borisuvarov/cursed_snake
Use it as introduction to curses module.
Warning: curses module available only in Unix.
On Windows use UniCurses (https://pypi.python.org/pypi/UniCurses).
UniCurses is not installed by default.
"""
import curses # https://docs.python.org/3/library/curses.html
import time
import random
def redraw(): # Redraws game field and it's content after every turn
# win.erase()
win.clear()
draw_food() # Draws food on the game field
draw_snake() # Draws snake
draw_menu()
win.refresh()
def draw_menu():
win.addstr(0,0, "Score: " + str(len(snake) - 2) + " Press 'q' to quit", curses.color_pair(5))
def draw_snake():
try:
n = 0 # There can be only one head
for pos in snake: # Snake is the list of [y, x], so we swap them below
if n == 0:
win.addstr(pos[1], pos[0], "@", curses.color_pair(ex_foodcolor)) # Draws head
else:
win.addstr(pos[1], pos[0], "#", curses.color_pair(ex_foodcolor)) # Draws segment of the body
n += 1
except Exception as drawingerror:
print(drawingerror, str(cols), str(rows))
def draw_food():
for pos in food:
win.addstr(pos[1], pos[0], "+", curses.color_pair(foodcolor))
def drop_food():
x = random.randint(1, cols - 2)
y = random.randint(1, rows - 2)
for pos in snake: # Do not drop food on snake
if pos == [x, y]:
drop_food()
food.append([x, y])
def move_snake():
global snake # List
global grow_snake # Boolean
global cols, rows # Integers
head = snake[0] # Head is the first element of "snake list"
if not grow_snake: # Remove tail if food was not eaten on this turn
snake.pop()
else: # If food was eaten on this turn, we don't pop last item of list,
grow_snake = False # but we restore default state of grow_snake
if direction == DIR_UP: # Calculate the position of the head
head = [head[0], head[1] - 1] # We will swap x and y in draw_snake()
if head[1] == 0:
head[1] = rows - 2 # Snake passes through the border
elif direction == DIR_DOWN:
head = [head[0], head[1] + 1]
if head[1] == rows - 1:
head[1] = 1
elif direction == DIR_LEFT:
head = [head[0] - 1, head[1]]
if head[0] == 0:
head[0] = cols - 2
elif direction == DIR_RIGHT:
head = [head[0] + 1, head[1]]
if head[0] == cols - 1:
head[0] = 1
snake.insert(0, head) # Insert new head
def is_food_collision():
for pos in food:
if pos == snake[0]:
food.remove(pos)
global foodcolor
global ex_foodcolor
ex_foodcolor = foodcolor
foodcolor = random.randint(1, 6) # Pick random color of the next food
return True
return False
def game_over():
global is_game_over
is_game_over = True
win.erase()
win.addstr(10, 20, "Game over! Your score is " + str(len(snake)) + " Press 'q' to quit", curses.color_pair(1))
def is_suicide(): # If snake collides with itself, game is over
for i in range(1, len(snake)):
if snake[i] == snake[0]:
return True
return False
def end_game():
curses.nocbreak()
win.keypad(0)
curses.echo()
curses.endwin()
# Initialisation starts --------------------------------------------
DIR_UP = 0 # Snake's directions, values are not important,
DIR_RIGHT = 1 # they сan be "a", "b", "c", "d" or something else
DIR_DOWN = 2
DIR_LEFT = 3
is_game_over = False
grow_snake = False
snake = [[10, 5], [9, 5]] # Set snake size and position
direction = DIR_RIGHT
food = []
foodcolor = 2
ex_foodcolor = 3
win = curses.initscr() # Game field in console initialised with curses module
curses.start_color() # Enables colors
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
curses.init_pair(4, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
curses.init_pair(5, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_YELLOW, curses.COLOR_BLACK)
win.keypad(1) # Enable arrow keys
win.nodelay(1) # Do not wait for keypress
curses.curs_set(0) # Hide cursor
curses.cbreak() # Read keys instantaneously
curses.noecho() # Do not print stuff when keys are pressed
rows, cols = win.getmaxyx() # Get terminal window size
# Initialisation ends ---------------------------------------------
# Main loop starts ------------------------------------------------
drop_food()
redraw()
while True:
if is_game_over is False:
redraw()
key = win.getch() # Returns a key, if pressed
time.sleep(0.1) # Speed of the game
if key != -1: # win.getch returns -1 if no key is pressed
if key == curses.KEY_UP:
if direction != DIR_DOWN: # Snake can't go up if she goes down
direction = DIR_UP
elif key == curses.KEY_RIGHT:
if direction != DIR_LEFT:
direction = DIR_RIGHT
elif key == curses.KEY_DOWN:
if direction != DIR_UP:
direction = DIR_DOWN
elif key == curses.KEY_LEFT:
if direction != DIR_RIGHT:
direction = DIR_LEFT
elif chr(key) == "q":
break
if is_game_over is False:
move_snake()
if is_suicide():
game_over()
if is_food_collision():
drop_food()
grow_snake = True
end_game()
# Main loop ends --------------------------------------------------
from learn-es6.
Linux scp命令
Linux scp命令用于Linux之间复制文件和目录。
scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令。
语法
scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 [...] [[user@]host2:]file2
简易写法:
scp [可选参数] file_source file_target
参数说明:
-1: 强制scp命令使用协议ssh1
-2: 强制scp命令使用协议ssh2
-4: 强制scp命令只使用IPv4寻址
-6: 强制scp命令只使用IPv6寻址
-B: 使用批处理模式(传输过程中不询问传输口令或短语)
-C: 允许压缩。(将-C标志传递给ssh,从而打开压缩功能)
-p:保留原文件的修改时间,访问时间和访问权限。
-q: 不显示传输进度条。
-r: 递归复制整个目录。
-v:详细方式显示输出。scp和ssh(1)会显示出整个过程的调试信息。这些信息用于调试连接,验证和配置问题。
-c cipher: 以cipher将数据传输进行加密,这个选项将直接传递给ssh。
-F ssh_config: 指定一个替代的ssh配置文件,此参数直接传递给ssh。
-i identity_file: 从指定文件中读取传输时使用的密钥文件,此参数直接传递给ssh。
-l limit: 限定用户所能使用的带宽,以Kbit/s为单位。
-o ssh_option: 如果习惯于使用ssh_config(5)中的参数传递方式,
-P port:注意是大写的P, port是指定数据传输用到的端口号
-S program: 指定加密传输时所使用的程序。此程序必须能够理解ssh(1)的选项。
实例
1、从本地复制到远程
命令格式:
scp local_file remote_username@remote_ip:remote_folder
# 或者
scp local_file remote_username@remote_ip:remote_file
# 或者
scp local_file remote_ip:remote_folder
# 或者
scp local_file remote_ip:remote_file
第1,2个指定了用户名,命令执行后需要再输入密码,第1个仅指定了远程的目录,文件名字不变,第2个指定了文件名;
第3,4个没有指定用户名,命令执行后需要输入用户名和密码,第3个仅指定了远程的目录,文件名字不变,第4个指定了文件名;
应用实例:
scp /home/space/music/1.mp3 [email protected]:/home/root/others/music
scp /home/space/music/1.mp3 [email protected]:/home/root/others/music/001.mp3
scp /home/space/music/1.mp3 www.runoob.com:/home/root/others/music
scp /home/space/music/1.mp3 www.runoob.com:/home/root/others/music/001.mp3
复制目录命令格式:
scp -r local_folder remote_username@remote_ip:remote_folder
# 或者
scp -r local_folder remote_ip:remote_folder
第1个指定了用户名,命令执行后需要再输入密码;
第2个没有指定用户名,命令执行后需要输入用户名和密码;
应用实例:
scp -r /home/space/music/ [email protected]:/home/root/others/
scp -r /home/space/music/ www.runoob.com:/home/root/others/
上面命令将本地 music 目录复制到远程 others 目录下。
2、从远程复制到本地
从远程复制到本地,只要将从本地复制到远程的命令的后2个参数调换顺序即可,如下实例
应用实例:
scp [email protected]:/home/root/others/music /home/space/music/1.mp3
scp -r www.runoob.com:/home/root/others/ /home/space/music/
说明
1.如果远程服务器防火墙有为scp命令设置了指定的端口,我们需要使用 -P 参数来设置命令的端口号,命令格式如下:
#scp 命令使用端口号 4588
scp -P 4588 [email protected]:/usr/local/sin.sh /home/administrator
2.使用scp命令要确保使用的用户具有可读取远程服务器相应文件的权限,否则scp命令是无法起作用的。
from learn-es6.
Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。
from learn-es6.
Related Issues (20)
- Weekly Digest (26 July, 2020 - 2 August, 2020)
- Weekly Digest (2 August, 2020 - 9 August, 2020)
- learn-MongoDB HOT 9
- learn-java-on-mac
- learn-nginx-on-mac HOT 2
- npm-pug
- npm-koa HOT 1
- learn-docker HOT 1
- npm-koa-bodyparser
- npm-koa-session
- npm-koa-static
- npm-koa-router
- npm-koa-views
- npm-koa-logger
- learn-vscode-ext HOT 3
- npm-nrm HOT 1
- learn-mysql HOT 1
- learn-mac-order HOT 5
- Weekly Digest (12 July, 2020 - 19 July, 2020)
- Weekly Digest (19 July, 2020 - 26 July, 2020)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn-es6.