Linux有hcidump这是一个非常方便的调试蓝牙问题的工具.
有人可以为Windows推荐类似的工具吗?如果有人知道任何好事,我也会对Linux的其他工具感兴趣.
我试图调查为什么我的BT设备在几秒后断开连接.我希望它是一个糟糕的迷你加密狗,但想了解更多关于断开连接的地方.
我正在构建一个系统状态记录器.我希望当任何活动/任务进入堆栈停止并且用户(而不仅仅是我写的那个)可见时,我会收到通知.
ActivityManager可以找出最重要的东西:http: //developer.android.com/reference/android/app/ActivityManager.html
然而,这需要我经常轮询以重新计算最重要的浪费大量资源.有没有办法在活动发生变化时收到事件/回调/通知?
**编辑**要清楚 - 我希望在任何活动成为活动活动时收到通知.
我来自C++并试图围绕scala的类型系统.
考虑以下C++模板类:
template<class T>
class Point2
{
Point2( T x, T y ) :
x(x),
y(y)
{}
T x;
T y;
Point2<T> operator+( Point<T> const& other ) const
{
return Point<T>(x+other.x, y+other.y);
}
T sumComponents() const { return x+y; }
}
Point2<Double> p0(12.3, 45.6)
Point2<Double> p1(12.3, 45.6)
Point2<Double> p = p1+p2
Double d = p1.sumComponents()
Run Code Online (Sandbox Code Playgroud)
我发现我想写这样的东西:
case class Point2[ T ] (x:T, y:T) {
def +() Point2[T]: = x+y
def sumComponents() T: = x+y
}
Run Code Online (Sandbox Code Playgroud)
或者,(因为编译有问题),
trait Addable[T] { // …
Run Code Online (Sandbox Code Playgroud) 奇...
val h = new HashMap[Long, Int]()
def mydefault0():Int = 101
println( h.getOrElse(99, default=mydefault0 _ ) ) // Prints <function0>
def mydefault1(key:Long):Int = 102
println( h.getOrElse(98, default=mydefault1 _ ) ) // Prints <function1>
Run Code Online (Sandbox Code Playgroud)
的文档说,默认类型必须为:=>乙
如果我理解正确,在这种情况下返回Int的无参数函数.
为什么采用mydefault1编译的示例,因为它需要一个参数,所以符合规范?
为什么返回函数,而不是调用函数来产生默认值?显然,类型安全已被破坏,因为getOrElse必须返回Int,而不是函数.(如果我误解了文档并错误地提供了需要Int值的函数,为什么编译器让我提供一个函数,而不是Int?).
编辑
很明显:
还让一个函数用于指定默认值.我想要的是能够使用在执行查找时提供的函数覆盖默认值(即函数可能在Map的生命周期中发生变化)
这可能吗?
我正在尝试创建一个@synchronized包装器,它为每个对象创建一个Lock并使方法调用线程安全.如果我可以在包装方法中访问方法的method.im_self,我只能这样做.
class B:
def f(self): pass
assert inspect.ismethod( B.f ) # OK
assert inspect.ismethod( B().f ) # OK
print B.f # <unbound method B.f>
print B().f # <bound method B.f of <__main__.B instance at 0x7fa2055e67e8>>
def synchronized(func):
# func is not bound or unbound!
print func # <function f at 0x7fa20561b9b0> !!!!
assert inspect.ismethod(func) # FAIL
# ... allocate one lock per C instance
return func
class C:
@synchronized
def f(self): pass
Run Code Online (Sandbox Code Playgroud)
(1)令人困惑的是传递给我的装饰器的func参数在传递给包装器生成器之前改变了类型.这似乎是粗鲁和不必要的.为什么会这样?
(2)是否有一些装饰器魔法,通过它我可以对一个对象互斥进行方法调用(即每个对象一个锁,而不是每个类).
更新:有许多@synchronized(lock)包装器的例子.但是,我真正想要的是@synchronized(self).我可以这样解决:
def synchronizedMethod(func):
def …
Run Code Online (Sandbox Code Playgroud) 根据 https://github.com/joblib/joblib/issues/180,有没有一种安全的方法从python中的线程创建子进程? Python多处理模块不允许在线程内使用.这是真的?
我的理解是,从线程中分叉是好的,只要你没有持有线程.当你这样做时(在当前线程中?在进程中的任何地方?).但是,Python的文档没有说明在fork之后是否安全地共享threading.Lock对象.
还有这个:从日志记录模块共享的锁导致fork问题.https://bugs.python.org/issue6721
我不确定这个问题是怎么产生的.听起来当进程中的任何锁的状态都被复制到当前线程分叉的子进程中(这看起来像设计错误并且肯定会死锁).如果是这样,那么使用多真正提供对这种任何保护(因为我可以自由地创建我multiprocessing.Pool被创建和被其它线程进入后threading.Lock,经过线程已经开始,使用不是叉安全日志模块) - 多处理模块docs也没有说明是否应该在Locks之前分配multiprocessing.Pools.
用多处理替换threading.Lock.Lock到处避免这个问题并允许我们安全地组合线程和分支?
看起来注释需要Java中的常量.我想这样做:
object ConfigStatics {
final val componentsToScan = Array("com.example")
}
@PropertySource( ConfigStatics.componentsToScan ) // error: constant value required
class MyConfig extends WebMvcConfigurerAdapter {
}
Run Code Online (Sandbox Code Playgroud)
哪里
@PropertySource( Array("com.example") )
class MyConfig extends WebMvcConfigurerAdapter {
}
Run Code Online (Sandbox Code Playgroud)
很好.
遗憾的是,scala不会将静态最终值视为常量值.
这里有什么可做的,或者它是不可能在scala中有命名常量?
在以下示例中,f3可以采用Iterable [Array [Int]]
def f3(o:Iterable[Iterable[Any]]):Unit = {}
f3(Iterable(Array(123))) // OK. Takes Iterable[Array[Int]]
Run Code Online (Sandbox Code Playgroud)
但是如果我将Iterable [Array [Int]]赋给局部变量,它不能:
val v3 = Iterable(Array(123))
f3(v3) // Fails to take Takes Iterable[Array[Int]]
Run Code Online (Sandbox Code Playgroud)
有错误:
Error:(918, 10) type mismatch;
found : Iterable[Array[Int]]
required: Iterable[Iterable[Any]]
f3(x)
Run Code Online (Sandbox Code Playgroud)
什么是软糖?为什么第一个例子工作,但不是秒.它似乎与嵌套泛型有关:
def f(o:Iterable[Any]):Unit = {}
f( Array(123))
val v1 = Array(123)
f(v1) // OK
def f2(o:Iterable[Any]):Unit = {}
f2( Iterable(Array(123)))
val v2 = Array(123)
f(v2) // OK
Run Code Online (Sandbox Code Playgroud)
用scala.2.11
根据这篇文章,我应该能够访问ndarray中列的名称作为a.dtype.names
但是,如果我将pandas DataFrame转换为带有df.as_matrix()或df.values的ndarray,则dtype.names字段为None.此外,如果我尝试将列名称分配给ndarray
X = pd.DataFrame(dict(age=[40., 50., 60.], sys_blood_pressure=[140.,150.,160.]))
print X
print type(X.as_matrix())# <type 'numpy.ndarray'>
print type(X.as_matrix()[0]) # <type 'numpy.ndarray'>
m = X.as_matrix()
m.dtype.names = list(X.columns)
Run Code Online (Sandbox Code Playgroud)
我明白了
ValueError: there are no fields defined
Run Code Online (Sandbox Code Playgroud)
更新:
我特别感兴趣的是矩阵只需要保存一个类型(它是一个特定数字类型的ndarray),因为我也想使用cython进行优化.(我怀疑numpy记录和结构化数组更难以处理,因为它们更自由地输入.)
实际上,我只想维护通过sci-kit预测器深层树的数组的column_name元数据.它的接口的.fit(X,y)和.predict(X)API不允许传递关于X和y对象之外的列标签的附加元数据.
s1 = image.shape # Image is an opencv2 image (ndarray)
w,h,d = s1
image_ = cv2.resize(image, (w*2, h*2), interpolation = cv2.INTER_CUBIC)
s2 = image_.shape
Run Code Online (Sandbox Code Playgroud)
在上面,我要求将输出大小调整为 (960,1280),但我得到 (1280, 960)。
那是怎么回事?
image_ = cv2.resize(image, None, fx=2, fy=2, interpolation = cv2.INTER_CUBIC)
Run Code Online (Sandbox Code Playgroud)
...按预期工作。(没有必要指出这一点)。
可运行示例:
import cv2
def run():
cap = cv2.VideoCapture(0)
while cap.isOpened():
success, image = cap.read() # (480, 640, 3)
if not success:
print("Ignoring empty camera frame.")
continue
s1 = image.shape
w, h, d = s1
s2 = (w * 2, h * …
Run Code Online (Sandbox Code Playgroud)