小编Pat*_*ryk的帖子

抑制InsecureRequestWarning:在Python2.6中进行未验证的HTTPS请求

我正在使用pyVmomi在Python2.6中编写脚本,并使用其中一种连接方法:

service_instance = connect.SmartConnect(host=args.ip,
                                        user=args.user,
                                        pwd=args.password)
Run Code Online (Sandbox Code Playgroud)

我收到以下警告:

/usr/lib/python2.6/site-packages/requests/packages/urllib3/connectionpool.py:734: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
  InsecureRequestWarning)
Run Code Online (Sandbox Code Playgroud)

有趣的是,我没有使用pip安装urllib3(但它位于/usr/lib/python2.6/site-packages/requests/packages/urllib3/).

我按照这里的建议尝试过

import urllib3
...
urllib3.disable_warnings()
Run Code Online (Sandbox Code Playgroud)

但这并没有改变任何事情.

python python-2.6 suppress-warnings urllib3 pyvmomi

283
推荐指数
11
解决办法
31万
查看次数

std :: string_view究竟比const std :: string&更快?

std::string_view已经使它成为C++ 17,并且它被广泛推荐使用它代替const std::string&.

其中一个原因是表现.

有人可以解释与用作参数类型相比,究竟 std::string_view是什么/将会更快const std::string&?(假设在被叫方中没有副本)

c++ string string-view c++17

195
推荐指数
5
解决办法
3万
查看次数

std :: move和std :: forward之间有什么区别

我在这里看到了这一点: Move Constructor调用基类Move Constructor

有人能解释一下:

  1. 之间的差std::movestd::forward,优选用一些代码示例?
  2. 如何轻松思考,何时使用哪个

c++ perfect-forwarding c++11

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

std :: reference_wrapper和简单指针之间的区别?

为什么需要std::reference_wrapper?应该在哪里使用?它与简单的指针有什么不同?它的性能与简单的指针相比如何?

c++ pointers reference c++11 reference-wrapper

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

何时使用async或packaged_task的承诺?

我应该什么时候使用std::promisestd::asyncstd::packaged_task?你能告诉我何时使用它们的实际例子吗?

c++ asynchronous future promise packaged-task

42
推荐指数
2
解决办法
6243
查看次数

为什么double.TryParse("0.0000",out doubleValue)返回false?

我试图解析字符串"0.0000" double.TryParse()但我不知道为什么它会在这个特定的例子中返回false.当我传递类似整数的字符串,例如"5"时,它正确地解析为值5.

任何想法为什么会发生?

c# double parsing

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

如何使用boost :: optional

我想尝试使用boost::optional如下.

#include <iostream>
#include <string>

#include <boost/optional.hpp>

struct myClass
{
   int myInt;
   void setInt(int input) { myInt = input; }
   int  getInt(){return myInt; }
};

