执手闯天涯

文章 评论 浏览 488

执手闯天涯 2025-02-20 14:18:16

输入自定义CSS:

.woocommerce div.images a img {
height: 400px! important;
object-fit: contain ;
object-position: top;
}

Enter in custom CSS:

.woocommerce div.images a img {
height: 400px! important;
object-fit: contain ;
object-position: top;
}

如何将不同尺寸的图像适合“框”在WooCommerce中,单产品页面图像滑块

执手闯天涯 2025-02-20 08:42:25

是的,您可以使用 fieldmanager 属性访问注册属性列表,并循环通过它们。

      foreach (var property in FieldManager.GetRegisteredProperties().Where(r=>r.Type == typeof(DateTime)))
      {
        BusinessRules.AddRule(new DateValidRule(property) { Severity = RuleSeverity.Warning });
      }

Yes, you can use the FieldManager property to access the list of registered properties and loop through them.

      foreach (var property in FieldManager.GetRegisteredProperties().Where(r=>r.Type == typeof(DateTime)))
      {
        BusinessRules.AddRule(new DateValidRule(property) { Severity = RuleSeverity.Warning });
      }

CSLA:对于每个特定类型的属性而不必为每个属性手动添加它,是否有可能为businessRule.add()添加它吗?

执手闯天涯 2025-02-19 23:43:49

您可以打开NETCDF文件以进行编辑。请参阅:
https://unididata.github.ioio oio oio of创建popeningclating-a-netcdf-file

而不是而不是:

data = netcdf4.Dataset(file)

尝试:

data = netCDF4.Dataset(file,'r+',clobber=True).

You can open a NetCDF file for editing in place. See:
https://unidata.github.io/netcdf4-python/#creatingopeningclosing-a-netcdf-file

Rather than:

data = netcdf4.Dataset(file)

Try:

data = netCDF4.Dataset(file,'r+',clobber=True).

更改python中NetCDF文件的维度和值

执手闯天涯 2025-02-19 17:41:25

请在应用程序的主要功能中添加这些行。

WidgetsFlutterBinding.ensureInitialized();   
await Firebase.initializeApp(
 options: DefaultFirebaseOptions.currentPlatform,   
);

根据Firebase文档

。 nofollow noreferrer“> this

Please add these lines in the main function of your app.

WidgetsFlutterBinding.ensureInitialized();   
await Firebase.initializeApp(
 options: DefaultFirebaseOptions.currentPlatform,   
);

Your initialization in the main function is wrong according to the firebase docs.

Check this

用flutter网(在macOS上)扑向扑面。 initializeapp()不起作用,没有返回错误

执手闯天涯 2025-02-19 15:17:12
echo $response->serializeToJsonString(); // Prints JSON string

$ wonsevy \ google \ analytics \ data \ v1beta \ runreporportresponse 的实例,它是从 \ google \ protobuf \ protobuf \ proteobuf \ internals \ internal \ sexpess 延长的实例。 。因此,您可以使用 serializetojsonstring()相同的方法。

echo $response->serializeToJsonString(); // Prints JSON string

$response is an instance of \Google\Analytics\Data\V1beta\RunReportResponse, which is extended from \Google\Protobuf\Internal\Message. Hence, you can use serializeToJsonString() method of the same.

Google Analytics(分析数据API V1 Runreport),仅返回JSON

执手闯天涯 2025-02-19 05:15:40

在更仔细地阅读文档后,我发现查询只需要采用JSON格式。现在在R中工作:

library(httr)
library(jsonlite)

username = "[email protected]"
personal_access_token = "mytoken"
url = "https://provider/api/query/dataset"

query_json <- data.frame(eClass = "Fermentation", 
                         collection = "fermentations")
filters <- data.frame(field = "attributes.experiment", 
                      value = "expnumber")
query_json[1, "filters"][[1]] <- list(filters)
query_json <- toJSON(query_json)

response <- POST(url,
                 add_headers("Content-Type" = "application/json"),
                 authenticate(username, personal_access_token),
                 body = query_json, 
                 encode = 'json'
)

content(response)

After reading the documentation more closely, I found that the query just needed to be in JSON format. The following works in R now:

library(httr)
library(jsonlite)

username = "[email protected]"
personal_access_token = "mytoken"
url = "https://provider/api/query/dataset"

query_json <- data.frame(eClass = "Fermentation", 
                         collection = "fermentations")
