Flutter remove null values from list [duplicate] - list

This question already has answers here:
How to convert a List<T?> to List<T> in null safe Dart?
(2 answers)
type 'List<Widget?>' is not a subtype of type 'List<Widget>' in type cast
(3 answers)
Closed 1 year ago.
I have a List of optional DateTimes. So the List can actually have null values inside. But now I need to remove all these null-values, to get a List<DateTime, instead of a List<DateTime?>. How is that possible?
I tried it like this:
List<DateTime> timesOfDayNotNull = timesOfDay.where((time) => time != null).toList();
But this is giving me:
A value of type 'List<DateTime?>' can't be assigned to a variable of type 'List'.
What am I missing here? Any help is appreciated!

Related

What does ":_*" mean in scala? (When using a List to filter a dataframe) [duplicate]

This question already has answers here:
What does `:_*` (colon underscore star) do in Scala?
(4 answers)
Closed 2 years ago.
When seeing some co-workers' Scala-Spark code, sometimes I encounter that they use lists to filter dataframes as in this example:
val myList: List[String] = List("0661", "0239", "0949", "0380", "0279", "0311")
df.filter(col("col1").isin(myList:_*)
The code above works perfectly, this one, however, does not:
df.filter(col("col1").isin(myList)
What I don't understand is, what is that "colon underscore star" :_* exactly doing?
Thanks in advance!
It does mean "pass list as a separate parameters". It works for methods, that have a vararg argument, like "any number of strings", but not a List[String] version.
Spark's isin function has signature isin(list: Any*): Column, Any* means "any number of arguments of type Any". Not very descriptive, but here you can pass either any number of strings, or any number of cols.
With :_* syntax, you're saying to compiler "replace my list with varargs", it's equialent to writing .isin("0661", "0239" ...)
Also, since Spark 2.4.0 there's function isInCollection, that takes Iterable, so you can pass List there directly.
This is sometimes called splat operator. It is used to to adapt a sequence (Array, List, Seq, Vector, etc.) so it can be passed as an argument for a varargs method parameter:
def printAll(strings: String*):Unit = {
strings.foreach(println)
}
val fruits = List("apple", "banana", "cherry")
printAll(fruits:_*)
If any method contains any repeated parameter. If you want to pass any Iterable in the method's repeated parameter, to convert your Iterable to repeated parameter you will use :_*
def x(y:Int*):Seq[Int]={ // y:Int* is a repeated parameter.
y
}
x(List(1,2,3,4):_*) <--- you are passing List into repeated parameter

How to query in Mongo for a String based on expressions [duplicate]

This question already has answers here:
Matching a Forward Slash with a regex
(9 answers)
Closed 3 years ago.
I have lot of Data in Mongo DB, I wanted to query based on a String value and that value contains a url
"url" : "http://some-host/api/name/service/list/1234/xyz"
I got records count when executed the below query
db.mycollection.find({url:"http://some-host/api/name/service/list/1234/xyz"}).count()
I want to get all the records which match with
some-host/api/name/service/list/
I tried using below saamples
db.mycollection.find({url:"some-host/api/name/service/list/"}).count()
Got zero records
db.mycollection.find({url:/.*"some-host/api/name/service/list/".*/}).count()
Got error
db.mycollection.find({"url":/.*"some-host/api/name/service/list/".*/}).count()
Got error
db.mycollection.find({"url":/.*some-host/api/name/service/list/.*/}).count()
Got Error
db.mycollection.find({"url":/.*some-host//api//name//service//list//.*/}).count()
Got ...
...
Then no response
Did you try with something like this:
db.mycollection.find({'url': {'$regex': 'sometext'}})
Please check also here

QTimeDate::currentDateTime not working as expected [duplicate]

This question already has answers here:
QDate - wrong year
(3 answers)
Closed 7 years ago.
i'm trying to use QDateTime for one of my project. But everything is going wrong when i use QDateTime::currentTime().msecsTo() ....
QString FORMAT = "d/MM/yy hh:mm:ss";
QDateTime at = QDateTime::fromString("30/06/15 12:00:00", FORMAT);
qDebug() << QDateTime::currentDateTime().msecsTo(at); //Current DateTIme : 30/06/15 11:51:00 OUTPUT : -3155755905986
And the out put gives me : -3155755905986
Which doesn't make any sens ...
Any idea ?
Thank you.
Actually everything is ok for qt this value is 100 years earlier - 30/06/1915
https://www.unitjuggler.com/convert-time-from-ms-to-yr-365.html?val=3155756569078
QDate - wrong year
I suggest using format "dd/MM/yyyy hh:mm:ss"
Qt doc says if the other datetime is earlier than this datetime, the value returned is negative. I think it is expected behaviour.

How To: Add Style in OSCommerce tep_image function [duplicate]

This question already has an answer here:
Adding class attribute to osCommerce tep_image function
(1 answer)
Closed 8 years ago.
Oscommerce function tep_image:
This is the code:
tep_image(DIR_WS_IMAGES . "partners_grey_top2.png", "ksa shopping", "395", "36");
How to add style?
The fifth argument of the tep_image function in a stock version of osCommerce accepts custom parameters. If you want to add, say, a CSS class like class="product_image", you would alter your function to look like this
tep_image(DIR_WS_IMAGES . "partners_grey_top2.png", "ksa shopping", "395", "36", 'class="product_image"');

how to get model field type for validation in django [duplicate]

This question already has answers here:
how to get field type string from db model in django
(3 answers)
Closed 9 years ago.
I have tried:
field = model._meta.get_field_by_name(field_name)[0]
my_type = field.get_internal_type
This does not work as it gives back some bound method like:
<bound method URLField.get_internal_type of <django.db.models.fields.URLField:my_url>>
I want something I can world with like CharField, URLField, DoubleField, etc.
How can I get something like URLField so that I can validate if the url is well formed for example?
In Python, if you want to call a function or method, you have to use parentheses around the arguments. If there are no arguments, you just use empty parentheses.
What you're doing is just referencing the method itself, not calling it.
Here's a simplified example:
>>> def foo():
... return 3
>>> foo()
3
>>> foo
<function __main__.foo>
You can't "extract" the result from the function; you have to call it.*
So, in your example, just change the second line to this:
my_type = field.get_internal_type()
* OK, in this case, because the function just always returns a constant value, you could extract it by, e.g., pulling it from the source or the func_code.co_consts tuple. But obviously that won't work in general; if you want to get, say, the value of datetime.now(), it's not stored anywhere in the now method, it's generated on the fly when you call the method.