小编Bra*_*roy的帖子

让favicon在跨浏览器/平台上工作的最佳方式

在阅读了这两篇文章(One Two)之后,我对如何覆盖所有平台和浏览器以获得最佳图标以供其使用感到困惑.

现在,我有这个,但我不确定这是否是最佳的.

<link rel="apple-touch-icon-precomposed" sizes="152x152" href="/apple-touch-icon-152x152-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="/apple-touch-icon-120x120-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="/apple-touch-icon-76x76-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-72x72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-precomposed.png">

<link rel="icon" href="/favicon.ico" sizes="16x16 32x32 48x48 64x64" type="image/vnd.microsoft.icon">
Run Code Online (Sandbox Code Playgroud)

我不确定apple-touch-icon-precomposed.png应该是什么尺寸.

但要切入追逐(tl; dr):什么是覆盖尽可能多的平台和浏览器的最佳方式以及推荐用于图标的大小?

Bounty将给予能够回答这两个问题的人:1.尽可能多地覆盖尽可能多的平台和浏览器的最佳方式是什么; 2.每次出现都需要哪些尺寸.

favicon icons cross-platform cross-browser

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

SCSS扩展:之后:之前

我想知道是否可以使用另一个伪元素扩展伪元素.我尝试了以下,但它没有用.

li {
    float: left;
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 12px 6px 0 6px;
    &:before {
        content: "";
        position: absolute;
        top: 0;
        right: 50%;
        border-top: 1px solid #ccc;
        width: 50%;
        height: 12px;
    }
    &:after{
        @extend &:before;
        right: auto;
        left: 50%;
        border-left: 1px solid #ccc;
    }
}
Run Code Online (Sandbox Code Playgroud)

sass css-selectors css3

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

在子处理程序中清除XML Twig

我正在使用XML :: Twig解析大型XML文件(60GB +)并在OO(Moose)脚本中使用它.我正在使用该twig_handlers选项在读入内存后立即解析元素.但是,我不确定如何处理Element和Twig.

在我使用Moose(和OO)之前,我的脚本看起来如下(和工作):

my $twig = XML::Twig->new(
  twig_handlers => {
    $outer_tag => \&_process_tree,
  }
);
$twig->parsefile($input_file);


sub _process_tree {
  my ($fulltwig, $twig) = @_;

  $twig->cut;
  $fulltwig->purge;
  # Do stuff with twig
}
Run Code Online (Sandbox Code Playgroud)

现在我就这样做了.

my $twig = XML::Twig->new(
  twig_handlers => {
    $self->outer_tag => sub {
      $self->_process_tree($_);
    }
  }
);
$twig->parsefile($self->input_file);

sub _process_tree {
  my ($self, $twig) = @_;

  $twig->cut;
  # Do stuff with twig
  # But now the 'full twig' is not purged
}
Run Code Online (Sandbox Code Playgroud)

问题是,我现在看到我错过了清除 …

xml perl xml-twig

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

使用交替比使用正则表达式中的后续替换更快

我有一个很直截了当的问题.在我工作的地方,我看到很多正则表达式都来了.它们在Perl中用于替换和/或删除文本中的一些字符串,例如:

$string=~s/^.+\///;
$string=~s/\.shtml//;
$string=~s/^ph//;
Run Code Online (Sandbox Code Playgroud)

我知道你不能连接第一个和最后一个替换,因为你可能只想ph在第一次替换后在字符串的开头替换.但是,我会将第一个和第二个正则表达式放在一起进行交替:$string=~s/(^.+\/|\.shtml)//;因为我们正在处理数千个文件(+500,000),所以我想知道哪种方法最有效.

regex perl alternation

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

读一剪!在序言中

我正在阅读Learn Prolog Now!的关于切割的章节,同时是 Bratko 的人工智能 Prolog 编程,第 5 章:控制回溯。起初,cut 似乎是模仿其他编程语言中已知的 if-else 子句的直接方式,例如