filters <- data.frame(field = "attributes.experiment", 
                      value = "expnumber")
query_json[1, "filters"][[1]] <- list(filters)
query_json <- toJSON(query_json)

response <- POST(url,
                 add_headers("Content-Type" = "application/json"),
                 authenticate(username, personal_access_token),
                 body = query_json, 
                 encode = 'json'
)

content(response)

翻译Python(请求)API调用为R(HTTR)

执手闯天涯 2025-02-17 23:29:40

您可以通过覆盖 has_add_permision() admin.py.py 文件中覆盖 has_add_permision()来设置该特定模型的限制。例如:

admin.py 文件:

# Let's say you have a model called Post
from django.contrib import admin
from .models import Post

MAX_OBJECTS = 5

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
     list_display = ['field 1', 'field 2', 'etc.']
     # other class attributes can be set here as well.

     # To allow the user to be able to add only 5 objects/rows for this model (The Post Model).
     def has_add_permission(self, request):
          if self.model.objects.count() >= MAX_OBJECTS:
               return False
          return super().has_add_permission(request)

这是您可以采用的一种方法,但是不会有任何错误消息。如果有五个现有,则添加按钮将在Django管理站点上不可见。

您还可以了解有关在 docs

You could set a restriction on that particular model by overriding the has_add_permission() in the admin.py file. For example:

admin.py file:

# Let's say you have a model called Post
from django.contrib import admin
from .models import Post

MAX_OBJECTS = 5

@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
     list_display = ['field 1', 'field 2', 'etc.']
     # other class attributes can be set here as well.

     # To allow the user to be able to add only 5 objects/rows for this model (The Post Model).
     def has_add_permission(self, request):
          if self.model.objects.count() >= MAX_OBJECTS:
               return False
          return super().has_add_permission(request)

That's an approach you could take, but there won't be any error messages though. If there are five existing rows then the add button will not be visible on the Django admin site.

You can also learn more about customizing the Django admin site in the docs.

我想设置仅5行的行,该行将从django.models admin面板上添加

执手闯天涯 2025-02-17 22:01:21

好的,首先,将一组字符[例如:重音]转换为同等形式[例如:未重新审议],称为“音译”。

INTL扩展提供了一个方便的音译类课程,我们可以简单地调用它:

$translit = Transliterator::create('Latin-ASCII;');
$foo = $translit->transliterate('Français'); // Francais

因此,不需要维护“不必要的”字符及其替代品的清单。

其次,重音字符并不总是单个编码点,ç可以由统一的codepoint表示,或者由普通 c 组成的两个编码序列和代表组合标记的序列表示。口音。

包含单个视觉字形的单元称为素数。

第三,您的要求[case-insensitve 不敏感的]本质上要求我们必须构建自己的自定义字符串匹配过程。

首先,我们需要一个闪光灯来正确穿越UTF8字符串。 INTL的 intlbreakiterator :: createCharacterInstance()进行繁重的举重,但返回字节偏移,因此让我们将其包裹在另一个迭代器中,该迭代器实际上弹出了图形:

class GraphemeIterator implements \Iterator {
    protected $i, $string, $offset;
    
    public function __construct($string) {
        $this->string = $string;
        
        $i = IntlBreakIterator::createCharacterInstance();
        $i->setText($string);
        $this->i = $i->getIterator();
        
        $this->init();
    }
    
    protected function init() {
        $this->offset = $this->i->current();
        $this->i->next();
    }
    
    public function length() {
        return grapheme_strlen($this->string);
    }
    
    public function tell() {
        return [ $this->offset, $this->i->current()];
    }
    
    // Iterator Interface functions
    public function current(): mixed {
        return substr($this->string, $this->offset, $this->i->current() - $this->offset);
    }
    
    public function key(): mixed {
        return $this->i->key();
    }
    
    public function next(): void {
        $this->offset = $this->i->current();
        $this->i->next();
    }
    
    public function rewind(): void {
        $this->i->rewind();
        $this->init();
    }
    
    public function valid(): bool {
        return $this->i->valid();
    }
}

现在,我们需要可以在应用两条派上的两个字符串后使用任意符号的东西比较:

class TransformingComparator {
    protected $transforms = [];
    
    public function __construct(array $transforms) {
        foreach($transforms as $transform) {
            $this->addTransform($transform);
        }
    }
    
    protected function addTransform(callable $transform) {
        $this->transforms[] = $transform;
    }
    
