javascript

java

python

c#

android

node.js

c++

reactjs

php

html

jquery

css

.net

ios

git

ruby-on-rails

sql

c

string

ruby

为何对列表进行硬编码比计算速度慢?

我想将此序列的前1024个术语分配给一个列表。 我最初猜想,对列表进行硬编码将是最快的方法。 我还尝试通过算法生成列表,并发现它比硬编码要快。 因此,我测试了各种折衷方法,使用了越来越长的硬编码列表,并从算法上扩展到了1024个项目。 我发现最快的方法涉及对前128个项目进行硬编码并生成其余项目。

我想了解为什么硬编码序列中的前128个项目并计算其余部分比硬编码所有1024个项目要快。 使用Python 3.4.2 Shell(IDLE)和cProfile timeit(感谢Veedrac对改进的性能分析代码的回答)。 我将硬编码列表留在很长的一行上,以避免用数字行将问题弄乱,但除此之外,代码不需要水平滚动。

def hardcoded():
    m = [0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,9,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,10]

def softcoded():
    m = [0]
    for k in range(10):
        m += m
        m[-1] += 1

def hybrid():
    m = [0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7]
    for k in range(3):
        m += m
        m[-1] += 1

from timeit import Timer

def p_time(func, n=10000):
    print(func.__name__)
    print(min(Timer(func).repeat(10, n)) / n)

p_time(hardcoded)
p_time(softcoded)
p_time(hybrid)

时机

hardcoded
1.593102711162828e-05
softcoded
1.1183638458442147e-05
hybrid
9.69246251002005e-06

我将所有计时运行了几次,并粘贴到最低的位置。

trans by 2020-02-22T17:24:03Z

ios-使用CocoaPods时如何向Xcode添加自定义项目配置?

我有一个iOS / OS X Xcode项目,我在这里使用CocoaPods,而且似乎无法弄清楚如何在不完全破坏构建的情况下添加自己的项目配置(除了Debug和Release)。

在该项目中,我针对两个平台上的应用程序及其扩展程序都有许多目标。 Xcode工作区当然也有Pods项目。

因为该项目为iOS和Mac构建目标,所以我使用CocoaPods“目标”将其吊舱分组在一起。 我的Podfile看起来像这样:

source 'https://github.com/CocoaPods/Specs.git'

target :iOS do
  platform :ios, '7.1'
  link_with 'iOS', 'NozbeToday', 'NozbeShare', 'NozbeWatch'

  # pods...
end

target :Mac do
  platform :osx, '10.9'
  link_with 'Mac'

  # pods...
end

现在这是我有问题的地方。 到目前为止,我的项目中仅具有默认的“调试”和“发布”配置。 我想更改它们,并为不同的供应配置文件/捆绑ID组合添加一些新的。

……我被困住了。 我不知道该怎么做。

问题的第一个迹象是对每个目标/配置组合发出警告Pods-something.a

[!] CocoaPods没有设置项目的基本配置   因为您的项目已经有一个自定义配置集。 为了   CocoaPods集成工作正常,请设置基础   目标Pods-something.aPods/Target Support Files/Pods-iOS/Pods-iOS.dev debug.xcconfig的配置,或包括   Pods/Target Support Files/Pods-iOS/Pods-iOS.dev debug.xcconfig中   您的构建配置。

我不知道这意味着什么以及如何解决此问题。 无论哪种方式,该项目都不会生成-在最佳情况下,我会收到一个链接器错误,指出无法找到Pods-something.a

trans by 2020-02-22T17:20:45Z

iPhone-服务(而非内容)的iOS定期订阅策略

事先为政策而不是编程问题表示歉意,但是鉴于在线提供的信息很少,我希望我能在这里提出要求得到原谅。

我想在iOS应用中使用Apple的新定期订阅。 我之前已经对付款进行了编码,并且在那里没有任何问题,但是我在哪里都找不到关于新订阅类型允许的指导。 暗示“似乎”是没有特别指导,但是我能找到的所有讨论都在谈论“内容”提供者,而不是服务提供者。

我想将定期订阅用于人们订阅的服务。 我本身不提供任何内容。

使用旧的非续订订阅类型(确实很破败,不值得使用),我99%肯定会接受该应用程序,但所有内容提供商的说法都让我担心Apple真的不想要 SAAS提供者可以使用定期订阅模型,并希望将其限制为内容的发布者。

有没有人有使用新的软件服务付款模式的经验?

在我们围绕该概念构建完整的支付解决方案之前,我想知道它是否可行的更好的主意!

trans by 2020-02-22T17:15:53Z

HttpRequest vs HttpRequestMessage vs HttpRequestBas

这些类在ASP.NET中有什么区别? 我发现这些类之间没有继承关系。

