lundi 27 septembre 2021

Adding condition & terms before registration on website

I would to adding a conditions & terms on before a user would signup on my wix website inside their code interpreter. But when i put the code it show me a verbose error for my variable accept from one modal to another i think it doesn't working maybe i missing import or something else on their API:

enter image description here

https://www.wix.com/velo/reference/wix-window/openlightbox

I have 2 lightbox (modal) :

Sign up modal box

  import wixWindow from 'wix-window';
  import wixUsers from 'wix-users';
  import window from 'wix-window';
  import wixUsersBackend from 'wix-users-backend';

  let email
  let password

  //...Enter his email & password 

  wixUsers.register(email, password)   // add email & password to database
     .then( (result) => {
      wixWindow.openLightbox("Conditions générales de vente"); // after adding to DB, displaying "condition & terms" modal(lightbox)
  if(accept.clicked == true);              // if user accecpt terms...
    let status = result.status;   // ..."Pending" the result
  else{
    let user = wixUsersBackend.currentUser;
    wixUsersBackend.deleteUser(user .id)      // delete the current user registration on DB
       }
   } );

Condition & terms

  import wixLocation from 'wix-location';
  import window from 'wix-window';
  import wixWindow from 'wix-window';

   $w.onReady(function () {
      $w('#button1').onClick(() => {
       let accept   // button have "accept" variable 
       wixLocation.to("/home"); // redirect to home page
         
         });
       
       $w('#button2').onClick(() => {
          window.lightbox.close();
          });
     });

I missing something in the script? Could anyone help me with this.

Skipping elif statements

My code is skipping the 3rd and 4th elif statement. Instead of plotting red or purple dots for values that fall between 86 and 106 and then values between 106 and 201, they are plotting maroon which is the else statement. Why is my code skipping over those two conditions? It reads the first two elif statements as I wish so I do no understand what is happening with the last two.

if zlist < '55':
    plt.scatter(x = xlist, y = ylist, color = 'green')
    plt.xticks(rotation=90)
    plt.text(xlist, ylist, zlist)
    
elif '55' < zlist < '71':
    plt.scatter(x =xlist, y =ylist, color = 'yellow')
    plt.xticks(rotation = 90)
    plt.text(xlist, ylist, zlist)
    
elif '71' < zlist < '86':
    plt.scatter(x =xlist, y =ylist, color = 'orange')
    plt.xticks(rotation = 90)
    plt.text(xlist, ylist, zlist)
             
elif '86' < zlist < '106':
    plt.scatter(x =xlist, y =ylist, color = 'red')
    plt.xticks(rotation = 90)
    plt.text(xlist, ylist, zlist)
             
elif '106' < zlist < '201':
    plt.scatter(x =xlist, y =ylist, color = 'purple')
    plt.xticks(rotation = 90)
    plt.text(xlist, ylist, zlist)
             
elif zlist > '201':
    plt.scatter(x =xlist, y =ylist, color = 'maroon')
    plt.xticks(rotation = 90)
    plt.text(xlist, ylist, zlist)
    

Change letters in string entered by user

I have a C programming question. Im taking the letters entered by the user and changing them. For instance the program needs the change this a becomes @ v becomes V e becomes 3 o becomes 0

How can I get this to print the new characters in a string properly in C?

Everytime I run this code, and I input something with the characters I want to be switched out with new characters, it only prints out the unchanged characters. What do I need to change to fix this?

#include <stdio.h>
#include "string.h"
int main()
{
 char originalPassword [50];
 char newPassword [50];
 int length;

printf("Please enter your current password. \n");
scanf("%s", originalPassword);
length = strlen(originalPassword);
for(int i = 0; i < length; i++)
{
    printf("%c\n", originalPassword[i]);
    if(originalPassword[i]=='i');
    {
       originalPassword[i] = '1';
    }
    
    if(originalPassword[i]=='a')
    {
       originalPassword[i]='@';
    }
    else
    {
        
    }
 }

}

Why is ifelse returning NA as false?

For some reason, my ifelse statement is returning NAs as if they are false and not as NAs. Any idea why might be happening?

The column in question has numbers from 1 to 10.

library(dplyr)

data <- read.csv('210901_CLEANN_Risks_Research.csv')

data <- data %>% mutate_if(is.character, as.factor)

data[data==""]<-NaN
data[data=="Refused to answer"]<-NaN

table(data$safety)
unique(data$safety)

a <- c(1,2,3,4,5)

data$safety <- ifelse(data$safety %in% a , "Yes", "No")

unique(data$safety)
table(data$safety)

The output is the following:

data <- read.csv('210901_CLEANN_Risks_Research.csv')

data <- data %>% mutate_if(is.character, as.factor)

data[data==""]<-NA
data[data=="Refused to answer"]<-NA 
table(data$safety)

>    1    2    3    4    5    6    7    8    9   10 
> 2936 1112  836  548  479  261  165   91   51   12 
unique(data$safety)
> [1]  1  2  3  7  5  6  4  8  9 10 NA
  
a <- c(1,2,3,4,5)
data$safety <- ifelse(data$safety %in% a , "Yes", "No")
 
unique(data$safety)
> [1] "Yes" "No" 
table(data$safety)
>  No  Yes 
> 583 5911 

Any clue why this might be happening?

Swift: If image exists, return it, otherwise return nil

I've been trying to find a way to check if SF Symbols and Images exist in swift.
In all of the answers I've come across, the nil coalescing operator (??) is used, which requires a default image that always exists. This doesn't work in my case.

I would like to test if an image (or a symbol) exists and then return it if it exists, otherwise return nil.

How can this be achieved?

IMPORTANT NOTE
I am trying to achieve this using SwiftUI's Image for a multiplatform application. I am trying to avoid using UIImage or NSImage to do my checks.

UPDATE 1

Note 1: When requesting an SF Symbol that does not exist (for example, there was a typo in the systemName: [name] parameter), the image appears as an empty area. (Tested with Label)

The following solutions have been tested and are ineffective:
(Note: in all of the attemps, there are is a variable name: String)

Solution 1

let image = Image(systemName: name)
if image {
    return image
} else {
    return nil
}

Throws the error:

Cannot convert value of type 'Image' to expected condition type 'Bool'

It throws the exact same error when: let image = Image(name)

Solution 2

if let image = Image(systemName: name) {
    return image
}

Throws the error:

Initializer for conditional binding must have Optional type, not 'Image'

Solution 3

let image = Image(systemName: name)
if image != nil {
    return image
}

Does not work and gives the warning:

Comparing non-optional value of type 'Image' to 'nil' always returns true

IntroJs Hints if parent not Visible

IntroJs hints How can I skip or hide when a parent element is not visible? For some reason only inline seems to be working for my hints.I have the data-hints in spans on the HTML and I need to check if the nearest element is visible or parent/child element.

var hints = false;

var all = document.getElementsByTagName("*");

function introFunction() {

for (var i = 0, max = all.length; i < max; i++) {
    if ((isHidden(all[i]) && hints));
    document.getElementById("#helpFunc").html("Show Help");
    introJs().hideHints();
} else {
    document.getElementById("#helpFunc").html("Hide Help");
    introJs().showHints();
}
hints = !hints;

function isHidden(el) {
    var style = window.getComputedStyle(el);
    return ((style.display === 'none') || (style.visibility === 'hidden'));
}

}