    protected function transform($input) {
        $output = $input;
        foreach($this->transforms as $transform) {
            $output = $transform($output);
        }
        return $output;
    }
    
    public function compare($a, $b) {
        return $this->transform($a) <=> $this->transform($b);
    }
}

一个可以使用这些函数来定位搜索字符串的出现:

function findAllInGraphemeString($needle, $haystack, $comparator) {
    $t_it = new GraphemeIterator($haystack);
    $s_it = new GraphemeIterator($needle);
    
    $s = 0;
    $sl = $s_it->length();
    
    $out = [];
    $cur = [];
    
    for( $t=0, $tl=$t_it->length(); $t<$tl; ++$t ) {
        if( $comparator($t_it->current(), $s_it->current()) === 0 ) {
            if( empty($cur) ) {
                $cur[] = $t_it->tell()[0];
            }
            if( ++$s >= $sl ) {
                $cur[] = $t_it->tell()[1];
                $out[] = $cur;
                $cur = [];
                $s = 0;
                $s_it->rewind();
            } else {
                $s_it->next();
            }
            $t_it->next();
        } else {
            // on aborted partial match restart from current
            if( count($cur) != 0 ) {
                $s = 0;
                $cur=[];
                --$t;
            } else {
                $t_it->next();
            }
            $s_it->rewind();
        }
    }
    
    return $out;
}

最后一个可以执行实际转换的函数:

function transformSubstrings(string $text, array $boundaries, callable $transform) {
    $output = '';
    $offset = 0;
    
    foreach($boundaries as $bound) {
        $output .= substr($text, $offset, $bound[0]-$offset);
        $output .= $transform(substr($text, $bound[0], $bound[1]-$bound[0]));
        $offset = $bound[1];
    }
    return $output . substr($text, $bound[1]);
}

我们最终可以将其放在::

$translit = Transliterator::create('Latin-ASCII;');
$transforms = [
    [$translit, 'transliterate'], // remove accents
    'mb_strtolower'
];
$tc = new TransformingComparator($transforms);

$text = 'lorem ipsum frFrançais dolor sit français amet adsplicing dit';
$search = 'Francais';

echo transformSubstrings(
    $text,
    findAllInGraphemeString($search, $text, [$tc, 'compare']),
    function($a){
        return sprintf('<mark>%s</mark>', $a);
    }
);

output:

lorem ipsum <mark>Français</mark> dolor sit <mark>français</mark> amet adsplicing dit <mark>francais</mark>

是的:是的,是的,我得到了 nerd sniped hard 在这一上。


编辑:既然您已经提到了Collat​​ions INTL具有 collat​​or 类,并且看起来 transforkingcomparator 现在更长的相关性,可以像以下方式替换:

$col = new Collator('fr-ca'); // or whatever locale you're using
$col->setStrength(Collator::PRIMARY);
// ...
transformSubstrings(
    $text,
    findAllInGraphemeString($search, $text, [$col, 'compare']),
    function($a){
        return sprintf('<mark>%s</mark>', $a);
    }
)

这也可能会更快一些,因为它可能使用查找而不是运行所有变换。

Okay so first of all, converting one set of characters [eg: accented] to an equivalent form [eg: unaccented] according to some rules is called "transliteration".

The intl extension provides a handy transliterator class that we can invoke with simply:

$translit = Transliterator::create('Latin-ASCII;');
$foo = $translit->transliterate('Français'); // Francais

So painstakingly maintaining a list of "unwanted" characters and their replacements is not necessary.

Secondly, accented characters are not always single codepoints, ç may be represented by either the unified codepoint, or a two-codepoint sequence consisting of a plain c and a combining mark representing the accent.

The unit comprising a single visual glyph is referred to as a Grapheme.

Thirdly, the your requirements [case-insensitve and accent-insensitive] essentially requires that we have to build our own custom string matching procedure.

First, we need a GraphemeIterator to traverse the UTF8 string properly. intl's IntlBreakIterator::createCharacterInstance() does the heavy lifting, but returns byte offsets, so lets wrap that in another iterator that actually pops out graphemes:

class GraphemeIterator implements \Iterator {
    protected $i, $string, $offset;
    
    public function __construct($string) {
        $this->string = $string;
        
        $i = IntlBreakIterator::createCharacterInstance();
        $i->setText($string);
        $this->i = $i->getIterator();
        
        $this->init();
    }
    
    protected function init() {
        $this->offset = $this->i->current();
        $this->i->next();
    }
    
