我一直在努力让Vagrant允许我设置一个Tiny Core Linux映像,并且无法解决以下错误:
Vagrant attempted to execute the capability 'configure_networks'
on the detect guest OS 'linux', but the guest doesn't
support that capability. This capability is required for your
configuration of Vagrant. Please either reconfigure Vagrant to
avoid this capability or fix the issue by creating the capability.
Run Code Online (Sandbox Code Playgroud)
我尝试使用http://docs.vagrantup.com/v2/networking/basic_usage.html上的配置选项,并且到目前为止无法找到config.vm.networks的配置,这避免了在Vagrant中调用configure_networks块.我错过了一个明显的配置,还是Vagrant中的一个错误?
我正在使用 Rails 5.0.1。使用 Rails 控制台,我想弄清楚获取字符串中第一个正则表达式出现的索引的最快方法是什么。所以我尝试了以下方法
2.4.0 :004 > Benchmark.bm do |x|
2.4.0 :005 > x.report { 50000.times { a = 'a@b.c'.index(/\@/) } }
2.4.0 :006?> x.report { 50000.times { a = 'a@b.c'.match(/\@/)[0] } }
2.4.0 :007?> end
user system total real
0.030000 0.000000 0.030000 ( 0.026763)
0.060000 0.000000 0.060000 ( 0.064986)
=> [#<Benchmark::Tms:0x007fe974e13f88 @label="", @real=0.026763000059872866, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.03000000000000025, @total=0.03000000000000025>, #<Benchmark::Tms:0x007fe973c9e9d8 @label="", @real=0.06498600030317903, @cstime=0.0, @cutime=0.0, @stime=0.0, @utime=0.06000000000000005, @total=0.06000000000000005>]
Run Code Online (Sandbox Code Playgroud)
我对如何阅读结果感到困惑。我“认为”它告诉我第一种方法平均需要“0.02”秒,而第二种方法需要“0.06”秒,所以我应该坚持使用“index”。我读得对吗?
我已经有一段时间进行网络抓取,但对 python 来说相对较新,最近将我所有的抓取活动从 ruby 切换到 python,主要是因为scrapy和scrapinghub似乎为大规模生产化抓取提供了更好的支持。
我在抓取电子商务网站时遇到的一个问题是,许多似乎使用“有状态”会话,即除非您发送从先前响应返回的相同 cookie,否则下一个请求可能会被阻止。特别是,许多使用IBM Websphere 的站点都表现出这种行为。
鉴于使用并发异步请求,这成为scrapy 的一个问题。
这些站点中的大多数都需要加载 JS 才能设置初始 cookie,因此我的方法是使用 Selenium(无头 chromedriver)加载初始页面,然后将 cookie 传递给普通的 scrapy 请求。
def __initialise_cookies(self):
# Where self is the spider and driver is the Selenium driver instance
self.session_cookies = self.driver.get_cookies()
Run Code Online (Sandbox Code Playgroud)
当 CONCURRENT_REQUESTS 在 scrapy 配置文件中设置为 1 时,这种方法完全正常。然而,这消除了所有并发性,显然会大大减慢刮擦速度。
我知道scrapy 已经发布了下载器中间件功能,允许在请求中命名cookiejar,然后传递给后续请求。我也读过这篇文章。然而,这似乎并没有解决我的问题 - 我只能假设是因为并发导致 cookiejar 被同时重复使用多次,即使您创建几个不同的 cookiejar 作为起点。
有没有人有关于如何解决这个问题的想法?
理想情况下,我想创建与 CONCURRENT_REQUESTS 设置(例如 16)相同数量的会话 cookiejar,但是我如何处理确保每个 cookiejar 一次最多只使用一次,然后将响应 cookie 传递给下一个请求。
我知道 Twisted 不使用线程,但是为 N 个 cookiejar 中的每一个创建一个信号量并使请求等待直到它未使用后再发送下一个请求是否有意义?
我有一个相对较大的矩阵NxN(N~20,000)和一个Nx1向量,用于识别必须组合在一起的索引.
我想将矩阵的一部分加在一起,原则上可以有不同数量的元素和非相邻元素.我很快写了一个正常工作的双循环,但当然效率很低.分析器将这些循环识别为我的代码中的瓶颈之一.
我试图找到一种智能矢量化方法来解决这个问题.我探索了arrayfun,cellfun和bsxfun函数,并寻找类似问题的解决方案......但我还没有找到最终的解决方案.
这是带有两个for循环的测试代码:
M=rand(10); % test matrix
idxM=[1 2 2 3 4 4 4 1 4 2]; % each element indicates to which group each row/column of M belongs
nT=size(M,1);
sumM=zeros(max(idxM),max(idxM));
for t1=1:nT
for t2=1:nT
sumM(t1,t2) = sum(sum(M(idxM==t1,idxM==t2)));
end
end
Run Code Online (Sandbox Code Playgroud) 我正在使用 Python 一次一行地将一批 CSV 文件加载到 SQL Server 表中。每个文件都包含许多自由文本字段和错误数据,我在尝试插入之前对其进行了修剪和重命名。
一般来说(大约 95% 的时间),代码似乎可以工作,但会出现异常并显示下面描述的错误消息。
我很困惑 a) 我的表中只有四列,并且不明白为什么它会寻找参数 7,并且 b) 文本列被加载到 nvarchar(max) 格式的列中,所以我不会'不要期望数据类型错误。
我检查了源文件以查看哪些行引发了错误,问题行和其他成功加载的行之间似乎没有明显区别。
我已经将过程修剪回仅插入 JobID(作为 bigint)并且它可以正常工作,但是一旦我引入文本字段,它就会导致错误。
我正在使用 Python 3.7.0 并加载到 SQL Server 14.0
import numpy as np
import pyodbc
import os
import glob
import pandas as pd
import csv
import config
import urllib
import shutil
import codecs
path = "C:\\myFilePath"
allFiles = glob.glob(os.path.join(path, "*.csv"))
for file_ in allFiles:
df = pd.concat((pd.read_csv(f, encoding='utf8') for f in allFiles))
cnxn = pyodbc.connect("Driver={ODBC Driver 13 for SQL …Run Code Online (Sandbox Code Playgroud) Ruby 2.7.0-preview1引入了方法引用运算符.:作为实验功能。(更多在这里和这里)。
对于如何使用此新运算符,有一些抽象示例可用:
method = 42.:to_s
=> #<Method: Integer#to_s>
method.receiver
=> 42
method.name
=> :to_s
method.call
=> "42"
Run Code Online (Sandbox Code Playgroud)
和:
method = File.:read
=> #<Method: File.read>
method.call('/Users/foo/.zshrc')
=> "export ZSH=$HOME/.zsh"
Run Code Online (Sandbox Code Playgroud)
这些抽象示例并不代表实际的实现。用实际和实际示例定义的方法引用运算符的目的和用法的英文解释是什么?
我将 Sidekiq 与 Rails 一起使用,返回的并发值似乎是错误的。Sidekiq.options[:concurrency]返回 10 而不是 3,这是我文件中的值config/sidekiq.yml:
:concurrency: 3
staging:
:concurrency: 3
production:
:concurrency: 3
:queues:
- critical
- default
- low
Run Code Online (Sandbox Code Playgroud)
为什么返回错误的值?
我刚刚发现了 Mongoose 的 Populate Virtuals 方法,它将为我当前的项目节省大量时间。不过,我希望进一步扩展它。有没有一种基于多个本地/外键对进行填充的简单方法?这是代码可能是什么样子的示例(注意:这可能不是一个很好的示例,但希望它传达了我的问题的基础)。
var workerSchema = new Schema({
name: String,
locationCode: String,
departmentCode: String
});
var deparmentSchema = new Schema({
locationCode: String, //Note: neither location nor code
code: String, //are unique, but the combination of them are
manager: String,
otherInfoAboutDepartment: String
});
workerSchema.virtual('department', {
ref: "Department",
localField: ["locationCode", "departmentCode"],
foreignField: ["locationCode", "code"]
});
Run Code Online (Sandbox Code Playgroud) 所以我对编码还很陌生,我为自己设定了一个任务,那就是使用 HTML、CSS 和 javaScript 从头开始重新创建我的 WordPress 网站,现在我已经在网上寻找资源以获得正在进行的制作一个的最佳方法响应式导航栏,当然,我在 W3Schools 上遇到过一个例子。
现在我的问题是处理相邻类的最佳方法是什么,我的 CSSLint 认为它是不好的做法(至少这是我要从它那里拿走的)所以我遇到了一个难题是否坚持使用它们并使其与 IE 6 不兼容(我相信)或者只是学习使用更好的标准。
@media screen and (max-width: 600px) {
.cMainNav.responsive {
position: relative;
}
.cMainNav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.cMainNav.responsive a {
float: none;
display: block;
text-align: left;
}
}
Run Code Online (Sandbox Code Playgroud) 我有Boy继承 class 的类Person,并包含 module Bipedal。和Person都有.Bipedal#two_legs
module Bipedal
def two_legs(name)
puts "#{name} has exactly two limbs used for walking."
end
end
class Person
def two_legs(name)
puts "#{name} has two human legs."
end
end
class Boy < Person
include Bipedal
attr_accessor :name
def initialize(name)
@name = name
end
def two_legs
super(@name)
end
end
Run Code Online (Sandbox Code Playgroud)
由于该Bipedal模块包含在 中Boy,Bipedal#two_legs因此优先于Person#two_legs. 当我调用super实例时Boy,模块Bipedal优先于父类Person。 …
ruby ×4
python ×2
benchmarking ×1
bsxfun ×1
css ×1
indexing ×1
inheritance ×1
matlab ×1
matrix ×1
mongoose ×1
populate ×1
ruby-2.7 ×1
scrapinghub ×1
scrapy ×1
sidekiq ×1
sql-server ×1
superclass ×1
vagrant ×1
web-scraping ×1