我已经.thor按照我喜欢的方式创建了一个用于设置新ruby项目的脚本.我正在使用Thor :: Actions directory命令完全从模板目录结构构建应用程序,而不是使用heredocs内联定义它们.脚本目录看起来像这样:
rubynu.thor
template/
bin/
lib/
%app_name%.rb.tt
%app_name%
README.markdown
.gitignore
...
Run Code Online (Sandbox Code Playgroud)
这非常有用,让我可以随着口味的变化轻松地想象和更改模板的各个部分.
但是,一旦.thor文件系统安装使用,我无法找到一个很好的方法来找到模板目录thor install rubynu.thor.安装将.thor文件的副本~/.thor粘贴到但忽略template/目录,因此不再找到模板.
我不想硬编码source_root路径或手动复制模板目录~/.thor.是否内置了一些内容来处理安装模板和.thor文件?如果它们在安装时可以打包在一起会很棒.
如果没有,最好的解决方法是什么?当然,在某处使用模板文件的系统安装了thor任务.你过得怎么样?我想我可以绕过thor install并提供这个作为一个宝石(虽然这看起来有点矫枉过正),或咬住子弹并将所有模板定义内联在一个巨大的.thor文件中(以后对结构进行更改不太令人愉快).
作为参考,这是.thor我正在使用的简单文件:
class Rubynu < Thor::Group
include Thor::Actions
argument :app_name
def self.source_root
File.dirname(__FILE__)
end
def apply_directory_template
directory 'template', app_name
end
end
Run Code Online (Sandbox Code Playgroud)
谢谢!
tl; dr版本:Berkshelf是否能够解决基于Git的cookbook中的递归依赖性,如果是 - 如何?
我尝试用Berkshelf管理我的Chef cookbook依赖项.这些食谱都存储在内部的Git存储库中.依赖关系如下:
env_dockerhub_dev
>>depends on>> app_dockerhub
>>depends on>> app_docker
Run Code Online (Sandbox Code Playgroud)
我项目中的主要Berksfile如下所示:
source "https://supermarket.chef.io"
cookbook "env_dockerhub_dev", git: "git@URL_TO_GIT_SERVER/chef_env_dockerhub_dev.git"
Run Code Online (Sandbox Code Playgroud)
这env_dockerhub_dev本食谱有metadata.rb这样的:
name 'env_dockerhub_dev'
...
depends 'app_dockerhub'
depends 'base_ubuntu'
Run Code Online (Sandbox Code Playgroud)
和Berksfile这样:
source "https://supermarket.chef.io"
cookbook "app_dockerhub", git: "git@URL_TO_GIT_SERVER/chef_app_dockerhub.git"
cookbook "base_ubuntu", git: "git@URL_TO_GIT_SERVER/chef_base_ubuntu.git"
Run Code Online (Sandbox Code Playgroud)
当我现在运行时,berks install我收到以下错误消息:
Resolving cookbook dependencies...
Fetching 'env_dockerhub_dev' from git@URL_TO_GIT_SERVER/chef_env_dockerhub_dev.git (at master)
Fetching cookbook index from https://supermarket.chef.io...
Unable to satisfy constraints on package app_dockerhub, which does not exist, due to solution constraint (env_dockerhub_dev …Run Code Online (Sandbox Code Playgroud) 在阅读 Spring 框架的文档时,我偶然发现了在工厂方法中传递 Bean 依赖关系的两种不同风格。第一个是这样的(直接使用依赖的工厂方法):
@Configuration
public class MessagingConfiguration {
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
connectionFactory.setUsername("guest");
connectionFactory.setPassword("guest");
return connectionFactory;
}
@Bean
public RabbitTemplate rabbitTemplate() {
return new RabbitTemplate(connectionFactory());
}
}
Run Code Online (Sandbox Code Playgroud)
第二个看起来像这样(将依赖项作为参数注入工厂方法中):
@Configuration
public class MessagingConfiguration {
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
connectionFactory.setUsername("guest");
connectionFactory.setPassword("guest");
return connectionFactory;
}
@Bean
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
return new RabbitTemplate(connectionFactory);
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道这两种解决方案的优点和缺点是什么,哪一种更可取?
我正在运行使用Java实现的Spark作业spark-submit.我想传递参数给这项工作-如time-start与time-end参数参数化星火应用.
我试过的是使用
--conf key=value
Run Code Online (Sandbox Code Playgroud)
spark-submit脚本的选项,但是当我尝试在我的Spark作业中读取参数时
sparkContext.getConf().get("key")
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
Exception in thread "main" java.util.NoSuchElementException: key
Run Code Online (Sandbox Code Playgroud)
此外,当我使用时,sparkContext.getConf().toDebugString()我没有在输出中看到我的价值.
进一步注意因为我想通过Spark REST服务提交我的Spark Job,所以我不能使用OS环境变量等.
有没有可能实现这个?
我正在尝试使用 aConverter来指定 DTO 中的简单字符串字段到作为TypedString另一个复杂对象一部分的 -Object的映射。问题是,这TypedString是多个实现的接口。如果我使用特定的实现,这样的转换器就可以工作,但如果我在运行时使用泛型来定义类型(见下文),则不能工作。在这种情况下,当我调用modelmapper.map().
这不适合我,因为我必须为每个实现编写转换器。
是否可以使用泛型在运行时定义目标类型?
PS:电流转换器通过反射创建一个实例,它有效!
谢谢。
此代码有效
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper;
import org.modelmapper.spi.MappingContext;
public class MyModelMapper extends ModelMapper {
public MyModelMapper() {
super();
Converter<?, ?> converter = new Converter<String, ParticularDestType>() {
@Override
public SupplierId convert(MappingContext<String, ParticularDestType> context) {
return (ParticularDestType) TypedStringConverter.createNewInstanceFromValue(context
.getSource(), ParticularDestType.class);
}
};
addConverter(converter);
}
}
@AllArgsConstructor
public class ParticularDestType implements TypedString {
private String value;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将其添加到MyModelMapper(即addConverter(new ModelMapperTypedStringConverter<ParticularDestType>()))中,这将不起作用!!!
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext; …Run Code Online (Sandbox Code Playgroud) 我想安装一个带有go install. 所以我已经下载了源代码
go get -v github.com/spf13/cobra/cobra\nRun Code Online (Sandbox Code Playgroud)\n\n这给了我
\n\n $GOPATH/src\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 github.com\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 spf13\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cobra\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pflag\nRun Code Online (Sandbox Code Playgroud)\n\n我创建了一个$GOPATH/bin目录。当我现在跑步时
go install github.com/spf13/cobra/cobra\nRun Code Online (Sandbox Code Playgroud)\n\n(如文档中所述),没有任何反应 - 没有错误消息,但命令运行后,$GOPATH/bin.
这是我的输出go env
GOARCH="amd64"\nGOBIN="/Users/user/Workspace/go/bin"\nGOEXE=""\nGOHOSTARCH="amd64"\nGOHOSTOS="darwin"\nGOOS="darwin"\nGOPATH="/Users/user/Workspace/go"\nGORACE=""\nGOROOT="/usr/local/Cellar/go/1.6/libexec"\nGOTOOLDIR="/usr/local/Cellar/go/1.6/libexec/pkg/tool/darwin_amd64"\nGO15VENDOREXPERIMENT="1"\nCC="clang"\nGOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"\nCXX="clang++"\nCGO_ENABLED="1"\nRun Code Online (Sandbox Code Playgroud)\n\n知道出了什么问题或者我如何调试这个吗?谢谢!
\n\n编辑
\n\n对我来说解决问题的是删除$GOPATH/src和$GOPATH/pkg文件夹并重新运行go get -v -x github.com/spf13/cobra/cobra.
该-x标志提供了更多输出,正如 @JimB 所说,它成功结束
mv $WORK/github.com/spf13/cobra/cobra/_obj/exe/a.out /Users/user/Workspace/go/bin/cobra\nRun Code Online (Sandbox Code Playgroud)\n 真的陷入了这个问题.我已经google了很多,无法弄清楚我做错了什么......
我正在尝试通过git add README.txt终端中的命令创建一个新文件...
(到目前为止,我已经创建了一个新文件夹Fundamentals.创建了一个子文件夹git-practice.并通过git init命令创建了一个git repo )
但是,当我尝试添加文件时fundamentals/git-practice,我收到以下错误..
fatal: pathspec 'README.txt' did not match any files
Run Code Online (Sandbox Code Playgroud)
不知道我做错了什么......一切似乎都有道理.这是代码:
Reenas-MBP:~ reenaverma$ cd ~
Reenas-MBP:~ reenaverma$ ls
72.png GitHub flask-workshop
Applications Library fundamentals
Creative Cloud Files Movies funny_things
Desktop Music get-pip.py
Documents Pictures world
Downloads Public wwlc
Dropbox Retrieved Contents
Reenas-MBP:~ reenaverma$ cd fundamentals
Reenas-MBP:fundamentals reenaverma$ ls
git-practice
Reenas-MBP:fundamentals reenaverma$ cd git-practice
Reenas-MBP:git-practice reenaverma$ ls -a
. .. .git
Reenas-MBP:git-practice reenaverma$ pwd …Run Code Online (Sandbox Code Playgroud) 我们有一组 Azure DevOps 管道模板,我们可以在多个存储库中重复使用这些模板。因此,我们希望有一个包含所有模板变量的文件。
回购结构看起来像这样
template repo
??? template-1.yml
??? template-2.yml
??? variables.yml
project repo
??? ...
??? azure-pipelines.yml
Run Code Online (Sandbox Code Playgroud)
在variables.yml这个样子的
...
variables:
foo: bar
Run Code Online (Sandbox Code Playgroud)
在template-1.yml我们导入这里variables.yml描述的
variables:
- template: variables.yml
Run Code Online (Sandbox Code Playgroud)
在azure-pipelines.yml我们使用这样的模板
resources:
repositories:
- repository: build-scripts
type: git
name: project-name/build-scripts
steps:
...
- template: template-1.yml@build-scripts
Run Code Online (Sandbox Code Playgroud)
当我们现在尝试运行管道时,我们收到以下错误消息:
template-1.yml@build-scripts (Line: 10, Col: 1): Unexpected value 'variables'
Run Code Online (Sandbox Code Playgroud) 为了针对Docker中的Gitlab实例测试命令行工具,我想使用用户名和密码登录Gitlab并获取创建的会话以验证我的API请求.
因此我会做以下事情:
curl -i http://localhost:8080/users/sign_in -s_gitlab_session从标题中找到我authenticity_token从登录表单中获取我的信息
curl 'http://localhost:8080/users/sign_in' \
-H "_gitlab_session=${cookie}" \
-H 'Origin: http://localhost:8080' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' \
-H 'Referer: http://localhost:8080/users/sign_in' \
-H 'Connection: keep-alive' \
--data-urlencode "authenticity_token=${token}" \
--data-urlencode "user[login]=root" \
--data-urlencode "user[password]=12341234" \
--data-urlencode "user[remember_me]=0"
Run Code Online (Sandbox Code Playgroud)
但是,我获得了一个而不是有效的用户登录
422 - The change you requested was rejected.
Run Code Online (Sandbox Code Playgroud)
在日志文件中,我看到了
==> gitlab-rails/production.log <==
Started POST "/users/sign_in" for 172.17.0.1 at 2017-12-23 00:22:16 +0000
Processing by SessionsController#create as HTML
Parameters: {"authenticity_token"=>"[FILTERED]", "user"=>{"login"=>"root", "password"=>"[FILTERED]", …Run Code Online (Sandbox Code Playgroud) 以下是错误跟踪
554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:7B140000, 4.30158:DC040000 [Hostname=MWHPR22MB0815.namprd22.prod.outlook.com]
DEBUG SMTP: got response code 554, with response: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:7B140000, 4.30158:DC040000 [Hostname=MWHPR22MB0815.namprd22.prod.outlook.com]
RSET
250 2.0.0 Resetting
DEBUG SMTP: MessagingException while sending, THROW:
com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:7B140000, 4.30158:DC040000 [Hostname=MWHPR22MB0815.namprd22.prod.outlook.com] …Run Code Online (Sandbox Code Playgroud) java ×4
command-line ×2
git ×2
spring-boot ×2
apache-spark ×1
azure ×1
azure-devops ×1
berkshelf ×1
chef-infra ×1
csrf ×1
curl ×1
dependencies ×1
email ×1
gitlab ×1
go ×1
javabeans ×1
macos ×1
modelmapper ×1
office365 ×1
ruby ×1
spring ×1
thor ×1
yaml ×1