我创建了一个名为'6796'的分支,然后我将其推送到远程,在另一台机器上检查,进行其他编辑,推送,然后将其与主设备合并,并将其删除 - 本地和远程(git push :6796) - 另一个机.现在,当我跑git pull:
fatal: Couldn't find remote ref refs/heads/6796
user@host:~/path/to/repo$ fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)
但git pull origin master工作正常.在我看来,有一些6796参考挂断...如何解决这个问题?
最近我发现tap可以用来"运用"为新变量赋值; 例如,用于创建和填充数组,如下所示:
array = [].tap { |ary| ary << 5 if something }
Run Code Online (Sandbox Code Playgroud)
此代码将推5入array,如果something是truthy; 否则,array将保持空白.
但我不明白为什么执行这段代码后:
array = [].tap { |ary| ary += [5] if something }
Run Code Online (Sandbox Code Playgroud)
array仍然是空的.谁能帮我?
在Ruby中这种类似Haskell的理解实现中,我从未在Ruby中看到过一些代码:
class Array
def +@
# implementation
end
def -@
# implementation
end
end
Run Code Online (Sandbox Code Playgroud)
做什么def +@和def -@意味着什么?哪里可以找到关于他们的(半)官方信息?
在bash上,您可以set -e在脚本内部使用以便在出错时退出:
set -e
cd unexisting-folder
echo "this line will not be printed"
Run Code Online (Sandbox Code Playgroud)
但是在鱼壳set -e上用来擦除变量:
set FOO bar
set -e FOO
echo {$FOO} # prints newline
Run Code Online (Sandbox Code Playgroud)
Bash set -eon Fish 相当于什么?
我无法less在psql中设置为寻呼机.
这是我的环境:
~/.psqlrc 内容:
# \setenv PAGER less
\x auto
\timing
\set VERBOSITY verbose
\pset null 'NULL'
\pset pager on
\set HISTSIZE
\set PROMPT1 '(%n@%M:%>) [%/] > '
\set PROMPT2 '%[%033[8m%](%n@%M:%>) [%/] >[%033[0m%]%'
Run Code Online (Sandbox Code Playgroud)
env | grep PAGER:
PAGER=less
Run Code Online (Sandbox Code Playgroud)
无论如何,当\dSpaceTabTaby我得到数字时,我得到:
table another_table
table another_table
...
--More--
Run Code Online (Sandbox Code Playgroud) 我有一个Rails应用程序,我在其中使用delayed_job.我想检测一下我是否处于delayed_job进程中; 就像是
if in_delayed_job?
# do something only if it is a delayed_job process...
else
# do something only if it is not a delayed_job process...
end
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何.这就是我现在使用的:
IN_DELAYED_JOB = begin
basename = File.basename $0
arguments = $*
rake_args_regex = /\Ajobs:/
( basename == 'delayed_job' ) ||
( basename == 'rake' && arguments.find{ |v| v =~ rake_args_regex } )
end
Run Code Online (Sandbox Code Playgroud)
另一种解决方案是,正如@MrDanA所说:
$ DELAYED_JOB=true script/delayed_job start
# And in the app:
IN_DELAYED_JOB = ENV['DELAYED_JOB'].present?
Run Code Online (Sandbox Code Playgroud)
但他们是IMHO弱的解决方案.有谁能建议更好的解决方案?
我正在接近Docker。我创建了一个图像 debootstraping Debian Jessie,我想将该contrib部分添加到 APT 源文件中。
/etc/apt/sources.list 内容是:
$ docker run some/image cat /etc/apt/sources.list
deb http://debian.fastweb.it/debian jessie main
deb http://debian.fastweb.it/debian jessie-updates main
deb http://security.debian.org/ jessie/updates main
Run Code Online (Sandbox Code Playgroud)
我希望他们是:
deb http://debian.fastweb.it/debian jessie main contrib
deb http://debian.fastweb.it/debian jessie-updates main contrib
deb http://security.debian.org/ jessie/updates main contrib
Run Code Online (Sandbox Code Playgroud)
所以我运行了这个命令:
docker run some/image sed -i 's/main/main contrib/g' /etc/apt/sources.list
Run Code Online (Sandbox Code Playgroud)
退出没有错误; 但它不会更新/etc/apt/sources.list内容:
$ docker run some/image cat /etc/apt/sources.list
deb http://debian.fastweb.it/debian jessie main
deb http://debian.fastweb.it/debian jessie-updates main
deb http://security.debian.org/ jessie/updates main
Run Code Online (Sandbox Code Playgroud) 我正在编写一个pgplsql函数,其中我有一个var可以NULL或已经定价的变量.在稍后的查询中我做:
SELECT * FROM table WHERE column = var
Run Code Online (Sandbox Code Playgroud)
如果是NULL var,则变为
SELECT * FROM table WHERE column = NULL
Run Code Online (Sandbox Code Playgroud)
因此,查询失败并返回NULL,因为正如PostgreSQL文档所述,
空值表示未知值,并且不知道两个未知值是否相等
我用CASE声明解决了这个问题:
SELECT * FROM table WHERE
( CASE WHEN var IS NULL THEN column IS NULL ELSE column = var END ) = TRUE
Run Code Online (Sandbox Code Playgroud)
但我不确定这是解决问题的最佳方法......你有什么好的选择吗?
我正在为 Rails 3 编写一个模板(您可以在此处找到它),但我在使用以下几行时遇到了问题:
# 8. config/database.yml modifications
if yes?("Do you want to set the database host to '/var/run/postgresql'?")
inject_into_file "config/database.yml", " host: /var/run/postgresql\n", :after => "development:\n"
# FIXME these two won't work :(((( why????
# inject_into_file "config/database.yml", " host: /var/run/postgresql\n", :after => "production:\n"
# inject_into_file "config/database.yml", " host: /var/run/postgresql\n", :after => "test:\n"
# Not finding other solutions, I rewrite the two blocks above with two seds
run %q(sed -i '/test:/a\ \ host: /var/run/postgresql' config/database.yml)
run %q(sed -i …Run Code Online (Sandbox Code Playgroud) 我想添加--group-directories-first到ls命令。如果~/.config/fish/config.fish我可以定义这样的别名:
alias ls "ls --group-directories-first"
Run Code Online (Sandbox Code Playgroud)
但它会覆盖鱼壳的ls函数定义:
function ls --description 'List contents of directory'
set -l param --color=auto
if isatty 1
set param $param --indicator-style=classify
end
command ls $param $argv
end
Run Code Online (Sandbox Code Playgroud)
我可以重新定义ls函数以添加所需的参数:
function ls --description 'List contents of directory'
set -l param --color=auto --group-directories-first
if isatty 1
set param $param --indicator-style=classify
end
command ls $param $argv
end
Run Code Online (Sandbox Code Playgroud)
但是我不喜欢这种解决方案:我想要的是重新定义ls以便ls使用参数调用前一个函数。有办法做到吗?