小编Mr_*_*s_D的帖子

Visual Studio C++多行注释

在VS C++代码中,如果我没有选择任何内容或选择完整行并按下注释选择(Ctrl + K + Ctrl + C),那么它将使用//注释整行

int x = 5;
Run Code Online (Sandbox Code Playgroud)

按Ctrl + K + Ctrl + C后不选择任何内容或选择全行.

// int x = 5;
Run Code Online (Sandbox Code Playgroud)

现在,如果我选择该行的某些部分并再次按下注释按钮,则仅评论所选文本(粗体表示已选中)

int x = 5 ;

按下Ctrl + K + Ctrl + C并选择x = 5.

int /*x = 5*/;
Run Code Online (Sandbox Code Playgroud)

包含多条线

int x = 5;

int y = 2;

int z = x*5;

评论后快捷方式

int/* x = 5;
int y = 2;
int z =*/ x * 5;
Run Code Online (Sandbox Code Playgroud)

我想要的是

//int x = 5;
//int y = 2; …
Run Code Online (Sandbox Code Playgroud)

c++ comments styling visual-studio-2010

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

无法为cmake指定BOOST_ROOT

我安装了多个版本的Boost(Windows 7/MinGW).我需要使用一个特定的(1.53.0).

我在CMakeFiles.txt文件中定义了BOOST_ROOT: SET(BOOST_ROOT C:/boost_1_53_0/)但是我一直收到这个错误:

> cmake .
BOOST_ROOT=C:/boost_1_53_0/
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1191 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.48.0

  Boost include path: C:/Boost/include/boost-1_48

  Detected version of Boost is too old.  Requested version was 1.53 (or
  newer).

  The following Boost libraries could not be found:

          boost_filesystem

  No Boost libraries were found.  You may need to set BOOST_LIBRARYDIR to the
  directory containing Boost libraries or BOOST_ROOT to the location of
  Boost.
Run Code Online (Sandbox Code Playgroud)

我还将BOOST_ROOT定义为环境变量,但结果相同.

为什么cmake还在寻找旧版本?

boost version cmake environment-variables

10
推荐指数
3
解决办法
4万
查看次数

当我明确地将键作为第一个元素提供时,为什么要更快地排序元组的python列表?

当我没有明确指定应该使用密钥时,对元组列表(字典键,密钥是随机字符串的值对)进行排序更快(编辑:在@Chepner的评论中添加了operator.itemgetter(0)和密钥版现在更快!):

import timeit

setup ="""
import random
import string

random.seed('slartibartfast')
d={}
for i in range(1000):
    d[''.join(random.choice(string.ascii_uppercase) for _ in range(16))] = 0
"""
print min(timeit.Timer('for k,v in sorted(d.iteritems()): pass',
        setup=setup).repeat(7, 1000))
print min(timeit.Timer('for k,v in sorted(d.iteritems(),key=lambda x: x[0]): pass',
        setup=setup).repeat(7, 1000))
print min(timeit.Timer('for k,v in sorted(d.iteritems(),key=operator.itemgetter(0)): pass',
        setup=setup).repeat(7, 1000))
Run Code Online (Sandbox Code Playgroud)

得到:

0.575334150664
0.579534521128
0.523808984422 (the itemgetter version!)
Run Code Online (Sandbox Code Playgroud)

但是,如果我创建一个自定义对象key=lambda x: x[0]显式传递sorted使其更快:

setup ="""
import random
import string

random.seed('slartibartfast')
d={}

class A(object):
    def __init__(self):
        self.s …
Run Code Online (Sandbox Code Playgroud)

python sorting tuples timeit python-2.7

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

如何在张量流中乘以向量和矩阵而不进行重新整形?

这个:

import numpy as np
a = np.array([1, 2, 1])
w = np.array([[.5, .6], [.7, .8], [.7, .8]])

print(np.dot(a, w))
# [ 2.6  3. ] # plain nice old matrix multiplication n x (n, m) -> m

import tensorflow as tf

a = tf.constant(a, dtype=tf.float64)
w = tf.constant(w)

with tf.Session() as sess:
    print(tf.matmul(a, w).eval())
Run Code Online (Sandbox Code Playgroud)

结果是:

C:\_\Python35\python.exe C:/Users/MrD/.PyCharm2017.1/config/scratches/scratch_31.py
[ 2.6  3. ]
# bunch of errors in windows...
Traceback (most recent call last):
  File "C:\_\Python35\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 671, in _call_cpp_shape_fn_impl
    input_tensors_as_shapes, status) …
Run Code Online (Sandbox Code Playgroud)

python matrix-multiplication tensorflow

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

大型内部类和私有变量

我遇到的一件事是服务类(比如JBoss服务)由于帮助器内部类而变得过大.我还没有找到一个打破课堂的好方法.这些助手通常是线程.这是一个例子:

/** Asset service keeps track of the metadata about assets that live on other
 * systems. Complications include the fact the assets have a lifecycle and their
 * physical representation lives on other systems that have to be polled to find
 * out if the Asset is still there. */
public class AssetService
{
  //...various private variables
  //...various methods

  public AssetService()
  {
    Job pollerJob = jobService.schedule( new AssetPoller() );
    Job lifeCycleJob = jobService.schedule( AssetLifecycleMonitor() );
  }

  class AssetPoller
  { …
Run Code Online (Sandbox Code Playgroud)

java jboss class-design

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

通知恢复活动

我知道,有几个这种类型的问题,但我尝试了所有这些,但它仍然无效.
好的,对于我的应用; 我有一个活动.在此活动中,有4个选项卡,第四个包含列表和记录按钮.当我推送记录时,有一个GPS监听器启动.获取新的gps值后,它会将其推送到列表中.
到目前为止这个工作!
如果我单击主页按钮它仍然有效,如果我长按它.它恢复了具有特定Tab的Activity,并且列表仍然保持listitems并且gps监听器仍处于活动状态.
这个工作也没关系!
现在我想添加一个通知,它将列表的gps值计数显示为.number.在每个新的gps信号上,它会使用新号码更新通知图标.这没问题,但点击通知的动作完全搞砸了我的申请.

实际代码如下所示:

public void callNotify(String text) {
    notif = new Notification();
    Intent contentIntent = new Intent(this, tabactivity.class);
    contentIntent.putExtra("fid", this.specialvalue);
    contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
        | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notif.icon = R.drawable.icon;
    notif.setLatestEventInfo(this, getString(R.string.app_name), text,
        PendingIntent.getActivity(this.getBaseContext(), 0, contentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));
    notif.ledARGB = Color.RED;
    notif.ledOnMS = 200;
    notif.ledOffMS = 200;
    notif.flags = Notification.FLAG_SHOW_LIGHTS
        | Notification.FLAG_ONGOING_EVENT
        | Notification.FLAG_ONLY_ALERT_ONCE;
    notif.number = notifyNumber;
    mNotificationManager.notify(notifyNumber, notif);
}

public void updateNotify(String text) {
    notifyNumber++;
    notif.number = (int) (notifyNumber / 2);
    Intent contentIntent = new Intent(this, tabactivity.class);
    contentIntent.putExtra("fid", this.specialvalue); …
Run Code Online (Sandbox Code Playgroud)

resume notifications android

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

如何获得gps定位android

我试图有一个恒定的gps监听器,每隔x分钟将其位置(长和lat坐标)发送到Web服务器.在按钮上单击它还会将其位置发送到Web服务器.我知道要获取gps信号,你可以输入寻找位置的频率,但是如何编写一个程序可以获得gps位置并每x分钟发送一次坐标(即使在背景中也没有按下按钮) ?

//在点击中

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
        LocationManager.GPS_PROVIDER, whatshouldIputhere?, 0, this);
Run Code Online (Sandbox Code Playgroud)

public void onLocationChanged(Location location) {
    if (location != null) {
        double lat = location.getLatitude();
        double lng = location.getLongitude();
    }
}
Run Code Online (Sandbox Code Playgroud)

gps android

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

pandas数据帧有2行标题并导出到csv

我有一个数据帧

df = pd.DataFrame(columns = ["AA", "BB", "CC"])
df.loc[0]= ["a", "b", "c1"]
df.loc[1]= ["a", "b", "c2"]
df.loc[2]= ["a", "b", "c3"]
Run Code Online (Sandbox Code Playgroud)

我需要在标题中添加secod行

df.columns = pd.MultiIndex.from_tuples(zip(df.columns, ["DD", "EE", "FF"]))
Run Code Online (Sandbox Code Playgroud)

我的df现在

  AA BB  CC
  DD EE  FF
0  a  b  c1
1  a  b  c2
2  a  b  c3
Run Code Online (Sandbox Code Playgroud)

但是当我将这个数据帧写入csv文件时

df.to_csv("test.csv", index = False)
Run Code Online (Sandbox Code Playgroud)

我按预期更多地获得一排

AA,BB,CC
DD,EE,FF
,,
a,b,c1
a,b,c2
a,b,c3
Run Code Online (Sandbox Code Playgroud)

python csv dataframe pandas

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

如何使用python argparse将add_argument_group添加到add_mutually_exclusive_group

我正在尝试实现以下内容:

$ prog.py -h
usage: prog.py [-h] [-s | -m] [[-y [year]] | [[-1 | -3] [month] [year]]]
Run Code Online (Sandbox Code Playgroud)

但是,无论我如何玩add_argument_group和add_mutually_exclusive_group,

#!/usr/bin/env python

import argparse

def main(opt):
    print(opt)

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    bar = parser.add_mutually_exclusive_group()
    bar.add_argument('-s', action='store_true', default=True)
    bar.add_argument('-m', action='store_true', default=False)

    #bar = parser.add_argument_group()
    bar = parser.add_mutually_exclusive_group()
    bar.add_argument('-y', metavar='year', type=int,
                     dest='iy', nargs='?', default=0)
    baz = bar.add_argument_group()
    g_13 = baz.add_mutually_exclusive_group()
    g_13.add_argument('-1', dest='i1',
                      help='Display single month output.',
                      action='store_true', default=True)
    g_13.add_argument('-3', dest='i3',
                      help='Display prev/current/next month output.',
                      action='store_true', default=False)
    #aaa = bar.add_argument_group()
    baz.add_argument(metavar='month', …
Run Code Online (Sandbox Code Playgroud)

python argparse

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

第一次通话后断开插槽的优雅方式

在构造函数内部,有一个连接:

connect(&amskspace::on_board_computer_model::self(),
      SIGNAL(camera_status_changed(const amskspace::camera_status_t&)),
      this,
      SLOT(set_camera_status(const amskspace::camera_status_t&)));
Run Code Online (Sandbox Code Playgroud)

方法:

void camera_model::
set_camera_status(const amskspace::camera_status_t& status) {
  disconnect(&amskspace::on_board_computer_model::self(),
             SIGNAL(camera_status_changed(const amskspace::camera_status_t&)),
             this,
             SLOT(set_camera_status(const amskspace::camera_status_t&)));

  // do the job
}
Run Code Online (Sandbox Code Playgroud)

我想在第一次通话后断开此插槽.

问题是:有没有办法只调用一次插槽?没有明确的断开连接?像单枪法一样?可能吗?

c++ qt signals slot

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