我们想要一个名为"Transaction"的模型,它对应于Rails中我们数据库的"事务"表,但这将与现有的ActiveRecord事务功能相冲突.
除了为交易模型提出不同的名称(我不想这样做)之外,还有什么我可以做的来支持这个模型吗?
我正在努力让我们的Rails应用程序使用rserve服务器和rserve-simpler gem 与R交谈.
当我加载我的应用程序时,一切都在本地工作正常,但在Heroku中,我的rails应用程序无法连接到rserve,即使该工作程序已成功启动部署.
app[web.1]: Rserve::Connection::RserveNotStartedError (Can't start Rserve):
Run Code Online (Sandbox Code Playgroud)
以下是我配置的详细信息.
.buildpacks
https://github.com/heroku/heroku-buildpack-ruby.git
http://github.com/virtualstaticvoid/heroku-buildpack-r.git#cedar-14
Run Code Online (Sandbox Code Playgroud)
Procfile
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
rserve: R -f rserve.r --gui-none --no-save
Run Code Online (Sandbox Code Playgroud)
rserve.r
require('Rserve')
# get the port allowed
port <- Sys.getenv('PORT')
# run Rserve in process
run.Rserve(debug = TRUE, port, args = NULL, config.file = "./rserve.conf")
Run Code Online (Sandbox Code Playgroud)
rserve.conf
remote enable
Run Code Online (Sandbox Code Playgroud)
如您所见,rails在一个dynco上运行,而rserver在heroku中的另一个dyno上运行.
我怀疑因为rserve正在使用不同的dyno运行,rails无法使用默认连接参数与rserve通信,但我不确定如何或者甚至可以解决这个问题.任何帮助将不胜感激.
编辑: 来自Dynos上的Heroku:
即使在相同的物理基础设施上,Dynos也可以彼此完全隔离.
这再次强化了我的怀疑,即使用rails连接到rserve运行到不同的dyno是不可能的.
有没有办法解决?
假设我有大约1000多个bookinfo节点的XML.
<results>
<books>
<bookinfo>
<name>1</dbname>
</bookinfo>
<bookinfo>
<name>2</dbname>
</bookinfo>
<bookinfo>
<name>3</dbname>
</bookinfo>
</books>
</results>
Run Code Online (Sandbox Code Playgroud)
我正在使用它来获取每本书的名称:
var books = this.req.responseXML.getElementsByTagName("books")[0].getElementsByTagName("bookinfo")
Run Code Online (Sandbox Code Playgroud)
然后使用for循环对每个书名做一些事情:
var bookName = books[i].getElementsByTagName("name")[0].firstChild.nodeValue;
Run Code Online (Sandbox Code Playgroud)
当书本真的很大时,我发现这真的很慢.不幸的是,没有办法限制结果集,也没有指定不同的返回类型.
有更快的方法吗?
我正在研究一个带有add_record方法的jQuery插件(见下文).如果查看函数定义,有两个$.each循环将值附加到plugin.payload.
现在,一切正常.但是,如果记录或选项真的很大怎么办?$.each()在发出传输呼叫之前,我是否需要关注未完成?
如果是这样,解决这个问题的最佳方法是什么?
plugin.add_record = function (records, options, callback) {
if (typeof (options) == "function") {
callback = options;
options = undefined;
}
if (options) {
$.each(options, function (index, value) {
plugin.payload.append($(value));
});
}
$.each(records, function (index, value) {
plugin.payload.append($(value));
});
transmit('API_AddRecord', plugin.payload, 'db', function (data) {
return typeof (callback) == "function" ? callback(data) : data;
});
}
Run Code Online (Sandbox Code Playgroud) 我在这里有一个基于几何的查询,它嵌套在 $or 中并与 $and 运算符结合使用。
Mongo 不断抛出以下错误:
MongoError: Can't canonicalize query: BadValue geoNear must be top-level expr
Run Code Online (Sandbox Code Playgroud)
我正在使用本机 Mongo 节点驱动程序 vs 1.4.3。我看到这里发布了一个类似的错误。
这是我构建查询错误的情况,还是应该向 Mongo 提交错误?
{
"$or": [
{
"$and": [
{
"startDate": {
"$gt": "2013-12-27T08:00:00.000Z"
}
},
{
"startDate": {
"$lt": "2013-02-08T08:00:00.000Z"
}
},
{
"loc": {
"$near": {
"$geometry": {
"type": "Point",
"coordinates": [
123.3423,
22.2131
]
},
"$maxDistance": 4
}
}
}
]
},
{
"$and": [
{
"startDate": {
"$gt": "2013-12-27T08:00:00.000Z"
} …Run Code Online (Sandbox Code Playgroud) 在Ruby中,如何从父类访问调用类的常量?
Module Foo
class Base
def test()
#how do I access calling class's constants here?
#ex: CallingClass.SOME_CONST
end
end
end
class Bar < Foo::Base
SOME_CONST = 'test'
end
Run Code Online (Sandbox Code Playgroud) 我想将常量转换FOO::BAR为 string "BAR"。
这与constantize所做的相反并且非常相似demodulize,除了我期望一个字符串而不是实际的 Module 引用。
我想我可以让我自己的助手来做到这一点,但我无法获得FOO::BAR.
理想情况下,我想避免使用任何 3rd 方宝石。
例子:
class FOO
BAR = {}
end
# this works
FOO #=> FOO
FOO.name #=> "FOO"
# this doesn't
FOO::BAR #=> {}
FOO::BAR.name #=> NoMethodError: undefined method `name' for {}:Hash
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python的PyYAML创建一个自定义标签,该标签将允许我使用YAML检索环境变量。
import os
import yaml
class EnvTag(yaml.YAMLObject):
yaml_tag = u'!Env'
def __init__(self, env_var):
self.env_var = env_var
def __repr__(self):
return os.environ.get(self.env_var)
settings_file = open('conf/defaults.yaml', 'r')
settings = yaml.load(settings_file)
Run Code Online (Sandbox Code Playgroud)
里面defaults.yaml就是:
example: !ENV foo
Run Code Online (Sandbox Code Playgroud)
我不断得到的错误:
yaml.constructor.ConstructorError:
could not determine a constructor for the tag '!ENV' in
"defaults.yaml", line 1, column 10
Run Code Online (Sandbox Code Playgroud)
我计划也有多个自定义标签(假设我可以使这一标签正常工作)
我有一个CircleCI配置文件,如下所示:
# Customize test commands
test:
override:
- docker run -e VAR1=$VAR! -e VAR2=$VAR2 -e $VAR3-$VAR3 --entrypoint python my_image:latest -m unittest discover -v -s test
Run Code Online (Sandbox Code Playgroud)
如何将docker run命令分解为多行,如:
docker run \
-e VAR1=$VAR! \
-e VAR2=$VAR2 \
-e $VAR3-$VAR3 \
--entrypoint python my_image:latest \
-m unittest discover -v -s test
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用|yaml 的运算符,但是CircleCI无法解析,因为它希望override是一个列表.
# Customize test commands
test:
override: |
docker run \
-e VAR1=$VAR! \
-e VAR2=$VAR2 \
-e $VAR3-$VAR3 \
--entrypoint python my_image:latest \ …Run Code Online (Sandbox Code Playgroud) 我有一个与PHP版本有关的问题.
这是传递给url的原始字符串:
?path=/2013/6/14/1371207330-SBM1_Today\'s Touch Strongsville.xls
Run Code Online (Sandbox Code Playgroud)
在PHP 5.3.21中,当我回显$ _GET ['path']时,它返回(错误):
/2013/6/14/1371207330-SBM1_Today\\\'s Touch Strongsville.xls
Run Code Online (Sandbox Code Playgroud)
在PHP 5.3.15中,它返回正确的版本(正确):
/2013/6/14/1371207330-SBM1_Today\'s Touch Strongsville.xls
Run Code Online (Sandbox Code Playgroud)
我如何解决这个问题,以便更高版本的PHP不添加额外的转义?
对于未来的读者
该错误与PHP的版本无关,而是两个不同的php安装的配置.在我的情况下,我的本地版本有一个关闭magic_quotes的php.ini配置,而客户共享托管服务提供商(HostGator)打开了它.