下面的代码返回request.Properties["MS_HttpContext"]的实例,其中is a HttpRequestBasehas a HttpRequest

HttpRequestMessage request = ...;
HttpRequestBase reqBase = (request.Properties["MS_HttpContext"] as HttpContextWrapper).Request;
// do somthing with reqBase.Cookies

微软似乎想让我们从HttpRequestMessage获取cookie时惹恼我们。

是否保证request.Properties["MS_HttpContext"]永远不会为空?

或者认为ajax请求是在ApiController的操作中处理的。 我可以通过两种不同的方式来获取客户端的IP。

var ip = (request.Properties["MS_HttpContext"] as HttpContextWrapper).Request.UserHostAddress

var ip = HttpContext.Current.Request.UserHostAddress

两者有什么区别?

或通常,我可以通过不同的方式访问相同的请求/响应数据,例如Cookie,标头,请求者信息等。 什么时候使用? 我们是否可以说类似“如果是ajax请求,由于缺少某些内容,不能保证HttpRequest正常工作,所以对于ajax请求,我们应该改用HttpRequestMessage”?

trans by 2020-02-22T17:13:28Z

如何防止.connect()之后Android蓝牙RFCOMM连接立即死亡?

这个问题已经解决了! 非常感谢Brad,Denis和瘾君子! 你是英雄! :)

这是工作代码。 它连接到Zeemote并从中读取数据。

=====代码=====

