小编NoB*_*ugs的帖子

为什么点击后触摸启动事件?

这有点奇怪,我觉得确实在早期的移动浏览器中工作:在Android上的Chrome和iOS上的Safari中,似乎touchstart事件在点击事件之后被触发,而不是之前.这什么时候改变了?

一个简单的例子:

jQuery(function($) {
    var touched = false;
    $('#clicky').on('touchstart', function(evt){
        touched = true;
        evt.preventDefault();
    })
    .click(function(){
        if (!touched) {
            alert("somehow touch didn't fire")
        }
    });
})
Run Code Online (Sandbox Code Playgroud)

运行这个小提琴,你会看到警告可以在Android和iOS上弹出,它应该实际上永远不会显示!

http://jsfiddle.net/quxnxu7d/2/

javascript android webkit touch ios

11
推荐指数
2
解决办法
2406
查看次数

为什么只导入OpenCV导致大量CPU使用?

在为Raspberry Pi尝试运动检测器时,我注意到了一些非常奇怪的事情:

从脚本中删除摄像机记录,使其几乎使用0 CPU:

#from gpiozero import MotionSensor
#import cv2
from datetime import datetime
from time import sleep
#camera = cv2.VideoCapture(0)
#pir = MotionSensor(4, queue_len=2, sample_rate=2, threshold=0.5)
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
PIR_PIN = 4
GPIO.setup(PIR_PIN, GPIO.IN)
while True:
    sleep(1)
    if GPIO.input(PIR_PIN):
        print( "detected!")
        filename = 'motionpics/' + datetime.now().strftime("%Y-%m-%d_%H.%M.%S.jpg")
        #ret, frame = camera.read()
        #cv2.imwrite(filename, frame)
        #camera.release()
        #pir.wait_for_no_motion()
Run Code Online (Sandbox Code Playgroud)

但是,取消注释只有一行 - 导入cv2,使这个脚本达到300%的CPU使用率!!

OpenCV有什么问题,为什么我不能开始使用它来获取usb相机图像而不使用一堆cpu,并且耗尽电池?

python opencv raspberry-pi3

11
推荐指数
2
解决办法
1451
查看次数

Android webkit浏览器中的宽度不正确

我注意到Android的默认浏览器存在问题,其中100%宽度实际上可能超过屏幕边缘.这是一个最小的测试用例:

  <div class='separator' width=100% style='border: 2px;padding: 2px;border-style: solid;'>&nbsp;</div>
  <div class='separator' width=100% style='border: 2px;padding: 2px;border-style: solid;'>New & improved div</div>
  <div class='separator' width=100% style='border: 2px;padding: 2px;border-style: solid;'>another working one</div>
  <div class='separator' width=100% style='border: 2px;padding: 2px;border-style: solid;'>another</div>
Run Code Online (Sandbox Code Playgroud)

这在桌面浏览器上按预期工作,但在Android webkit浏览器中,第一个div离开屏幕,并且在放大和缩小时不会改变宽度.div正常工作后.

更新:我已经在2.3,3.0,3.1和一个新创建的2.2模拟器上测试了它们,它们都无法正确调整大小.看起来其他人已经注意到这一点,看到这里这里.有人知道这个bug的好方法吗?

html android webkit width

10
推荐指数
2
解决办法
7398
查看次数

事件监听器 - 相当于Firefox?

我注意到Chromium在检查器/调试器中有一个有趣的功能:事件监听器.Chromium Inspector

我还没有找到Firefox Firebug中的等效功能.我在几年前看到一个问题,说Firefox没有相同的功能,但我想知道是否有任何更新...是否还有一个列出听众的Firebug插件?或者,有没有关于Firefox的实现,这使得这不实用?

javascript firefox firebug google-chrome chromium

10
推荐指数
1
解决办法
5542
查看次数

wordpress 3.5媒体管理器 - 添加我自己的backbone.js视图

我目前正在尝试使用新的WordPress 3.5媒体管理器,它使用backbone.js来创建和填充其模态窗口.

我想要做的是:用户点击上传按钮,媒体管理器弹出,用户选择图像,印刷机插入,然后图像被保存到自定义字段.

所有这些都已经有效,我唯一想改变的是用我自己的模板填充媒体上传者的边栏(用户可以添加标题,标题,选择大小等).

我已经阅读了很多关于如何使用骨干的教程,但现在有点卡住了.这是我到目前为止的一些代码:

//defined earlier:
var frame;

//on click:

