待"谢繁草

文章 评论 浏览 28

待"谢繁草 2025-02-21 01:20:46

以前的大多数答案都清除了有关切片符号的问题。

用于切片的扩展索引语法是alist [start:stop:step],基本示例为:

“输入图像描述这里“

更多切片示例:

Most of the previous answers clears up questions about slice notation.

The extended indexing syntax used for slicing is aList[start:stop:step], and basic examples are:

Enter image description here:

More slicing examples: 15 Extended Slices

Python中的切片如何工作

待"谢繁草 2025-02-20 17:28:43

您可以在超级集中添加列。悬停在标题上的“源”上,然后选择“表”。然后从那里选择编辑表记录的选项。在此您可以添加计算的列/自定义列。
要添加holder_type的列,让我们将自定义列命名为lands_type。用varchar(100)填充新列的数据类型。从下拉菜单中选择表。在表达式中,将json_column->“ $。所有者_type”,然后点击保存。此表达式用于MySQL数据库。您可以在您的特定DB中找到解析JSON的表达式。

You can add columns to your table in Superset. Hover on 'Sources' on the header and select 'Tables'. Then from there, choose the option to edit the record of your table. In that you can add a calculated column/custom column.
To add a column for owner_type, lets name the custom column as owner_type. Fill the datatype for the new column as VARCHAR(100). Choose the table from the dropdown. In the expression, put json_column->"$.owner_type" and then hit save. This expression is for MySQL database. You can find the expression to parse JSON in your particular DB.

如何在超集中设置自定义字段?

待"谢繁草 2025-02-19 19:45:24

一些代码应该更容易,但这是Spring Boot和Maven的工作示例。

我在文件夹src/main/resources/模板中有一个称为“ myTemplate.html”的模板。

在我的一堂课中,我有:

ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);

TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context context = new Context();
//... then here i fill all the variables used in my template

String filledTemplate = templateEngine.process("templates/myTemplate", context);

一切正常,

希望它能有所帮助:)

it should be easier with some code, but here is a working example with spring boot and Maven.

I have a template called "myTemplate.html" in the folder src/main/resources/templates.

In one of my class I have :

ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);

TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context context = new Context();
//... then here i fill all the variables used in my template

String filledTemplate = templateEngine.process("templates/myTemplate", context);

And everything works as expected

Hope it helps a bit :)

错误解决模板***,模板可能不存在或可能无法通过任何配置的模板解析器访问

待"谢繁草 2025-02-18 17:41:40

您可以使用比Wander Nauta的复杂结构,但是您有一个更改事物的空间。

将您的IPS放入c:\ tmp \ ips.txt用新行类似:

192.168.1.1
1.1.1.1
1.2.3.4

start脚本:

Clear-Host
$ips = Get-Content "C:\tmp\ips.txt"
foreach($ip in $ips) {
    if(Test-Connection $ip -Count 1 -ErrorAction SilentlyContinue) {
        #Write-Output "Alive ip - $ip"
    } else {
        Write-Output "Dead ip - $ip"
    }
}

结果:Dead ip -1.2.3.4 spline sward

You can use a bit complex construction than Wander Nauta, but you have a room to change things.

Put your IPs in C:\tmp\ips.txt splitted with new line like:

192.168.1.1
1.1.1.1
1.2.3.4

And start script:

Clear-Host
$ips = Get-Content "C:\tmp\ips.txt"
foreach($ip in $ips) {
    if(Test-Connection $ip -Count 1 -ErrorAction SilentlyContinue) {
        #Write-Output "Alive ip - $ip"
    } else {
        Write-Output "Dead ip - $ip"
    }
}

The result will be: Dead ip - 1.2.3.4

我想过滤ping

待"谢繁草 2025-02-18 17:41:01

从单个字符串的角度(在您的Strin中)考虑中间的例子,您要求JSON加载。通过添加第一个,您是一个人缩小所有字符串:

h = '"[{"b": [2, 4], "c": 3.0, "a": "A"}]"'
      --   ----------   -------   --
Strings surrounded by quotes

因此,当您首次达到非字符串b时,JSON不知道该怎么办。如果您想要将整个内容视为字符串,您需要逃脱引号\\“。因此看起来像这样:

h = '"[{\\"b\\": [2, 4], \\"c\\": 3.0, \\"a\\": \\"A\\"}]"'

