我想使用WebP格式优化我网站上的一些图像.
Webp图像是高度压缩的jpeg和png,借助Google开发的算法.
但是,webp图像只能在现代Chrome和Opera中显示.如果浏览器支持webp,则image/webp在AcceptHTTP标头中指定.
如果浏览器支持webp格式并且磁盘上是否存在图像的webp版本,那么检查nginx是个好主意,如果是这样的话 - 提供webp图像,如果没有 - 提供默认图像.
例如:
http://example.com/dog.png,Accept: image/webp, image/png, image/jpeg.nginx必须发送dog.png.webp
http://example.com/dog.png,Accept: image/png, image/jpeg.nginx必须发送dog.png
在这个nginx配置中可以找到更多解释https:// github.com/igrigorik/webp-detect/blob/master/nginx.conf和https:// github.com/kavu/sprockets-webp#nginx
没关系.但我正在使用CloudFlare CDN来加速资产交付.
有了这样的图像服务条件,我们必须添加标题,Vary: Accept以便在浏览器和代理中缓存将正常工作.但有个问题!CloudFlare仅支持Vary: Accept-Encoding.这在这里描述.
客户端将获得首先由CloudFlare缓存的图像版本(webp或常规),如果客户端不支持webp,则不会看到图像,这很糟糕.
有什么解决方案吗?
我有表连接问题。ActiveRecord 生成的 SQL 将同一个表连接两次。假设我们有模型:
class Product < ActiveRecord::Base
has_many :characteristics
has_many :properties, through: :characteristics
has_many :values, through: :characteristics
end
class Value < ActiveRecord::Base
has_many :characteristics
end
class Property < ActiveRecord::Base
has_many :characteristics
end
class Characteristic < ActiveRecord::Base
belongs_to :product
belongs_to :property
belongs_to :value
end
Run Code Online (Sandbox Code Playgroud)
所以我想加入属性和值。Product.joins(:properties).joins(:values)将产生下一个 SQL:
SELECT `products`.*
FROM `products`
INNER JOIN `characteristics` ON `characteristics`.`product_id` = `products`.`id`
INNER JOIN `properties` ON `properties`.`id` = `characteristics`.`property_id`
INNER JOIN `characteristics` `characteristics_products_join` ON `characteristics_products_join`.`product_id` = `products`.`id`
INNER JOIN `values` ON `values`.`id` = …Run Code Online (Sandbox Code Playgroud) Assume I have such Dockerfile:
FROM ubuntu:16.04
EXPOSE 5000
CMD ["some", "app"]
Run Code Online (Sandbox Code Playgroud)
And such docker-compose.yml:
version: '2.3'
services:
app:
build:
context: .
exposes:
- 6000
Run Code Online (Sandbox Code Playgroud)
After I do docker-compose up -d docker ps outputs:
CONTAINER ID NAMES STATUS CREATED PORTS
3315ec1be1b3 app Up 41 hours 41 hours ago 5000/tcp, 6000/tcp
Run Code Online (Sandbox Code Playgroud)
Is it possible to unexpose port 5000 and leave only 6000?
无法弄清楚 Rails gem 必须在哪里指定其依赖项?在 Gemfile 中的 gemspec 中?生成的 Gemfile 有以下描述:
# Declare your gem's dependencies in malibu.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# …Run Code Online (Sandbox Code Playgroud) 看看这段代码:
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iterator>
using namespace std;
int main()
{
ifstream text("text.txt");
istreambuf_iterator<char> iis(text);
string longest_phrase, _longest;
while (iis != istreambuf_iterator<char>()) {
if ( *iis != '.' ) {
_longest.push_back(*iis);
++iis;
continue;
}
if ( _longest.size() > longest_phrase.size() )
longest_phrase = move(_longest); //I want to move the data of _longest to longest_phrase. Just move! Not to copy!
cout << _longest.empty(); //why _longest is not empty??
//_longest.clear();
++iis;
}
text.close();
longest_phrase.push_back('.');
cout << "longest phrase is …Run Code Online (Sandbox Code Playgroud) struct Foo
{
constexpr static int n = 10;
};
void f(const int &x) {}
int main()
{
Foo foo;
f(Foo::n);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到错误:main.cpp | 11 |未定义引用`Foo :: n'|.为什么?
<div class="outer-wrapper">
<div class="inner-wrapper">
<div class="item">1</div>
<!--...-->
<div class="item">12</div>
</div>
</div>
.outer-wrapper {
position: relative;
min-width: 900px;
max-width: 900px;
min-height: 600px;
max-height: 600px;
}
.inner-wrapper {
position: relative;
width: 20000em;
}
.item {
min-height: 350px;
max-height: 350px;
min-width: 350px;
max-width: 350px;
background: cornflowerblue;
font-size: 40px;
float: left;
}
Run Code Online (Sandbox Code Playgroud)
我有附图:

如何在没有将组(每六个项目)包装在另外的容器中的情况下以这种方式安排物品?可能吗?
我正在处理一些项目,并且在复制功能代码方面存在问题.有没有办法只声明一个函数的单一签名,它将适用于const和非const参数?const和非const函数的实现是相同的.
#include <iostream>
template <class Data>
struct Processor {
int process(const Data &data)
{
return 42;
}
int process(Data &data)
{
return 42;
}
};
int main() {
using data_type = int;
data_type non_const_data = 1;
const data_type const_data = 2;
std::cout << Processor<data_type>().process(non_const_data) << std::endl;
std::cout << Processor<data_type>().process(const_data) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
感谢您的答复
UPDATE
这个例子怎么样?
#include <iostream>
#include <vector>
template <class Container, class Function>
struct Invoker {
const Container& invoke(const Container &container, Function function)
{
for …Run Code Online (Sandbox Code Playgroud) 我的表有posts超过 650 万条记录。每个帖子都使用固定长度表示name。我使用 MySQL Community 5.7,SSD 磁盘,大约 10K-20K IOPS 和 1GB 内存,key-buffer-size设置为 512M(顺便说一句,我主要使用默认 MySQL 配置驱动)。我的资源有限,因此我选择 MyISAM 作为我的存储引擎。我的基准测试表明,就我而言,MyISAM 更快。而且我不太关心数据,因为它可以更新。
所以,这是我的计划信息:
+------------+--------+------------+
| TABLE_NAME | ENGINE | row_format |
+------------+--------+------------+
| posts | MyISAM | Fixed |
+------------+--------+------------+
+---------------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| name | char(30) | NO | UNI | …Run Code Online (Sandbox Code Playgroud)