我一直在阅读网络上的文章,以了解以下key
类型之间的差异.但这对我来说似乎很难掌握.实例肯定有助于更好地理解.
primary key,
partition key,
composite key
clustering key
Run Code Online (Sandbox Code Playgroud) 我的HTML有一个被调用的类.required
,它被分配给必需的字段.这是html:
<form action="/accounts/register/" method="post" role="form" class="form-horizontal">
<input type='hidden' name='csrfmiddlewaretoken' value='brGfMU16YyyG2QEcpLqhb3Zh8AvkYkJt' />
<div class="form-group required">
<label class="col-md-2 control-label">Username</label>
<div class="col-md-4">
<input class="form-control" id="id_username" maxlength="30" name="username" placeholder="Username" required="required" title="" type="text" />
</div>
</div>
<div class="form-group required"><label class="col-md-2 control-label">E-mail</label><div class="col-md-4"><input class="form-control" id="id_email" name="email" placeholder="E-mail" required="required" title="" type="email" /></div></div>
<div class="form-group required"><label class="col-md-2 control-label">Password</label><div class="col-md-4"><input class="form-control" id="id_password1" name="password1" placeholder="Password" required="required" title="" type="password" /></div></div>
<div class="form-group required"><label class="col-md-2 control-label">Password (again)</label><div class="col-md-4"><input class="form-control" id="id_password2" name="password2" placeholder="Password (again)" required="required" title="" type="password" /></div></div>
<div class="form-group required"><label …
Run Code Online (Sandbox Code Playgroud) 我有一些节点来自我想要映射到图表的脚本.在下面,我想使用箭头从A到D,并且边缘也可能有颜色(红色或其他东西).这基本上就像所有其他节点都存在时从A到D的路径.您可以将每个节点想象为城市,从A到D行进需要方向(带箭头).下面的代码构建了图表
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edges_from(
[('A', 'B'), ('A', 'C'), ('D', 'B'), ('E', 'C'), ('E', 'F'),
('B', 'H'), ('B', 'G'), ('B', 'F'), ('C', 'G')])
val_map = {'A': 1.0,
'D': 0.5714285714285714,
'H': 0.0}
values = [val_map.get(node, 0.25) for node in G.nodes()]
nx.draw(G, cmap = plt.get_cmap('jet'), node_color = values)
plt.show()
Run Code Online (Sandbox Code Playgroud)
但我想要一些像图中所示的东西.
第一个图像的箭头和第二个图像的红色边缘.谢谢
我正在学习用来ExectorService
汇集threads
和发送任务.我有一个简单的程序如下
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
class Processor implements Runnable {
private int id;
public Processor(int id) {
this.id = id;
}
public void run() {
System.out.println("Starting: " + id);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println("sorry, being interupted, good bye!");
System.out.println("Interrupted "+Thread.currentThread().getName());
e.printStackTrace();
}
System.out.println("Completed: " + id);
}
}
public class ExecutorExample {
public static void main(String[] args) {
Boolean isCompleted=false;
ExecutorService executor = Executors.newFixedThreadPool(2);
for(int i=0; i<5; i++) {
executor.execute(new …
Run Code Online (Sandbox Code Playgroud) n log n > n
- 但这就像是一段pseudo-linear
感情.如果n=1 billion
,log n~30;
所以,n log n
将30 billion
是30 X n
,顺序n
.我想知道这个时间复杂度之间n log n and n
的差异在现实生活中是否显着.
例如:quick select
在未排序数组中查找第k个元素是O(n)
使用快速选择算法.
如果我对数组进行排序并找到第k个元素,那就是O(n log n)
.要排序一个数组1 trillion
的元素,我会很60 times
慢,如果我做quicksort
和index it
.
我正在使用弹簧靴1.4.0.RELEASE
.我正在为我的控制器类编写测试.我得到以下异常.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.concur.cognos.authentication.service.ServiceControllerITTest': Unsatisfied dependency expressed through field 'restTemplate': No qualifying bean of type [org.springframework.boot.test.web.client.TestRestTemplate] found for dependency [org.springframework.boot.test.web.client.TestRestTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.boot.test.web.client.TestRestTemplate] found for dependency [org.springframework.boot.test.web.client.TestRestTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Run Code Online (Sandbox Code Playgroud)
这是我的测试课
public class ServiceControllerITTest extends ApplicationTests {
@Autowired …
Run Code Online (Sandbox Code Playgroud) 来自python wiki:
In Py3.0, the cmp parameter was removed entirely (as part of a larger effort to simplify and unify the language, eliminating the conflict between rich comparisons and the __cmp__ methods).
我不明白为什么在py3.0中删除cmp的原因
考虑这个例子:
>>> def numeric_compare(x, y):
return x - y
>>> sorted([5, 2, 4, 1, 3], cmp=numeric_compare)
[1, 2, 3, 4, 5]
Run Code Online (Sandbox Code Playgroud)
现在考虑这个版本(推荐并与3.0兼容):
def cmp_to_key(mycmp):
'Convert a cmp= function into a key= function'
class K(object):
def __init__(self, obj, *args):
self.obj = obj
def __lt__(self, other):
return …
Run Code Online (Sandbox Code Playgroud) 我们有一个即将投入生产的Spring项目.目前,该项目正在使用Apache Http Client
.有一种使用RestTemplate
as 的想法HttpClient
.
我正在四处寻找使用RestTemplate
结束的任何明显优势Apache's
.此外,了解RestTemplate在其实现中的HTTP传输是很有趣的.Apache Http Client已被多个团体使用多年,并且享有良好的声誉.
我们有冒险搬到RestTemplate
哪儿?
此外,该博客指出需要为生产配置RestTemplate,尽管配置很少.
谢谢
请考虑以下代码:
class AA { }
class BB extends AA { }
public class Testing {
public static void main(String[] args) {
BB[] arr = new BB[10];
AA[] arr2 = arr;
BB b = new BB();
AA a = new AA();
arr2[0] = a; // ArrayStoreException at runtime
arr2[1] = b;
List<BB> listBB = new ArrayList<>();
List listAA = listBB;
listAA.add("hello world.txt");
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,ArrayStoreException
我尝试了arr2[0] = a
.这意味着数组会记住它必须接受的类型.但是List
不记得他们了.它只是编译并运行良好.在ClassCastException
当我检索对象将被抛出BB
.
所以问题是:
数组如何记住它的类型(我知道它被称为"具体化").这究竟是怎么发生的?
并且为什么只有阵列才能获得这种功率,但是ArrayList …
此链接说明如何使用pytest捕获控制台输出.我尝试了以下简单的代码,但是我收到了错误
import sys
import pytest
def f(name):
print "hello "+ name
def test_add(capsys):
f("Tom")
out,err=capsys.readouterr()
assert out=="hello Tom"
test_add(sys.stdout)
Run Code Online (Sandbox Code Playgroud)
输出:
python test_pytest.py
hello Tom
Traceback (most recent call last):
File "test_pytest.py", line 12, in <module>
test_add(sys.stdout)
File "test_pytest.py", line 8, in test_add
out,err=capsys.readouterr()
AttributeError: 'file' object has no attribute 'readouterr'
Run Code Online (Sandbox Code Playgroud)
什么是错的,需要什么修复?谢谢
编辑:根据评论,我改变了capfd
,但我仍然得到相同的错误
import sys
import pytest
def f(name):
print "hello "+ name
def test_add(capfd):
f("Tom")
out,err=capfd.readouterr()
assert out=="hello Tom"
test_add(sys.stdout)
Run Code Online (Sandbox Code Playgroud) python ×3
java ×2
spring-boot ×2
algorithm ×1
arraylist ×1
arrays ×1
big-o ×1
cassandra ×1
cmp ×1
cql ×1
css ×1
database ×1
form-fields ×1
forms ×1
generics ×1
graph ×1
networkx ×1
object ×1
plot ×1
printing ×1
pytest ×1
resttemplate ×1
sorting ×1
spring ×1
spring-mvc ×1
spring-test ×1
stdout ×1
threadpool ×1