Consider the middle example, from the perspective of individual strings (within your strin), you are asking json to load. By adding the first ", you are shifing all strings by one:

h = '"[{"b": [2, 4], "c": 3.0, "a": "A"}]"'
      --   ----------   -------   --
Strings surrounded by quotes

So when you first reach a non string b, json has no idea what to do with it. If you want to treat the entire content as a string, you need to escape the quotes \\". So it would look like this:

h = '"[{\\"b\\": [2, 4], \\"c\\": 3.0, \\"a\\": \\"A\\"}]"'

Python JSON.LOADS格式

待"谢繁草 2025-02-18 04:34:08

据我了解,XSD(甚至1.1)都没有提供将混合内容文本限制为简单类型的方法,因此,如果您真的需要该元素,则唯一的方法似乎是做一个断言;这意味着,不幸的是,您需要复制一个属性的值。

因此,有些(略微适应,请参阅我对“ @until ='随机'检查)样本模式的评论

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
    
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
                <xs:element name="instruction" maxOccurs="unbounded" minOccurs="0">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="type">
                                <xs:alternative test="@until = 'random'" type="complexTypeContent"/>
                                <xs:alternative type="simpleTypeContent"/>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>  
    
    <xs:complexType name="complexTypeContent" mixed="true">
        <xs:complexContent>
            <xs:extension base="simpleTypeContent">
                <xs:sequence>
                    <xs:element name="random" type="random" minOccurs="0" maxOccurs="1"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:complexType name="random">
        <xs:attribute name="start">
            <xs:simpleType>
                <xs:restriction base="xs:integer"/>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="end">
            <xs:simpleType>
                <xs:restriction base="xs:integer"/>
            </xs:simpleType>
        </xs:attribute>
        <xs:assert test="@start le @end"/>
    </xs:complexType>
    
    <xs:complexType name="simpleTypeContent" mixed="true">
        <xs:attribute name="until">
            <xs:simpleType>
                <xs:union memberTypes="type2 annotation xs:integer until"/>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="condition">
            <xs:simpleType>
                <xs:union memberTypes="type2 annotation extended"/>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="repeat" type='xs:integer'/>
        <xs:assert test=". = ('Dice Roll', 'Wait', 'Repeat', 'Double Roll', 'Instruction')"/>
    </xs:complexType>

    <xs:simpleType name="type2">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Dice Roll"/>
            <xs:enumeration value="Wait"/>
            <xs:enumeration value="Repeat"/>
            <xs:enumeration value="Double Roll"/>
            <xs:enumeration value="Instruction"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="until">
        <xs:restriction base="xs:string">
            <xs:enumeration value="end"/>
            <xs:enumeration value="random"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="annotation">
        <xs:restriction base="xs:string">
            <xs:enumeration value="rolltwice"/>
            <xs:enumeration value="halfcount"/>
            <xs:enumeration value="doublecount"/>
            <xs:enumeration value="roll-"/>
            <xs:enumeration value="roll+"/>
            <xs:enumeration value="numberChange"/>
            <xs:enumeration value="NoNumberChange"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="extended">
        <xs:restriction base="xs:string">
            <xs:enumeration value="noRolling"/>
            <xs:enumeration value="noEven"/>
            <xs:enumeration value="noUneven"/>
            <xs:enumeration value="stopped"/>
        </xs:restriction> 
    </xs:simpleType>    
</xs:schema>

,然后在下面的样本中制作第一个指令模式和示例(dice Roll vs. dice roll)之间的差异)有效,而第二个则无效:

<root>
    <instruction>
        <type repeat='1' until='random'><random start='1' end='6'/>Dice Roll</type>
    </instruction>
    <instruction>
        <type repeat='1' until='2'><random start='1' end='6'/>Dice Roll</type>
    </instruction>
</root>

As far as I understand, XSD (not even 1.1) doesn't offer a way to restrict the mixed content text to some simple type, so the only way, if you really need that single element together with a certain list of values seems to be an assertion; that means, unfortunately, you need to duplicate the values you also want for an attribute.

