String array in asp.net - asp.net

I have a string array(strLarge) containing 5 values say 1,2,3,4,5.
I have another string(strSmall) containing a value say 3.
Now I need to remove this strSmall from strLarge and finally get the result as 1,2,4,5.

strLarge.Except(strSmall);
in LINQ
Produces the set difference of two
sequences.
See
msdn

string[] strLarge = { "1", "2", "3", "4", "5" };
string[] strSmall = { "3" };
strLarge = strLarge.Where(x => !strSmall.Contains(x)).ToArray();

use Except() for strLarge

Related

How to filter Journald PRIORITY in Vector?

I'm trying to limit the journald logs my vector config picks up but it appears not to work. There are no error messages. Vector is sending all logs to loki. The vector version is 0.22.2.
Here is my vector.toml file:
[sources.host_journald_source]
type = "journald"
current_boot_only = true
[transforms.host_journald_filter]
type = "filter"
inputs = ["host_journald_source"]
condition = '''
includes(["0", "1", "2", "3", "4"], .PRIORITY)
'''
Here is an example of a log I want to exclude in my grafana loki datasource explorer:
Log labels
boot_id 7d16b8f4fc2a4366b9e705f52b75979e
cmdline /sbin/init
host myhost-test
message run-docker-runtime\x2drunc-moby-3995a89e568b3d38fd01a158b8bfd5e02e27b05c60c128aed8a71ed121b44c07-runc.t7aKhj.mount: Deactivated successfully.
Detected fields
CODE_FILE "src/core/unit.c"
CODE_FUNC "unit_log_success"
CODE_LINE "5553"
INVOCATION_ID "e5b739ebc26a4897bd1288844a875d10"
MESSAGE_ID "7ad2d189f7e94e70a38c781354912448"
PRIORITY "6"
SYSLOG_FACILITY "3"
SYSLOG_IDENTIFIER "systemd"
TID "1"
Time 1655917978170
UNIT "run-docker-runtime\\x2drunc-moby-3995a89e568b3d38fd01a158b8bfd5e02e27b05c60c128aed8a71ed121b44c07-runc.t7aKhj.mount"
_BOOT_ID "7d16b8f4fc2a4366b9e705f52b75979e"
_CAP_EFFECTIVE "1ffffffffff"
_CMDLINE "/sbin/init"
_COMM "systemd"
_EXE "/usr/lib/systemd/systemd"
_GID "0"
_MACHINE_ID "fff69d4a6e8643678404cfa6b346143b"
_PID "1"
_SELINUX_CONTEXT "unconfined\n"
_SOURCE_REALTIME_TIMESTAMP "1655917978170117"
_SYSTEMD_CGROUP "/init.scope"
_SYSTEMD_SLICE "-.slice"
_SYSTEMD_UNIT "init.scope"
_TRANSPORT "journal"
_UID "0"
__MONOTONIC_TIMESTAMP "35722646432"
__REALTIME_TIMESTAMP "1655917978172193"
host "myhost-test"
labels [object Object]
message "run-docker-runtime\\x2drunc-moby-3995a89e568b3d38fd01a158b8bfd5e02e27b05c60c128aed8a71ed121b44c07-runc.t7aKhj.mount: Deactivated successfully."
source_type "journald"
tsNs 1655917978170117000
My vector.toml file now looks like this:
[sources.host_journald_source]
type = "journald"
current_boot_only = true
since_now = true
include_units = [ "systemd" ]
include_matches.PRIORITY = [ "0", "1", "2", "3", "4" ]
[sinks.loki]
type = "loki"
inputs = [ "host_journald_source" ]
endpoint = "http://localhost:3100"
compression = "none"
request.concurrency = "adaptive"
out_of_order_action = "accept"
[sinks.loki.labels]
boot_id = '{{ "_BOOT_ID" }}'
message = "{{ message }}"
cmdline = '{{ "_CMDLINE" }}'
host = "{{ host }}"
user_unit = '{{ "USER_UNIT" }}'
[sinks.loki.encoding]
codec = "json"

Firestore update array field in a Document

