Wednesday, April 28, 2021

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


Can't change element properties in css using tag selectors

Posted: 28 Apr 2021 08:56 AM PDT

I'm a fresher in Web Development field, and I've taken Angela Yu's Web development bootcamp. I'm currently using bootstrap v5 , html5 , CSS3

I came across a problem, I couldn't change properties of body tag when I target using Tag selection

Here's my index.html

<!DOCTYPE html>  <html>    <head>    <meta charset="utf-8">    <title>TinDog</title>      <!-- External style Sheet -->    <link rel="stylesheet" href="css/styles.css">      <!-- bootstrap -->    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>    <!-- Google fonts -->    <link rel="preconnect" href="https://fonts.gstatic.com">    <link href="https://fonts.googleapis.com/css2?family=Montserrat&family=Ubuntu:wght@500&display=swap" rel="stylesheet">    <!-- font awesome -->    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">  </head>    <body>    <section id="title">      <!-- Nav Bar -->      <nav class="navbar navbar-expand-lg navbar-dark">        <div class="container-fluid p-0 title-container">          <a href="#" class="navbar-brand">tinCat</a>          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">            <span class="navbar-toggler-icon"></span>          </button>          <div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">            <ul class="nav navbar-nav">              <li class="nav-item"><a class="nav-link" href="">Contact</a></li>              <li class="nav-item"><a class="nav-link" href="">Pricing</a></li>              <li class="nav-item"><a class="nav-link" href="">Download</a></li>              </ul>          </div>        </div>        </nav>      <!-- Nav Bar end -->          <!-- Download Section -->      <div class="container-fluid p-0 title-things">        <div class="row">          <div class="col-lg-6 ">            <h1>Meet new and interesting cats nearby.</h1>            <button type="button" class="btn btn-light download-button"><i class="fab fa-apple"></i> Download</button>            <button type="button" class="btn btn-dark download-button"><i class="fab fa-google-play"></i> Download</button>          </div>          <div class="col-lg-2">            <img class="cat-profile"src="images/iphone6.png" alt="iphone-mockup">          </div>        </div>      </section>    </div>        </body>    </html>    

Here's my Styles.css

body{    font-family: 'Montserrat', sans-serif;     }    #title{    padding: 3% 15%;    background-color: #ff4c68;    font-family: 'Montserrat', sans-serif;    color: #ffffff;  }  .navbar-brand{    font-family: 'Ubuntu', sans-serif;    font-weight: bold;    font-size: 2.5rem !important;    }    .cat-profile  {    transform: rotate(10deg);    width: 360px;    margin-top: 20px;  }    .download-button{    margin-top:  20px;    }    .title-things{    margin-top: 100px ;  }    .title-container {  padding: 0% 15%;  }    /* .col{    padding: 0px;  } */  /* .title-text  {  font-family: 'Montserrat', sans-serif;  font-weight: bold;  size : 3rem;  line-height: 1.5;  } */  

Conversely I added a new class to the tag and in External Style sheet, I targeted it using Class selector and it worked! Can someone explain why?

Cannot complete wordpress setup aftern installing it with Docker Desktop + WSL2

Posted: 28 Apr 2021 08:56 AM PDT

I am trying to install wordpress using Docker Desktop and WSL2. I was able to compose an image creating the following docker-compose.yml file and then running docker-compose up

version: '3.1'    services:      wordpress:      image: wordpress      restart: always      ports:        - 8080:80      environment:        WORDPRESS_DB_HOST: db        WORDPRESS_DB_USER: exampleuser        WORDPRESS_DB_PASSWORD: examplepass        WORDPRESS_DB_NAME: exampledb      volumes:        - wordpress:/var/www/html      db:      image: mysql:5.7      restart: always      environment:        MYSQL_DATABASE: exampledb        MYSQL_USER: exampleuser        MYSQL_PASSWORD: examplepass        MYSQL_RANDOM_ROOT_PASSWORD: '1'      volumes:        - db:/var/lib/mysql    volumes:    wordpress:    db:  