boost::optional<myClass> func(const std::string &str)
{
   boost::optional<myClass> value;
   if(str.length() > 5)
   {
      // If greater than 5 length string. Set value to 10
      value.get().setInt(10);
   }
   else if (str.length() < 5)
   {
      // Else set it to 0
      value.get().setInt(0);
   }
   else
   {
      // If it is 5 set the value to 5
      value.get().setInt(5);
   }

   return …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-optional

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

基于策略的设计和最佳实践 - C++

struct InkPen
{
  void Write()
  {
    this->WriteImplementation();
  }

  void WriteImplementation()
  {
    std::cout << "Writing using a inkpen" << std::endl;
  }

};

struct BoldPen
{
  void Write()
  {
    std::cout << "Writing using a boldpen" << std::endl;
  }
};

template<class PenType>
class Writer : public PenType
{
public:
  void StartWriting()
  {
    PenType::Write();
  }
};

int main()
{
  Writer<InkPen> writer;
  writer.StartWriting();
  Writer<BoldPen> writer1;
  writer1.StartWriting();
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我将上述代码编写为学习基于策略的设计的一部分.我对上面的代码几乎没有疑问

1 - 此实现看起来是否正确?我的意思是:它真的看起来像一个基于政策的设计吗?

2 - 我现在可以将任何类型的笔钩到作家身上.但是当我拿到没有默认构造函数的笔(仅参数化构造函数)时,我会怎么做?我该如何处理这种情况?

template<class PenType>
class Writer : public PenType …
Run Code Online (Sandbox Code Playgroud)

c++ design-patterns policy-injection policy-based-design

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

测量linux内核中函数的执行时间

我正在使用Linux安全模块挂钩为recv()系统调用添加一些自定义功能.与pristine recv()相比,我想测量此功能的开销.我编写了一个简单的tcp服务器,我运行和没有我的模块.此tcp服务器调用recv()函数'N'次.它通过以下方式测量每个recv所花费的时间:

clock_gettime(before);
recv()
clock_gettime(after);
global_time += after - before.
Run Code Online (Sandbox Code Playgroud)

最后,我使用"global_time/N"打印单个recv()的平均时间.让我们把这次称为"user_space_avg_recv"时间.

在我的模块中,我想放置时间测量函数来计算我的钩子的确切执行时间.我尝试了3种方法.

  1. 我用jiffies如下:

    sj = jiffies;
    my_hook();
    ej = jiffies;
    current->total_oh = ej - sj;
    
    Run Code Online (Sandbox Code Playgroud)

    但我发现sj和ej值之间没有区别.因此total_oh没有变化.

  2. 我使用current_kernel_time(),因为我认为它以纳秒为单位返回时间.但是,再一次,之前和之后没有差别.

  3. 我用了get_cycles.我打印进程退出时的总循环数.但是,当我将总周期值转换为毫秒时,它会比"user_space_avg_recv"值大得多.这没有意义,因为内核中的测量值总是小于从用户空间测量的时间值.这可能意味着我要么使用正确的API进行测量,要么在将值从周期转换为毫秒时出错.

我基本上使用以下公式将周期转换为毫秒:

avg overhead of my hook in milliseconds = 
             (((cycles / 2.99) / 10^6) / N)
Run Code Online (Sandbox Code Playgroud)

2.99因为我的时钟频率是2.99Ghz

一些要点:

  • 我的用户空间程序使用set affinity绑定到单个核心.

  • 我正在使用内核2.6.22.14

  • 为了阻止内核在我的钩子内切换上下文,我使用preempt_disable()和preempt_enable().因此,它不会计算其他内核线程的执行时间.即便如此,由于我的钩子使用了一些I/O,我的线程可能会自动释放控制,或者可能会发生一些可能会增加总周期数的中断.

问题:如何在内核中准确测量函数执行时间?

linux-kernel

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

如何将bootstrap形式的输入与input-group-addons对齐?

我有一个非常简单的Bootstrap 3表单,当我不使用input-group-addons 时,我可以轻松(自动)对齐.

在我的表单中使用它们后,它是不可能对齐的(由于添加了插件,带插件的线条更宽)

<form class="form-horizontal" role="form">

    <div class="form-group">
      <label for="product_name" class="col-sm-2 control-label">Product name</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="product_name" placeholder="Product name">
      </div>
    </div>

    <div class="form-group">
      <label for="product_price" class="col-sm-2 control-label">Price</label>
      <div class="col-sm-4 input-group">
        <span class="input-group-addon">$</span>
        <input type="text" class="form-control bfh-number" id="product_price" placeholder="Price" data-min="0" data-max="9999999">
        <span class="input-group-addon">.00</span>
      </div>
    </div>

    <div class="form-group">
      <label for="product_description" class="col-sm-2 control-label">Description</label>
      <div class="col-sm-6">
        <textarea class="form-control" id="product_description" placeholder="Description" rows="5"></textarea>
      </div>
    </div>

    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" class="btn btn-default">Submit</button>
      </div>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

JsFiddle:http://jsfiddle.net/Yzxy3/

html css alignment twitter-bootstrap

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