public class ZeeTest extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
            for (int i = 0; i < 3; i++) {
                test();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private boolean connected = false;
    private BluetoothSocket sock;
    private InputStream in;
    public void test() throws Exception {
        if (connected) {
            return;
        }
        BluetoothDevice zee = BluetoothAdapter.getDefaultAdapter().
            getRemoteDevice("00:1C:4D:02:A6:55");
        Method m = zee.getClass().getMethod("createRfcommSocket",
            new Class[] { int.class });
        sock = (BluetoothSocket)m.invoke(zee, Integer.valueOf(1));
        Log.d("ZeeTest", "++++ Connecting");
        sock.connect();
        Log.d("ZeeTest", "++++ Connected");
        in = sock.getInputStream();
        byte[] buffer = new byte[50];
        int read = 0;
        Log.d("ZeeTest", "++++ Listening...");
        try {
            while (true) {
                read = in.read(buffer);
                connected = true;
                StringBuilder buf = new StringBuilder();
                for (int i = 0; i < read; i++) {
                    int b = buffer[i] & 0xff;
                    if (b < 0x10) {
                        buf.append("0");
                    }
                    buf.append(Integer.toHexString(b)).append(" ");
                }
                Log.d("ZeeTest", "++++ Read "+ read +" bytes: "+ buf.toString());
            }
        } catch (IOException e) {}
        Log.d("ZeeTest", "++++ Done: test()");
    }
    @Override
    public void onDestroy() {
        try {
            if (in != null) {
                in.close();
            }
            if (sock != null) {
                sock.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        super.onDestroy();
    }
}

=====原始问题=====

我正在尝试从运行2.0.1固件的Moto Droid连接到Zeemote([http://zeemote.com/)]游戏控制器。 下面的测试应用程序确实已连接到设备(LED闪烁),但此后立即断开连接。

我在下面粘贴了两个测试应用程序:一个实际上尝试从输入流中读取,另一个则只是坐在那里,等待设备在5秒钟后断开连接。 是的,我确实有第三个版本:),它首先等待ACL_CONNECTED,然后打开套接字,但是它的行为没有新内容。

一些背景信息:我可以使用bluez工具(也附带日志)从我的笔记本电脑连接到Zeemote,效果非常好。 我确定Droid也可以与Zeemote进行对话,因为来自Market的“ Game Pro”可以很好地工作(但是那是驱动程序/服务,所以也许它使用了较低级的API?)。

我注意到,“ adb bugreport”既没有报告Zeemote的UUID也没有报告RFCOMM频道,而报告了所有其他设备(包括Moto HS815耳机,另一个“ sdp浏览”不报告的哑设备)。 同样,当设备启动时,Zeemote的优先级为0(其他优先级为100+)。

我在这里很茫然,我花了很长时间从事研究,以至于我耗尽了想法,所以任何帮助将不胜感激(即使您不知道答案:))

谢谢,最高

测试申请号1

此应用尝试实际从设备读取。

=====代码=====

public class ZeeTest extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
            test();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private BluetoothSocket sock;
    private InputStream in;
    public void test() throws IOException {
        BluetoothDevice zee = BluetoothAdapter.getDefaultAdapter().
                      getRemoteDevice("00:1C:4D:02:A6:55");
        sock = zee.createRfcommSocketToServiceRecord(
                      UUID.fromString("8e1f0cf7-508f-4875-b62c-fbb67fd34812"));
        Log.d("ZeeTest", "++++ Connecting");
        sock.connect();
        Log.d("ZeeTest", "++++ Connected");
        in = sock.getInputStream();
        byte[] buffer = new byte[1];
        int bytes = 0;
        int x = 0;
        Log.d("ZeeTest", "++++ Listening...");
        while (x < 2) {
            x++;
            try {
                bytes = in.read(buffer);
                Log.d("ZeeTest", "++++ Read "+ bytes +" bytes");
            } catch (IOException e) {
                e.printStackTrace();
                try { Thread.sleep(100); } catch (InterruptedException ie) {}
            }
        }
        Log.d("ZeeTest", "++++ Done: test()");
    }
    @Override
    public void onDestroy() {
        try {
            if (in != null) {
                in.close();
            }
            if (sock != null) {
                sock.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        super.onDestroy();
    }
}

=====日志=====

04-19 22:27:01.147: DEBUG/ZeeTest(8619): ++++ Connecting
04-19 22:27:04.085: INFO/usbd(1062): process_usb_uevent_message(): buffer = add@/devices/virtual/bluetooth/hci0/hci0:1
04-19 22:27:04.085: INFO/usbd(1062): main(): call select(...)
04-19 22:27:04.327: ERROR/BluetoothEventLoop.cpp(4029): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/4121/hci0/dev_00_1C_4D_02_A6_55
04-19 22:27:04.491: VERBOSE/BluetoothEventRedirector(7499): Received android.bleutooth.device.action.UUID
04-19 22:27:04.905: DEBUG/ZeeTest(8619): ++++ Connected
04-19 22:27:04.905: DEBUG/ZeeTest(8619): ++++ Listening...
04-19 22:27:05.538: WARN/System.err(8619): java.io.IOException: Software caused connection abort
04-19 22:27:05.600: WARN/System.err(8619):     at android.bluetooth.BluetoothSocket.readNative(Native Method)
...
04-19 22:27:05.717: WARN/System.err(8619): java.io.IOException: Software caused connection abort
04-19 22:27:05.717: WARN/System.err(8619):     at android.bluetooth.BluetoothSocket.readNative(Native Method)
...
04-19 22:27:05.819: DEBUG/ZeeTest(8619): ++++ Done: test()
04-19 22:27:07.155: VERBOSE/BluetoothEventRedirector(7499): Received android.bleutooth.device.action.UUID
04-19 22:27:09.077: INFO/usbd(1062): process_usb_uevent_message(): buffer = remove@/devices/virtual/bluetooth/hci0/hci0:1
04-19 22:27:09.085: INFO/usbd(1062): main(): call select(...)
04-19 22:27:09.139: ERROR/BluetoothEventLoop.cpp(4029): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/4121/hci0/dev_00_1C_4D_02_A6_55

测试申请号2

此测试将连接并等待-对于显示自动断开连接问题很有用。

=====代码=====

public class ZeeTest extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        getApplicationContext().registerReceiver(receiver,
                    new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));
        getApplicationContext().registerReceiver(receiver,
                    new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
        try {
            BluetoothDevice zee = BluetoothAdapter.getDefaultAdapter().
                            getRemoteDevice("00:1C:4D:02:A6:55");
            sock = zee.createRfcommSocketToServiceRecord(
                            UUID.fromString("8e1f0cf7-508f-4875-b62c-fbb67fd34812"));

            Log.d("ZeeTest", "++++ Connecting");
            sock.connect();
            Log.d("ZeeTest", "++++ Connected");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static final LogBroadcastReceiver receiver = new LogBroadcastReceiver();
    public static class LogBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d("ZeeReceiver", intent.toString());
            Bundle extras = intent.getExtras();
            for (String k : extras.keySet()) {
                Log.d("ZeeReceiver", "    Extra: "+ extras.get(k).toString());
            }
        }
    }

    private BluetoothSocket sock;
    @Override
    public void onDestroy() {
        getApplicationContext().unregisterReceiver(receiver);
        if (sock != null) {
            try {
                sock.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        super.onDestroy();
    }
}

=====日志=====

04-19 22:06:34.944: DEBUG/ZeeTest(7986): ++++ Connecting
04-19 22:06:38.202: INFO/usbd(1062): process_usb_uevent_message(): buffer = add@/devices/virtual/bluetooth/hci0/hci0:1
04-19 22:06:38.202: INFO/usbd(1062): main(): call select(...)
04-19 22:06:38.217: ERROR/BluetoothEventLoop.cpp(4029): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/4121/hci0/dev_00_1C_4D_02_A6_55
04-19 22:06:38.428: VERBOSE/BluetoothEventRedirector(7499): Received android.bleutooth.device.action.UUID
04-19 22:06:38.968: DEBUG/ZeeTest(7986): ++++ Connected
04-19 22:06:39.061: DEBUG/ZeeReceiver(7986): Intent { act=android.bluetooth.device.action.ACL_CONNECTED (has extras) }
04-19 22:06:39.108: DEBUG/ZeeReceiver(7986):     Extra: 00:1C:4D:02:A6:55
04-19 22:06:39.538: INFO/ActivityManager(4029): Displayed activity zee.test/.ZeeTest: 5178 ms (total 5178 ms)
04-19 22:06:41.014: VERBOSE/BluetoothEventRedirector(7499): Received android.bleutooth.device.action.UUID
04-19 22:06:43.038: INFO/usbd(1062): process_usb_uevent_message(): buffer = remove@/devices/virtual/bluetooth/hci0/hci0:1
04-19 22:06:43.038: INFO/usbd(1062): main(): call select(...)
04-19 22:06:43.069: ERROR/BluetoothEventLoop.cpp(4029): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/4121/hci0/dev_00_1C_4D_02_A6_55
04-19 22:06:43.124: DEBUG/ZeeReceiver(7986): Intent { act=android.bluetooth.device.action.ACL_DISCONNECTED (has extras) }
04-19 22:06:43.124: DEBUG/ZeeReceiver(7986):     Extra: 00:1C:4D:02:A6:55

系统日志

=====终端日志=====

$ sdptool browse
Inquiring ...
Browsing 00:1C:4D:02:A6:55 ...

$ sdptool records 00:1C:4D:02:A6:55
Service Name: Zeemote
Service RecHandle: 0x10015
Service Class ID List:
  UUID 128: 8e1f0cf7-508f-4875-b62c-fbb67fd34812
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 1
Language Base Attr List:
  code_ISO639: 0x656e
  encoding:    0x6a
  base_offset: 0x100

$ rfcomm connect /dev/tty10 00:1C:4D:02:A6:55
Connected /dev/rfcomm0 to 00:1C:4D:02:A6:55 on channel 1
Press CTRL-C for hangup

# rfcomm show /dev/tty10
rfcomm0: 00:1F:3A:E4:C8:40 -> 00:1C:4D:02:A6:55 channel 1 connected [reuse-dlc release-on-hup tty-attached]

# cat /dev/tty10
(nothing here)

# hcidump
HCI sniffer - Bluetooth packet analyzer ver 1.42
device: hci0 snap_len: 1028 filter: 0xffffffff
< HCI Command: Create Connection (0x01|0x0005) plen 13
> HCI Event: Command Status (0x0f) plen 4
> HCI Event: Connect Complete (0x03) plen 11
< HCI Command: Read Remote Supported Features (0x01|0x001b) plen 2
> HCI Event: Read Remote Supported Features (0x0b) plen 11
< ACL data: handle 11 flags 0x02 dlen 10
    L2CAP(s): Info req: type 2
> HCI Event: Command Status (0x0f) plen 4
> HCI Event: Page Scan Repetition Mode Change (0x20) plen 7
> HCI Event: Max Slots Change (0x1b) plen 3
< HCI Command: Remote Name Request (0x01|0x0019) plen 10
> HCI Event: Command Status (0x0f) plen 4
> ACL data: handle 11 flags 0x02 dlen 16
    L2CAP(s): Info rsp: type 2 result 0
      Extended feature mask 0x0000
< ACL data: handle 11 flags 0x02 dlen 12
    L2CAP(s): Connect req: psm 3 scid 0x0040
> HCI Event: Number of Completed Packets (0x13) plen 5
> ACL data: handle 11 flags 0x02 dlen 16
    L2CAP(s): Connect rsp: dcid 0x04fb scid 0x0040 result 1 status 2
      Connection pending - Authorization pending
> HCI Event: Remote Name Req Complete (0x07) plen 255
> ACL data: handle 11 flags 0x02 dlen 16
    L2CAP(s): Connect rsp: dcid 0x04fb scid 0x0040 result 0 status 0
      Connection successful
< ACL data: handle 11 flags 0x02 dlen 16
    L2CAP(s): Config req: dcid 0x04fb flags 0x00 clen 4
      MTU 1013
(events are properly received using bluez)

===== adb bugreport的一部分=====

--Known devices--
00:19:A1:2D:16:EA     bonded (0) LG U830
    00001105-0000-1000-8000-00805f9b34fb RFCOMM channel = 17
00:1C:4D:02:A6:55     bonded (0) Zeemote JS1
00:0B:2E:6E:6F:00     bonded (0) Motorola HS815
    00001108-0000-1000-8000-00805f9b34fb RFCOMM channel = 1
    0000111e-0000-1000-8000-00805f9b34fb RFCOMM channel = 2
00:1F:3A:E4:C8:40     bonded (0) BRCM BT4X
    00001105-0000-1000-8000-00805f9b34fb RFCOMM channel = 9
00:18:42:EC:E2:99     bonded (0) N95
    00001105-0000-1000-8000-00805f9b34fb RFCOMM channel = 9

=====摘录自启动日志=====

04-18 21:55:10.382: VERBOSE/BluetoothEventRedirector(1985): Received android.bluetooth.adapter.action.STATE_CHANGED
04-18 21:55:10.421: DEBUG/BT HSHFP(1237): Loaded priority 00:19:A1:2D:16:EA = 100
04-18 21:55:10.428: DEBUG/BT HSHFP(1237): Loaded priority 00:1C:4D:02:A6:55 = 0
04-18 21:55:10.444: DEBUG/BT HSHFP(1237): Loaded priority 00:0B:2E:6E:6F:00 = 101
04-18 21:55:10.749: DEBUG/BT HSHFP(1237): Loaded priority 00:1F:3A:E4:C8:40 = 100
04-18 21:55:10.780: DEBUG/BT HSHFP(1237): Loaded priority 00:18:42:EC:E2:99 = 100
trans by 2020-02-22T17:08:38Z

内容类型-HttpWebResponse上的ContentType属性是否有枚举(“文本/纯文本”,“应用程序/八位字节流”等)?

我能找到的最接近的东西是System.Net.Mime.MediaTypeNames,但这似乎不具备所有功能(例如json),因为它似乎更集中于电子邮件附件。

trans by 2020-02-22T17:04:45Z

vba-Solidworks C#插件-将字符串发送到m

我目前正在处理一个新的Solidworks任务窗格,主要是实现一些我以更方便的格式编写的“旧”宏。 其中一些需要用户通过文本框输入,我想将其包含在任务窗格中。

问题是,我找不到写暂存文件或将这些字符串导入宏的方法(我宁愿不花时间重写)

还有其他方法可以将这些字符串发送到我的宏吗? 插件使用C#,并且我目前正在使用Solidworks的“ RunMacro2”方法。

谢谢!

编辑:在下面添加一些代码段。 有问题的主要宏用于在整个程序集中传播自定义属性文件。

namespace Efficiency_Interface
{
    [ComVisible(true)]
    [ProgId(ProjMan_Tab_PROGID)]
    public partial class Project_Management_Tab : UserControl
    {

        SwAddin SolidRun = new SwAddin();
        public const string ProjMan_Tab_PROGID = "Proj Management";
        public const string scratchFile = "C:\\keyStoneAddinScratch.txt";
        StreamWriter writeText = new StreamWriter(scratchFile);

        public Project_Management_Tab()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (var textBox in this.Controls.OfType<TextBox>())
            {
                writeText.WriteLine(textBox.Text);
            }
            writeText.Close();
            SolidRun.runGen("proc");
        }
    }
}

上面是我的任务窗格的基本代码。下面是我的主要addin类的代码片段,其中还包含其他按钮之一的代码。

public void runCreate4Pack()
{
    iSwApp.RunMacro2(macroPath + "CREATE 4 SIZE PACKAGE.swp", "", "", 0, out runMacroError);
    return;
}

public void runGen(string procName)
{
    iSwApp.RunMacro2(macroPath + "Efficiency Interface.swp", "hitButton", procName, 0, out runMacroError);
    File.Delete("C:\\Users\\Public\\keyStoneAddinScratch.txt");
    return;
}

最后,是我要与之交互的宏的主要代码。

Private Sub fillProps_Click()
    Dim doneParts() As Variant
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set part = swApp.ActiveDoc

    If firstAssem = "" Then
        referenceList (0)
    End If

    i = 0
    ReDim Preserve doneParts(1)
    Set custPropMgr = part.Extension.CustomPropertyManager(part.GetActiveConfiguration.name)
    setProps "", "", ""

    While i <= 1000 And Not assemComps(i, j) = ""
        parentAssemNum = Left(assemComps(i, 0), InStrRev(assemComps(i, 0), ".") - 1)
        parentAssemDesc = assemComps(i, 1)
        j = 2
        While j <= 10000 And Not assemComps(i, j) = ""
            k = 0
            While k < UBound(doneParts())
                If doneParts(k) = assemComps(i, j) Then
                    GoTo skipEntry
                End If
                k = k + 1
            Wend
            Set part = swApp.ActivateDoc3(assemComps(i, j), True, 1, 1)
            If part.GetType = 1 Then
                Set swpartdoc = part
            End If

            If InStr(part.IGetActiveConfiguration.name, "Default") > 0 Then
                Set custPropMgr = part.Extension.CustomPropertyManager("")
            End If
            Debug.Print custPropMgr.Get("Description")
            setProps parentAssemNum + "", parentAssemDesc + "", ""

            ReDim Preserve doneParts(UBound(doneParts) + 1)
            doneParts(UBound(doneParts)) = assemComps(i, j)
            If i > 0 Or j > 0 Then
                swApp.QuitDoc (assemComps(i, j))
            End If
skipEntry:
            j = j + 1
        Wend
        i = i + 1
    Wend   
End Sub

Sub setProps(parentAssemNum As String, parentAssemDesc As String, stockSize  As String)
    If custPropMgr.Get("StockSize") = "" Then
        If part.GetType = swDocPART Then
            If swpartdoc.IsWeldment = False Then
                Dim sizeArray(2)
                vboundbox = swpartdoc.GetPartBox(False)
                size1 = Round(Abs(vboundbox(0) - vboundbox(3)), 2)
                size2 = Round(Abs(vboundbox(1) - vboundbox(4)), 2)
                size3 = Round(Abs(vboundbox(2) - vboundbox(5)), 2)
                sizeArray(0) = size1
                sizeArray(1) = size2
                sizeArray(2) = size3
                rectVol = size1 * size2 * size3
                Set swmass = part.Extension.CreateMassProperty
                swmass.UseSystemUnits = False
                swVol = swmass.Volume
                QuickSort sizeArray, LBound(sizeArray), UBound(sizeArray)
                eq = 0
                If size1 = size2 Then
                    eq = 1
                    cylVol = 3.14159 * ((size1 / 2) * (size1 / 2)) * size3
                End If
                If size1 = size3 Then
                    eq = 1
                    cylVol = 3.14159 * ((size1 / 2) * (size1 / 2)) * size2
                End If
                If size3 = size2 Then
                    eq = 1
                    cylVol = 3.14159 * ((size2 / 2) * (size2 / 2)) * size1
                End If
                If eq = 1 Then
                    If Abs(swVol - cylVol) < Abs(swVol - rectVol) Then
                        boolstatus = custPropMgr.Set("StockSize", "ROUND BAR, " & size2 & " OD X " & size3 & "LG")
                    End If
                    If Abs(swVol - rectVol) < Abs(swVol - cylVol) Then
                        'If size3 > size2 Then
                            boolstatus = custPropMgr.Set("StockSize", size2 & " SQ X " & size3 & "LG")
                        'End If
                        'If size3 < size2 Then
                        '    boolstatus = custPropMgr.Set("StockSize", "PLATE," & size2 & " SQ X " & size3 & "LG")
                        'End If
                    End If
                    If Abs(swVol - cylVol) = Abs(swVol - rectVol) Then
                        'If size3 > size2 Then
                            boolstatus = custPropMgr.Set("StockSize", "BAR, " & size2 & " X " & size3 & "LG")
                        'End If
                        'If size3 < size2 Then
                        '    boolstatus = custPropMgr.Set("StockSize", "PLATE," & size2 & " SQ X " & size3 & "LG")
                        'End If
                    End If
                End If
                If eq = 0 Then
                    boolstatus = custPropMgr.Set("StockSize", sizeArray(2) & " X " & sizeArray(1) & " X " & sizeArray(0))
                End If
            End If
        End If
    End If
    If Len(custPropMgr.Get("DATE")) = 0 Then
        boolstatus = custPropMgr.Set("Date", Left(Now, InStrRev(Now, "/") + 4))
    End If

    boolstatus = custPropMgr.Set("Workorder", Interface.workorder.Text)
    boolstatus = custPropMgr.Set("Plant", Interface.plantBox.Text)
    boolstatus = custPropMgr.Set("AssemblyNumber", parentAssemNum)
    boolstatus = custPropMgr.Set("Line2", parentAssemDesc)
    boolstatus = custPropMgr.Set("Line3", Interface.projBox.Text)

    If Len(custPropMgr.Get("Finish")) = 0 Then
        'boolstatus = custPropMgr.Set("Finish", Interface.finish.Text)
    End If
    If Len(custPropMgr.Get("DesignBy")) = 0 Then
        'boolstatus = custPropMgr.Set("DesignBy", Interface.creator.Text)
    End If
    If Len(custPropMgr.Get("DrawnBy")) = 0 Then
        'boolstatus = custPropMgr.Set("DrawnBy", Interface.creator.Text)
    End If
End Sub

我确实希望这会有所帮助,并且不要太困惑。

trans by 2020-02-22T17:02:42Z

如何在case语句中使用C#枚举值的字符串值?

我已将C#枚举定义为

public enum ORDER
{
    ...
    unknown,
    partial01,
    partial12,
    partial23,
}

并可以将其值用作字符串,如下所示:

            string ss = ORDER.partial01.ToString();

但是,当我尝试在case语句中使用它时,它无法编译:

string value = ...
switch (value)
{
    case null:
        break;
    case "s":
        // OK
        break;
    case ORDER.partial01.ToString():
        // compiler throws "a constant value is expected"

        break;
  ...

我以为枚举是常量。 我该如何解决?

(我无法将值解析为枚举,因为某些值超出了范围)

trans by 2020-02-22T16:55:34Z

html-使用jQuery可调整大小的表列

这是我可以找到的唯一一个调整表列宽度大小的jQuery插件,但是它与我的表的集成度不高,并且具有不必要的膨胀(节省cookie)。 还有其他用于调整列大小的插件吗? (不是datagrid插件,请不要建议那些插件)。

如果没有,我会自己写,应该不会太难,我只是不知道如何检测用户何时单击td边框(以调整大小)。 有任何想法吗?

trans by 2020-02-22T16:48:57Z

缩进-删除Vim中一行之前的所有任意空格

我编写了一个插件来解析XML标签。 标记内的内容是缩进的,当我将解析的字符串复制到文件中时,它会像这样:

    Example line
        This is part of the parsed line
        Thats goes one
    End of line

我要删除这些行前面的所有空格,最后的文字应该是

Example line
This is part of the parsed line
Thats goes one
End of line

我尝试使用=,但它无法按照我想要的方式工作。 如何用最少的按键操作做到这一点?

trans by 2020-02-22T16:43:33Z

如何在网站上显示来自Google云端硬盘的图像?

我的一个客户已将一些照片上传到他们的Google云端硬盘,希望我在他们的公司网站上显示他们的照片。 我查看了用于在网页中显示Google云端硬盘内容的文档,但是看来,这只是在网页中显示内容的说明,它已经做到了。

我的问题是,如何直接在客户的网页上显示内容?

谢谢。

trans by 2020-02-22T16:33:43Z

为什么我不能在Eclipse中设置断点?

由于某些奇怪的原因,我无法在eclipse项目中使用断点。 我设置的所有断点在它们的对角线上,在相应行中的点上方(在窗口的左边缘),好像它们被阻塞一样。 当我在调试模式下运行时,将忽略断点。 有任何想法吗?

trans by 2020-02-22T16:29:00Z

android-如何解决“ ADB服务器未确认”错误?

这个问题已经在这里有了答案:

  • Eclipse错误“ ADB服务器未确认,无法启动守护程序”                                     22个答案
  • 亚行将无法启动                                     21个答案

我试图同时在5个AVD上安装我的项目,但我不断收到此错误,我正在Windows 8.1上执行它

"* daemon not running. starting it now on port 5037 *
ADB server didn't ACK
* failed to start daemon *
error: cannot connect to daemon"

我已经尝试阅读关于此错误的所有关于stackoverflow的帖子,并且所有这些帖子都只提到尝试杀死adb进程并重新启动eclipse,然后一切都会好起来的。 我已经尝试了帖子中提到的方法,并且我也关闭了安全和防火墙,以使端口5037上没有阻塞。有人需要帮助我,因为我需要执行我的项目,但我无法 这样做:(。作为参考,我可以提供以下命令的输出“ netstat -ano | findstr“ 5037”“

 TCP    127.0.0.1:5037         0.0.0.0:0              LISTENING       7144
 TCP    127.0.0.1:5037         127.0.0.1:57410        ESTABLISHED     7144
 TCP    127.0.0.1:5037         127.0.0.1:57411        ESTABLISHED     7144
 TCP    127.0.0.1:5037         127.0.0.1:57414        ESTABLISHED     7144
 TCP    127.0.0.1:5037         127.0.0.1:57415        ESTABLISHED     7144
 ...

有人请提出解决此问题的方法,这可能是造成此问题的原因。 您也可以看下面的图片来推断可能发生的情况。

trans by 2020-02-22T16:20:40Z

克隆MySQL数据库

我的服务器上有120个表的数据库。

我想用新的数据库名称和复制的数据克隆整个数据库。

有有效的方法吗?

trans by 2020-02-22T16:15:13Z

c#-将UTF-8转换为base64字符串

我正在尝试将base64转换为base64字符串。

示例:我在base64中有“ abcdef ==”。实际上,它是base64字符串的“表示形式”。

如何检索“ abcdef ==“ base64”字符串(请注意,我不希望从base64获得“ abcdef ==”“翻译”,我想获取以base64编码的字符串,即“ abcdef ==”)。

编辑
我的问题似乎不清楚,这里是一个重新表述:

我的字节数组(假设我将其命名为A)由base64字符串表示。 将A转换为base64会得到“ abcdef ==“。

此字符串表示形式是通过UTF-8中的套接字发送的(请注意,字符串表示形式在UTF-8和base64中是完全相同的)。 因此,我收到一个UTF-8消息,它在UTF-8中包含“ whatever / abcdef == / whatever”。

因此,我需要从此套接字消息中检索base64“ abcedf ==”字符串,以获取A。

我希望这更加清楚!

trans by 2020-02-22T16:12:36Z

CSS并排div的自动等宽

<div id="wrapper" style="width:90%;height:100px;background-color:Gray;">
    <div id="one" style="height:100px;background-color:Green;float:left;"></div>
    <div id="two" style="height:100px;background-color:blue;float:left;"></div>
    <div id="three" style="height:100px;background-color:Red;float:left;"></div>
</div>

我有一个父div,其中将包含2或3个子div。 我希望子div自动采用相等的宽度。

谢谢

trans by 2020-02-22T16:07:26Z

php-PHPMai中的“ SMTP错误:无法验证”

我在用于通过Gmail发送电子邮件的简单脚本中使用PHPMailer,但遇到了“未知错误”(至少对我来说!):

SMTP错误:无法验证。   错误:SMTP错误:无法   认证。

SMTP服务器错误:5.7.1用户名和   密码不被接受。 了解更多   535 5.7.1   [http://mail.google.com/support/bin/answer.py?answer=14257]   p18sm2467302ybk.16

我已经阅读了有关为SSL / TLS连接配置OpenSSL的信息,并且做到了。 正确配置了Apache和PHP(使用在PHP中运行的OpenSSL扩展名和在Apache 2.2.16中运行的mod_ssl)。

这是PHP脚本:

 <?php
  require_once ("PHPMailer\class.phpmailer.php");
  $Correo = new PHPMailer();
  $Correo->IsSMTP();
  $Correo->SMTPAuth = true;
  $Correo->SMTPSecure = "tls";
  $Correo->Host = "smtp.gmail.com";
  $Correo->Port = 587;
  $Correo->UserName = "foo@gmail.com";
  $Correo->Password = "gmailpassword";
  $Correo->SetFrom('foo@gmail.com','De Yo');
  $Correo->FromName = "From";
  $Correo->AddAddress("bar@hotmail.com");
  $Correo->Subject = "Prueba con PHPMailer";
  $Correo->Body = "<H3>Bienvenido! Esto Funciona!</H3>";
  $Correo->IsHTML (true);
  if (!$Correo->Send())
  {
    echo "Error: $Correo->ErrorInfo";
  }
  else
  {
    echo "Message Sent!";
  }
?>

用户名和密码都可以,我在Thunderbird中尝试了,没有任何问题。我还使用了SSL身份验证和端口465,但得到了相同的错误。

trans by 2020-02-22T15:58:55Z

c#-从字符串中删除所有非ASCII字符

我有一个C#例程,该例程从CSV文件导入数据,将其与数据库匹配,然后将其重写为文件。 源文件似乎包含一些非ASCII字符,这些字符使处理例程无法正常运行。

我已经有一个静态方法可以运行每个输入字段,但是它执行基本的检查,例如删除逗号和引号。 有人知道我如何添加也可以删除非ASCII字符的功能吗?

trans by 2020-02-22T15:54:05Z

我使用cx_Freez时出现KeyError:“ TCL_Library”

当我使用cx_Freeze时,在构建我的pygame程序时遇到keyerror KeyError: 'TCL_Library'。 为什么会得到这个,如何解决?

我的setup.py如下:

from cx_Freeze import setup, Executable

setup(
    name = "Snakes and Ladders",
    version = "0.9",
    author = "Adam",
    author_email = "Omitted",
    options = {"build_exe": {"packages":["pygame"],
                         "include_files": ["main.py", "squares.py",
                         "pictures/Base Dice.png", "pictures/Dice 1.png",
                         "pictures/Dice 2.png", "pictures/Dice 3.png",
                         "pictures/Dice 4.png", "pictures/Dice 5.png",
                         "pictures/Dice 6.png"]}},
    executables = [Executable("run.py")],
    )
trans by 2020-02-22T15:48:56Z

硒-如何控制Chromedriver打开的窗口大小?

我正在使用Selenium WebDriver进行自动化,并且正在使用Chromedriver。

我注意到,当我的驱动程序运行并打开chrome浏览器时,它会以奇怪的大小打开浏览器。我试图解决它,但没有成功。

有人知道我该如何更改吗?

trans by 2020-02-22T15:41:38Z

上一页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 下一页 共3510页