So some (slightly adapted, see my comment about the `@until = 'random' check) sample schema would be

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
    
    <xs:element name="root">
        <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
                <xs:element name="instruction" maxOccurs="unbounded" minOccurs="0">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="type">
                                <xs:alternative test="@until = 'random'" type="complexTypeContent"/>
                                <xs:alternative type="simpleTypeContent"/>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>  
    
    <xs:complexType name="complexTypeContent" mixed="true">
        <xs:complexContent>
            <xs:extension base="simpleTypeContent">
                <xs:sequence>
                    <xs:element name="random" type="random" minOccurs="0" maxOccurs="1"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <xs:complexType name="random">
        <xs:attribute name="start">
            <xs:simpleType>
                <xs:restriction base="xs:integer"/>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="end">
            <xs:simpleType>
                <xs:restriction base="xs:integer"/>
            </xs:simpleType>
        </xs:attribute>
        <xs:assert test="@start le @end"/>
    </xs:complexType>
    
    <xs:complexType name="simpleTypeContent" mixed="true">
        <xs:attribute name="until">
            <xs:simpleType>
                <xs:union memberTypes="type2 annotation xs:integer until"/>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="condition">
            <xs:simpleType>
                <xs:union memberTypes="type2 annotation extended"/>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="repeat" type='xs:integer'/>
        <xs:assert test=". = ('Dice Roll', 'Wait', 'Repeat', 'Double Roll', 'Instruction')"/>
    </xs:complexType>

    <xs:simpleType name="type2">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Dice Roll"/>
            <xs:enumeration value="Wait"/>
            <xs:enumeration value="Repeat"/>
            <xs:enumeration value="Double Roll"/>
            <xs:enumeration value="Instruction"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="until">
        <xs:restriction base="xs:string">
            <xs:enumeration value="end"/>
            <xs:enumeration value="random"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="annotation">
        <xs:restriction base="xs:string">
            <xs:enumeration value="rolltwice"/>
            <xs:enumeration value="halfcount"/>
            <xs:enumeration value="doublecount"/>
            <xs:enumeration value="roll-"/>
            <xs:enumeration value="roll+"/>
            <xs:enumeration value="numberChange"/>
            <xs:enumeration value="NoNumberChange"/>
        </xs:restriction>
    </xs:simpleType>
    
    <xs:simpleType name="extended">
        <xs:restriction base="xs:string">
            <xs:enumeration value="noRolling"/>
            <xs:enumeration value="noEven"/>
            <xs:enumeration value="noUneven"/>
            <xs:enumeration value="stopped"/>
        </xs:restriction> 
    </xs:simpleType>    
</xs:schema>

and that then makes the first instruction in below sample (also slightly adapted as there was a spelling difference between the schema and the sample (Dice roll vs. Dice Roll) in your snippets) valid while the second is invalid:

<root>
    <instruction>
        <type repeat='1' until='random'><random start='1' end='6'/>Dice Roll</type>
    </instruction>
    <instruction>
        <type repeat='1' until='2'><random start='1' end='6'/>Dice Roll</type>
    </instruction>
</root>

带有元素和简单的XSD复杂型

待"谢繁草 2025-02-18 03:44:53

这就是您可以做的:

library(data.table)

# minimal example
set.seed(1)
DATA <- data.table(V1    = sample(3, 10, replace = T),
                   V7101 = sample(3, 10, replace = T),
                   V7102 = sample(3, 10, replace = T),
                   V712  = sample(3, 10, replace = T),
                   V7200 = sample(3, 10, replace = T),
                   V507  = sample(3, 10, replace = T))

# variables you need to cycle on
vars <- c("V7101", "V7102", "V712", "V7200")

# create all formulas you need (set names for clarity)
frms <- setNames(sprintf("V507 ~ %s + V1", vars), vars)

# cycle with lapply over your formulas
lapply(frms, function(frm) dcast(data = DATA, frm, fun.aggregate = length))
#> $V7101
#>    V507 1_1 1_2 1_3 2_1 2_2 2_3 3_1 3_2
#> 1:    1   0   0   0   0   0   1   0   0
#> 2:    2   1   1   2   1   1   1   0   1
#> 3:    3   0   0   0   0   0   0   1   0
#> 
#> $V7102
#>    V507 1_1 1_2 1_3 2_2 2_3 3_1
#> 1:    1   0   0   0   0   1   0
#> 2:    2   2   2   2   1   1   0
#> 3:    3   0   0   0   0   0   1
#> 
#> $V712
#>    V507 1_2 1_3 2_1 2_2 2_3 3_1 3_3
#> 1:    1   0   0   0   0   1   0   0
#> 2:    2   1   1   0   2   1   2   1
#> 3:    3   0   0   1   0   0   0   0
#> 
#> $V7200
#>    V507 1_1 1_3 2_1 2_2 3_1 3_3
#> 1:    1   0   1   0   0   0   0
#> 2:    2   1   1   0   3   1   2
#> 3:    3   0   0   1   0   0   0

在2022-06-28创建的 reprex package (v2(v2)。 0.1)

This is how you could do:

library(data.table)

# minimal example
set.seed(1)
DATA <- data.table(V1    = sample(3, 10, replace = T),
                   V7101 = sample(3, 10, replace = T),
                   V7102 = sample(3, 10, replace = T),
                   V712  = sample(3, 10, replace = T),
                   V7200 = sample(3, 10, replace = T),
                   V507  = sample(3, 10, replace = T))

# variables you need to cycle on
vars <- c("V7101", "V7102", "V712", "V7200")

# create all formulas you need (set names for clarity)
frms <- setNames(sprintf("V507 ~ %s + V1", vars), vars)

# cycle with lapply over your formulas
lapply(frms, function(frm) dcast(data = DATA, frm, fun.aggregate = length))
#> $V7101
#>    V507 1_1 1_2 1_3 2_1 2_2 2_3 3_1 3_2
#> 1:    1   0   0   0   0   0   1   0   0
#> 2:    2   1   1   2   1   1   1   0   1
#> 3:    3   0   0   0   0   0   0   1   0
#> 
#> $V7102
#>    V507 1_1 1_2 1_3 2_2 2_3 3_1
#> 1:    1   0   0   0   0   1   0
#> 2:    2   2   2   2   1   1   0
#> 3:    3   0   0   0   0   0   1
#> 
#> $V712
#>    V507 1_2 1_3 2_1 2_2 2_3 3_1 3_3
#> 1:    1   0   0   0   0   1   0   0
#> 2:    2   1   1   0   2   1   2   1
#> 3:    3   0   0   1   0   0   0   0
#> 
#> $V7200
#>    V507 1_1 1_3 2_1 2_2 3_1 3_3
#> 1:    1   0   1   0   0   0   0
#> 2:    2   1   1   0   3   1   2
#> 3:    3   0   0   1   0   0   0

Created on 2022-06-28 by the reprex package (v2.0.1)

我如何重复对多个变量的组对分类变量的频率/表分析

待"谢繁草 2025-02-18 02:05:32

⚠️功能组件

我认为,一种超级干净的方法是创建一个自定义挂钩,它提供了将回调传回设置器函数的能力,那么,在此之后精确地采取某些操作将是100%保证国家的更新。

通过查看这篇文章您可以理解如何制作usestatecallback hook。通过使用usestatecallback来定义状态,就像以下内容:

const [count, setCount] = useStateCallback(0);

const handleFooBar = () => {
  setCount(c => c + 1, () => { // The callback function
    // All actions here will be run exactly AFTER the update of the count state
  })
};

⚠️ Functional Components

I believe a super clean way would be to create a custom hook that provides the ability to pass a callback to the setter function, then it would be a 100% guarantee to do some actions exactly after the update of the state.

By taking a look at this post you can understand how to make the useStateCallback hook. Defining a state by using the useStateCallback would be like the following:

const [count, setCount] = useStateCallback(0);

const handleFooBar = () => {
  setCount(c => c + 1, () => { // The callback function
    // All actions here will be run exactly AFTER the update of the count state
  })
};

USESTATE SET方法不是立即反映更改

待"谢繁草 2025-02-17 15:53:09

iOS 14.0 +

使用iOS下方的扩展

import UniformTypeIdentifiers

extension NSURL {
    public func mimeType() -> String {
        if let pathExt = self.pathExtension,
            let mimeType = UTType(filenameExtension: pathExt)?.preferredMIMEType {
            return mimeType
        }
        else {
            return "application/octet-stream"
        }
    }
}

extension URL {
    public func mimeType() -> String {
        if let mimeType = UTType(filenameExtension: self.pathExtension)?.preferredMIMEType {
            return mimeType
        }
        else {
            return "application/octet-stream"
        }
    }
}

extension NSString {
    public func mimeType() -> String {
        if let mimeType = UTType(filenameExtension: self.pathExtension)?.preferredMIMEType {
            return mimeType
        }
        else {
            return "application/octet-stream"
        }
    }
}

extension String {
    public func mimeType() -> String {
        return (self as NSString).mimeType()
    }
}

14

mimeType.swift

import Foundation

internal let DEFAULT_MIME_TYPE = "application/octet-stream"

internal let mimeTypes = [
    "html": "text/html",
    "htm": "text/html",
    "shtml": "text/html",
    "css": "text/css",
    "xml": "text/xml",
    "gif": "image/gif",
    "jpeg": "image/jpeg",
    "jpg": "image/jpeg",
    "js": "application/javascript",
    "atom": "application/atom+xml",
    "rss": "application/rss+xml",
    "mml": "text/mathml",
    "txt": "text/plain",
    "jad": "text/vnd.sun.j2me.app-descriptor",
    "wml": "text/vnd.wap.wml",
    "htc": "text/x-component",
    "png": "image/png",
    "tif": "image/tiff",
    "tiff": "image/tiff",
    "wbmp": "image/vnd.wap.wbmp",
    "ico": "image/x-icon",
    "jng": "image/x-jng",
    "bmp": "image/x-ms-bmp",
    "svg": "image/svg+xml",
    "svgz": "image/svg+xml",
    "webp": "image/webp",
    "woff": "application/font-woff",
    "jar": "application/java-archive",
    "war": "application/java-archive",
    "ear": "application/java-archive",
    "json": "application/json",
    "hqx": "application/mac-binhex40",
    "doc": "application/msword",
    "pdf": "application/pdf",
    "ps": "application/postscript",
    "eps": "application/postscript",
    "ai": "application/postscript",
    "rtf": "application/rtf",
    "m3u8": "application/vnd.apple.mpegurl",
    "xls": "application/vnd.ms-excel",
    "eot": "application/vnd.ms-fontobject",
    "ppt": "application/vnd.ms-powerpoint",
    "wmlc": "application/vnd.wap.wmlc",
    "kml": "application/vnd.google-earth.kml+xml",
    "kmz": "application/vnd.google-earth.kmz",
    "7z": "application/x-7z-compressed",
    "cco": "application/x-cocoa",
    "jardiff": "application/x-java-archive-diff",
    "jnlp": "application/x-java-jnlp-file",
    "run": "application/x-makeself",
    "pl": "application/x-perl",
    "pm": "application/x-perl",
    "prc": "application/x-pilot",
    "pdb": "application/x-pilot",
    "rar": "application/x-rar-compressed",
    "rpm": "application/x-redhat-package-manager",
    "sea": "application/x-sea",
    "swf": "application/x-shockwave-flash",
    "sit": "application/x-stuffit",
    "tcl": "application/x-tcl",
    "tk": "application/x-tcl",
    "der": "application/x-x509-ca-cert",
    "pem": "application/x-x509-ca-cert",
    "crt": "application/x-x509-ca-cert",
    "xpi": "application/x-xpinstall",
    "xhtml": "application/xhtml+xml",
    "xspf": "application/xspf+xml",
    "zip": "application/zip",
    "epub": "application/epub+zip",
    "docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
    "mid": "audio/midi",
    "midi": "audio/midi",
    "kar": "audio/midi",
    "mp3": "audio/mpeg",
    "ogg": "audio/ogg",
    "m4a": "audio/x-m4a",
    "ra": "audio/x-realaudio",
    "3gpp": "video/3gpp",
    "3gp": "video/3gpp",
    "ts": "video/mp2t",
    "mp4": "video/mp4",
    "mpeg": "video/mpeg",
    "mpg": "video/mpeg",
    "mov": "video/quicktime",
    "webm": "video/webm",
    "flv": "video/x-flv",
    "m4v": "video/x-m4v",
    "mng": "video/x-mng",
    "asx": "video/x-ms-asf",
    "asf": "video/x-ms-asf",
    "wmv": "video/x-ms-wmv",
    "avi": "video/x-msvideo"
]

internal func MimeType(ext: String?) -> String {
    return mimeTypes[ext?.lowercased() ?? "" ] ?? DEFAULT_MIME_TYPE
}

extension NSURL {
    public func mimeType() -> String {
        return MimeType(ext: self.pathExtension)
    }
}

extension URL {
    public func mimeType() -> String {
        return MimeType(ext: self.pathExtension)
    }
}

extension NSString {
    public func mimeType() -> String {
        return MimeType(ext: self.pathExtension)
    }
}

extension String {
    public func mimeType() -> String {
        return (self as NSString).mimeType()
    }
}

如何使用

let string = "https://homepages.cae.wisc.edu/~ece533/images/boat.png"

let mimeType = string.mimeType()

nsurl 一起使用, url nsString string

参考2

iOS 14.0 +

Use the extensions

import UniformTypeIdentifiers

extension NSURL {
    public func mimeType() -> String {
        if let pathExt = self.pathExtension,
            let mimeType = UTType(filenameExtension: pathExt)?.preferredMIMEType {
            return mimeType
        }
        else {
            return "application/octet-stream"
        }
    }
}

extension URL {
    public func mimeType() -> String {
        if let mimeType = UTType(filenameExtension: self.pathExtension)?.preferredMIMEType {
            return mimeType
        }
        else {
            return "application/octet-stream"
        }
    }
}

extension NSString {
    public func mimeType() -> String {
        if let mimeType = UTType(filenameExtension: self.pathExtension)?.preferredMIMEType {
            return mimeType
        }
        else {
            return "application/octet-stream"
        }
    }
}

extension String {
    public func mimeType() -> String {
        return (self as NSString).mimeType()
    }
}

Below iOS 14

MimeType.swift

import Foundation

internal let DEFAULT_MIME_TYPE = "application/octet-stream"

internal let mimeTypes = [
    "html": "text/html",
    "htm": "text/html",
    "shtml": "text/html",
    "css": "text/css",
    "xml": "text/xml",
    "gif": "image/gif",
    "jpeg": "image/jpeg",
    "jpg": "image/jpeg",
    "js": "application/javascript",
    "atom": "application/atom+xml",
    "rss": "application/rss+xml",
    "mml": "text/mathml",
    "txt": "text/plain",
    "jad": "text/vnd.sun.j2me.app-descriptor",
    "wml": "text/vnd.wap.wml",
    "htc": "text/x-component",
    "png": "image/png",
    "tif": "image/tiff",
    "tiff": "image/tiff",
    "wbmp": "image/vnd.wap.wbmp",
    "ico": "image/x-icon",
    "jng": "image/x-jng",
    "bmp": "image/x-ms-bmp",
    "svg": "image/svg+xml",
    "svgz": "image/svg+xml",
    "webp": "image/webp",
    "woff": "application/font-woff",
    "jar": "application/java-archive",
    "war": "application/java-archive",
    "ear": "application/java-archive",
    "json": "application/json",
    "hqx": "application/mac-binhex40",
    "doc": "application/msword",
    "pdf": "application/pdf",
    "ps": "application/postscript",
    "eps": "application/postscript",
    "ai": "application/postscript",
    "rtf": "application/rtf",
    "m3u8": "application/vnd.apple.mpegurl",
    "xls": "application/vnd.ms-excel",
    "eot": "application/vnd.ms-fontobject",
    "ppt": "application/vnd.ms-powerpoint",
    "wmlc": "application/vnd.wap.wmlc",
    "kml": "application/vnd.google-earth.kml+xml",
    "kmz": "application/vnd.google-earth.kmz",
    "7z": "application/x-7z-compressed",
    "cco": "application/x-cocoa",
    "jardiff": "application/x-java-archive-diff",
    "jnlp": "application/x-java-jnlp-file",
    "run": "application/x-makeself",
    "pl": "application/x-perl",
    "pm": "application/x-perl",
    "prc": "application/x-pilot",
    "pdb": "application/x-pilot",
    "rar": "application/x-rar-compressed",
    "rpm": "application/x-redhat-package-manager",
    "sea": "application/x-sea",
    "swf": "application/x-shockwave-flash",
    "sit": "application/x-stuffit",
    "tcl": "application/x-tcl",
    "tk": "application/x-tcl",
    "der": "application/x-x509-ca-cert",
    "pem": "application/x-x509-ca-cert",
    "crt": "application/x-x509-ca-cert",
    "xpi": "application/x-xpinstall",
    "xhtml": "application/xhtml+xml",
    "xspf": "application/xspf+xml",
    "zip": "application/zip",
    "epub": "application/epub+zip",
    "docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
    "mid": "audio/midi",
    "midi": "audio/midi",
    "kar": "audio/midi",
    "mp3": "audio/mpeg",
    "ogg": "audio/ogg",
    "m4a": "audio/x-m4a",
    "ra": "audio/x-realaudio",
    "3gpp": "video/3gpp",
    "3gp": "video/3gpp",
    "ts": "video/mp2t",
    "mp4": "video/mp4",
    "mpeg": "video/mpeg",
    "mpg": "video/mpeg",
    "mov": "video/quicktime",
    "webm": "video/webm",
    "flv": "video/x-flv",
    "m4v": "video/x-m4v",
    "mng": "video/x-mng",
    "asx": "video/x-ms-asf",
    "asf": "video/x-ms-asf",
    "wmv": "video/x-ms-wmv",
    "avi": "video/x-msvideo"
]

internal func MimeType(ext: String?) -> String {
    return mimeTypes[ext?.lowercased() ?? "" ] ?? DEFAULT_MIME_TYPE
}

extension NSURL {
    public func mimeType() -> String {
        return MimeType(ext: self.pathExtension)
    }
}

extension URL {
    public func mimeType() -> String {
        return MimeType(ext: self.pathExtension)
    }
}

extension NSString {
    public func mimeType() -> String {
        return MimeType(ext: self.pathExtension)
    }
}

extension String {
    public func mimeType() -> String {
        return (self as NSString).mimeType()
    }
}

How to use

let string = "https://homepages.cae.wisc.edu/~ece533/images/boat.png"

let mimeType = string.mimeType()

Workes with NSURL, URL, NSString, String

Reference 1

Reference 2

Swift中的路径扩展和MIME类型的文件类型

待"谢繁草 2025-02-17 12:26:40

您可以使用CSS样式的Z-Index在顶部显示菜单。

#menu
{
z-index: 100;
}

You can use CSS style z-Index to show your menu on top.

#menu
{
z-index: 100;
}

固定位置div总是出现在顶部吗?

待"谢繁草 2025-02-17 07:50:33

做到这一点的一种方法是创建一个空列表和一个临时字符串变量,然后循环遍历字符串中的字母。对于每次迭代,您可以检查当前字符是否是数字。如果是这样,请将其附加到临时字符串。如果不是,请检查温度字符串是否为空。如果是空的,那就什么也不做。如果温度字符串中有一个值(例如'1345'),请将临时字符串值添加到列表中,然后将临时字符串的值重置为''。当循环结束时,临时字符串中有一个数字,因此您没有一个不完整的列表,因此您需要确保处理边缘情况。

这是一些伪代码:

list = []
temp = ''

for char in string {
    if char is digit {
        append char to temp
    }
    else {
        if temp != '' {
            append temp to list
            temp = ''
        }
    }
}

if temp != '' {
    append temp to list
}

One way to do this would be to create an empty list and a temporary string variable, then to loop through the letters in the string. For each iteration, you check if the current character is a digit. If it is, append it to to the temporary string. If it isn't, check if the temp string is empty. If it's empty, do nothing. If there's a value in the temp string (say, '1345'), add the temp string value to the list and reset the value of the temp string back to ''. You'll need to make sure you handle the edge case where there's a number in the temporary string when the loop ends also so you don't have an incomplete list.

Here's some pseudocode:

list = []
temp = ''

for char in string {
    if char is digit {
        append char to temp
    }
    else {
        if temp != '' {
            append temp to list
            temp = ''
        }
    }
}

if temp != '' {
    append temp to list
}

如何从没有正则的字符串中提取数字?

待"谢繁草 2025-02-17 06:56:36

您的清单是空的,您期望它打印什么?

尝试使用此

std::list<int> mlist;  // empty list
mlist.push_front(123); // add 123 to the beginning of the list
std::list<int>::iterator head = mlist.begin(); // iterator to the first element of the list
std::cout << *head << std::endl; // prints 123

代码,您可以使用auto而不是std :: list&lt; int&gt; :: iterator(编译器知道哪种类型<代码>头部必须是)。

std::list<int> mlist;  // empty list
mlist.push_front(123); // add 123 to the beginning of the list
auto head = mlist.begin(); // iterator to the first element of the list
std::cout << *head << std::endl; // prints 123

对于迭代变量,使用auto通常。

对于下一个和上一个,只需使用++和 - 与其他迭代器相同。

std::list<int> mlist;  // empty list
mlist.push_back(123); // add 123 to the end of the list
mlist.push_back(456); // add 456 to the end of the list
mlist.push_back(789); // add 789 to the end of the list
// loop through list from first to last, using ++
for (auto i = mlist.begin(); i != mlist.end(); ++i)
    std::cout << *i << '\n';

Your list is empty, what were you expecting it to print?

Try this instead

std::list<int> mlist;  // empty list
mlist.push_front(123); // add 123 to the beginning of the list
std::list<int>::iterator head = mlist.begin(); // iterator to the first element of the list
std::cout << *head << std::endl; // prints 123

You can make this code a bit shorter and more readable by using auto instead of std::list<int>::iterator (the compiler knows what type head must be).

std::list<int> mlist;  // empty list
mlist.push_front(123); // add 123 to the beginning of the list
auto head = mlist.begin(); // iterator to the first element of the list
std::cout << *head << std::endl; // prints 123

It's common to use auto for iterator variables.

For next and previous, just use ++ and -- same as other iterators.

std::list<int> mlist;  // empty list
mlist.push_back(123); // add 123 to the end of the list
mlist.push_back(456); // add 456 to the end of the list
mlist.push_back(789); // add 789 to the end of the list
// loop through list from first to last, using ++
for (auto i = mlist.begin(); i != mlist.end(); ++i)
    std::cout << *i << '\n';

如何使用STD ::列表接下来?

待"谢繁草 2025-02-17 04:13:54

这是与使用选择(..)相关的常见陷阱之一。实际上,您将两次扩展数据,一旦WRT置于根级别,然后再次使用.flags []导致组合爆炸

解决方案将是移动.flags []外部选择如下所示

map(.flags[] as $x | select ((.link_type == "ether") and ( $x | contains ("UP"))))

。 /code>和lower_up,如果您正在寻找确切的匹配项,请使用equality operation ==或严格的延期匹配项,例如,带有test(.. )

一个简单的查找up,如果您是不是跑入上述爆炸

map(select( (.link_type == "ether") and (.flags[] == "UP") ))

This is one of common pitfalls associated with using select(..). You are actually expanding the data twice, once w.r.t. to the root level and once again with .flags[] leading to combinatorial explosion

The solution would be to move .flags[] outside select as below

map(.flags[] as $x | select ((.link_type == "ether") and ( $x | contains ("UP"))))

Also it seems the flags can take the values UP and LOWER_UP, if you were looking for an exact match, use an equality operator == or a strict regex match, e.g. with test(..)

A simple lookup for just UP in case if you are not running into the above explosion would be to just do

map(select( (.link_type == "ether") and (.flags[] == "UP") ))

在``select''行为(有时)中使用```'select''条件

待"谢繁草 2025-02-16 10:15:15

取决于模型的细节(例如离散时间与连续时间等)。没有更多详细信息,这将无法回答。如何建模转换是众所周知的,但是解释这需要一些文本,数学和图形,并不真正适合这个论坛。您可能需要进行文献搜索,以查看其他人在这一领域所做的事情。请注意,没有现有的已发布模型会准确地做您想要的事情,但它应该给您一些想法。

Depends on the details of the model (e.g. discrete-time vs continuous-time etc). This cannot be answered without much more detailed information. How to model changeovers is well known, but explaining this requires quite some text and math and graphics, not really suited for this forum. You may want to do a literature search to see what others have done in this area. Note that no existing published model will exactly do what you want, but it should give you some ideas.

LP Python系列生产计划中的切换

待"谢繁草 2025-02-15 18:19:37

考虑示例&lt; number&gt;+如何处理? 编号甚至Integer中都没有添加

更糟糕的是,考虑最终类FunkyNumber扩展了数字{...怪异的东西,不添加op ...}

Consider Example<Number>, how would + work on that? There is no add or similar in Number or even the likes of Integer.

Worse consider final class FunkyNumber extends Number { ... weird stuff, no add op ... }.

我可以在基本数字上进行算术操作吗?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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