    public function length() {
        return grapheme_strlen($this->string);
    }
    
    public function tell() {
        return [ $this->offset, $this->i->current()];
    }
    
    // Iterator Interface functions
    public function current(): mixed {
        return substr($this->string, $this->offset, $this->i->current() - $this->offset);
    }
    
    public function key(): mixed {
        return $this->i->key();
    }
    
    public function next(): void {
        $this->offset = $this->i->current();
        $this->i->next();
    }
    
    public function rewind(): void {
        $this->i->rewind();
        $this->init();
    }
    
    public function valid(): bool {
        return $this->i->valid();
    }
}

Now we need something that can compare two strings after applying some arbitrary comparisons:

class TransformingComparator {
    protected $transforms = [];
    
    public function __construct(array $transforms) {
        foreach($transforms as $transform) {
            $this->addTransform($transform);
        }
    }
    
    protected function addTransform(callable $transform) {
        $this->transforms[] = $transform;
    }
    
    protected function transform($input) {
        $output = $input;
        foreach($this->transforms as $transform) {
            $output = $transform($output);
        }
        return $output;
    }
    
    public function compare($a, $b) {
        return $this->transform($a) <=> $this->transform($b);
    }
}

and a function that can use those to locate the occurrences of the search string:

function findAllInGraphemeString($needle, $haystack, $comparator) {
    $t_it = new GraphemeIterator($haystack);
    $s_it = new GraphemeIterator($needle);
    
    $s = 0;
    $sl = $s_it->length();
    
    $out = [];
    $cur = [];
    
    for( $t=0, $tl=$t_it->length(); $t<$tl; ++$t ) {
        if( $comparator($t_it->current(), $s_it->current()) === 0 ) {
            if( empty($cur) ) {
                $cur[] = $t_it->tell()[0];
            }
            if( ++$s >= $sl ) {
                $cur[] = $t_it->tell()[1];
                $out[] = $cur;
                $cur = [];
                $s = 0;
                $s_it->rewind();
            } else {
                $s_it->next();
            }
            $t_it->next();
        } else {
            // on aborted partial match restart from current
            if( count($cur) != 0 ) {
                $s = 0;
                $cur=[];
                --$t;
            } else {
                $t_it->next();
            }
            $s_it->rewind();
        }
    }
    
    return $out;
}

and finally a function that can perform the actual transformation:

function transformSubstrings(string $text, array $boundaries, callable $transform) {
    $output = '';
    $offset = 0;
    
    foreach($boundaries as $bound) {
        $output .= substr($text, $offset, $bound[0]-$offset);
        $output .= $transform(substr($text, $bound[0], $bound[1]-$bound[0]));
        $offset = $bound[1];
    }
    return $output . substr($text, $bound[1]);
}

We can finally put this together as::

$translit = Transliterator::create('Latin-ASCII;');
$transforms = [
    [$translit, 'transliterate'], // remove accents
    'mb_strtolower'
];
$tc = new TransformingComparator($transforms);

$text = 'lorem ipsum frFrançais dolor sit français amet adsplicing dit';
$search = 'Francais';

echo transformSubstrings(
    $text,
    findAllInGraphemeString($search, $text, [$tc, 'compare']),
    function($a){
        return sprintf('<mark>%s</mark>', $a);
    }
);

Output:

lorem ipsum <mark>Français</mark> dolor sit <mark>français</mark> amet adsplicing dit <mark>francais</mark>

and yes, I got nerd sniped hard on this one.


Edit: Now that you've mentioned collations it occurs to me that intl has a Collator class, and it looks like TransformingComparator is now longer relevant and can be substituted out like:

$col = new Collator('fr-ca'); // or whatever locale you're using
$col->setStrength(Collator::PRIMARY);
// ...
transformSubstrings(
    $text,
    findAllInGraphemeString($search, $text, [$col, 'compare']),
    function($a){
        return sprintf('<mark>%s</mark>', $a);
    }
)

Which will likely also be a fair bit faster, since it's likely using a lookup instead of running all the transforms.

php str_ireplace同一个词带有口音是否

执手闯天涯 2025-02-17 17:25:58

您需要检查浏览器的控制台和网络选项卡。很可能是 cors jupares

You need to check your browser's console and Network tab. Most probably it's the CORS issue

数据不使用自定义URL Axios React fitchs

执手闯天涯 2025-02-17 15:22:15

