Is there a name for Juniper/Nginx/Caddy-like configuration format?
It looks like this: juniper -- number 12, or nginx, or caddy:
simpleProperty value;
arrayProperty firstValue optionalValue optionalValue;
objectProperty requiredValue optionalValue {
subSimpleNumberProperty 123;
subArrayProperty "stringValue" "string value 2";
subObjectProperty {
nestedProperty value;
}
}
Is there a name for this kind of format? (this is obviously not json/cson/json5, not yaml, not ini/cfg, also not toml)
Related
Good afternoon, I want to make a universal sort for all tables. The idea is that the method will receive the name of the column as input and, through reflection, I will receive a link to the field of the same name.
val id = "id"
var a = JobSeekerTable::class
a.memberProperties.forEach { e ->
if (e.name == id) {
transaction {
JobSeeker.all().sortedBy { e.getter }
}
}
}
Unfortunately, this does not work. There was an option, through the fields field that the table has
JobSeekerTable.fields.forEach {v->
transaction {
JobSeeker.all().sortedBy { v }
}
}
but also unsuccessfully :(
If there is any way to refer to the required field through the name. Not using if and stuff like that?
First, you are probably looking for orderBy, not sortedBy. The former is to order SQL query results, the later is to sort a collection.
Second, you want to pass an instance of a column:
val id = "id"
JobSeekerTable.selectAll().orderBy(JobSeekerTable.columns.find {
it.name == id // Here I used the name you provided, although probably it should be named something like columnName
} !! to SortOrder.ASC)
Using "screaming" operator (!!) in Kotlin is a bad practice. So if all of your tables have ID column, for example, you can use "elvis" operator instead.
JobSeekerTable.selectAll().orderBy((JobSeekerTable.columns.find {
it.name == id
} ?: JobSeekerTable.id) to SortOrder.ASC)
My database contain a column which is the type of varchar.
In that column i am storing value in the form [1,2] .
I need to get first value '1'.
I need to write jpql query using #query of spring data jpa.
I have decided to remove the braces of the value by using substring function then i need to convert it to array.
So, I have tried like this for the substring extraction.
SUBSTRING(u.output,1,LENGTH(u.output-2))
Is this syntax correct for substring extraction? how convert it to array.
If you cannot normalise the database then I would normalise the domain model via a JPA Converter.
You can these just load the entity and navigate the array as normal.
https://www.baeldung.com/jpa-attribute-converters
#Entity
public MyEntity{
#Convert(converter = MyArrayConverter.class)
int [] values;
}
Create a JPA Converter:
#Converter
public class MyArrayConverter implements
AttributeConverter<Integer [], String> {
#Override
public String convertToDatabaseColumn(int [] values) {
//convert int [] to string "[1,2,3]"
}
#Override
public Integer [] convertToEntityAttribute(String dbValue) {
//convert string "[1,2,3]" to int []
}
}
I have a variable nodename = v445 and another variable nodepatch=v445-sctpsv
I want to compare as
if { $nodename == ???????} {
}
so here I just want to compare only part before certain - the second variable could contain more than one - in name, so I just want to extract equivalent string to nodename to compare with.
after string manipulation second part should come up like this:
if { $nodename == "v445"} {
proceed } else {
}
Try
set nodename v445
set nodepatch v445-sctpsv
if {[string match $nodename* $nodepatch]} {
proceed
} else {
}
string match does a glob-style match against a string, in this case the string that starts with the value in $nodename and contains zero or more characters is matched against the string $nodepatch.
If you need to ensure that the dash occurs, use string match $nodename-* $nodepatch instead.
Documentation: if, set, string
I'm getting the following JSON response from the server:
{
"userId":"123456789",
"displayName":"display name"
}
When I use NSJSONSerialization.JSONObjectWithData and then prints the result NSDictionary I see in the console the following:
userId = 123456789
displayName = "display name"
Why do JSONObjectWithData changes the userId field type from String to a number?
It doesn't. The JSON deserialisation respects the data type and will maintain it. You can't tell the data type from a simple description log, you need to actually interrogate the class. The description log will quote some things if it makes more sense for the human reader, like spaces in the description, but it also omits quotes in some cases.
It doesn't.
Don't infer a variable type from its log representation, just test. Fire a Playground with this, for example:
let str = "{\"userId\":\"123456789\",\"displayName\":\"display name\"}"
if let data = str.dataUsingEncoding(NSUTF8StringEncoding),
jsonResult = try? NSJSONSerialization.JSONObjectWithData(data, options: []),
jsonObject = jsonResult as? [String:String],
id = jsonObject["userId"] {
print("User ID is " + id)
}
I want to retrieve data from a fluid contact set only if the contact is from a certain type.
This is what i wrote:
ContactSet fcset = FcSetGridBox.Tag as ContactSet;
foreach (Contact fc in fcset.Contacts)
{
if (fc.ContactType.Equals(oilwater))
{
args.OilZoneContV=fc.GetZValue();
}
else
if (fc.ContactType = "oilgas"')
{
args.GasZoneContV = fc.GetZValue();
}
}
But I don't know what to compare the ContactType to. The Ocean manual mention the contact type enumeration but i cant use them as string
I just found the answer: I need to test against the actual enumeration values.
if (fc.ContactType.Equals(ContactType.OilGas))
{ ... }
And Enumerations can safely be compared with the == operator as well.