Jcmarimarissa's Profile

230
Points

Questions
43

Answers
45

  • Remove the hardcoded top margin of the EditDate, and center it vertically in parent with app:layout_constraintBottom_toBottomOf="parent"

    Also add app:layout_constraintBottom_toBottomOf="parent" to the bottom button so that you can make sure it won’t get beyond the bottom of the screen.

    <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context=".MainActivity">      <AutoCompleteTextView         android:id="@+id/clubname"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_marginStart="96dp"         android:layout_marginLeft="96dp"         android:layout_marginEnd="102dp"         android:layout_marginRight="102dp"         android:layout_marginBottom="36dp"         android:gravity="center"         android:hint="@string/club_name"         app:layout_constraintBottom_toTopOf="@+id/EditDate"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintHorizontal_bias="0.5"         app:layout_constraintStart_toStartOf="parent" />      <Button         android:id="@+id/EditDate"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_marginStart="96dp"         android:layout_marginLeft="96dp"         android:layout_marginEnd="102dp"         android:layout_marginRight="102dp"         android:ems="10"         android:gravity="center"         android:hint="@string/date_button"         android:onClick="sendButton"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintHeight_percent="0.1"         app:layout_constraintHorizontal_bias="0.5"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toTopOf="parent"         app:layout_constraintWidth_percent="0.3" />      <Spinner         android:id="@+id/eventName"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_marginStart="100dp"         android:layout_marginLeft="100dp"         android:layout_marginTop="44dp"         android:layout_marginEnd="102dp"         android:layout_marginRight="102dp"         android:ems="10"         android:gravity="center"         android:visibility="visible"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintHorizontal_bias="1.0"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintTop_toBottomOf="@+id/EditDate" />       <Button         android:id="@+id/button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginTop="104dp"         android:onClick="sendButton"         android:text="@string/send"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintHorizontal_bias="0.498"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintBottom_toBottomOf="parent"         app:layout_constraintTop_toBottomOf="@+id/eventName" />  </androidx.constraintlayout.widget.ConstraintLayout> 
    • 927 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in XML.

    The where clause in your first example queries /Operaciones_por_Dia/OperacionDia/@fecha[1] independently of the nodes('/Operaciones_por_Dia/OperacionDia/PagoRecibo') query so will always be comparing @FechaOperacion against the first date attribute – which is 2020-01-30 in this document.

    declare @FechaOperacion date = convert(date, '2020-01-30', 120); select     ph.value('@NumFinca', 'INT'),     ph.value('@TipoRecibo', 'INT'),     ph.value('../@fecha', 'DATE') from @DocumentoXML.nodes('/Operaciones_por_Dia/OperacionDia/PagoRecibo') AS t(ph) where @DocumentoXML.value('(/Operaciones_por_Dia/OperacionDia/@fecha)[1]', 'DATE') = @FechaOperacion 

    Depending on the value of @FechaOperacion it will either return all rows in the document (when it matches) or now rows at all (when it doesn’t)…

    (No column name) (No column name) (No column name) ---------------- ---------------- ---------------- 9782331          5                2020-01-30 6696849          5                2020-01-30 1423800          7                2020-04-08 1393022          7                2020-04-08 

    The solution is to query for nodes('/Operaciones_por_Dia/OperacionDia') and then use a cross apply to query the PagoRecibo child nodes.

    declare @FechaOperacion date = convert(date, '2020-01-30', 120); select     ph.value('@NumFinca', 'INT'),     ph.value('@TipoRecibo', 'INT'),     od.value('@fecha', 'DATE') from @DocumentoXML.nodes('/Operaciones_por_Dia/OperacionDia') AS s(od) cross apply s.od.nodes('PagoRecibo') AS t(ph) where s.od.value('@fecha', 'DATE') = @FechaOperacion 

    Which returns…

    (No column name) (No column name) (No column name) ---------------- ---------------- ---------------- 9782331          5                2020-01-30 6696849          5                2020-01-30 
    • 299 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in XML.

    Works fine:

    $commaValues = '5773270,5778216'; $lubuvnaCommas = explode(',', $commaValues); $destinations = '';  foreach($lubuvnaCommas as $row){     // Concatenate current value with previous ones     $destinations .= "<cl_id>".$row."</cl_id>"; }  $xml ='    <?xml version="1.0" encoding="UTF-8"?>    <destinations>    '.$destinations.'    </destinations>'; 

    Fiddle here.

    • 342 views
    • 1 answers
    • 0 votes
  • Asked on July 16, 2020 in Mysql.

    You can order the rows putting two rows for admin and one for user at the top:

    select t.* from (select t.*,              row_number() over (partition by role order by rand()) as seqnum       from t      ) t order by ((case when role = 'admin' then seqnum else 999 end) <= 2) desc,          ((case when role = 'user' then seqnum else 999 end) <= 2) desc,          rand() limit 4 

    This assigns a sequential number to each role. It then uses multiple keys in the order by to retrieve the numbers that you want.

    Here is a db<>fiddle.

    • 300 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Mysql.

    This might work as you want

    CREATE TABLE `topics` (     `id` INT(11) NOT NULL AUTO_INCREMENT,     `name` VARCHAR(250),     PRIMARY KEY (`id`) );    INSERT INTO `topics` VALUES (1, 'aaaa'); INSERT INTO `topics` VALUES (2, 'bbbb'); INSERT INTO `topics` VALUES (4, 'dddd'); INSERT INTO `topics` VALUES (7, 'gggg');  SELECT     (SELECT MAX(`id`) FROM `topics` WHERE id < `tmpTopics`.`id`) AS `prev_id`,     (SELECT MIN(`id`) FROM `topics` WHERE id > `tmpTopics`.`id`) AS `next_id` FROM     `topics` AS `tmpTopics` WHERE     `id` = 1; 

    Here is SQL Fiddle example http://sqlfiddle.com/#!9/83968c/8

    • 286 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Mysql.

    This should do

    select * from user_skill where skill_id in (?) and knowledge >= ? and knowledge <= ? 

    The ? represent the values that will change. Would suggest you to use prepared statements if possible to substitute the ?. Otherwise can substitute and test them manually as well if you want.

    Refer the example I made at http://sqlfiddle.com/#!9/bd0f2b6/4

    • 291 views
    • 1 answers
    • 0 votes
  • It’s not exactly the same.

    useEffect(() => doRequest(), []); 

    In this case your callback will implicitly return the value that doRequest() returns. A useEffect callback can only return a function (for cleanup of the effect) or undefined. You can use that syntax if doRequest either returns nothing (meaning undefined) or a cleanup function.

    EDIT: As noted by @3limin4t0r () => fn() is the same as () => { return fn(); }:

    useEffect(() => {   doRequest(); }, []); 

    By having a function body and not explicitly returning something your function implicitly returns undefined which is fine if there is nothing to cleanup.

    • 315 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    Firtsly, If you put variable b above loop, in your case, python sets b variable only once, based on value of i. During while loop you change i variable but not rewrite b because it out of scope. Simpler example:

    lst = [0, 1, 2, 3, 4] n = len(lst)  # n=5 i = 0 b1 = lst[i] while i < n:     b2 = lst[i]     print(f'Loop {i+1}: b1={b1} | b2={b2}')     i += 1 

    Output:

    Loop 1: b1=0 | b2=0 Loop 2: b1=0 | b2=1 Loop 3: b1=0 | b2=2 Loop 4: b1=0 | b2=3 Loop 5: b1=0 | b2=4 

    Secondly, for your task you should use so called "list comprehension" – they are more compact and easy to read. Also, in your code you do not use numpy module, so there is no need to import it.

    lst = [0, 1, 2, 3, 4] lst_2 = [i+1 for i in lst] print(lst_2) 

    Output:

    [1, 2, 3, 4, 5] 
    • 316 views
    • 3 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    Lots of python password checkers online, for example: https://www.geeksforgeeks.org/password-validation-in-python/

    Here’s a quick console program you can call like:

    $ python3 password_checker.py "Testf7788790##$" Testing password:  Testf7788790##$ Password is valid:  True $ python3 password_checker.py "insecurePassword" Testing password:  insecurePassword Password should contain at least one number Password is valid:  False 

    Contents of password_checker.py:

    #!/usr/bin/python  import sys  def password_check(passwd):     symbols = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=']     isValid = False            if len(passwd) < 10:         print('Password should be at least 10 characters')     elif not any(char.isdigit() for char in passwd):         print('Password should contain at least one number')     elif not any(char.isupper() for char in passwd):         print('Password should contain at least one uppercase character')     elif not any(char.islower() for char in passwd):         print('Password should contain at least one lowercase character')     elif not any(char in symbols for char in passwd):         print('Password should contain at least one special character from list: ', symbols)     else:       isValid = True      return isValid  arguments = sys.argv if len(arguments) < 2:     print('No password could be parsed by argv')     valid_password = False else:     password = arguments[1]     print('Testing password: ', password)     valid_password = password_check(password)  print('Password is valid: ', valid_password) 
    • 312 views
    • 4 answers
    • 0 votes
  • Asked on July 16, 2020 in Python.

    You’re currently only asking the user if he wants to play again once, and keep it going with the while loop. You should ask the user again after every time the game is played, like so:

    choose = input("Would you like to play again?\n") while choose == "yes":             game()     choose = input("Would you like to play again?\n") #add this line     if choose == "no":         break 
    • 263 views
    • 2 answers
    • 0 votes