# Find the largest number
max(X,Y,Y):- X =< Y,!. 
max(X,Y,X).
Run Code Online (Sandbox Code Playgroud)

但是,正如下面所指出的,即使在我们期望的情况下,在所有变量都被实例化的情况下,此代码将失败false,例如

?- max(2,3,2).
true.
Run Code Online (Sandbox Code Playgroud)

原因很明显:第一个规则失败,第二个不再有任何条件与之相关,所以它会成功。我明白这一点,但随后提出了一个解决方案(这是一个swish):

max(X,Y,Z):- X =< Y,!, Y = Z. 
max(X,Y,X).
Run Code Online (Sandbox Code Playgroud)

我很困惑我应该如何阅读这个。我认为的!意思是:“如果在此之前的所有内容!都是真的,请停止终止,包括具有相同谓词的任何其他规则”。但是,这不可能是正确的,因为这意味着 的实例化Y = Z仅在失败的情况下发生,这对于该规则是无用的。

那么应该如何以“人”的方式阅读剪辑?而且,作为扩展,我应该如何阅读上述建议的解决方案max/3

prolog prolog-cut swi-prolog-for-sharing

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

仅通过加载模块的一部分来节省资源?

我正在阅读O'Reilly的Perl对象,参考和模块,更具体地说是关于模块的部分.它声明在使用时use Some::Module您可以指定导入列表.从它的解释看来,使用这个列表的唯一好处是为了保持命名空间的清洁.换句话说,如果包中有子程序some_sub,main并且加载的模块有一个同名的子程序,则子程序将被覆盖.但是,如果您指定导入列表some_sub从此列表中省略,则不会发生此冲突.然后,您可以仍然some_sub从模块通过声明它像这样运行:Some::Module::some_sub.

除了上面描述的那个之外还有其他好处吗?我问这个是因为在某些情况下你加载了具有大量功能的模块,即使你只对它的一些方法感兴趣.起初我认为通过指定一个导入列表,你只加载那些方法,而不是用你不会使用的方法来膨胀内存.但是,从上面的解释看来并非如此.您是否可以通过仅加载模块的部分来有选择地节省资源?或者Perl是否足够智能,在编译时无需程序员干预?

perl perl-module

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

结合 HiDPI 显示器了解 srcset 和尺寸

我已经研究 CSS 有一段时间了,但是srcset图像sizes元素让我感到困惑。这是一个我认为可行的例子。

<img alt="Background image flowers"
    srcset="img/flowers-480.jpg 480w,
            img/flowers-480@2x.jpg 480w 2x,
            img/flowers-768.jpg 768w,
            img/flowers-768@2x.jpg 768w 2x,
            img/flowers-960.jpg 960w,
            img/flowers-960@2x.jpg 960w 2x,
            img/flowers-1280.jpg 1280w,
            img/flowers-1280@2x.jpg 1280w 2x" 
    sizes="(max-width: 1279px) 100vw,
           (min-width: 1280) 1280px"
    src="img/flowers-960.jpg">
Run Code Online (Sandbox Code Playgroud)

这个想法是让图像占视口的 100%,直到视口宽度达到 1280 像素或更宽,然后图像将是固定大小。但是,为了补偿更高 DPI 的设备,我认为建议添加 DPI 描述符(1.5x、2x 等),如此处此处建议。

我认为上面的代码会做的是:

  • 检查尺寸,查看图像的预期尺寸(如果给出了相对单位,例如 % 或 vw,则计算像素宽度)
  • 查找 srcset 宽度中最接近该宽度的图像
  • 从这些图像中,过滤掉 DPI 描述符最接近设备 DPI 的图像

但是,当我将其通过验证器时,我收到以下错误:

错误:元素 img 上的属性 srcset 值错误:图像宽度img/flowers-480@2x.jpg与图像宽度相同 img/flowers-480.jpg