该函数的每个专业化都有其自己的静态变量副本。


编译器是否为每个函数调用创建一个单独的函数?

相反,对于每组使用的模板参数集。

Each specialization of the function gets its own copy of the static variable.


Does the compiler create a separate function for each function invocation?

Rather, for each used set of template arguments.

变量模板功能中的静态变量

执手闯天涯 2025-02-17 12:19:33

这是我设法解决此问题的方式,使用 bytematchstatement 比较主机标头 starts_with '{clientname}',希望它可以帮助某人:

{
  "Name": "foobar-acl",
  "DefaultAction": {
    "Allow": {}
  },
  "Description": "",
  "Rules": [
    {
      "Name": "rate-limit-main",
      "Priority": 0,
      "Statement": {
        "RateBasedStatement": {
          "Limit": 3000,
          "AggregateKeyType": "IP"
        }
      },
      "Action": {
        "Block": {
          "CustomResponse": {
            "ResponseCode": 429,
            "CustomResponseBodyKey": "html_responce"
          }
        }
      },
      "VisibilityConfig": {
        "SampledRequestsEnabled": false,
        "CloudWatchMetricsEnabled": false,
        "MetricName": "foobar-rate-limit-main"
      }
    },
    {
      "Name": "rate-limit-clientname",
      "Priority": 1,
      "Statement": {
        "RateBasedStatement": {
          "Limit": 100,
          "AggregateKeyType": "IP",
          "ScopeDownStatement": {
            "ByteMatchStatement": {
              "SearchString": "clientname",
              "FieldToMatch": {
                "SingleHeader": {
                  "Name": "host"
                }
              },
              "TextTransformations": [
                {
                  "Priority": 1,
                  "Type": "NONE"
                }
              ],
              "PositionalConstraint": "STARTS_WITH"
            }
          }
        }
      },
      "Action": {
        "Block": {
          "CustomResponse": {
            "ResponseCode": 409,
            "CustomResponseBodyKey": "html_responce"
          }
        }
      },
      "VisibilityConfig": {
        "SampledRequestsEnabled": false,
        "CloudWatchMetricsEnabled": true,
        "MetricName": "foobar-clientname"
      }
    },
    {
      "Name": "rate-limit-clientname2",
      "Priority":21,
      "Statement": {
        "RateBasedStatement": {
          "Limit": 100,
          "AggregateKeyType": "IP",
          "ScopeDownStatement": {
            "ByteMatchStatement": {
              "SearchString": "clientname2",
              "FieldToMatch": {
                "SingleHeader": {
                  "Name": "host"
                }
              },
              "TextTransformations": [
                {
                  "Priority": 2,
                  "Type": "NONE"
                }
              ],
              "PositionalConstraint": "STARTS_WITH"
            }
          }
        }
      },
      "Action": {
        "Block": {
          "CustomResponse": {
            "ResponseCode": 409,
            "CustomResponseBodyKey": "html_responce"
          }
        }
      },
      "VisibilityConfig": {
        "SampledRequestsEnabled": false,
        "CloudWatchMetricsEnabled": true,
        "MetricName": "foobar-clientname2"
      }
    }
  ],
  "VisibilityConfig": {
    "SampledRequestsEnabled": false,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "foobar-acl"
  },
  "Capacity": 6,
  "ManagedByFirewallManager": false,
  "CustomResponseBodies": {
    "html_responce": {
      "ContentType": "TEXT_HTML",
      "Content": "<div>You exceeded the maximum number of requests !</div>"
    }
  }
}

Here is how I managed to solve this, used ByteMatchStatement comparing if the host header STARTS_WITH '{clientname}', hope it helps someone:

