$ cat test.pl
my $pid = 5892;
my $not = system("top -H -p $pid -n 1 | grep myprocess | wc -l");
print "not = $not\n";
$ perl test.pl
11
not = 0
$
Run Code Online (Sandbox Code Playgroud)
我想将结果捕获11到变量中.我怎样才能做到这一点?
我有一些代码试图在另一个指定的索引处找到数组的内容,这可能指定超出前一个数组范围的索引.
input = np.arange(0, 5)
indices = np.array([0, 1, 2, 99])
Run Code Online (Sandbox Code Playgroud)
我想要做的是:打印输入[indices]并得到[0 1 2]
但这会产生异常(如预期的那样):
IndexError: index 99 out of bounds 0<=index<5
Run Code Online (Sandbox Code Playgroud)
所以我想我可以使用蒙面数组来隐藏越界索引:
indices = np.ma.masked_greater_equal(indices, 5)
Run Code Online (Sandbox Code Playgroud)
但仍然:
>print input[indices]
IndexError: index 99 out of bounds 0<=index<5
Run Code Online (Sandbox Code Playgroud)
即使:
>np.max(indices)
2
Run Code Online (Sandbox Code Playgroud)
所以我必须首先填充蒙面数组,这很烦人,因为我不知道我可以使用什么填充值来不为超出范围的那些选择任何索引:
打印输入[np.ma.filled(indices,0)]
[0 1 2 0]
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如何有效地使用numpy从数组安全地选择索引而不超出输入数组的边界?
我有一个很常见的问题.在WPF应用程序中进行本地化的最佳方法是什么.好吧,我在SO和Binged中搜索了很多.但我找不到任何非常简单和优雅的指针.
假设我必须在UI中显示如下内容:
英语:Orgnanization - Beoing
法语:Organizzazione - Beoing
<StackPanel Orientation="Horizontal">
<TextBlock Text="Organization -"></TextBlock>
<TextBlock Text="{Binding Path=OrganizationName}">
</TextBlock>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
基本上,我需要将本地化文本分配给Organization Label TextBlock.我应该将连字符与"组织 - "分开并将其放在单独的标签中吗?
我怎么做?
有没有办法可以为'toggle'事件处理程序使用'bind'语法?
从文档我可以理解,正确的方法是
$('.selector').toggle( function() {}, function() {} );
Run Code Online (Sandbox Code Playgroud)
我的问题是我出于某种原因删除了该元素,然后再将其添加到DOM中.再次添加时,切换不起作用.
因此,我认为应该有一种方法来"绑定"切换.
请帮忙.
这是我关注的文档:http: //jqapi.com/#p=toggle
我有.NET服务,我需要调试它.
当它到达代码中的某个位置并启动调试器时,我希望它停止.有人可以提供一些代码示例吗?
UPDATE
简单地添加
Debugger.Launch();
Run Code Online (Sandbox Code Playgroud)
不适用于Windows服务.
我想防止我有两种形式之间的换行符.
所以基本上:
<form action="...">
<input type="submit" />
</form>
LINE BREAK HERE
<form action="...">
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
我想删除换行符.我希望输入按钮位于同一行,就像菜单一样.
我想将JPA2 Criteria API与元模型对象一起使用,这看起来很简单:
...
Root<JPAAlbum> albm = cq.from(JPAAlbum.class);
... albm.get(JPAAlbum_.theme) ... ;
Run Code Online (Sandbox Code Playgroud)
但是这个Root.get总是抛出一个NullPointerException.JPAAlbum_.theme是由Hibernate自动生成的,看起来像
public static volatile SingularAttribute<JPAAlbum, JPATheme> theme;
Run Code Online (Sandbox Code Playgroud)
但它显然从未填充过.
我错过了框架初始化的一个步骤吗?
编辑:这是我在崩溃时如何使用JPA和元模型的片段:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<JPAAlbum> cq = cb.createQuery(JPAAlbum.class) ;
Root<JPAAlbum> albm = cq.from(JPAAlbum.class);
cq.where(cb.equal(albm.get(JPAAlbum_.theme).get(JPATheme_.id),
session.getTheme().getId())) ;
Run Code Online (Sandbox Code Playgroud)
(JPAAlbum_是一个类,所以我就import在之前)和相关的堆栈跟踪:
Caused by: java.lang.NullPointerException
at org.hibernate.ejb.criteria.path.AbstractPathImpl.get(AbstractPathImpl.java:138)
at net.wazari.dao.jpa.WebAlbumsDAOBean.getRestrictionToAlbumsAllowed(WebAlbumsDAOBean.java:55)
Run Code Online (Sandbox Code Playgroud)
编辑2:
在JBoss EntityManager指南中,我可以看到
当构建Hibernate EntityManagerFactory时,它将查找每个托管类型的规范元模型类,如果它找到任何它将向它们注入适当的元模型信息,如[JPA 2规范,第6.2节中所述] .2,页码200]
我也可以验证
for (ManagedType o : em.getMetamodel().getManagedTypes()) {
log.warn("___") ;
for (Object p : o.getAttributes()) {
log.warn(((Attribute)p).getName()) ;
} …Run Code Online (Sandbox Code Playgroud) 我想在python中生成一些字母数字密码.一些可能的方法是:
import string
from random import sample, choice
chars = string.letters + string.digits
length = 8
''.join(sample(chars,length)) # way 1
''.join([choice(chars) for i in range(length)]) # way 2
Run Code Online (Sandbox Code Playgroud)
但我不喜欢两者,因为:
i变量未使用,我找不到如何避免这种情况的好方法那么,还有其他好的选择吗?
PS所以这里我们正在进行一些timeit100000次迭代的测试:
''.join(sample(chars,length)) # way 1; 2.5 seconds
''.join([choice(chars) for i in range(length)]) # way 2; 1.8 seconds (optimizer helps?)
''.join(choice(chars) for _ in range(length)) # way 3; 1.8 seconds
''.join(choice(chars) for _ in xrange(length)) # way 4; 1.73 seconds
''.join(map(lambda x: …Run Code Online (Sandbox Code Playgroud) 我希望能够SwingWorker多次使用子类.这可能吗?
我在java doc中读过:
SwingWorker仅设计为执行一次.执行SwingWorker多次不会导致doInBackground两次调用该方法.
如何CREATE LOGIN在SQL Server 2005上使用该语句?
我几乎尝试了所有东西:用逗号,没有它们,用字符串,没有它们等等.
CREATE LOGIN @loginame WITH PASSWORD = 'pass',
DEFAULT_DATABASE='dbname' DEFAULT_LANGUAGE='us_english', CHECK_POLICY= OFF;
Run Code Online (Sandbox Code Playgroud)
我总是得到这个错误:
关键字'with'附近的语法不正确.如果此语句是公用表表达式或xmlnamespaces子句,则必须以分号结束前一个语句.
.net ×2
java ×2
python ×2
c# ×1
command ×1
criteria-api ×1
css ×1
debugging ×1
hibernate ×1
html ×1
indexing ×1
javascript ×1
jpa-2.0 ×1
jquery ×1
jquery-ui ×1
localization ×1
numpy ×1
passwords ×1
perl ×1
sql ×1
sql-server ×1
swing ×1
swingworker ×1
system ×1
t-sql ×1
toggle ×1
wpf ×1
xaml ×1