(This is taken from the official wordpress image's page on docker hub. I have change the default environment variables for DB_USER, DB_PASSWORD and DB_NAME but they were set equal to MYSQL_USER, MYSQL_PASSWORD and MYSQL_DATABASE respectively.)

Back to Docker Desktop, I ran the container, which seems to work correctly because when I got to localhost:8080 I find Wordpress' first setup process. However, when I plug-in the database name, username, password and host that I used in the file I get the error "Error establishing a database connection".

I tried the following for as Database host, but none worked: localhost, localhost:8080, localhost:80 and db.

Any idea?

How to Write a Python program that simulates 60 samples from a normal random

Posted: 28 Apr 2021 08:55 AM PDT

Write a Python program that simulates 60 samples from a normal random with true mean 0.10 and true variance of 0.20^2.Then how to compute the sample mean and sample variance. Thanks!

Multiple Datasources / JDBCTemplate In Spring Boot

Posted: 28 Apr 2021 08:55 AM PDT

I know it is duplicate- Spring Boot Configure and Use Two DataSources But posting a slightly different scenario related to design considerations.

I am creating a dashboard application that has to fetch transaction count from a table in 16 different databases. I have created a jdbcTemplate per Datasource which is configured within the application.properties files. Now I am looping through each jdbcTemplate stored in List and collecting count in hashMap (key: databaseName, value: count). After I am having all data in a hashMap, I am simply inserting the data to target DB which connects to the dashBoard app.

Is there any optimized solution for this scenario, considering the performance?

(Note: I have scheduled a job which will run once a day at 23:30 PM to fetch data from source dbs and insert to target)

Visual Studio 2019 showing unknown value for database profiling

Posted: 28 Apr 2021 08:55 AM PDT

I am doing database profiling using built in visual studio database profiler. The problem is the time taken for query are showing as "unknown"

Screenshot

Convert HTML Template to PDF using itext7, how to move a table that prints across pages

Posted: 28 Apr 2021 08:55 AM PDT

I'm developing an asp.net mvc project and I'm using an html template to generate an invoice document with dynamic data which I filled up thanks to handlebars. The html resulting is being converted to PDF by using itext7, since is the tool required by the company for using to, however I'm facing an issue when converting that to a PDF because of an html table that shows data, some times has enough data to fit just into one page, but in other cases, there are many rows that meet into a page break, printing the data across both pages. I need to move the whole table block to the next page whenever the data doesn't fit in one page.

Thanks for any help.

Android CameraX seems to crop analysis images slightly for specific PreviewView sizes

Posted: 28 Apr 2021 08:54 AM PDT

Dependencies used:

implementation 'androidx.camera:camera-camera2:1.1.0-alpha04'  implementation 'androidx.camera:camera-lifecycle:1.1.0-alpha04'  implementation 'androidx.camera:camera-view:1.0.0-alpha24'  

Pretend that for simplicity you're using a device with:

  • a portrait default orientation
  • 1080x1920 screen resolution
  • with ImageAnalysis configured to use 1080x1920 as frames analysis resolution

When a PreviewView is laid out with sizes close to 1080x1920 and FILL_CENTER as a scale type, we're getting analysis frames with the same contents as we see in the PreviewView - it's ok. When our PreviewView becomes a little bit more narrow, for example 700x1920 - it gets cropped parts of analysis frames: some parts of the frames on the left and right now look cropped - it's ok too.

But when we change the sizes of the PreviewView to make it look as landscape, for example - to 1080x500 there is an issue appears. Our PreviewView makes the frames from the camera look cropped from top and bottom - it's ok. But what's not ok - is that our analysis frames become actually cropped veeery slightly at left and right. That means I expect to see the same capture bounds horizontally both in PreviewView and frames (because due to scaling only vertical parts are cropped), but PreviewView actually shows a little bit more along its width rather than the corresponding frame, so it looks like the frame looses about 20px horizontally, what shouldn't occur, because due to frame (1080x1920) and PreviewView (1080x500) sizes, only vertical parts should be clipped.

Attaching an illustration: enter image description here

Do anyone encounter the same behaviour in the CameraX?

How can I add various options to my script

Posted: 28 Apr 2021 08:57 AM PDT

I am very new to Python. In the following script, how can I add more options to the files that I want to obtain. Like, let's say that I am not sure how the file is called. My options for the name of that file are: "Unicorn 1.pdf", "Unicorn 2.pdf, and "Apple 1.pdf".

import os  import smtplib  from email.message import EmailMessage  from email.mime.text import MIMEText  from email.mime.multipart import MIMEMultipart  from email.mime.base import MIMEBase  from email import encoders    def fsf():      for root, dirs, files in os.walk('C:\\'):          for file in files:              **if file.endswith("Unicorn 1.pdf"):**                  pis = os.path.join(root, file)                  if pis == os.path.join(root, file):                      pass  

I think that I need to add an else after the if file.endswith("Unicorn 1.pdf"): , right?

Please help me as I don't know what to do.

Note that I am not sure how the file is called, and I want to have more options for the name of the file in case the first one is incorrect.

Different names of JSON property during serialization and deserialization in golang

Posted: 28 Apr 2021 08:55 AM PDT

Is it possible: to have one field in the struct, but different names for it during serialization/deserialization in Golang?

For example, I have the struct "Coordinates".

type Coordinates struct {    red int  }  

For deserialization from JSON want to have a format like this:

{    "red":12  }  

But when I will serialize the struct, the result should be like this one:

{    "r":12  }  

Should I put my classes inside or outside the main class? (Best Practices)

Posted: 28 Apr 2021 08:56 AM PDT

I'm just starting with Java, although I already have some experience with OOP in PHP

In this example, I have a simple class called Person, with fields such as name, age, and sex. I was wondering what is considered the best practice, to do something like this:

public class Main {      public static void main(String[] args){          Person customer = new Person("Jonh Smith", 21, 'M');          System.out.println(customer.name);      }        public static class Person {          public String name;          public int age;          public char sex;            public Person(String name, int age, char sex){              this.name = name;              this.age = age;              this.sex = java.lang.Character.toUpperCase(sex);          }      }  }  

In this way, the Person class needs to be static for it to work, and this is what made me wonder that it might not be the best way to do it, here is the other way:

public class Main {      public static void main(String[] args) {          Person customer = new Person("Jonh Smith", 21, 'M');          System.out.println(customer.name);      }  }        class Person {      public String name;      public int age;      public char sex;        public Person(String name, int age, char sex){          this.name = name;          this.age = age;          this.sex = java.lang.Character.toUpperCase(sex);      }  }    

So, what's the best way to do this moving forward? I will still need to add other classes, like Company.

how to handle an error caused by another module

Posted: 28 Apr 2021 08:54 AM PDT

I'm new to python and I'm trying to make a web spider and everything is working fine except when I try to get the link I can't really control the input with try and expect and what I noticed is like there are two errors are actually happening

what I'm trying to accomplish here is if any thing other than a regular URL is given as an input it shows a message and ask for the input again (I don't know how to address the error)