{
  "Name": "foobar-acl",
  "DefaultAction": {
    "Allow": {}
  },
  "Description": "",
  "Rules": [
    {
      "Name": "rate-limit-main",
      "Priority": 0,
      "Statement": {
        "RateBasedStatement": {
          "Limit": 3000,
          "AggregateKeyType": "IP"
        }
      },
      "Action": {
        "Block": {
          "CustomResponse": {
            "ResponseCode": 429,
            "CustomResponseBodyKey": "html_responce"
          }
        }
      },
      "VisibilityConfig": {
        "SampledRequestsEnabled": false,
        "CloudWatchMetricsEnabled": false,
        "MetricName": "foobar-rate-limit-main"
      }
    },
    {
      "Name": "rate-limit-clientname",
      "Priority": 1,
      "Statement": {
        "RateBasedStatement": {
          "Limit": 100,
          "AggregateKeyType": "IP",
          "ScopeDownStatement": {
            "ByteMatchStatement": {
              "SearchString": "clientname",
              "FieldToMatch": {
                "SingleHeader": {
                  "Name": "host"
                }
              },
              "TextTransformations": [
                {
                  "Priority": 1,
                  "Type": "NONE"
                }
              ],
              "PositionalConstraint": "STARTS_WITH"
            }
          }
        }
      },
      "Action": {
        "Block": {
          "CustomResponse": {
            "ResponseCode": 409,
            "CustomResponseBodyKey": "html_responce"
          }
        }
      },
      "VisibilityConfig": {
        "SampledRequestsEnabled": false,
        "CloudWatchMetricsEnabled": true,
        "MetricName": "foobar-clientname"
      }
    },
    {
      "Name": "rate-limit-clientname2",
      "Priority":21,
      "Statement": {
        "RateBasedStatement": {
          "Limit": 100,
          "AggregateKeyType": "IP",
          "ScopeDownStatement": {
            "ByteMatchStatement": {
              "SearchString": "clientname2",
              "FieldToMatch": {
                "SingleHeader": {
                  "Name": "host"
                }
              },
              "TextTransformations": [
                {
                  "Priority": 2,
                  "Type": "NONE"
                }
              ],
              "PositionalConstraint": "STARTS_WITH"
            }
          }
        }
      },
      "Action": {
        "Block": {
          "CustomResponse": {
            "ResponseCode": 409,
            "CustomResponseBodyKey": "html_responce"
          }
        }
      },
      "VisibilityConfig": {
        "SampledRequestsEnabled": false,
        "CloudWatchMetricsEnabled": true,
        "MetricName": "foobar-clientname2"
      }
    }
  ],
  "VisibilityConfig": {
    "SampledRequestsEnabled": false,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "foobar-acl"
  },
  "Capacity": 6,
  "ManagedByFirewallManager": false,
  "CustomResponseBodies": {
    "html_responce": {
      "ContentType": "TEXT_HTML",
      "Content": "<div>You exceeded the maximum number of requests !</div>"
    }
  }
}

AWS WAF率限制每个主机名

执手闯天涯 2025-02-17 02:54:31

由于自动对焦不起作用,因此您可以尝试 settimeout

我所做的是检查 openSearchId true
demo

  React.useEffect(() => {
    if (openSearchId) {
      setTimeout(() => {
        inputRef.current?.focus();
        console.log("focused");
      }, 300);
    }
  }, [openSearchId]);

对您有用吗?当然,您可以更改MILLIS。

Since autofocus is not working, then you can try with setTimeout.

What I did was to check if openSearchId is true
Demo

  React.useEffect(() => {
    if (openSearchId) {
      setTimeout(() => {
        inputRef.current?.focus();
        console.log("focused");
      }, 300);
    }
  }, [openSearchId]);

Does this work for you? You can change the millis of course.

如何专注于React中动态添加的输入字段

执手闯天涯 2025-02-16 20:18:20

尝试以下操作:

with cte as ( 
select timest, 1 as stsVal from created
  union all
select timest, -1 as stsVal from deleted
 ),
  cte2 as
 (
 select T1.timest,T1.stsVal from
 cte T1 inner join 
   (select timest, sum(stsVal) from cte
    group by timest having sum(stsVal) <> 0) T2
 on T1.timest=T2.timest
 )
 select distinct timest,sum(stsVal) over (order by timest) as numberofitems from cte2

第一个 cte 是将两个表合并到一个表中,并为创建的日期设置1个值1,删除日期为-1。此值存储在 stsval 中。

对于使用相同的时间戳和相同数量的条目删除的, sum(stsval)将为零,因此在 cte2 中,所有 stsval的总和代码>对于每个时间戳计算,不包括<代码>具有sum(stsval)&lt;&gt; 0 的零和。

现在,使用 cte2 我们可以为每个时间戳找到 stsval 的累加总和。

请参阅在这里的演示。

该演示在 mysql 8.0 中,如果您知道一个人友善地更新我,我找不到 presto 的在线操场。

Try the following:

