如果我的.emacs为空或仅包含行
(require 'cc-mode)
(add-to-list 'c-offsets-alist '(annotation-top-cont .0))
(add-hook 'java-mode-hook
'(lambda () (c-set-offset 'annotation-top-cont 0)))
Run Code Online (Sandbox Code Playgroud)
而不是保护与@Override对齐
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)
相对于@Override而言,protected会出现缩进
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)
我应该对我的.emacs进行哪些更改,以便缩进作为上面的顶部示例出现?
如果无意在 C++ 中使用参数,则只需省略变量名称,但在函数声明中保留类型即可。这样做是一种轻量级方法,用于向编译器发出信号表明不打算使用给定参数。
这可以在 Java 中复制吗?
场景是这样的:我不想@SuppressWarnings("unused")为每个按钮侦听器淹没我的代码(因为按钮侦听器通常会忽略View v他们收到的),但我希望得到警告,说,不犯愚蠢的错误通过参数初始化成员变量。
如果除了(或代替)CheckBoxes之外你对RadioButtons感兴趣,请参阅此问题.
尽管存在
<item name="android:layout_gravity">center_horizontal</item>
Run Code Online (Sandbox Code Playgroud)
在样式文件中,两个复选框不居中,但显示为"左对齐".

RES /布局/ activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MyLL"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/cb1"
style="@style/CB_style" />
<CheckBox
android:id="@+id/cb2"
style="@style/CB_style" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
RES /值/ styles.xml
<style name="CB_style" parent="@android:style/TextAppearance.Medium">
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:checked">false</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我发现.razmatazz在HTML文件中使用了某个CSS类,但是这个标识符不在任何现有的CSS文件中.这解释了不正确的演示,我已经"踢了一段时间".
> git log -S razmatazz --source --all
847d9d8 Thu Jun 25 10:05:07 2018 Joe C helpful commit message.
9384843 Wed May 20 14:10:34 2018 Joe C ever more helpful commit message.
2093483 Mon Apr 15 11:15:51 2018 Joe C yet another great message.
Run Code Online (Sandbox Code Playgroud)
但同时我一直在合并/取消合并/重命名我的CSS文件,因此我不知道CSS文件名.
如何确定添加或删除给定标识符的文件名?
由于"pickaxe"git选项没有说明是否添加或删除了标识符,我会尝试找到的哈希值和它们的前辈
git show 847d9d8:/path/to/file
git show 847d9d8^:/path/to/file
git show 9384843:/path/to/file
git show 9384843^:/path/to/file
git show 2093483:/path/to/file
git show 2093483^:/path/to/file
Run Code Online (Sandbox Code Playgroud)
以获取丢失的定义.
所以我认为代码
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Log Canvas Width</title>
<style>
#canvas {
background: #888888;
width: 600px;
height: 600px;
}
</style>
<script>
function draw() {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
document.write(canvas.width);
}
</script>
</head>
<body onload="draw();">
<canvas id='canvas'>
Canvas not supported
</canvas>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
打印 300 而不是 600,因为<body onload="draw();">使脚本在页面加载时运行,而此时画布尚未捕获修改后的值 (600)。
但后来我将代码修改为:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Log Canvas Width</title>
<style>
#canvas {
background: #888888;
width: 600px;
height: 600px;
}
</style>
</head>
<body>
<canvas id='canvas'>
Canvas not supported …Run Code Online (Sandbox Code Playgroud) 经过2个 提问有关数据类型之间的区别str和unicode,我还在疑惑在下面.
在第1区,我们看到城市的类型unicode正如我们所期望的那样.
然而在方框2中,在通过磁盘往返(redis)之后,城市的类型是str(并且表示不同).
存储在磁盘上,读入和写入的教条在某处失败了.utf-8unicodeutf-8
为什么是第二个实例type(city) str而不是unicode?
同样重要的是,这有关系吗?你关心你的变量是否unicode还是str,还是你忘却的区别只是,只要代码"做正确的事"?
# -*- coding: utf-8 -*-
# Block 1
city = u'Düsseldorf'
print city, type(city), repr(city)
# Düsseldorf <type 'unicode'> u'D\xfcsseldorf'
# Block 2
import redis
r_server = redis.Redis('localhost')
r_server.set('city', city)
city = r_server.get('city')
print city, type(city), repr(city)
# Düsseldorf <type 'str'> 'D\xc3\xbcsseldorf'
Run Code Online (Sandbox Code Playgroud) 忍受我.我正在编写每个细节,因为工具链的很多部分都不能优雅地处理Unicode,并且不清楚什么是失败的.
序幕
我们首先建立并使用最近的Scrapy.
source ~/.scrapy_1.1.2/bin/activate
Run Code Online (Sandbox Code Playgroud)
由于终端的默认值是ascii,而不是unicode,我们设置:
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Run Code Online (Sandbox Code Playgroud)
此外,因为默认情况下Python使用ascii,我们修改编码:
export PYTHONIOENCODING="utf_8"
Run Code Online (Sandbox Code Playgroud)
现在我们准备开始一个Scrapy项目了.
scrapy startproject myproject
cd myproject
scrapy genspider dorf PLACEHOLDER
Run Code Online (Sandbox Code Playgroud)
我们被告知我们现在有一只蜘蛛.
Created spider 'dorf' using template 'basic' in module:
myproject.spiders.dorf
Run Code Online (Sandbox Code Playgroud)
我们修改myproject/items.py为:
# -*- coding: utf-8 -*-
import scrapy
class MyprojectItem(scrapy.Item):
title = scrapy.Field()
Run Code Online (Sandbox Code Playgroud)
ATTEMPT 1
现在我们写蜘蛛,依靠urllib.unquote
# -*- coding: utf-8 -*-
import scrapy
import urllib
from myproject.items import MyprojectItem
class DorfSpider(scrapy.Spider):
name = "dorf"
allowed_domains = [u'http://en.sistercity.info/']
start_urls = (
u'http://en.sistercity.info/sister-cities/Düsseldorf.html',
) …Run Code Online (Sandbox Code Playgroud) 以下代码定义了两个枚举
class Insect:
BEE = 0x00
WASP = 0x01
BUMBLEBEE = 0x02
class Breakfast:
HAM = 0x00
EGGS = 0x01
PANCAKES = 0x02
b = Insect.WASP
if b == Breakfast.EGGS:
print("ok")
Run Code Online (Sandbox Code Playgroud)
正如条件所示,一个人保持开放,以便对完全不同的枚举进行测试.如何通过类型而不是通过不同的值来隔离枚举,以便上面的测试会产生错误?
更新
我发现这是从Python 2迁移到Python 3的道路上的一个更好的点.
感谢wim的建议,如果我尝试比较苹果和橙子,下面的代码会产生错误.
from enum import Enum
class Apple(Enum):
RED_DELICIOUS = 0x00
GALA = 0x01
FUJI = 0x02
def __eq__(self, other):
if type(other) is not type(self):
raise Exception("You can't compare apples and oranges.")
return super().__eq__(other)
class Orange(Enum):
NAVEL = 0x00
BLOOD = 0x01
VALENCIA …Run Code Online (Sandbox Code Playgroud) 我正在 Flask 应用程序中为 JSON 端点编写测试用例。
import unittest
from flask import json
from app import create_app
class TestFooBar(unittest.TestCase):
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
def test_ham(self):
resp = self.client.post('/endpoint',
headers={'Content-Type': 'application/json'},
data=json.dumps({'foo': 2,
'bar': 3}))
assert resp.status_code == 200
def test_eggs(self):
resp = self.client.post('/endpoint', data={'foo': 5,
'bar': 7})
assert resp.status_code == 200
def test_ham_and_eggs(self):
with self.app.test_client() as self.client:
self.test_ham()
self.test_eggs()
Run Code Online (Sandbox Code Playgroud)
只是为了了解发生了什么,请使用两种发送方式POST上面代码中发送消息的两种方式都有意义吗?特别是,我在第一种情况下是否使用双 JSON 编码?
test_ham或者,简单地说,和之间有什么区别test_eggs?有没有?
在 DockerCon 2020 的鼓励下,我再次解决在 AWS EC2 上运行 Flask 应用程序的问题,但这次我不想接触 AWS 仪表板。我想完全留在命令行(osx 终端)上。
这个精美的教程描述了如何构建一个映像并在 AWS ECR 上运行它,显然它本身最终在 EC2 实例上运行。
我猜是翻译到 AWS CLI v2 的开始
v1: aws ecr get-login --region us-east-1 --no-include-email
Run Code Online (Sandbox Code Playgroud)
是
v2: aws ecr get-login-password --region us-east-1
Run Code Online (Sandbox Code Playgroud)
v1 命令显然生成了一个正确格式化的字符串,供后续运行使用。(好的摆脱、剪切和粘贴不会产生可靠或可定制的 CLI。)
v2 替换为后续命令生成一个长密码。
v2 中的哪些命令完全替换了 v1 的命令aws ecr get-login?
python ×3
android ×2
flask ×2
java ×2
amazon-ecr ×1
amazon-ecs ×1
canvas ×1
docker ×1
eclipse ×1
emacs23 ×1
enums ×1
git ×1
html ×1
indentation ×1
javascript ×1
json ×1
redis ×1
scrapy ×1
string ×1
testing ×1
type-safety ×1
unicode ×1
utf-8 ×1