我一直在编辑.bashrc文件和其他初始化文件,似乎我留下了一些代码片段或两个在提示符处导致一些错误的代码片段(例如文件丢失),但我找不到它们.
如何调试提示以找出我不小心入侵的init脚本?
今天我看到一个bash脚本使用冒号来表示评论.使用冒号和哈希标记有什么区别?
: This is a comment.
# This is also a comment.
Run Code Online (Sandbox Code Playgroud)
首先,我知道你不能使用冒号作为结尾评论:
cd somedir : This won't work as a comment.
Run Code Online (Sandbox Code Playgroud)
但上述例子有效的事实让我对如何:评估感到困惑.
我正在尝试为模块功能创建私有帮助器方法无济于事.我觉得我有一些非常简单的东西.
使用更易理解的用例更新示例:
module FancyScorer
module_function
def score(ary)
scores = []
ary.each_slice(2).with_index do |slice, i|
scores <<
case i % 2
when 0
score_eventh(ary)
else
score_oddth(ary)
end
end
scores.inject(:+)
end
private
def score_eventh(ary)
ary.inject(:+) / (ary.size - 1)
end
def score_oddth(ary)
ary.inject(:*) / (ary.size - 1)
end
end
FancyScorer.score([1,2,3,4])
# => `block in score_curiously': undefined method `score_eventh'
# for FancyScorer:Module (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
注意:私有方法应保持私有.
这里的使用情况:有一些含有各种评分技术的几个模块,例如FancyScorer,SimpleScorer,ComplexScorer.这些函数是独立测试的,然后用于score为不同的类创建方法.例如:
class A
...
def score
FancyScorer.score(metrics) + 2*SimpleScorer.score(metrics)
end
end …Run Code Online (Sandbox Code Playgroud) 如何直接将模板分配给Vue类组件?在下面的示例中,我可以将子组件渲染为节点,但从不渲染模板.我试图给模板分配许多不同的方法来渲染它,但似乎没有任何工作:
<template>
<div>
<p>This should render one, two, three below twice.</p>
<div v-for="item in items" :key="item">
{{ item }}
<Subcomponent :item="item" />
</div>
</div>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
@Component({ template:`<span>{{item}}</span>` })
class Subcomponent extends Vue {
template = `<span>{{ item }}</span>`
@Prop({required: true})
item: string
}
@Component({ components: { Subcomponent } })
export default class Test extends Vue {
items = ['one', 'two', 'three']
}
</script>
Run Code Online (Sandbox Code Playgroud)
注意如果我直接使用Vue.component,我也会遇到同样的问题:
Vue.component('Subcomponent', {
props: ['item'],
template: '<span>{{item}}</span>' …Run Code Online (Sandbox Code Playgroud) 在标准盒子上,我通常会进行如下设置:
/timestamp-1/
/public/ (Symlink to /timestamp-1/)
Run Code Online (Sandbox Code Playgroud)
然后,我将新站点上传为/timestamp-2/,然后完成更新/public/符号链接以指向/timestamp-2/。
使用S3静态站点可以实现与此类似的功能吗?
现在,我已经在Cloudflare上成功托管了一个指向没有问题的存储桶的域。
我曾考虑过重命名存储桶以实现此目的,但事实证明,这样做并非不可能。
此处的目标是减少将更新换出到站点所需的时间。
我部署相同的应用程序,以两种不同的环境app-web和app-worker。这些环境的配置略有不同(例如,它们运行不同的进程),因此.ebextensions每种环境都将需要一些不同的配置。有没有一种方法可以指定仅应在特定环境下运行特定配置文件?
这是仅需要为工作环境设置的配置文件:
packages:
yum:
monit: []
files:
"/etc/monit.d/resque_worker":
mode: "000644"
owner: root
group: root
content: |
check process resque_worker_QUEUE
with pidfile /var/app/resque_worker_QUEUE.pid
start program = "/bin/sh -l -c 'cd /var/app/current; nohup rake environment resque:work QUEUE=* VERBOSE=1 PIDFILE=/var/app/resque_worker_QUEUE.pid >> log/resque_worker_QUEUE.log 2>&1'" as uid webapp and gid webapp
stop program = "/bin/sh -c 'cd /var/app/current && kill -9 $(cat tmp/pids/resque_worker_QUEUE.pid) && rm -f /var/app/resque_worker_QUEUE.pid; exit 0;'"
if totalmem is greater than 300 MB for 10 cycles …Run Code Online (Sandbox Code Playgroud) Ruby经典地支持以下文字:
%q[quack quack] #=> "quack quack"
%r[quack quack] #=> /quack quack/
%w[quack quack] #=> ["quack", "quack"]
%x[echo quack quack] #=> "quack quack\n"
Run Code Online (Sandbox Code Playgroud)
我对它们起源的理解如下:
%q[]适用于q uotes%r[]是- [R egex%w[]是为了w ords%x[]是电子X ecuteRuby 2.0引入了%i符号:
%i[quack quack] #=> [:quack, :quack]
Run Code Online (Sandbox Code Playgroud)
为什么i?
在新数据库上运行迁移会导致以下错误.
>> rake db:drop; rake db:create:all; rake db:migrate
1 activity-image-additions-!?
== CreateSomething: migrating ================================================
-- create_table(:somethings)
-> 0.0042s
== CreateSomething: migrated (0.0043s) =======================================
rake aborted!
An error has occurred, this and all later migrations canceled:
PG::UndefinedColumn: ERROR: column "id" does not exist
LINE 1: ...O "schema_migrations" ("version") VALUES ($1) RETURNING "id"
^
: INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "id
Run Code Online (Sandbox Code Playgroud)
生成的SQL查询不应包括,RETURNING "id"因为schema_migrations表没有id.
如果我在失败后尝试迁移数据库,它会成功:
>> rake db:migrate
== CreateSomething: migrating ================================================
-- create_table(:somethings)
-> 0.0041s
== CreateSomething: migrated …Run Code Online (Sandbox Code Playgroud) 我希望向 Postgres 数据库发送多个读取查询,以减少需要前往令人痛苦的远程数据库的次数。有什么东西libpq支持这种行为吗?
在我的过滤器参数初始化程序中,我将过滤掉所有与密码相关的参数:
# config/initializers/filter_parameter_logging.rb
Rails.application.config.filter_parameters += [:password, :password_confirmation]
Run Code Online (Sandbox Code Playgroud)
但是过滤掉的参数比我预期的要多.它看起来像从日志中过滤的名称中包含"password"的任何内容.
{"password_invite_form"=>"[FILTERED]"}
Run Code Online (Sandbox Code Playgroud)
有没有办法阻止过滤参数的模式匹配并匹配我设置的精确参数?
ruby ×4
bash ×2
amazon-s3 ×1
debugging ×1
javascript ×1
linux ×1
module ×1
postgresql ×1
rake ×1
syntax ×1
typescript ×1
vue.js ×1