小编Jos*_*non的帖子

如何检测有人摇动iPhone的时间?

当有人动摇iPhone时,我想做出反应.我并不特别在乎它们是如何摇晃它的,只是它在一瞬间大力挥手.有谁知道怎么检测到这个?

accelerometer motion-detection shake ios

339
推荐指数
12
解决办法
12万
查看次数

gradle扩展可以处理属性的惰性评估吗?

我正在编写一个自定义gradle插件来处理一些模糊的复杂工作,我在使用属性配置插件应用的一些任务时遇到了令人沮丧的问题.

apply plugin: myPlugin

//Provide properties for the applied plugin
myPluginProps {
    message = "Hello"
}

//Define a task that uses my custom task directly
task thisTaskWorksFine(type: MyTask) {
    input = myPluginProps.message
}

//Define a plugin that will apply a task of my custom type
class MyPlugin implements Plugin<Project> {
    void apply(Project project) {
        project.extensions.create('myPluginProps', MyPluginExtension)

        project.task(type: MyTask, 'thisTaskWorksIncorrectly') {
            input = project.myPluginProps.message
        }
    }
}

//The extension used by my custom plugin to get input
class MyPluginExtension {
    def …
Run Code Online (Sandbox Code Playgroud)

gradle

16
推荐指数
2
解决办法
4310
查看次数

为什么"刀上传角色"没有上传任何角色?

我遵循了OpsCode 快速入门指南,事情进展顺利,但现在我遇到了试验角色的问题.我在我的仓库中有一个"起始"角色,由OpsCode提供.当我按照第一份官方文档,我可以找到并从我的厨师回购顶部运行以下内容:

knife upload roles
Run Code Online (Sandbox Code Playgroud)

它只是返回而没有任何反应.我的厨师服务器上没有任何角色(新的或更新的).下面这行工作,为创建和更新:

knife role from file .\roles\starter.rb
Run Code Online (Sandbox Code Playgroud)

但我发现它过于繁琐,我更喜欢把我的整个回购推送到服务器(或至少所有角色)的东西,让我更自信一切都是最新的.

chef-infra knife

13
推荐指数
2
解决办法
7629
查看次数

在gradle中重用Exec任务以进行常见命令行操作的最合适方法是什么?

我正在编写一个gradle构建文件,它将为我们的产品安装一个基本的开发域.基本上所有真正的代码都将在自定义插件和自定义任务中.涉及的几个步骤相当重复(多个sudo调用,多个用户添加),我想将常见的东西封装到一个任务中.

例如:

task('addDBUser', type:AddUser) {
    username = joeUser
}

task('startService', type:SudoExec) {
    workingDir = "not/too/relevant"
    commandLine = "/etc/init.d/coolService start"
}
Run Code Online (Sandbox Code Playgroud)

我想尽可能地重用Exec给我的各种功能(stdin,stdout等),同时自动提供样板("sudo ...").我很确定我可以扩展Exec而不是DefaultTask,但我不知道触发实际操作的标准方法.用我需要的东西修改commandLine属性似乎很容易,但是当我想要Exec实际去的时候,没有通用的"run()"等.

我是否打开Exec以确定哪种方法是它的工作方法然后直接调用它?或者是否有更通用的方法来实现我的目标?

plugins gradle

11
推荐指数
1
解决办法
4947
查看次数

如何在puppet中使用augeas创建格式良好的xml?

我正在尝试使用puppet来编辑jenkins config.xml.由于种种原因,我认为augeas最有意义,而且我几乎拥有我需要的东西,但格式化非常粗糙.

这是我的木偶文件:

augeas { 'jenkins_config.xml' :
  incl    => '/tmp/config.xml',
  lens    => 'Xml.lns',
  context => '/files/tmp/config.xml/hudson',
  changes => [
    "set securityRealm/#attribute/class hudson.security.PAMSecurityRealm",
    "set securityRealm/#attribute/plugin pam-auth@1.0",
    "set securityRealm/serviceName/#text sshd",
  ],
}
Run Code Online (Sandbox Code Playgroud)

我在找什么:

<hudson>
  <securityRealm class="hudson.security.PAMSecurityRealm" plugin="pam-auth@1.0">
    <serviceName>sshd</serviceName>
  </securityRealm>
</hudson>
Run Code Online (Sandbox Code Playgroud)

我得到了什么:

<hudson>
<securityRealm class="hudson.security.PAMSecurityRealm" plugin="pam-auth@1.0"><serviceName>sshd</serviceName>
</securityRealm>
</hudson>
Run Code Online (Sandbox Code Playgroud)

内容很好(顺便说一句,这太棒了),但阅读起来并不好玩.augeas可以为我处理缩进和换行吗?如果我必须自己做,有人可以提供缩进提示吗?我的尝试都失败了.

xml puppet augeas

3
推荐指数
1
解决办法
2376
查看次数