很明显,我完全忽略了 srcset 和 size 的工作原理。我究竟做错了什么?

html image srcset responsive-images

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

ThreadPoolExecutor、ProcessPoolExecutor 和全局变量

我是一般并行化的新手,特别是 concurrent.futures。我想对我的脚本进行基准测试并比较使用线程和进程之间的差异,但我发现我什至无法运行它,因为在使用时ProcessPoolExecutor我无法使用我的全局变量。

以下代码将按Hello我的预期输出,但是当您更改ThreadPoolExecutor为 时ProcessPoolExecutor,它将输出None.

from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor

greeting = None

def process():
    print(greeting)

    return None


def main():
    with ThreadPoolExecutor(max_workers=1) as executor:
        executor.submit(process)

    return None


def init():
    global greeting
    greeting = 'Hello'

    return None

if __name__ == '__main__':
    init()
    main()
Run Code Online (Sandbox Code Playgroud)

我不明白为什么会这样。在我的真实程序中,init是用来设置全局变量到CLI参数的,而且有很多。因此,似乎不建议将它们作为参数传递。那么如何将这些全局变量正确地传递给每个进程/线程呢?

我知道我可以改变周围的东西,这会起作用,但我不明白为什么。例如,以下内容适用于两个 Executor,但这也意味着必须对每个实例进行全局初始化。

from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor

greeting = None

def init():
    global greeting
    greeting = 'Hello'

    return None


def main():
    with ThreadPoolExecutor(max_workers=1) as executor:
        executor.submit(process)

    return None …
Run Code Online (Sandbox Code Playgroud)

python python-multithreading python-3.x concurrent.futures python-multiprocessing

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

如何使用 install_requires 从 setup.py 安装 git+https://

我有一个必须从 git+https 安装的项目:

我可以让它以这种方式工作:

virtualenv -p python3.5 bla
. bla/bin/activate
pip install numpy # must have numpy before the following pkg...
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
Run Code Online (Sandbox Code Playgroud)

但是,我想在 setup.py 文件中使用它install_requires

from setuptools import setup
setup(install_requires='git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI', setup_requires='numpy')
Run Code Online (Sandbox Code Playgroud)

然后,pip install -e .从包含setup.py

由于解析错误,这不起作用:

    Complete output (1 lines):                                                                                                             
    error in bla_bla setup command: 'install_requires' must be a string or list of strings containing valid project/version requireme
nt specifiers; Invalid requirement, parse error at "'+https:/'"                                                                             
    ----------------------------------------
ERROR: Command errored out with exit …
Run Code Online (Sandbox Code Playgroud)

python git pip setuptools setup.py

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

如何将参数化夹具作为参数传递给另一个夹具

我试图避免在测试中重复太多样板文件,并且我想以更结构化的方式重写它们。假设我有两个不同的解析器,它们都可以将文本解析为doc. 该文档随后将用于其他测试。最终目标是公开一个doc()可在其他测试中使用的固定装置,并且以运行给定解析器和文本的所有组合的方式进行参数化。

@pytest.fixture
def parser_a():
    return "parser_a"  # actually a parser object

@pytest.fixture
def parser_b():
    return "parser_b"  # actually a parser object

@pytest.fixture
def short_text():
    return "Lorem ipsum"

@pytest.fixture
def long_text():
    return "If I only knew how to bake cookies I could make everyone happy."
Run Code Online (Sandbox Code Playgroud)

现在的问题是,如何创建一个doc()如下所示的装置:

@pytest.fixture(params=???)
def doc(parser, text):
    return parser.parse(text)
Run Code Online (Sandbox Code Playgroud)

其中parser参数化为parser_a和parser_b,以及textshort_text和long_text。这意味着总共doc将测试解析器和文本的四种组合。

PyTest 参数化装置的文档非常模糊,我找不到如何解决这个问题的答案。欢迎大家帮忙。

python fixtures pytest parameterized-unit-test

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