I have a document like below, in my document, have a Array . in array have Objects. How can i update new object to an Array.
As you see below i can add document in a colletion wit an array, but when i tried to update it gives error
java.lang.IllegalArgumentException: Invalid data. Unsupported type: com.test.data.modal.Product
What i tried;
var pid = ""
btnAdd.setOnClickListener {
val list = ArrayList<Product>()
list.add(Product("u1", "1", 1))
list.add(Product("u2", "2", 1))
list.add(Product("u3", "3", 1))
val testObject = TestObject("Talha", "Kosen", list)
FirebaseFirestore.getInstance().collection("Test")
.add(testObject)
.addOnCompleteListener { task ->
pid = task.result.id
}
}
btnUpdate.setOnClickListener {
val list = ArrayList<Product>()
list.add(Product("u1", "1", 1))
list.add(Product("u2", "2", 1))
list.add(Product("u3", "3", 1))
list.add(Product("u4", "4", 4))
FirebaseFirestore.getInstance()
.collection("Test")
.document(pid)
.update("product", list)
}
document:
POJO:
#IgnoreExtraProperties
#Keep
class TestObject {
var name: String = ""
var surname: String = ""
lateinit var productList: List<Product>
constructor()
constructor(name: String, surname: String, productList: List<Product>) {
this.name = name
this.surname = surname
this.productList = productList
}
}
#IgnoreExtraProperties
#Keep
class Product {
var imagePath: String = ""
var productUrl: String = ""
var brand: Int = 0
constructor()
constructor(imagePath: String, productUrl: String, brand: Int) {
this.imagePath = imagePath
this.productUrl = productUrl
this.brand = brand
}
}
I have probably not the answer but this could help :
You try to update with an ArrayList but you store a List (in your TestObject)
Refer to the documentation to update fields in nested objects https://firebase.google.com/docs/firestore/manage-data/add-data#update_fields_in_nested_objects
It could be a good idea to store a collection in your TestObject document instead of a list ? You'll able to update easily your fields

Small float being saved in scientific notation instead of decimal

When I try to declare a float variable with a very small value it changes the notation.
Global $interior = 0.00008972
MsgBox(4096, "1", $interior)
$file = FileOpen("Balance.txt", 2)
FileWrite($file, ""&$interior)
FileClose($file)
It shows and writes to file 8.972e-005 not 0.00008972.
You can use StringFormat to specify the precision you want for the float value.
Global $interior = 0.00008972
$interior = StringFormat("%.8f", $interior)
MsgBox(4096, "1", $interior)
$file = FileOpen("Balance.txt", 2)
FileWrite($file, ""&$interior)
FileClose($file)

QML QComboBox.find() can not find element by text

In QML I have a QComboBox:
ComboBox {
id: myCBox
model: [ "1.5", "2", "2.5", "3", "3.5", "4", "5", "6", "7", "8", "9" ]
}
When I try to find an element in the ComboBox by text it returns -1.
Log with this:
console.log(myCBox.find("5"))
And it outputs -1 (which means not found).
QML QComboBox documentation
You should check, when do you the call myCBox.find, look at this code:
ComboBox {
id: myCBox
model: [ "1.5", "2", "2.5", "3", "3.5", "4", "5", "6", "7", "8", "9" ]
Component.onCompleted: {
console.log("After this line it should work fine.");
}
Item {
Component.onCompleted: {
console.log("myCBox is not completed:", myCBox.find("5"));
}
}
}
Component.onCompleted: {
console.log("myCBox here must be completed:", myCBox.find("5"));
}
and the output:
myCBox is not completed: -1
After this line it should work fine.
myCBox must be completed: 6
Uppon creation, Component creates all items and then arranging them in a tree. From the most inner object, it updates properties and bindings to the most overrided value and calls attached method Component.onCompleted.

JSON.Net error reading

I'm trying to parse some JSON data with Json.Net. Here is my data:
[
{
"UIDClan": "1",
"UIDKnjiga": "1",
"Naslov": "Title1",
"DatumZaKada": "2013-08-09 00:00:00",
"DatumIstekRez": null,
"Spremno": "0"
},
{
"UIDClan": "1",
"UIDKnjiga": "2",
"Naslov": "Title2",
"DatumZaKada": "2013-08-08 00:00:00",
"DatumIstekRez": null,
"Spremno": "0"
},
{
"UIDClan": "1",
"UIDKnjiga": "3",
"Naslov": "Title3",
"DatumZaKada": "2013-08-09 00:00:00",
"DatumIstekRez": "2013-10-09 00:00:00",
"Spremno": "1"
}
]
With this piece of code i want to extract UIDClan data:
JObject o = JObject.Parse(s);
Console.WriteLine(o["UIDClan"]);
The error is
Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
I've checked with JSONLint and it's valid.
The examples that I found doesn't start with [.
Am I doing something wrong?
You could try using a JArray.
This JSON data is actually an array.
JArray v = JArray.Parse(s);
To get the first item.
var firstItem = v[0]["UIDClan"].ToString();
You can even use linq
var items = v.Where(x => x["UIDClan"].ToString() == "1").ToList();
To overcome the error plz serialize the jsonstring in below format.this serialize string we are able parse as Jobject
Newtonsoft.Json.JsonConvert.SerializeObject(new {JsonString})

Resources