小编swa*_*nee的帖子

何时在gitignore中使用前导斜杠

我试图更清楚地理解.gitignore语法,特别是对于https://github.com/github/gitignore gitignores而言.

我看到前导斜杠仅用于匹配相对于.gitignore文件位置的路径名(来自http://git-scm.com/docs/gitignore):

前导斜杠与路径名的开头匹配.例如,"/*.c"匹配"cat-file.c"但不匹配"mozilla-sha1/sha1.c".

但是当我删除主要斜线时会发生什么?据我所知,有两种情况:

  1. 如果模式不包含斜杠(或者它只包含一个尾部斜杠,这意味着它应该与目录匹配),则在整个目录树中执行搜索.例如,该图案dir/将匹配<root>/dir,<root>/a/dir,<root>/a/b/c/.../dir等,其中<root>是的位置.gitignore的文件.
  2. 如果模式包含斜杠,该斜杠不在尾随位置(它不是最后一个字符),则它仅与相对于.gitignore文件位置的路径名匹配.

这些是我检查此行为的示例:

# Directory structure:
<root>
?? dir/
?   ?? test
?? src/
?   ?? dir/
?   ?   ?? test
test file is there only because Git does not track empty directories.
Run Code Online (Sandbox Code Playgroud)

第一次测试:

# .gitignore
dir/

# git status
nothing to commit
Run Code Online (Sandbox Code Playgroud)

所以Git忽略了这两个dir目录.这与案例编号1一致:模式没有斜杠(除了尾部),因此Git正在观察整个目录树,忽略与模式匹配的所有内容.

第二次测试:

# .gitignore
/dir/

# git status
Untracked …
Run Code Online (Sandbox Code Playgroud)

git gitignore

101
推荐指数
2
解决办法
1万
查看次数

Java - 使用WatchEvent抑制未经检查的强制转换警告是否安全?

我有以下测试代码:

FileSystem fs = FileSystems.getDefault();
Path conf = fs.getPath(".");
WatchKey key = null;
try {
    WatchService watcher = fs.newWatchService();
    conf.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
    while(true) {
        key = watcher.take(); // waits
        for (WatchEvent<?> event : key.pollEvents()) {

            WatchEvent.Kind<?> kind = event.kind();
            if (StandardWatchEventKinds.OVERFLOW == kind) continue;

            WatchEvent<Path> ev = (WatchEvent<Path>)event;
            Path file = ev.context();
            System.out.println(file);
        }
    }
} catch (IOException | InterruptedException e) {
    throw new RuntimeException(e.getMessage(), e);
}
Run Code Online (Sandbox Code Playgroud)

编译器unchecked cast发出与该行相关的警告

WatchEvent<Path> ev = (WatchEvent<Path>)event;
Run Code Online (Sandbox Code Playgroud)

因为作为一个event出来,编译器无法判断在运行时它是否真的要包含一个,而不是其他东西.key.pollEvents()WatchEvent<?>Path …

java generics casting unchecked-cast

6
推荐指数
1
解决办法
733
查看次数

Haskell primPutChar定义

我试图弄清楚如何IO定义基本的Haskell函数,所以我使用了这个引用,我得到了putChar函数定义:

putChar    :: Char -> IO ()
putChar    =  primPutChar
Run Code Online (Sandbox Code Playgroud)

但是,现在我无法在primPutChar任何地方找到有关此功能的更多信息.也许它可能是指一个预编译的函数,可以作为共享对象的二进制文件?如果是这种情况,是否可以查看其源代码?

io haskell definition

6
推荐指数
1
解决办法
121
查看次数

包含演示者或返回数据的用例?

考虑到 Clean Architecture定义,尤其是描述控制器、用例交互者和演示者之间关系的小流程图,我不确定我是否正确理解“用例输出端口”应该是什么。

干净的架构,如端口/适配器架构,区分主要端口(方法)和次要端口(由适配器实现的接口)。按照通信流程,我希望“用例输入端口”是一个主要端口(因此,只是一个方法),而“用例输出端口”是一个要实现的接口,可能是一个采用实际适配器的构造函数参数,以便交互者可以使用它。

举一个代码示例,这可能是控制器代码:

Presenter presenter = new Presenter();
Repository repository = new Repository();
UseCase useCase = new UseCase(presenter, repository);
useCase->doSomething();
Run Code Online (Sandbox Code Playgroud)

演示者界面:

// Use Case Output Port
interface Presenter
{
    public void present(Data data);
}
Run Code Online (Sandbox Code Playgroud)

最后,交互器本身:

class UseCase
{
    private Repository repository;
    private Presenter presenter;

    public UseCase(Repository repository, Presenter presenter)
    {
        this.repository = repository;
        this.presenter = presenter;
    }

    // Use Case Input Port
    public void doSomething()
    {
        Data data = this.repository.getData();
        this.presenter.present(data);
    }
}
Run Code Online (Sandbox Code Playgroud)

这种解释似乎得到了前面提到的图表本身的证实,其中控制器和输入端口之间的关系由带有“锋利”头的实心箭头表示(UML 表示“关联”,意思是“有一个”,其中控制器“有一个”用例),而演示者和输出端口之间的关系由带有“白色”头的实心箭头表示(UML 表示“继承”,这不是“实现”的那个,但可能就是这样反正意思)。 …

architecture hexagonal-architecture clean-architecture

6
推荐指数
2
解决办法
2266
查看次数

无法使suexec与mod_fastcgi一起使用

我成功地设法使mod_fastcgi与fpm一起工作,这使我能够设置用户:通过fpm池定义运行脚本的组.但是,没有类似的替代方案,例如,通过mod_fastcgi运行的python脚本,所以我试图学习如何使用suexec通过mod_fastcgi运行任何脚本与用户:我选择的组.

我从这个工作配置开始:

#/etc/apache2/sites-available/test1
<VirtualHost *:80>
    ServerName test1.slothcompany.net
    DocumentRoot /var/www/test1

    LogLevel Debug
    ErrorLog /var/www/test1/error.log

    <Directory /var/www/test1/>
        Options Indexes Includes FollowSymLinks ExecCGI
        AllowOverride All
        DirectoryIndex index.php
        AddHandler php5-fastcgi .php
        Action php5-fastcgi /php5.fcgi
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

#/var/www/test1/php5.fcgi
#!/bin/bash
PHPRC="/var/www/test1/php.ini"
PHP_FCGI_CHILDREN=5
export PHPRC
export PHP_FCGI_CHILDREN
exec /usr/bin/php5-cgi
Run Code Online (Sandbox Code Playgroud)

我把一个phpInfo()内部/var/www/test1/index.php,显示正确的php.ini路径.

现在,激活suexec我:

  • 已安装apache2-suexec:sudo apt-get install apache2-suexec
  • 已激活mod_suexec:sudo a2enmod suexec
  • 更改文件的权限: sudo chown -R michele:michele /var/www/test1
  • 将此行添加到vhost配置: SuexecUserGroup michele michele …

apache

5
推荐指数
1
解决办法
6610
查看次数

命令git ls-remote在Bitbucket上超时,git clone工作

我正在尝试使用Capistrano设置自动部署配置,但是当Capistrano尝试运行命令时我一直都会遇到故障

git ls-remote -h git@bitbucket.org:vendor/repo.git
Run Code Online (Sandbox Code Playgroud)

该用户的SSH密钥在Bitbucket中正确设置,因为我可以git clone git@bitbucket.org:vendor/repo.git在该服务器内部没有问题.

我还在ls-remote我的常规开发机器中测试了临时服务器外部的命令,我每天都在使用Git工作,我发现它在Bitbucket上也不起作用(我的开发机器中的SSH密钥显然已经设置好了) .

实际输出是:

git ls-remote -h ssh://git@bitbucket.org/vendor/repo.git
ssh: connect to host bitbucket.org port 22: Operation timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

虽然我可以在那些相同的目录上做到push并且pull没有任何问题.

ls-remoteBitbucket 上的命令怎么了?除常规配置外,我是否应该进行一些额外配置才能使其正常工作?

git ssh capistrano bitbucket

2
推荐指数
1
解决办法
4001
查看次数

在Gherkin中分组步骤或连接场景

我正在使用Gherkin语言定义要在BDD工作流程中使用BehatCucumber等工具的功能.这是到目前为止的功能定义:

Feature: Save Resource
    In order to keep interesting resources that I want to view later
    As a user
    I need to be able to save new resources

    Scenario: Saving a new resource
        Given "http://google.com" is a valid link
        When I insert "http://google.com" as the new resource link
        And I insert "Google Search Engine" as the new resource title
        Then I should see a confirmation message with the inserted link and title
        When I …
Run Code Online (Sandbox Code Playgroud)

bdd scenarios cucumber gherkin behat

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

Mockito 验证错误的重载方法

我正在尝试为一个用作依赖项的类编写单元测试AsynchronousSocketChannel

final AsynchronousSocketChannel channel = mock(AsynchronousSocketChannel.class);
final Client client = new Client(channel);

client.read();
verify(channel).read(isA(ByteBuffer.class), eq(client), isA(CompletionHandler.class));
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误:

Invalid use of argument matchers!
5 matchers expected, 3 recorded:
Run Code Online (Sandbox Code Playgroud)

发生这种情况是因为AsynchronousSocketChannel.read有 4 个不同的重载版本,并且出于某种原因verify不断选择具有 5 个参数的版本,即使我传递的匹配器与read(ByteBuffer dst, A attachment, CompletionHandler<Integer,? super A> handler).

这个答案中,建议这确实可能是实际编译器的问题,并且可以指示编译器选择正确的重载方法,例如

verify(channel).read(
        ArgumentMatchers.<ByteBuffer>isA(ByteBuffer.class),
        ArgumentMatchers.<Client>eq(client),
        ArgumentMatchers.<CompletionHandler>isA(CompletionHandler.class)
);
Run Code Online (Sandbox Code Playgroud)

但这样做我总是遇到同样的错误。

知道是否有可能实现这项工作吗?否则我相信我可以只使用 5 个参数重载,null作为额外的 2 个参数传递,但这对我来说有点像黑客。

java unit-testing overloading mocking mockito

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

使用预定的执行程序而不是 Java 中的硬循环监视目录

在我之前的问题中,我正在做一个简单的练习,观察目录中的文件更改。我从这个 oracle docs 中获取了代码,它没有问题,除了我不确定的小未经检查的强制转换警告。

我对这段代码的下一个问题是它在线程中放置了一个硬循环,这至少在理论上是阻塞的。现在,我知道如果操作系统使用时间切片,即使是硬循环也会被分成小块,这些小块与应用程序正在运行的其他线程共享处理器的时间,事实上我可以制作各种硬循环的例子在不同的线程中运行不会互相阻塞(只要它们具有相同的优先级),即使是在一个明确创建的只有一个内核的虚拟机上。

但是,Java 语言不保证它使用哪种调度来管理线程,如果是时间片还是轮询;这取决于实际的 VM 实现和操作系统。所以我在学习这个主题时得到的建议是编写代码,就好像它必须在循环线程调度上运行一样,从而避免在线程中放置硬循环,除非我的代码可以不断地将控制权交还给其他线程与sleep()wait()yeld()等(我可以想到一个 GUI,其中主线程是一个硬循环监视事件,并将控制权发送回侦听器来处理它们的线程)。

但是,在我的情况下,我想不出一种方法在处理文件更改后让线程进入睡眠状态,或者将控制权返回主循环,因为核心思想基本上是不断询问是否有对文件系统的更改。所以我想到的是一个定期调用监视线程的预定执行程序。显然,这是在拥有“阻塞”线程和在发生文件系统更改时立即得到通知之间的权衡。由于在实际情况下我将进行此练习,因此我可能不需要立即通知,我对此很满意。代码非常简单:

// imports...
public class Main
{
    public static FileSystem fs;
    public static Path dir;
    public static WatchService watcher;
    public static WatchKey key;

    public static void main(String[] args)
    {
        fs = FileSystem.getDefault();
        dir = fs.getPath(".");

        try {
            watcher = fs.newWatchService();
            dir.register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
        } catch (IOException e) {
            System.err.println(e.getMessage());
            return;
        }

        Executors.newScheduledThreadPool(1).scheduleAtFixedRate(new Runnable()
            {
                public void run()
                {
                    Main.key = Main.watcher.poll(); …
Run Code Online (Sandbox Code Playgroud)

java multithreading nonblocking watch executorservice

0
推荐指数
1
解决办法
7100
查看次数