if ( file_frame )
{
    file_frame.open();
    return;
}
else
{
    // Create the media frame.
    file_frame  = wp.media(
    {
    frame:   'select',
    state:   'mystate',
    library:   {type: 'image'},
    multiple:   false
    });

    file_frame.states.add([

    new media.controller.Library({
        id:         'mystate',
        title: 'my title',
        priority:   20,
        toolbar:    'select',
        filterable: 'uploaded',
        library:    media.query( file_frame.options.library ),
        multiple:   file_frame.options.multiple ? 'reset' : false,
        editable:   true,
        displayUserSettings: false,
        displaySettings: true,
        allowLocalEdits: true,
          //AttachmentView: ?

    }),
    ]);

file_frame.open();

}
Run Code Online (Sandbox Code Playgroud)

我也尝试过注册我自己的模板:

media.view.Attachment.mySidebar …
Run Code Online (Sandbox Code Playgroud)

wordpress backbone.js backbone-views wordpress-3.5

9
推荐指数
1
解决办法
2753
查看次数

在没有完全https网站的情况下,html5中的推送通知是否可行?

看起来推送通知最终可用于网络应用程序!不幸的是,这需要ServiceWorker的https,并非所有站点都可以使用.

我在提到的规范中注意到一件事:

if r's url's scheme is not one of "http" and "https", then: Throw a TypeError."

所以我很困惑 - 只要它包含来自https的服务工作者,该网站是否可以是http?例如,mydomain.com可以包含来自https://anotherdomain.com的https服务工作者?

另一个标准,web-api simple-push,没有提到需要https(可能是文档中的遗漏?),并且"Firefox桌面上的用户体验还没有被提取出来".关于这个过时的文档,还是推送真的只支持FirefoxOS?

html5 google-chrome firefox-os service-worker web-push

9
推荐指数
1
解决办法
5433
查看次数

Data.MemoCombinators,我在哪里可以找到示例?

这个包有一些函数可以将递归函数转换为动态编程递归函数,以获得更好的性能:

http://hackage.haskell.org/packages/archive/data-memocombinators/0.3/doc/html/Data-MemoCombinators.html#t:Memo

不幸的是,它们只有最简单类型函数的示例,并且没有关于如何使用2个变量函数的示例.我在哪里可以找到如何将[Int] -> Int -> Int功能转换为动态编程功能的示例?文档说memo2需要两个Memos作为第一个参数,但我不确定这意味着什么.

解:

正如Hammar所描述的那样,而不是将函数定义为:

foo :: [Int] -> Int -> Int
foo list value = ...
Run Code Online (Sandbox Code Playgroud)

使用memo2:

import qualified Data.MemoCombinators as Memo

foo = Memo.memo2 (Memo.list Memo.integral) Memo.integral foo'
  where ... (define foo' with recursive calls to foo.)
Run Code Online (Sandbox Code Playgroud)

recursion haskell dynamic-programming

8
推荐指数
1
解决办法
475
查看次数

确保首先运行Javascript脚本?

我注意到某些脚本似乎在某个页面上被其他人调用,我想知道,脚本加载的具体顺序是什么?在引用.js脚本之前的页内?它们是按照从首次<script>提到的顺序运行到最后一页,还是依赖于浏览器?如何确保首先在页面中运行特定脚本?

javascript operator-precedence hoisting

8
推荐指数
3
解决办法
2万
查看次数

为什么DDMS不再开放?

Android DDMS前几天正在运行,但是今天(1.1更新后)它总是会弹出一条错误消息,说明要检查日志文件.日志文件的结尾是:

!ENTRY org.eclipse.osgi 4 0 2015-02-23 20:36:49.944
!MESSAGE Application error
!STACK 1
java.lang.NullPointerException
    at org.eclipse.core.runtime.URIUtil.toURI(URIUtil.java:280)
    at org.eclipse.e4.ui.internal.workbench.ResourceHandler.loadMostRecentModel(ResourceHandler.java:127)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.loadApplicationModel(E4Application.java:370)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:220)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:557)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at com.android.ide.eclipse.monitor.MonitorApplication.start(MonitorApplication.java:86)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Run Code Online (Sandbox Code Playgroud)

SDK似乎是最新的但没有ddms,Ubuntu 14.04.这是一个已知的错误还是这个更新需要额外的设置?

java eclipse ddms android-studio

8
推荐指数
2
解决办法
1373
查看次数

任何与PHP中的子进程等价的东西?

在Java和Python,你有ProcessBuilder子流程,让您轻松使用转义字符串例如启动一个进程模块["ls", "some unescaped directory name"]-他们也给你强大的工具,如访问从标准输出读取,标准错误.PHP的任何等价功能是否比仅仅更加智能和有用exec()

php shell exec

8
推荐指数
1
解决办法
1967
查看次数