当我做一个git diff时,它会显示已添加的行:
+ this line is added
Run Code Online (Sandbox Code Playgroud)
已删除的行:
- this line is removed
Run Code Online (Sandbox Code Playgroud)
但它也显示了许多未修改的行:
this line is not modified
this line is also not modified
Run Code Online (Sandbox Code Playgroud)
这导致实际的git diff看起来像这样:
+ this line is added
this line is not modified
- this line is removed
this line is not modified
Run Code Online (Sandbox Code Playgroud)
我可以要求git只显示已修改的行并忽略所有其他未修改的代码吗?我写了一个方法,它将删除所有在它们前面没有"+"或" - "符号的行,但我相信必须有一个更简单的方法来执行此操作.
在我的git diff中,我只对看到已修改的行感兴趣.
提前致谢.
我有两个问题:
有没有办法查看.docx文件Github?我们已将所有作业上传到Github,但我们无法在浏览器中查看它.如果我们可以.docx在不下载文件的情况下在浏览器中查看这些文件,那就太好了.
如何使用git diff的.docx文件格式?我尝试使用catdoc但它对我不起作用.我想我以前曾git diff在Windows上用过这种.doc格式,但它在Mac上并不适用于我.
非常感谢.
我上周主持了我的Rails应用程序.今天我正在浏览我们的日志文件并注意到很多这样的请求.
I, [2016-03-14T00:42:18.501703 #21223] INFO -- : Started GET "/testproxy.php" for 185.49.14.190 at 2016-03-14 00:42:18 -0400
F, [2016-03-14T00:42:18.510616 #21223] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/testproxy.php"):
Run Code Online (Sandbox Code Playgroud)
有人试图testproxy.php从不同的IP地址前往.有些ip来自波兰,有些来自香港.我被某人袭击了吗?我有什么保护自己的选择.
以下是日志文件中的其他输出:
I, [2016-03-14T03:09:24.945467 #15399] INFO -- : Started GET "/clientaccesspolicy.xml" for 107.22.223.242 at 2016-03-14 03:09:24 -0400
F, [2016-03-14T03:09:24.949328 #15399] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/clientaccesspolicy.xml"):
Run Code Online (Sandbox Code Playgroud)
不同的IP地址:
I, [2016-03-14T16:03:47.793731 #15399] INFO -- : Started GET "/testproxy.php" for 178.216.200.48 at 2016-03-14 16:03:47 -0400
F, [2016-03-14T16:03:47.818519 #15399] FATAL -- …Run Code Online (Sandbox Code Playgroud) 假设我在文件中添加了两行hello.rb.
# this is a comment
puts "hello world"
Run Code Online (Sandbox Code Playgroud)
如果我这样做git diff,它会显示我添加了两行.
我不希望git显示任何Ruby注释的行.我试过用git diff -G <regular expression>,但它对我不起作用.我怎么这样做git diff,它不会显示任何Ruby评论?
我有以下课程:
class Company < ActiveRecord::Base
validates :name, :presence => true
has_many :employees, :dependent => :destroy
end
class Employee < ActiveRecord::Base
validates :first_name, :presence => true
validates :last_name, :presence => true
validates :company, :presence => true
belongs_to :company
end
Run Code Online (Sandbox Code Playgroud)
我正在为Employee课程编写测试,因此我试图创建double供Company所使用Employee。
以下是我的Rspec的代码段
let(:company) { double(Company) }
let(:employee) { Employee.new(:first_name => 'Tom', :last_name => 'Smith', :company => company) }
context 'valid Employee' do
it 'will pass validation' do
expect(employee).to be_valid
end
it 'will have no …Run Code Online (Sandbox Code Playgroud) 在我们的应用程序中,我们从外部服务器获取加密文本 此文本已openssl在php中加密.
当我试图解密我的Ruby代码中的文本时,我收到以下错误消息:
OpenSSL::Cipher::CipherError: wrong final block length
Run Code Online (Sandbox Code Playgroud)
我在Stackoverflow上阅读了几个解决方案,并建议在代码中添加以下行cipher.padding = 0.但添加后padding = 0,我得到了不同的错误:
OpenSSL::Cipher::CipherError: data not multiple of block length
Run Code Online (Sandbox Code Playgroud)
下面是我编写的用于解密代码的粗略脚本.
require 'openssl'
require 'digest/sha1'
require 'base64'
encrypted = "VaZYJzn9QVEQIH4fmtA1Cg=="
key = "my_secret_key"
cipher = OpenSSL::Cipher::Cipher.new("aes-128-ecb")
cipher.decrypt
cipher.padding = 0
cipher.key = key
decrypted = cipher.update(encrypted)
decrypted << cipher.final
puts Base64.decode64(decrypted)
Run Code Online (Sandbox Code Playgroud)
如果我使用加密文本,Ruby那么我可以很容易地解密它.我有问题解密加密的代码php.有什么方法可以使PHP和Ruby之间的加密和解密兼容.
我们有2个Rails应用程序(一个用于前端,另一个用于后端(api)托管在2个不同的服务器上.用户来到我们的前端应用程序并填写订单表单.然后我们将json请求发送到后端并且后端发送确认json响应到前端.后端只能从我们的办公地址访问,并设置为只与我们的前端应用程序通信.
今天我们为我们的前端应用程序购买了EV ssl证书DigiCert,一切正常.但是,由于我们在后端没有ssl证书,这是否意味着我们从前端传递到后端的数据是不加密的?
DigiCert?(有点贵)我已经经历了几个堆栈溢出问题,看起来建议是在两个服务器上安装ssl.这是我第一次尝试在服务器上设置ssl证书,所以只想在我为后端应用购买另一个ssl证书之前仔细检查.
更新
我发现很少有廉价的ssl证书提供,人们对这个更便宜的提供商的建议是什么https://cheapsslsecurity.com.au/
这是我的代码,它给了我 N + 1 查询。
\nclass User < ApplicationRecord\n has_many_attached :resumes, dependent: :destroy\n has_many_attached :cover_letters, dependent: :destroy\nend\n\nclass ResumesController < ApplicationController\n def new\n @user = User.includes(resumes_attachments: :blob).find(params[:user_id])\n end\n\n def create\n @user = User.includes(resumes_attachments: :blob).find(params[:user_id])\n\n if @user.resumes.attach(params[:user][:resume])\n redirect_to new_user_resume_path(@user)\n else\n render :new\n end\n end\nend\nRun Code Online (Sandbox Code Playgroud)\n我已经注释掉了所有内容,以确保那里没有发生任何事情。render :new子弹宝石仅在创建操作失败并被触发时才会抱怨。为了成功创建操作子弹宝石,不会给出任何错误。
但是当我检查服务器日志ActiveStorage::Blob被调用很多次时。我缺少什么?我正在使用 Rails 6。
更新:
\n下面是我的日志。
\n \xe2\x86\xb3 app/controllers/resumes_controller.rb:17:in `create'\n ActiveStorage::Blob Load (0.2ms) SELECT "active_storage_blobs".* FROM "active_storage_blobs" WHERE "active_storage_blobs"."id" = $1 LIMIT $2 [["id", "13e9e539-8c45-473f-b849-9e459646a1a1"], ["LIMIT", 1]]\n \xe2\x86\xb3 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用发送电子邮件,sidekiq但它不起作用。这是我的设置sidekiq方法ActiveJob
宝石文件
gem 'sidekiq'
Run Code Online (Sandbox Code Playgroud)
然后我就跑bundle install。
应用程序.rb
config.active_job.queue_adapter = :sidekiq
config.active_job.queue_name_prefix = Rails.env
Run Code Online (Sandbox Code Playgroud)
用户邮件程序.rb
class UserMailer < ApplicationMailer
def activation_needed_email(user)
@user = user
@url = activate_user_url(@user.activation_token)
mail(to: user.email, subject: 'Welcome to My website')
end
end
Run Code Online (Sandbox Code Playgroud)
用户控制器
def create
...
if @user.save
UserMailer.activation_needed_email(@user).deliver_later # this is were i am sending email.
end
...
end
Run Code Online (Sandbox Code Playgroud)
Rails 服务器日志
[ActiveJob] Enqueued ActionMailer::MailDeliveryJob (Job ID: e61df8eb-c6c1-417a-af59-d55fdc13ec98) to Sidekiq(mailers) with arguments: "UserMailer", "activation_needed_email", "deliver_now", {:args=>[#<GlobalID:0x00007fabff6a3c60 @uri=#<URI::GID gid://jobs-in-nepal/User/83c17355-db86-4ca1-b674-a97fde512592>>]}
Run Code Online (Sandbox Code Playgroud)
根据上面的日志文件 ActiveJob …
我正在使用 Active Storage 来存储比赛得分图像。我的班级看起来像这样
class TournamentMatch < ApplicationRecords
has_many_attached :score_cards
end
Run Code Online (Sandbox Code Playgroud)
我的记分卡控制器看起来像这样
class Public::ScoreCardsController < Public::BaseController
def new
session[:tournament_match_id] = params[:tournament_match_id]
end
def create
tournament_match_id = session[:tournament_match_id]
tournament_id = session[:tournament_id]
session[:tournament_match_id] = nil
session[:tournament_id] = nil
tournament_match = TournamentMatch.find_by(id: tournament_match_id)
if tournament_match.score_cards.attach(params['score_cards'])
flash[:notice] = 'Score card uploaded'
else
flash[:error] = 'Score card upload failed'
end
redirect_to public_results_path(tournament_id: "#{tournament_id}/", anchor: 'results')
end
def view
@tournament_match = TournamentMatch.find_by(id: params[:tournament_match_id])
render layout: "application"
end
end
Run Code Online (Sandbox Code Playgroud)
因此,在我的创建操作中,我通过 id 查找 TournamentMatch,然后将记分卡附加到其上。我每次上传时都使用相同的图像文件。但有时图像会被附加,有时则不会。tournament_match.score_cards.attach(params['score_cards']在控制器中始终返回 true。但如果我找到相同的锦标赛比赛并tournament_match.score_cards.attach(params['score_cards'] …
我正在尝试为我的Rails 2.3应用程序编写一个简单的脚本,但我遇到了一个问题.
当我开始rails console并键入Time.now - 1.month它时给出正确的输出:
>> Time.now - 1.month
=> Mon Dec 07 17:05:50 +0100 2015
Run Code Online (Sandbox Code Playgroud)
当我在文件(script/foo.rb)中使用相同的代码时,我得到错误
undefined method 'month' for 1:Fixnum (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
我也无法require从"lib"目录中获取文件.在Rails 2.3中,"lib"目录已经在里面了$LOAD_PATH.这个问题让我很头疼.希望有人可以帮助我.
以下是我的系统的详细信息:
$ which -a ruby
/usr/bin/ruby
/Users/rakesh/.rvm/rubies/ruby-1.8.7-p374/bin/ruby
Run Code Online (Sandbox Code Playgroud)
同样的脚本在我朋友的机器上工作正常,所以我猜我的电脑出了问题.