while True:      try:          url=input("please enter your site (with no http:// ) : ")          link = ur.urlopen("http://"+url)          break      except:          print("Unexpected error:", sys.exc_info()[0])          raise  

This code gives

Unexpected error: <class 'urllib.error.URLError'>  

assuming we enter an invalid url

and the rest goes like this idk if it's important or not

import urllib.request as ur  from bs4 import BeautifulSoup    ##core   while True:      try:          url=input("please enter your site (with no http:// ) : ")          link = ur.urlopen("http://"+url)          break      except:          print("please enter a valid url ")          raise      source=link.read()  scrapy = BeautifulSoup(source,'html.parser')  

Change table data when hovering over table/tabel row

Posted: 28 Apr 2021 08:57 AM PDT

I'm trying to make my table data change color upon hovering over a table row. Is that possible? I tried searching everywhere, but none seems to match my description.

I want to change the color of "Hello World" when I am hovering over the table row.

table tr:hover {    color: black  }
<table>    <tbody>      <tr>        <td> Hello World </td>      </tr>    </tbody>  </table>

Cross-platform way to check if "DUAL" table exists in SQL

Posted: 28 Apr 2021 08:54 AM PDT

I have an application that has the potential to use either an Oracle, MySQL, or SQL Server. In a few queries, I need to use the "DUAL" table, for example:

SELECT (CASE WHEN EXISTS (SELECT 1 FROM MYTABLE) THEN 1 ELSE 0 END) FROM DUAL  

However, the "DUAL" table is not supported in SQL Server.

Is there a SQL statement I can use that will check if the "DUAL" table is supported? This way I can branch to a different query if it's not supported.

I tried querying INFORMATION_SCHEMA.TABLES, but the "DUAL" table is not listed there, even in Oracle and MySQL where it's supported.

Can't upload video file over 80 mb with Apache and PHP 8 - No error in logs

Posted: 28 Apr 2021 08:56 AM PDT

So last weekend I updated to PHP 8.0.3, and since then I've been having problems uploading video files greater than 80 mb.

What I've tried:

  • I've confirmed that the post_max_size and upload_max_size are high enough in the php.ini (first I set them to 10G. Now I have them set to 0 in order to test an unlimited upload size).
  • I've checked both Apache's error.log and PHP's php_errors.log (where I have it configured to save the errors), but no new errors appear in either log when I make this request.
  • I've ensured that error logging is enabled in php.ini.
  • I have xdebug and have placed a breakpoint at the very first line of my index.php. It doesn't get there.
  • I've ensured there's nothing funny in my .htaccess (it's just the default Laravel .htaccess)
  • This isn't a timeout problem (I get the 500 error almost immediately). But I did increase the memory_limit to 2G just to rule out memory issues.
  • I've restarted Apache a billion times after each change

The 500 error I get is the typical Apache 500 error screen ("The server encountered an internal error or misconfiguration and was unable to complete your request...")

I'm stumped. This started happening with the switch to PHP 8 so I'm inclined to think it's something to do with that, but I don't know what else to try.

I'm running my tesing on:

  • Apache 2.4.35
  • Windows 10
  • Laragon
  • Laravel

Here's my php -i: https://github.com/chrisrollins65/dev/blob/main/phpinfo

Anything else I need to do?

Read a Date from text file and compare with current Date in Powershell

Posted: 28 Apr 2021 08:56 AM PDT

I pipelined date to a text file through Powershell. Now i need to compare the date in the text file with the current date. I am unable to figure it out. Pls help.

(get-date).AddDays(3) | Out-File -FilePath c:\time.txt  $deadline = Get-Content -Path C:\time.txt  $currenttime = Get-Date  IF ($currenttime -lt $deadline)   {Write-host "Continue Working"}  Else   {Write-Host "Your Logic is Wrong"}  

I do not get any output. Pls help.

Running discord bot alongside twitch bot

Posted: 28 Apr 2021 08:56 AM PDT

I have twitch bot and discord bot. I would like to control the twitch bot via discord, and send some data from twitch bot to discord bot. For example, I would type "?unload xx" in discord and it would turn off some feature in the twitch bot. Another example is that after some twitch event, I would send data to discord bot, and discord bot would show it in channel. I was trying to run the discord bot, and then twitch bot in backgrond loop, but that didn't work. I was also trying to setup http server for webhooks, but that didn't work either. Is there something I am missing? I can't solve this problem. Thank's for help guys.

EDIT Both are in python, different files but imported to the main and run in one. I was trying asyncio, that was the discord bot and twitch in background, but I was getting "this event loop is already running" error. I was also trying discord bot and http server in differet threads, but it was working really weirdly, not responding sometimes, sometimes not event starting, turning off after while.

How to Group and sum values of two Column in C# Linq

Posted: 28 Apr 2021 08:56 AM PDT

enter image description here

I have this Code. I am unable to add more columns like Date, Name...

        var dtt = dt.AsEnumerable()                .GroupBy(p => p.Field<Int64>("ID"))                .Select(p => new                {                    ID = p.Key,                    Debit = p.Sum(a => a.Field<Decimal>("Debit")),                    Credit = p.Sum(a => a.Field<Decimal>("Credit"))                }).ToArray();  

JS/Jquery, is there a way to populate my input text with fixed string and leading zeros?

Posted: 28 Apr 2021 08:56 AM PDT

I am planning to have an input textbox with leading string and zeros with maximum length of 6 leading zeros. When user type in the input box, the leading zero will be erase until it reach max 6 letters. The initial string is fixed and cannot be erase.

For example,

JS000000 //a fixed string (which is the letter 'JS') followed by 6 leading zeros  JS000010 //user has typed the letter '10'  JS123456 //user has typed the letter '123456' and cannot be type further  

HTML

<input type="text" name="js" class="form-control" id="js_leading_zero">  

JS/JQUERY

$('#js_leading_zero').on('keyup', function() {      console.log('i really have no ideas what to do here')  });  

Event click show the selected data with FullCalendar function

Posted: 28 Apr 2021 08:56 AM PDT

I have a problem for event click show the selected data with FullCalendar function in the popup modal. I just can show the start date data in the popup modal.

Below is my sample coding:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>  <script src="https://cdn.jsdelivr.net/npm/fullcalendar-scheduler@5.6.0/main.min.js"></script>  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fullcalendar-scheduler@5.6.0/main.css">  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>    <script>  //suppose this is array  var arrays = [{    "title": "All Day Event",    "start": "2021-04-01 00:00:00",    "color": "#40E0D0"  }, {    "title": "Long Event",    "start": "2016-01-07 00:00:00",    "color": "#FF0000"  }, {    "title": "Repeating Event",    "start": "2016-01-09 16:00:00",    "color": "#0071c5"  }, {    "title": "Conference",    "start": "2016-01-11 00:00:00",    "color": "#40E0D0"  }, {    "title": "Meeting",    "start": "2016-01-12 10:30:00",    "color": "#000"  }, {    "title": "Lunch",    "start": "2016-01-12 12:00:00",    "color": "#0071c5"  }, {    "title": "Happy Hour",    "start": "2016-01-12 17:30:00",    "color": "#0071c5"  }, {    "title": "Dinner",    "start": "2016-01-12 20:00:00",    "color": "#0071c5"  }, {    "title": "Birthday Party",    "start": "2016-01-14 07:00:00",    "color": "#FFD700"  }, {    "title": "Double click to change",    "start": "2016-01-28 00:00:00",    "color": "#008000"  }, {    "title": "512",    "start": "2021-04-04 00:00:00",    "color": "#FF0000"  }, {    "title": "21512",    "start": "2021-04-06 00:00:00",    "color": "#FF0000"  }, {    "title": "236234",    "start": "2021-04-07 00:00:00",    "color": "#FF0000"  }, {    "title": "3521",    "start": "2021-04-03 00:00:00",    "color": "#00FF00"  }, {    "title": "HHH",    "start": "2021-04-02 00:00:00",    "color": "#FFFF00"  }]    document.addEventListener('DOMContentLoaded', function() {    var calendarEl = document.getElementById('calendar');      var calendar = new FullCalendar.Calendar(calendarEl, {      headerToolbar: {        left: 'prev,next today',        center: 'title',        right: 'dayGridMonth,timeGridWeek,timeGridDay'      },      initialDate: '2021-04-25',      navLinks: true, // can click day/week names to navigate views      selectable: true,      selectMirror: true,      eventDidMount: function(view) {        //loop through json array        $(arrays).each(function(i, val) {          //find td->check if the title has same value-> get closest daygird ..change color there          $("td[data-date=" + moment(val.start).format("YYYY-MM-DD") + "] .fc-event-title:contains(" + val.title + ")").closest(".fc-daygrid-event-harness").css("background-color", val.color);        })      },      select: function(arg) {        $('#createEventModal #startTime').val(arg.start);        $('#createEventModal 

No comments:

Post a Comment