小编ben*_*888的帖子

Javascript递归函数性能下降

在招聘过程技能测试期间,我遇到了以下问题:

var x = function(z) {
    console.log(z);    
    if (z > 0) {
        x(z-1);
    }
};
Run Code Online (Sandbox Code Playgroud)

为什么随着z变高,这会逐渐变慢?提出一个更好的版本,保持递归.

我想知道答案只是为了了解它.我回答说它变慢了,因为随着z的增加,递归调用的数量也增加了,但我无法提供更好的版本.另外,我不知道为什么当z越高时函数变慢的原因还有什么.

javascript recursion performance

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

如何表达symfony路由占位符不等于某个值

我有一个 symfony 项目,我需要在其中管理动态子域,并且我以下一种方式定义了 route.yml 文件:

home:
    path: /
    host: "www.mydomain.com"
    defaults: {_controller: ApplicationBundle:Home:homePage}

subdomain_mainpage:
    path: /
    host: "{subdomain}.mydomain.com"
    defaults: {_controller: ApplicationBundle:Subdomain:showDescription}    

subdomain_otherpage:
    path: /anothersegment
    host: "{subdomain}.mydomain.com"
    defaults: {_controller: ApplicationBundle:Subdomain:showOtherSegment}       
    requirements:
        subdomain: !(www)
Run Code Online (Sandbox Code Playgroud)

问题是“subdomain_otherpage”路由不起作用,我尝试了一些其他方法来做到这一点,但我无法让它工作。不能做这样的事情吗?不是说占位符不能等于任何特定值吗??

谢谢你的帮助!

php symfony

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

SpringBoot @WebMvcTest和@MockBean无法正常工作

似乎@WebMvcTest@MockBean没有按预期工作。也许我缺少了一些东西……我有一个带有一些依赖关系的控制器@MockBean,但是我的应用程序无法启动,因为它找不到另一个我认为在这种情况下不需要的bean。

控制器:

@RestController
public class ExchangeRateStoreController {
    private AddExchangeRate addExchangeRate;
    private AddExchangeRateRequestAdapter addExchangeRateRequestAdapter;
    private GetExchangeRate getExchangeRate;
    private GetExchangeRateRequestAdapter getExchangeRateRequestAdapter;

    @Autowired
    public ExchangeRateStoreController(ExchangeRateRepository exchangeRateRepository, ExchangeRateDateValidator exchangeRateDateValidator, ExchangeRateView exchangeRateView) {
        addExchangeRate = new AddExchangeRate(exchangeRateRepository, exchangeRateDateValidator);
        addExchangeRateRequestAdapter = new AddExchangeRateRequestAdapter();
        getExchangeRate = new GetExchangeRate(exchangeRateView);
        getExchangeRateRequestAdapter = new GetExchangeRateRequestAdapter();
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public void create(@RequestBody AddExchangeRateRequest addExchangeRateRequest) {
        addExchangeRate.execute(addExchangeRateRequestAdapter.toCommand(addExchangeRateRequest));
    }
}
Run Code Online (Sandbox Code Playgroud)

测试:

@RunWith(SpringRunner.class)
@WebMvcTest(ExchangeRateStoreController.class)
public class ExchangeRateStoreControllerTest {

    @Autowired
    private MockMvc mvc;  
    @MockBean
    ExchangeRateRepository exchangeRateRepository;
    @MockBean
    ExchangeRateDateValidator exchangeRateDateValidator; …
Run Code Online (Sandbox Code Playgroud)

java spring unit-testing spring-mvc spring-boot

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

将参数传递给Symfony @ParamConverter

我在我的控制器中使用symfony @ParamConverter通过它的slug获取一个实体,但是我没有使用"findBySlug()"方法而是使用更具体的"findWithSomeFeaturesBySlug($ slug)",我遇到了问题因为在findWithSomeFeaturesBySlug($ slug)方法中,我收到$ slug参数作为一个带有'slug'键的关联数组,而不是slug的值.

我的控制器代码如下所示:

/**
* @Route("/some-route/{slug}")
* @ParamConverter("object", class="AcmeBundle:Object", options={"repository_method" = "findWithSomeFeaturesBySlug"})
*/
public function acmeDemoAction(Object $object)
{
    // Controller code here
}
Run Code Online (Sandbox Code Playgroud)

我希望有人可以帮助我.

谢谢.

更新:

对不起,我认为我没有正确解释我的问题.问题是我在"findWithSomeFeaturesBySlug($ slug)"函数中得到了一个关联数组,我需要直接得到$ slug值.

// ObjectRepository
public function findWithSomeFeatures($slug) 
{
    // here I get an associative array in the slug parameter:
    // $slug = array('slug' => 'some_value')
    // And I need $slug = 'some_value'
}
Run Code Online (Sandbox Code Playgroud)

php symfony

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

Read命令停止bash脚本的执行

我有一个 bash 脚本,我使用read命令将多行字符串存储到变量中,但由于某种我不明白的原因,它停止了脚本的执行,并以状态码退出1

#!/usr/bin/env bash

# some setup code
# ...

read -r -d '' test_command <<EOF
CI_TIMEOUT_MINUTES=20 \
FOO=foo \
BAR=${bar} \
yarn test "path/to/tests/"
EOF

echo "test_command: ${test_command}"

if ! kubectl exec -it "$pod" -- /bin/sh -c "${test_command}"; then
# ...
Run Code Online (Sandbox Code Playgroud)

执行脚本时,它会以命令执行1时的状态退出read,而不会到达行echo "test_command: ${test_command}"

bash

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

从 jodatime DateTime 中提取时区

我收到一个包含 ISO8601 日期时间的日期时间字符串,像这样"2001-07-04T12:08:56.235-07:00",然后这个字符串被解析为一个 jodatime 日期时间对象new DateTime("2001-07-04T12:08:56.235-07:00"),然后使用参数传递的变量格式化程序模式再次将其转换为字符串,但是当发生这种情况时,没有使用时区,因此使用系统的默认时区。我想要的是从第一个给定日期中提取时区(或偏移量),并使用它相应地打印它。是否可以?

先谢谢了!

java datetime jodatime

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