with cte as ( 
select timest, 1 as stsVal from created
  union all
select timest, -1 as stsVal from deleted
 ),
  cte2 as
 (
 select T1.timest,T1.stsVal from
 cte T1 inner join 
   (select timest, sum(stsVal) from cte
    group by timest having sum(stsVal) <> 0) T2
 on T1.timest=T2.timest
 )
 select distinct timest,sum(stsVal) over (order by timest) as numberofitems from cte2

The first cte is to merge the two tables into one and set a value of 1 for created dates and a value of -1 for deleted dates. This value stored in stsVal.

For created and deleted with the same timestamp and same number of entries, the sum(stsVal) will be zero, so in cte2 the sum of all stsVal for each timestamp is calculated excluding zero sums by having sum(stsVal)<>0.

Now, using cte2 we can find the accumulative sum of stsVal for each timestamp.

See a demo from here.

The demo is in MySQL 8.0, I couldn't find an online playground for Presto, if you know one kindly update me.

SQL汇总事件由时间戳计数

执手闯天涯 2025-02-16 06:40:25

在Shell中编写代码时,您只能做很多事情,但让我们从基础知识开始。

  • 命令替换, $(...),很昂贵:他们需要创建一个FIFO, fork()新的子过程,将FIFO连接到该子过程的Stdout,阅读从FIFO,等待在该子壳中运行的命令退出。
  • 外部命令(例如 cat )很昂贵:它们需要链接并加载单独的可执行文件;当您在没有 exec 的情况下运行它们(在这种情况下,它们继承并消耗了Shell的进程ID)时,它们也需要一个新的过程才能 fork()< /代码> off。

所有符合POSIX的外壳都会为您提供读取命令:

for sensor_node in /sys/class/thermal/thermal_zone*; do
  read -r sensor_type <"$sensor_node/type" || continue
  read -r sensor_temp <"$sensor_node/temp" || continue
  printf '%s: %s\n' "$sensor_type" "$sensor_temp"
done

...您可以避免命令替换开销和 cat 的开销。但是,读取一次仅读取一个字节;因此,尽管您没有支付开销,但它仍然相对较慢。

如果您从/bin/sh 切换到 bash ,则获得更快的替代方案:

for sensor_node in /sys/class/thermal/thermal_zone*; do
  printf '%s: %s\n' "$(<"$sensor_node/type)" "$(<"$sensor_node/temp")"
done

... AS $(&lt; file) don' t需要进行单字节读取读取做的读取。但是,这只是bash 的速度更快。这并不意味着它实际上是 fast 。现代生产监控系统通常是在 go 或使用javascript运行时(如Node)。

There's only so much you can do while writing your code in shell, but let's start with the basics.

  • Command substitutions, $(...), are expensive: They require creating a FIFO, fork()ing a new subprocess, connecting the FIFO to that subprocess's stdout, reading from the FIFO and waiting for the commands running in that subshell to exit.
  • External commands, like cat, are expensive: They require linking and loading a separate executable; and when you run them without exec (in which case they inherit and consume the shell's process ID), they also require a new process to be fork()ed off.

All POSIX-compliant shells give you a read command:

for sensor_node in /sys/class/thermal/thermal_zone*; do
  read -r sensor_type <"$sensor_node/type" || continue
  read -r sensor_temp <"$sensor_node/temp" || continue
  printf '%s: %s\n' "$sensor_type" "$sensor_temp"
done

...which lets you avoid the command substitution overhead and the overhead of cat. However, read reads content only one byte at a time; so while you're not paying that overhead, it's still relatively slow.

If you switch from /bin/sh to bash, you get a faster alternative:

for sensor_node in /sys/class/thermal/thermal_zone*; do
  printf '%s: %s\n' "$(<"$sensor_node/type)" "$(<"$sensor_node/temp")"
done

...as $(<file) doesn't need to do the one-byte-at-a-time reads that read does. That's only faster for being bash, though; it doesn't mean it's actually fast. There's a reason modern production monitoring systems are typically written in Go or with a JavaScript runtime like Node.

Linux-更快地读取或收集文件内容(例如,每秒钟的CPU温度)。

执手闯天涯 2025-02-16 03:45:34

尝试此

<div class="dt">{{transaction.transactionDate | shortDate}}</div>

尝试添加独立:true 标志到管道装饰器

@Pipe({
  name: 'shortDate',
  standalone: true
})

Try this

<div class="dt">{{transaction.transactionDate | shortDate}}</div>

Try adding standalone: true flag to the Pipe decorator

@Pipe({
  name: 'shortDate',
  standalone: true
})

Angular 13看不到自定义管道

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文