小编Ann*_*nie的帖子

使用Sidekiq安排后台任务

我有部署heroku的Rails 3应用程序.我有一名Sidekiq工人app/workers/task_worker.rb:

class TaskWorker
  include Sidekiq::Worker
  def perform
    ...
  end
end
Run Code Online (Sandbox Code Playgroud)

如何TaskWorker.perform_async在凌晨12:01 安排每日执行?

cron ruby-on-rails-3 sidekiq

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

在CMD中运行PowerShell命令(带管道)

当我们在PowerShell中运行以下命令时:

get-date | sc C:\temp\date.log
Run Code Online (Sandbox Code Playgroud)

它使用当前日期创建date.log文件.

但如果我们通过CMD运行相同的:

powershell get-date | sc C:\temp\date.log
Run Code Online (Sandbox Code Playgroud)

它抱怨说:

错误:无法识别的命令

DESCRIPTION:
        SC is a command line program used for communicating with the
        Service Control Manager and services.
USAGE:
        sc <server> [command] [service name] <option1> <option2>...
Run Code Online (Sandbox Code Playgroud)

显然,CMD将用于POSH的管道与其自身混淆.

谁能指出我如何通过CMD运行它?

谢谢你的期待.

powershell command-prompt

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

在MVC 5中使用电子邮件登录

在新创建的ASP.NET MVC5应用程序中,登录屏幕会要求您输入电子邮件地址.但在引擎盖下,它使用用户名进行身份验证,假设为applicationUser.UserName== applicationUser.Email.

如何更改它以使其通过电子邮件地址验证用户?

似乎是他们在这方面已经改变了身份2.X的东西.

注意:我想通过电子邮件登录.

例如,在注册视图中,我们的用户需要提供:

电子邮件: last.first@example.com

用户:最后,第一

在登录期间,将使用该电子邮件.目前,它使用电子邮件但身份验证失败,因为它将电子邮件作为用户名传递.

asp.net-mvc-5 asp.net-identity-2

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

浏览器中的 XPath 3

当我们看到一致性图表时,例如https://caniuse.com/#search=xpathhttps://developer.microsoft.com/en-us/microsoft-edge/platform/status/domlevel3xpath/?q=xpath,它通常是关于DOM Level 3 XPath 的,重点是使用 XPath 1.0访问 DOM 对象,但不一定是 XPath 3.0 或更高版本。

问题 1 - W3C 等对浏览器是否有明确的版本要求以支持较新版本的 XPath?

此 XPath 1.0 功能有效:

document.evaluate(
  'normalize-space(" X  ")',
  document, null, XPathResult.ANY_TYPE, null ).stringValue

// => "X"
Run Code Online (Sandbox Code Playgroud)

但是这个 XPath 3.0 内联函数功能 ( ref ) 会抛出:

document.evaluate(
  'let $incr := function($n as xs:integer) as xs:integer { $n +1 } return $incr(2)',
  document, null, XPathResult.ANY_TYPE, null ).stringValue
Run Code Online (Sandbox Code Playgroud)

边缘:

XPATH15001:不支持 XPath 查询“let $incr := function($n as xs:integer) as xs:integer …

javascript xml browser xpath dom

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

使用var分配给变量的Javascript函数

我使用http://js2coffee.org将我的CoffeeScript代码转换为JavaScript

ResetControls = ->
  $("#menu_item_url").val ""
  $("#menu_item_name").val ""
  $("#resource_id").prop "selectedIndex", 0
  $("#resource_type_id").prop "selectedIndex", 0
Run Code Online (Sandbox Code Playgroud)

它将其转换为:

var ResetControls;

ResetControls = function() {
  $("#menu_item_url").val("");
  $("#menu_item_name").val("");
  $("#resource_id").prop("selectedIndex", 0);
  return $("#resource_type_id").prop("selectedIndex", 0);
};
Run Code Online (Sandbox Code Playgroud)

转换后的JavaScript代码中的第一行表明,在将函数赋值给变量时,将var关键字放在变量名之前是一种最佳实践.是这样吗?怎么样?

