我可以通过命令找到安装了哪个gem gem list,但它没有告诉我gems的安装位置.
我怎样才能找到宝石的位置,如何在安装宝石之前知道它?
如何unique: true在Rails数据库中为已存在的索引添加约束?
我试图迁移
def change
add_index :editabilities, [:user_id, :list_id], unique: true
end
Run Code Online (Sandbox Code Playgroud)
但是迁移失败并出现这样的错误.
表'editabilities'上的索引名称'index_editabilities_on_user_id_and_list_id'已存在
我正在使用rails4和postgresql.
这是一个类.
module Foo
class Bar
end
end
Run Code Online (Sandbox Code Playgroud)
我希望得到Bar没有的班级名称Foo.
bar = Foo::Bar.new
bar.class.to_s.match('::(.+)$'){ $1 }
Run Code Online (Sandbox Code Playgroud)
我可以通过这段代码得到类名,但我不认为这是获得它的最佳方法.
是否有更好的方法来获取没有命名空间的类的名称?
我想添加一个不同名称的git子模块,如:
git submodule add --name foo git@bitbucket.org:ironsand/cookbook-foo.git
Run Code Online (Sandbox Code Playgroud)
我想创建一个名为的git子模块目录foo,但是使用名称创建存储库cookbook-foo.
我很可能做错了什么,但我不知道出了什么问题.
如何更改git子模块目录的名称?
我安装的一些elisp函数会生成警告:
`flet' is an obsolete macro (as of 24.3); use either `cl-flet' or `cl-letf'.
Run Code Online (Sandbox Code Playgroud)
它是危险的,如果我只是更换所有flet有cl-flet?如果可以更换它们,哪一个更好?
如果更换它没有危险,我会向项目发送拉取请求.
有什么理由他们不改变它吗?
我有两个哈希应该有相同的键,如:
a = {a: 1, b: 2, c: 3}
b = {a: 2, b: 3, c: 4}
Run Code Online (Sandbox Code Playgroud)
我想总结这样的每个值:
if a.keys == b.keys
a.values.zip(b.values).map{|a, b| a+b}
end
Run Code Online (Sandbox Code Playgroud)
但是如果键的顺序不同,则此代码不起作用b = {a: 2, c: 4, b: 3}.
如何在考虑密钥顺序的情况下编写代码?
而不是写作
File.open("foo.txt", "w"){|f| f.write("foo")}
Run Code Online (Sandbox Code Playgroud)
我们可以写出来
File.write("foo.txt", "foo")
Run Code Online (Sandbox Code Playgroud)
有没有更简单的方法来写这个?
File.open("foo.txt", "a"){|f| f.write("foo")}
Run Code Online (Sandbox Code Playgroud) 我getUseMedia在我的应用程序中使用功能.每次我打开Firefox权限弹出窗口都会出现.没有always allow选择.
根据Bugzilla的说法,该功能已经实现Firefox 30- 当前版本是43.
我这样使用getUserMedia:
navigator.getUserMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
Run Code Online (Sandbox Code Playgroud)
这样对吗?为什么我不能选择allow always选项?
有一个Company类has_many QuarterValue,我有一个RSpec测试.
let(:company) { Company.create }
describe 'company has many quarter values' do
before do
10.times { create(:quarter_value, company: company) }
end
it 'has 10 quarter values' do
expect(company.quarter_values.count).to eq(10)
end
end
Run Code Online (Sandbox Code Playgroud)
测试通过.我的问题是,当我放在我无法访问binding.pry的expect匹配器上方时company.quarter_values,返回空数组[].
如何使用?访问测试中的has_many模型对象?RSpecbinding.pry
FactoryGirl.define do
factory :company do
sequence(:code) { |n| n + 1000 }
end
factory :quarter_value do
company
end
end
Run Code Online (Sandbox Code Playgroud) 要对 Python 使用 linting,我配置VS Code如下:
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.pep8Enabled": true,
"python.linting.lintOnTextChange": true,
"python.linting.lintOnSave": true
Run Code Online (Sandbox Code Playgroud)
然后我打开一个*.py文件并添加了一个不必要的空间并保存,然后我得到一个错误:Linter pep8 is not installed.
但我已经安装了pep8. 通过使用 VS Code 控制台,我可以找到pep8.
/usr/bin/python -m pip install pep8
loading ~/.zshrc_osx
ironsand@macbook ~ % /usr/bin/python -m pip install pep8
/usr/bin/python: No module named pip
ironsand@macbook ~ % which python
/usr/bin/python
ironsand@macbook ~ % which pep8
/usr/local/bin/pep8
ironsand@macbook ~ % pep8 --version
1.7.0
ironsand@macbook ~ % …Run Code Online (Sandbox Code Playgroud) ruby ×4
emacs ×1
factory-bot ×1
firefox ×1
git ×1
hash ×1
html5 ×1
javascript ×1
namespaces ×1
postgresql ×1
python ×1
rspec ×1
rubygems ×1