Firebug表示(new Array(N))
为包含N
undefined
s 的数组.我最近遇到了一个场景,它表明一个大小的数组,其中包含所有undefined
值,与新构造的大小数组不同.我想了解其中的差异.
假设您要生成0到1000之间的随机整数列表.
function kilorange() {
return Math.floor(Math.random() * (1001));
}
no_random_numbers = (new Array(6)).map(kilorange);
my_random_numbers = [undefined, undefined, undefined,
undefined, undefined, undefined].map(kilorange);
Run Code Online (Sandbox Code Playgroud)
我本来期望no_random_numbers
并且my_random_numbers
相同,但他们不是.no_random_numbers
是另一个undefined
s 数组,而是my_random_numbers
一个包含六个随机整数的数组.此外,在抛出一个console.count
语句之后kilorange
,我了解到我的函数永远不会被使用Array构造函数创建的数组调用.
有什么区别,为什么map
(并且可能是其他可迭代的方法)不对上述数组进行相同处理?
好吧,所以我有这个原型对象Stage,除了这个递归调用之外,它的每个部分都有效.
Stage.prototype.start = function(key) {
//var maxScrollLeft = document.getElementById("content").scrollWidth;
$content.scrollLeft($content.scrollLeft() + this.initspeed);
if(key < this.maxScrollLeft || key > 0) {
setTimeout(function() {
this.start(key+2);
},1);
}else{
console.log("stop");
}
}
Run Code Online (Sandbox Code Playgroud)
我试图使用this.start();在这个if语句中调用Stage.prototype.start.但是我总觉得
Uncaught TypeError: Object [object global] has no method 'start'
我觉得它与匿名函数中的调用有关,关于如何解决这个问题的任何想法?
我在想binascii是我正在寻找的模块,但我似乎无法得到我正在寻找的确切结果.
这就是我想要做的.我想转换:
>>> s = '356a192b7913b04c54574d18c28d46e6395428ab'
>>> print len(s)
40
Run Code Online (Sandbox Code Playgroud)
至
>>> hs = '\x35\x6a\x19\x2b\x79\x13\xb0\x4c\x54\x57\x4d\x18\xc2\x8d\x46\xe6\x39\x54\x28\xab'
>>> print len(hs)
20
Run Code Online (Sandbox Code Playgroud)
任何Pythonist都知道这样做很酷(或者,坦率地说,功能性)吗?
我在我的magento自定义模块中使用session .Below是我的代码
$session = Mage::getSingleton("core/session", array("name"=>"frontend"));
$session->setData("day_filter", 'weeks');
$session->setData("days", '5');
$session->setData("next_delivery_date", '2012-05-12');
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,但现在我想取消或破坏所有的价值?能否请您解决如何解除所有设定值的问题?
我今天发现,除了对象和原语之外,PHP还有资源.该文档指出,默认情况下,php按值传递名称.但我们知道在PHP 5中,对象是由句柄引用的,因此当句柄按值传递时,您可以将句柄视为引用本身,从而避免了问题.
但资源呢?它们是否像对象一样,只是将句柄视为引用本身,还是它们实际上是在传递时被复制的值?
例如:
/**
* Close the ftp connection and throw an exception.
*
* @hack Because php doesn't have a `finally` statement,
* we workaround it to make sure the ftp connection is closed.
* @param resource $conn FTP Buffer
* @param Exception $e
*/
function ftpCloseWithException($conn, $e) {
ftp_close($conn); // <-- Is this the same FTP Buffer resource or a new one?
throw $e;
}
/**
* Copy the …
Run Code Online (Sandbox Code Playgroud) 无意中创建了一个分支.我想删除它.事实上,我认为我上周删除了它,并且它没有出现在bitbucket的搜索中,所以我倾向于认为问题只在我的本地回购中.为什么分支仍然出现在我的本地仓库中?
$ git branch -d ebc_193_157_154_order_creation_xsd_validation_and_refactored_code
error: branch 'ebc_193_157_154_order_creation_xsd_validation_and_refactored_code' not found.
$ git push bitbucket :ebc_193_157_154_order_creation_xsd_validation_and_refactored_code
error: unable to delete 'ebc_193_157_154_order_creation_xsd_validation_and_refactored_code': remote ref does not exist
error: failed to push some refs to 'bitbucket.org:trueaction/eb2c'
Run Code Online (Sandbox Code Playgroud)
它仍然是:
$ git branch -r | grep ebc_193
bitbucket/ebc_193_157_154_order_creation_xsd_validation_and_refactored_code
$ git branch -a | grep ebc_193
remotes/bitbucket/ebc_193_157_154_order_creation_xsd_validation_and_refactored_code
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能摆脱它?
据我所知,[[
并且[
可以预期其行为大致相同,考虑到一些额外的功能[[
.但最近我注意到bash如何处理八进制扩展的差异:
$ b=010; echo $((b))
8
$ [[ $b -eq 8 ]]; echo $?
0
Run Code Online (Sandbox Code Playgroud)
但
$ [ $b -eq 8 ]; echo $?
1
$ test $b -eq 8; echo $?
1
$ [ $b -eq 10 ]; echo $?
0
Run Code Online (Sandbox Code Playgroud)
为什么后一个表达式会降低自动八进制转换?-eq
根据help test
Bash和Bash参考手册中的"算术" 表达式,并且根据参考手册的下一部分,具有前导零的常量可以被视为八进制.
POSIX sh 在这个问题上有点不太清楚:尽管POSIX算术表达式仍然将前导零整数扩展到它们的八进制值,但它将-eq
表达式test
称为代数而不是算术.
是否有任何文件或证据表明bash 故意区分[[
和[
进行八进制扩展,或者它只是一个偶然的特征?
我正在尝试使用python进行匹配.
我有一个字符串列表(len~3000)和一个文件,我想检查文件中的每一行是否至少有一个列表中的字符串.
最直接的方法是逐个检查,但需要时间(不过很长时间).
有没有办法可以更快地搜索?
例如:
list = ["aq", "bs", "ce"]
if the line is "aqwerqwerqwer" -> true (since has "aq" in it)
if the line is "qweqweqwe" -> false (has none of "aq", "bs" or "ce")
Run Code Online (Sandbox Code Playgroud) 尝试使用XCode版本4.4.1(4F1003)在MountainLion上构建mod_auth_openid,我收到有关缺少'cc'命令的投诉,如下所示:
/usr/share/apr-1/build-1/libtool --silent --mode=link /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -o mod_auth_openid.la -rpath /usr/libexec/apache2 -module -avoid-version libmodauthopenid.la -I/usr/include/apache2 -I/usr/include/apr-1 -I/usr/local/include -L/usr/local/lib -lopkele -lcurl -lexpat -ltidy -lssl -lcrypto -lz -L/usr/lib -lpcre -lcurl
/usr/share/apr-1/build-1/libtool: line 4574: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
apxs:Error: Command failed with rc=8323072
Run Code Online (Sandbox Code Playgroud)
该怎么办?
当以前版本的 Docker 中的构建失败时,我可以依靠如下输出:
---> 8f9941c285e2
Removing intermediate container 9a543227b6b8
Step 6/21 : RUN adduser -s /bin/sh -h /home/user -D user && mkdir -p /whl && chown -R user:user /srv /whl
---> Running in 93a90935664d
---> 7f700d063b68
Removing intermediate container 93a90935664d
Run Code Online (Sandbox Code Playgroud)
如果该步骤失败,中间图像7f700d063b68
仍然存在。我可以docker run
尝试弄清楚发生了什么。
但现在,使用 docker client 20.10.2 我只能得到以下输出:
=> [dev 1/3] COPY --from=build /whl /whl
.1s
=> [dev 2/3] COPY --chown=user:user . .
.9s
=> ERROR [dev 3/3] RUN python3 -m pip install --find-links /whl -e ".[bpython,test]" …
Run Code Online (Sandbox Code Playgroud)