在我的理解中,var在递归调用中很方便,你的意图是在递归函数内部复制变量(否则它们将在递归调用之间共享或保持静态).

还有其他意义var吗?

javascript scripting-language

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

yield关键字来消化像Ruby这样的代码块

在Ruby中,我们可以从其他范围生成代码块,以优化编写代码的数量:

  def get_resource(published=true)
    find_resources do
      if I18n.locale == :ar && @resource_slug == "home"
        Resource.find_by_slug("home")
      else
        ResourceType.find_by_slug(@type_slug).resources.send(
          published ? :published : :unpublished
        ).find_by_slug(@resource_slug)
      end
    end
  end

  def get_resources(published=true)
    find_resources do
      ResourceType.includes(:resources).find_by_slug(@type_slug).resources.send(
        published ? :published : :unpublished
      )
    end
  end

  def find_resources
    begin
      @type_slug, @resource_slug = params[:type], params[:resource]
      yield
    rescue Mongoid::Errors::DocumentNotFound, NoMethodError
      nil
    end
  end
Run Code Online (Sandbox Code Playgroud)

在C#中,我们还有yield关键字。这是来自文档的示例:

//using System.Collections;  
//using System.Diagnostics; 
public static void Process()
{
    // Display powers of 2 up to the exponent of 8:  
    foreach (int number in …
Run Code Online (Sandbox Code Playgroud)

.net c# syntax

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

在Less中将px转换为em

什么相当于Scss' emCalc()更少?

padding: emCalc(24px);
Run Code Online (Sandbox Code Playgroud)

在Scss中将根据视点和缩放级别计算em.是否有更少的内置功能?

css less

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

在catch区继续

这是:

// retry
for (int i = 0; i < length; ++i)
{
    try
    {
        sqlCommand.ExecuteNonQuery();
    }
    catch (SqlException e)
    {
        if (e.Number == 64)
        {
            continue;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

相当于:

// retry
for (int i = 0; i < length; ++i)
{
    try
    {
        sqlCommand.ExecuteNonQuery();
    }
    catch (SqlException e) { }
}
Run Code Online (Sandbox Code Playgroud)

(因为在后一种情况下循环将继续)

有什么区别(如果有的话)?

c# exception-handling

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

在Powershell中的webget

有没有相当于的命令 webget在WindOS的PowerShell中?

我正在尝试创建一个脚本来从网站下载所有公开可用的文件.我正在制作自定义脚本,因为我需要将文件存储在特定的目录结构中(取决于名称,类型和大小).

powershell

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

jQuery UI:dragenter上的draggable

我正在关注jQuery draggable项目的这个指南.

我唯一想念的是dragenterdragleave临时元素的CSS一起玩的事件.它只hoverClass为可拖动元素提供属性,当可拖动元素移动到它们上时.如果我们需要更改其他元素的CSS怎么样?

当前代码如下所示:

$(".part").draggable({
    start: startDrag,
    stop: stopDrag,
    revert: true
});
$(".parts-action").droppable({
    accept: '.part',
    hoverClass: 'hovered',
    drop: handleDrop
});
Run Code Online (Sandbox Code Playgroud)

除此之外,我还需要:

$(".wrapper").on('dragenter', function (e) {
    $(this).next(".parts-action").show();
});

$(".wrapper").on('dragleave', function (e) {
    $(this).next(".parts-action").hide();
});
Run Code Online (Sandbox Code Playgroud)

但它在使用时不起作用draggable().

我也尝试过:

$(".part").draggable({
    drag: handleDrag
})

function handleDrag(e, ui){
    /* how to know if active draggable is on some element other than droppable? */
}
Run Code Online (Sandbox Code Playgroud)

这是非常令人困惑的,因为它与可拖动和可拖放相关联!

javascript jquery html5 drag-and-drop jquery-ui

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

如何在目录中的所有文件和Powershell中的子目录中运行dos2unix

我可以dos2unix在PowerShell中运行一个文件:

dos2unix ./assets/style.css
Run Code Online (Sandbox Code Playgroud)

如何为其下的所有CSS文件./assets/及其子目录执行此操作?

powershell

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