我想重命名一个在 Emacs 中绑定当前缓冲区的文件。
我从这篇文章中找到了以下 elisp: 如何在 Emacs 中重命名打开的文件?
;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)
(progn
(rename-file name new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil))))))
Run Code Online (Sandbox Code Playgroud)
它工作正常,但如果可能的话,我想将当前文件名设置为默认值。我会怎么写这个?
我通常不需要ri和rdoc,所以我这样写~/.gemrc.
install: --no-ri --no-rdoc
update: --no-ri --no-rdoc
Run Code Online (Sandbox Code Playgroud)
我有空的时候想安装它们.之后如何为已安装的gem安装ri和rdoc文件?
我想通过 ssh 登录远程服务器时更改颜色。
这个问题就解决了这个问题。
当我 ssh 到特定服务器时,如何使苹果终端窗口自动更改配色方案
但上面的解决方案有一点问题。
所以我想在打开新的终端选项卡时“重置”背景颜色。我该怎么做?
我一直在尝试用RSpec测试OmniAuth,但是它没有用。
在 spec_helper.rb
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:twitter, {:uid => '12345'})
Run Code Online (Sandbox Code Playgroud)
和在 spec/requests/static_pages_spec.rb
describe "for signed-in users" do
before do
visit "auth/twitter"
end
it { should have_content("Log out") }
end
Run Code Online (Sandbox Code Playgroud)
而且我得到以下错误。
Failure/Error: visit "auth/twitter"
ActionView::Template::Error:
Real HTTP connections are disabled. Unregistered request:
Run Code Online (Sandbox Code Playgroud)
根据正式文件的要求,auth/twitter应重定向到auth/twitter/callback。为什么尝试建立HTTP连接?
我已经阅读了以下网页和问题,但无法找到测试失败的原因。
http://blog.zerosum.org/2011/03/19/easy-rails-outh-integration-testing.html https://github.com/intridea/omniauth/wiki/Integration-Testing omniauth-facebook并使用rspec http://blog.plataformatec.com.br/2010/12/acceptance-tests-for-omniauth/
我有一个Company模型有很多Disclosures. 将Disclosure有一个名为列title,pdf和pdf_sha256。
class Company < ActiveRecord::Base
has_many :disclosures
end
class Disclosure < ActiveRecord::Base
belongs_to :company
end
Run Code Online (Sandbox Code Playgroud)
我想让它独特的pdf_sha256,如果pdf_sha256就是nil应该被视为是唯一的。
如果是Array,我会这样写。
companies_with_sha256 = company.disclosures.where.not(pdf_sha256: nil).group_by(&:pdf_sha256).map do |key,values|
values.max_by{|v| v.title.length}
end
companies_without_sha256 = company.disclosures.where(pdf_sha256: nil)
companies = companies_with_sha256 + companeis_without_sha256
Run Code Online (Sandbox Code Playgroud)
如何使用 ActiveRecord 查询获得相同的结果?
我想dotenv在纯红宝石环境中使用。我的意思是我没有使用Rails。
github指令说有两种加载变量的方法。
require 'dotenv/load'
# or
require 'dotenv'
Dotenv.load
Run Code Online (Sandbox Code Playgroud)
在我的环境中,后一种方法可行,但是`require'dotenv / load'会引发以下错误:
LoadError: cannot load such file -- dotenv/load
Run Code Online (Sandbox Code Playgroud)
Dotenv.load如果以前的方法不起作用,我会使用,但我想知道错误的原因。
我正在使用ruby 2.3.3p222和dotenv (2.1.1)。我究竟做错了什么?
我正在使用bundle exec pry`load'myapp.rb'。加载脚本时出现错误。
我想Times在Unity中使用函数,通过这个站点我使用这个脚本.
public static class IntExtensions
{
public static void Times(this int i, Action<int> func)
{
for(int j = 0; j < i; j++)
{
func(j);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但它会导致错误Assets/Resources/Scripts/Board.cs(27,40): error CS0246: The type or namespace name动作1' could not be found. Are you missing a using directive or an assembly reference?.
Action在Unity C#中看起来没有.
有没有办法在Unity中使用该功能?如果我想在整个Unity项目中使用,我应该把文件放在哪里?
def track_for stat
# This is a hash with 2 elements of proc
{
symbol: -> { send(stat) },
array: -> { send(stat[0], stat[1]) }
}.freeze[stat.class.name.underscore.to_sym].call
end
Run Code Online (Sandbox Code Playgroud)
Frozen [stat.class.name.underscore.to_sym] .call,我对这段代码一无所知。里面的代码有什么功能[],为什么要使用callmethod?谁能帮助我?非常感谢。
我正在使用bootstrap-sass (3.3.1.0)我的Rails项目.
我怎么知道twitter bootstrap本身的版本?
我发现了这个问题,但Rails环境没有答案.
$ bundle exec gem which bootstrap-sass
/Users/ironsand/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bootstrap-sass-3.3.1.0/lib/bootstrap-sass.rb
$ cd /Users/ironsand/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bootstrap-sass-3.3.1.0/
$ find . -name "*.css"
$ find . -name "_bootstrap.scss"
./assets/stylesheets/_bootstrap.scss
Run Code Online (Sandbox Code Playgroud)
所以我找不到bootstrap.css哪个版本号.
在RSpec我可以存根这样的方法:
allow(company).to receive(:foo){300}
Run Code Online (Sandbox Code Playgroud)
我怎样才能存根一个方法ActiveSupport::TestCase?
我有一个这样的测试。
class CompanyTest < ActiveSupport::TestCase
test 'foobar' do
company = companies(:base)
#company.stubs(:foo).returns(300)
assert_nil(company.calculate_bar)
end
end
Run Code Online (Sandbox Code Playgroud)