问:
Static files not loading
url inside main 'mySite' directory

```<code>urlpatterns = [
    path('admin/', admin.site.urls),
    path('coming-soon/', include('comingSoon.urls')),
]
</code>```

url inside comingSoon app directory

```<code>urlpatterns = [
    path("", views.index, name="coming-Soon")
]
</code>```

views.index inside comingSoon app

```<code>def index(request):
return render(request, 'comingSoon/coming-soon.html')
</code>```

inside template "coming-soon.html'

```<code><!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <title>My Website</title>
    <link rel="icon" href="images/fav.png" type="image/png" sizes="16x16">
    {% load static %}
    {% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/main.min.css' %}">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<link rel="stylesheet" href="{% static 'css/color.css' %}">
<link rel="stylesheet" href="{% static 'css/responsive.css' %}">

</head>
<body>
<div class="theme-layout">

    <div class="gap2 mate-black medium-opacity vh100">
        <div class="bg-image" style="background-image:url(images/resources/coming-soon-bg.jpg);"></div>
        <div class="container">
            <div class="row">
                <div class="col-lg-12">
                    <div class="coming-head">
                        <div class="logo">
                            <a href="index.html" title=""><img src="images/logo.png" alt=""></a>
                        </div>
                        <ul class="social-circle ">
                            <li><a class="facebook-color" href="#" title=""><i class="fa fa-facebook"></i></a></li>
                            <li><a class="twitter-color" href="#" title=""><i class="fa fa-twitter"></i></a></li>
                            <li><a class="google-color" href="#" title=""><i class="fa fa-google-plus"></i></a></li>
                            <li><a class="vk-color" href="#" title=""><i class="fa fa-vk"></i></a></li>
                        </ul>
                    </div>
                    <div class="coming-meta">
                        <h1>We're Coming!</h1>
                        <p>We are working hard to bring you new experience</p>
                        <ul class="countdown">
                           <li><span class="days">00</span><p class="days_ref"></p></li>
                           <li> <span class="hours">00</span><p class="hours_ref"></p></li>
                           <li> <span class="minutes">00</span><p class="minutes_ref"></p></li>
                           <li> <span class="seconds">00</span><p class="seconds_ref"></p></li>
                        </ul>
                        <form method="post">
                            <input type="text" placeholder="Submit inquiry...">
                            <button type="submit"><i class="fa fa-arrow-right"></i></button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>

    <script src="{% static 'js/main.min.js' %}"></script>
    <script src="{% static 'js/downCount.js' %}"></script>
    <script src="{% static 'js/script.js' %}"></script>

</body>
</html>
</code>```

at this point if I try to run, its loading with html but failed to load css and js

Folder Structure - 1

```<code>mySite.com
|-- mySite                   // django project directory
|   |-- mySite               // app directory
|   |   |-- __init__.py
|   |   |-- wsgi.py
|   |   |-- urls.py
|   |   |-- asgi.py
|   |   |-- setting.py
|   |
|   |-- comingSoon          // comingsoon  app
|   |   |-- migrations
|   |   |-- __init__.py
|   |   |-- admin.py
|   |   |-- apps.py
|   |   |-- models.py
|   |   |-- tests.py
|   |   |-- urls.py
|   |   |-- views.py
|   |
|   |-- static         // static files intentionally placing outside app directory (***but not loading***)
|   |   |-- css
|   |   |-- js
|   |   |-- images
|   |   |-- fonts
|   |
|   |-- templates                // templates folder for base templates.
|   |   |-- base1.html
|   |   |-- base2.html
|   |   |-- comingSoon           // comingSoon directory
|   |   |   |-- coming-soon.html // html file - this is loading
</code>```

I have done few modification like i have added an app called 'audio' and created a static folder inside it and now if i access my static folder its working fine. But i want to access by keeping static files as like in Folder Structure - 1

```<code>mySite.com
    |-- mySite                   // django project directory
    |   |-- mySite               // app directory
    |   |   |-- __init__.py
    |   |   |-- wsgi.py
    |   |   |-- urls.py
    |   |   |-- asgi.py
    |   |   |-- setting.py
    |   |
    |   |-- audio          // Audio app
    |   |   |-- migrations
    |   |   |-- static
    |   |   |   |-- audio
    |   |   |       |-- css
    |   |   |       |-- js
    |   |   |-- __init__.py
    |   |   |-- admin.py
    |   |   |-- apps.py
    |   |   |-- models.py
    |   |   |-- tests.py
    |   |   |-- urls.py
    |   |   |-- views.py
    |   |
    |   |-- comingSoon          // comingsoon  app
    |   |   |-- migrations
    |   |   |-- __init__.py
    |   |   |-- admin.py
    |   |   |-- apps.py
    |   |   |-- models.py
    |   |   |-- tests.py
    |   |   |-- urls.py
    |   |   |-- views.py
    |   |
    |   |-- static         // static files intentionally placing outside app directory (***but not loading***)
    |   |   |-- css
    |   |   |-- js
    |   |   |-- images
    |   |   |-- fonts
    |   |
    |   |-- templates                // templates folder for base templates.
    |   |   |-- base1.html
    |   |   |-- base2.html
    |   |   |-- comingSoon           // comingSoon directory
    |   |   |   |-- coming-soon.html // html file - this is loading
</code>```

STATIC at settings.py - Updated

```<code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
</code>```

not finding the actual mistake/s after several attempts

errors what i am getting is as follows

```<code>[02/Jun/2020 02:28:05] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:05] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:05] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:05] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:05] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:05] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:05] "GET /static/main.min.js HTTP/1.1" 404 1657
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:05] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:28:05] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:05] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:28:05] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:05] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:06] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:06] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:06] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:28:06] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:06] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:06] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:06] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:06] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:06] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:06] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:28:06] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:06] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:07] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:07] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:07] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:07] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:07] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:28:07] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:07] "GET /static/css/color.css HTTP/1.1" 404 1663
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:07] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:07] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:28:07] "GET /static/js/downCount.js HTTP/1.1" 404 1669
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:07] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:28:07] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:07] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:07] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:07] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:07] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:07] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:07] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:28:07] "GET /static/js/downCount.js HTTP/1.1" 404 1669
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:07] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:28:07] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:07] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:28:07] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:07] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:08] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:08] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:08] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:08] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:08] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:08] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:08] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:28:08] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:08] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:08] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:28:08] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:08] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:32:34] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:32:34] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:32:34] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:32:34] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:32:34] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:32:34] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:32:34] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:32:34] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:32:34] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:32:34] "GET /static/js/downCount.js HTTP/1.1" 404 1669
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:32:34] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:32:34] "GET /static/js/script.js HTTP/1.1" 404 1660
</code>```

答:
Change the   STATICFILES_DIRS

```<code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
</code>```

Title: Static files not loading

Body:
url inside main 'mySite' directory

urlpatterns = [
    path('admin/', admin.site.urls),
    path('coming-soon/', include('comingSoon.urls')),
]

url inside comingSoon app directory

urlpatterns = [
    path("", views.index, name="coming-Soon")
]

views.index inside comingSoon app

def index(request):
return render(request, 'comingSoon/coming-soon.html')

inside template "coming-soon.html'

<!DOCTYPE html>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <title>My Website</title>
    <link rel="icon" href="images/fav.png" type="image/png" sizes="16x16">
    {% load static %}
    {% load staticfiles %}
<link rel="stylesheet" href="{% static 'css/main.min.css' %}">
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<link rel="stylesheet" href="{% static 'css/color.css' %}">
<link rel="stylesheet" href="{% static 'css/responsive.css' %}">

We're Coming!

We are working hard to bring you new experience

00

 00

 00

 00

                        <form method="post">
                            <input type="text" placeholder="Submit inquiry...">
                            <button type="submit"></button>
                        </form>

at this point if I try to run, its loading with html but failed to load css and js

Folder Structure - 1

mySite.com
|-- mySite                   // django project directory
|   |-- mySite               // app directory
|   |   |-- __init__.py
|   |   |-- wsgi.py
|   |   |-- urls.py
|   |   |-- asgi.py
|   |   |-- setting.py
|   |
|   |-- comingSoon          // comingsoon  app
|   |   |-- migrations
|   |   |-- __init__.py
|   |   |-- admin.py
|   |   |-- apps.py
|   |   |-- models.py
|   |   |-- tests.py
|   |   |-- urls.py
|   |   |-- views.py
|   |
|   |-- static         // static files intentionally placing outside app directory (***but not loading***)
|   |   |-- css
|   |   |-- js
|   |   |-- images
|   |   |-- fonts
|   |
|   |-- templates                // templates folder for base templates.
|   |   |-- base1.html
|   |   |-- base2.html
|   |   |-- comingSoon           // comingSoon directory
|   |   |   |-- coming-soon.html // html file - this is loading

I have done few modification like i have added an app called 'audio' and created a static folder inside it and now if i access my static folder its working fine. But i want to access by keeping static files as like in Folder Structure - 1

mySite.com
    |-- mySite                   // django project directory
    |   |-- mySite               // app directory
    |   |   |-- __init__.py
    |   |   |-- wsgi.py
    |   |   |-- urls.py
    |   |   |-- asgi.py
    |   |   |-- setting.py
    |   |
    |   |-- audio          // Audio app
    |   |   |-- migrations
    |   |   |-- static
    |   |   |   |-- audio
    |   |   |       |-- css
    |   |   |       |-- js
    |   |   |-- __init__.py
    |   |   |-- admin.py
    |   |   |-- apps.py
    |   |   |-- models.py
    |   |   |-- tests.py
    |   |   |-- urls.py
    |   |   |-- views.py
    |   |
    |   |-- comingSoon          // comingsoon  app
    |   |   |-- migrations
    |   |   |-- __init__.py
    |   |   |-- admin.py
    |   |   |-- apps.py
    |   |   |-- models.py
    |   |   |-- tests.py
    |   |   |-- urls.py
    |   |   |-- views.py
    |   |
    |   |-- static         // static files intentionally placing outside app directory (***but not loading***)
    |   |   |-- css
    |   |   |-- js
    |   |   |-- images
    |   |   |-- fonts
    |   |
    |   |-- templates                // templates folder for base templates.
    |   |   |-- base1.html
    |   |   |-- base2.html
    |   |   |-- comingSoon           // comingSoon directory
    |   |   |   |-- coming-soon.html // html file - this is loading

STATIC at settings.py - Updated

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

not finding the actual mistake/s after several attempts

errors what i am getting is as follows

[02/Jun/2020 02:28:05] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:05] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:05] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:05] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:05] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:05] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:05] "GET /static/main.min.js HTTP/1.1" 404 1657
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:05] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:28:05] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:05] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:28:05] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:05] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:06] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:06] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:06] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:28:06] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:06] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:06] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:06] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:06] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:06] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:06] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:28:06] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:06] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:07] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:07] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:07] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:07] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:07] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:28:07] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:07] "GET /static/css/color.css HTTP/1.1" 404 1663
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:07] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:07] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:28:07] "GET /static/js/downCount.js HTTP/1.1" 404 1669
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:07] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:28:07] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:07] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:07] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:07] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:07] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:07] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:07] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:28:07] "GET /static/js/downCount.js HTTP/1.1" 404 1669
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:07] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:28:07] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:07] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:28:07] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:07] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:28:08] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:28:08] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:08] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:28:08] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:08] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:28:08] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:28:08] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:28:08] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:28:08] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:28:08] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:28:08] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:28:08] "GET /static/js/script.js HTTP/1.1" 404 1660
[02/Jun/2020 02:32:34] "GET /coming-soon/ HTTP/1.1" 200 2555
[02/Jun/2020 02:32:34] "GET /static/css/color.css HTTP/1.1" 404 1663
[02/Jun/2020 02:32:34] "GET /static/main.min.js HTTP/1.1" 404 1657
[02/Jun/2020 02:32:34] "GET /static/css/responsive.css HTTP/1.1" 404 1678
[02/Jun/2020 02:32:34] "GET /static/js/downCount.js HTTP/1.1" 404 1669
[02/Jun/2020 02:32:34] "GET /static/css/main.min.css HTTP/1.1" 404 1672
[02/Jun/2020 02:32:34] "GET /static/css/style.css HTTP/1.1" 404 1663
[02/Jun/2020 02:32:34] "GET /static/js/script.js HTTP/1.1" 404 1660
Not Found: /coming-soon/images/logo.png
[02/Jun/2020 02:32:34] "GET /coming-soon/images/logo.png HTTP/1.1" 404 3713
[02/Jun/2020 02:32:34] "GET /static/js/downCount.js HTTP/1.1" 404 1669
Not Found: /coming-soon/images/resources/coming-soon-bg.jpg
[02/Jun/2020 02:32:34] "GET /coming-soon/images/resources/coming-soon-bg.jpg HTTP/1.1" 404 3773
[02/Jun/2020 02:32:34] "GET /static/js/script.js HTTP/1.1" 404 1660

Body:
Change the   STATICFILES_DIRS

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')


来源: stackexchange

问:
Is there any way to emulate inline let expressions in JavaScript?
I'm writing a compiler from a functional language to JavaScript. Since my language is based on expressions, it is natural to compile it to a JavaScript expression too. The problem is that when compiling let expressions, we need the ability to declare and assign variables "inline". For example:

```<code>function foo(x) {
  return (let y = x * x; y);
}
</code>```

This code, obviously, doesn't work since we can't use let inside expressions. One solution would be to wrap everything inside a lambda:

```<code>function foo(x) {
  return (()=>{let y = x*x; return y})();
}
</code>```

But this has a significant runtime cost in some cases. The other alternative would be to just adjust the compiler to produce statements instead of expressions, but this would be a non-trivial change and I'd rather avoid it if possible.

Is there any way to declare and assign local variables to JavaScript as an expression rather than a statement that has no extra runtime costs?

答:
You should avoid creating new variables and just return the value directly:

```<code>function foo(x) {
  return  x * x;
}
</code>```

But if you really need to inline a let, this should work:

```<code>const foo = (x) => {let y=x*x;return y;}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I'm writing a compiler from a functional language to JavaScript. Since my language is based on expressions, it is natural to compile it to a JavaScript expression too. The problem is that when compiling let expressions, we need the ability to declare and assign variables "inline". For example:

function foo(x) {
  return (let y = x * x; y);
}

This code, obviously, doesn't work since we can't use let inside expressions. One solution would be to wrap everything inside a lambda:

function foo(x) {
  return (()=>{let y = x*x; return y})();
}

But this has a significant runtime cost in some cases. The other alternative would be to just adjust the compiler to produce statements instead of expressions, but this would be a non-trivial change and I'd rather avoid it if possible.

Is there any way to declare and assign local variables to JavaScript as an expression rather than a statement that has no extra runtime costs?

Body:
You should avoid creating new variables and just return the value directly:

function foo(x) {
  return  x * x;
}

But if you really need to inline a let, this should work:

const foo = (x) => {let y=x*x;return y;}


问:
PHP start_session() error
Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

I am getting this error while accessing the database. and in my project session is getting cleared automatically and i could not able to connect to server through filezilla .can you tell me how to solve this problem

答:
Please set error_reporting to E_ALL and display errors set to On. You will see some PHP error messages logged when you get this message.

It might be that IIS doesn't have write permissions to your temp directory where the sessions are stored.

ContentLicense: CC BY-SA 3.0

Title: PHP start_session() error


问:
when showing large amount of data graph not displaying from middle
Using Chartjs-v2.9.3, the line or bar from the middle to the end of the graph is not displaying. But the tooltip is showing data.

However, when using same data in Chartjs-v2.4.0, all the data lines are displayed in the graph.

Here is  Chartjs-v2.9.3 result:

But with Chartjs-v2.4.0, there is no display problem.

Here is the data used for both.

```<code>var ctx = document.getElementById('chartJSContainer');
new Chart(ctx, {
  type: 'line',
  data: {
    "labels": ["03/01 00:00", "03/01 01:00", "03/01 02:00", "03/01 03:00", "03/01 04:00", "03/01 05:00", ...x500],
    "datasets": [{
      "pointRadius": 0,
      "pointBorderWidth": 0,
      "pointStyle": "rectRounded",
      "lineTension": 0,
      "borderWidth": 1,
      "fill": false,
      "borderColor": "blue",
      "backgroundColor": "blue",
      "data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...x500]
    }]
  },
  options: {
    maintainAspectRatio:false,
    responsive:true,
    legend:{
      display:false,position:"top",align:"start"},
    scales:{
      yAxes:[
        {ticks:{min:0,beginAtZero:true}}],
      xAxes:[
        {ticks:{minRotation:0,maxRotation:80}}]},
      tooltips:{intersect:false,position:"nearest",callbacks:{}}
    }
})
</code>```

and just a simple display in Html:

```<code><body>
  <div style="overflow:auto;position:relative;width:33480px;height:500px;" >
    <canvas id="chartJSContainer"></canvas>
  </div>
</body>
</code>```

jsfiddle link

Is there a display limit in Chartjs?

答:
I think the problem lies in your html div style.

Don't know what you want to achieve with these numbers, but without them everything is fine.

https://jsbin.com/gogufonibi/1/edit?html,js,output

```<code><div>
  <canvas id="chartJSContainer" width="3480px" height="500"></canvas>
</div>
</code>```

Body:
Using Chartjs-v2.9.3, the line or bar from the middle to the end of the graph is not displaying. But the tooltip is showing data.

However, when using same data in Chartjs-v2.4.0, all the data lines are displayed in the graph.

Here is  Chartjs-v2.9.3 result:

But with Chartjs-v2.4.0, there is no display problem.

Here is the data used for both.

var ctx = document.getElementById('chartJSContainer');
new Chart(ctx, {
  type: 'line',
  data: {
    "labels": ["03/01 00:00", "03/01 01:00", "03/01 02:00", "03/01 03:00", "03/01 04:00", "03/01 05:00", ...x500],
    "datasets": [{
      "pointRadius": 0,
      "pointBorderWidth": 0,
      "pointStyle": "rectRounded",
      "lineTension": 0,
      "borderWidth": 1,
      "fill": false,
      "borderColor": "blue",
      "backgroundColor": "blue",
      "data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...x500]
    }]
  },
  options: {
    maintainAspectRatio:false,
    responsive:true,
    legend:{
      display:false,position:"top",align:"start"},
    scales:{
      yAxes:[
        {ticks:{min:0,beginAtZero:true}}],
      xAxes:[
        {ticks:{minRotation:0,maxRotation:80}}]},
      tooltips:{intersect:false,position:"nearest",callbacks:{}}
    }
})

and just a simple display in Html:

    <canvas id="chartJSContainer"></canvas>

jsfiddle link

Is there a display limit in Chartjs?

Body:
I think the problem lies in your html div style.

Don't know what you want to achieve with these numbers, but without them everything is fine.

https://jsbin.com/gogufonibi/1/edit?html,js,output

<div>
  <canvas id="chartJSContainer" width="3480px" height="500"></canvas>
</div>


问:
Changing the width of AutoCompleteTextView in Android
I've been stumped on this for a few days. I have an autoCompleteTextView and a button split 50/50 in my layout. The autocomplete works, but the suggestions only take up half of the screen (equivalent to the size that my textView takes up). How could I change this to take up the whole width?

Pardon my terrible paint skills:

Blue = AutoCompleteTextView
Red = desired autocomplete suggestions

This seems like a trivial problem, but simply changing the width to fill_parent doesn't work. Any ideas xml or programatically?

SOLUTION: myAutoCompleteTextView.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT)

EDIT:
My first question seems to be solved, but now if I switch my button and my autoCompleteTextView I get another weird problem. The width starts at where the textView starts. Leaving me with an undesireable result.

SOLUTION: See edit 1 from user: vikram

答:
In my case AutoCompleteTextView occupied a whole width. Looking at change position of spinner dropdown list I set

```<code>android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
</code>```

to create left and right margins of a list.

Body:
In my case AutoCompleteTextView occupied a whole width. Looking at change position of spinner dropdown list I set

android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"

to create left and right margins of a list.


问:
Jooq unable to find database when triggered via a gradle image on Dockerfile
I have a Dockerfile that uses gradle to build my Spring boot application just before coping it into the container and trigger it. This is how it looks:

```<code>FROM gradle:5.4.1-jdk8-alpine AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle build --no-daemon

FROM openjdk:8-jdk-alpine
EXPOSE 8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/*.jar yurlapp.jar
ENTRYPOINT ["java","-jar" , "/yurlapp.jar"]
</code>```

It's quite simple, it will execute Gradle and the jar will be added into the docker container. So far so good. This Dockerfile will be used inside a docker-compose.yml once the database is provided(the DB is required for the app to work). This is how that docker-compose.yml looks like:

```<code>version: '2.1'
services:
  yurldb:
    image: postgres:11
    container_name: yurldb
    networks:
      - yunet
    ports:
      - 5432:5432
    environment:
      - POSTGRES_DB=yurldb
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=somepassword
    volumes:
      - ./init.sql:/docker-entrypoint-initdb.d/
      - yudata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 10s
      retries: 5
  flyway:
    image: boxfuse/flyway
    command: -url=jdbc:postgresql://yurldb:5432/yurldb -schemas=public -user=postgres -password=somepassword migrate
    networks:
      - yunet
    volumes:
      - .:/flyway/sql
    depends_on:
      yurldb:
        condition: service_healthy
  yurlapp:
    container_name: yurlapp
    image: javing/yurlapp:0.0.1
    build:
      context: .
      dockerfile: Dockerfile
    networks:
      - yunet
    ports:
      - 8080:8080
    environment:
      - DB_HOST=yurldb #the name of the DB container is used as url
    depends_on:
      yurldb:
        condition: service_healthy
      flyway:
        condition: service_healthy
networks:
  yunet:
volumes:
  yudata:
</code>```

As you can see the app image be built last, once the database image is ready and also after flyway performs the migrations. The problem that I have happens during the building of the app.
So once gradle starts it will do all it has to do. But at one point it requires Jooq, to autogenerate some classes based on the existing tables on the database. And in here something goes wrong. The build blows up and tells me this:

Task :generateSampleJooqSchemaSource FAILED

```<code>FAILURE: Build failed with an exception.

* Where:
Build file '/home/gradle/src/build.gradle' line: 81

* What went wrong:
Execution failed for task ':generateSampleJooqSchemaSource'.
> jOOQ source code generation failed:

  Jun 01, 2020 7:37:39 PM org.jooq.tools.JooqLogger info
  INFO: Initialising properties  : /home/gradle/src/build/tmp/generateSampleJooqSchemaSource/config.xml
  Jun 01, 2020 7:37:39 PM org.jooq.tools.JooqLogger error
  SEVERE: Cannot read /home/gradle/src/build/tmp/generateSampleJooqSchemaSource/config.xml. Error : Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
  org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:285)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
    at org.postgresql.Driver.makeConnection(Driver.java:459)
    at org.postgresql.Driver.connect(Driver.java:261)
    at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:342)
    at org.jooq.codegen.GenerationTool.run(GenerationTool.java:221)
    at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:216)
    at org.jooq.codegen.GenerationTool.main(GenerationTool.java:188)
  Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:81)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:93)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
    ... 8 more
</code>```

It says that it can't connect to the database. Why is that? This is the Jooq configuration I have in my build.gradle file

```<code>jooq {
    sample(sourceSets.main) {
        jdbc {
            driver = 'org.postgresql.Driver'
            url = 'jdbc:postgresql://localhost:5432/yurldb'
            user = 'postgres'
            password = 'somepassword'
        }
        generator {
            database() {
                name = 'org.jooq.meta.postgres.PostgresDatabase'
                inputSchema = 'public'
                includes = '.*'
            }
            target {
                packageName = 'com.javing.yurl'
                directory = 'build/generated/java'
            }
        }
    }
}

tasks.generateSampleJooqSchemaSource.with {
    def out = new ByteArrayOutputStream()
    javaExecSpec = { JavaExecSpec s ->
        s.standardOutput = out
        s.errorOutput = out
        s.ignoreExitValue = true
        s.jvmArgs '-Xmx512M'
    }
    execResultHandler = { ExecResult r ->
        if (r.exitValue != 0) {
            throw new RuntimeException('jOOQ source code generation failed:\n\n' + out.toString())
        }
    }
}
</code>```

I am very confused, I am not sure I understand what is happening. If I was to use docker-compose to just boot the database image just by itself and then I run gradle manually from my terminal(not the gradle from docker), those classes will be generated without problem. So I don't know when the gradle is used from the Dockerfile Jooq fails to find the DB. Any idea?
Do i also need to trigger Jooq maybe from the Dockerfile somehow, in the same way that I triggered gradle? Can someone help me with this please, I am a bit stuck.

Update
I tried changing the url in the jooq config to use yurldb instead of localhost since maybe when networking inside the container the url resloves to the name of the container, but that didn't work. What happens is this:

```<code>FAILURE: Build failed with an exception.

* Where:
Build file '/home/gradle/src/build.gradle' line: 81

* What went wrong:
Execution failed for task ':generateSampleJooqSchemaSource'.
> jOOQ source code generation failed:

  Jun 01, 2020 8:29:57 PM org.jooq.tools.JooqLogger info
  INFO: Initialising properties  : /home/gradle/src/build/tmp/generateSampleJooqSchemaSource/config.xml
  Jun 01, 2020 8:30:08 PM org.jooq.tools.JooqLogger error
  SEVERE: Cannot read /home/gradle/src/build/tmp/generateSampleJooqSchemaSource/config.xml. Error : The connection attempt failed.
  org.postgresql.util.PSQLException: The connection attempt failed.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:297)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
    at org.postgresql.Driver.makeConnection(Driver.java:459)
    at org.postgresql.Driver.connect(Driver.java:261)
    at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:342)
    at org.jooq.codegen.GenerationTool.run(GenerationTool.java:221)
    at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:216)
    at org.jooq.codegen.GenerationTool.main(GenerationTool.java:188)
  Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:81)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:93)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
    ... 8 more
</code>```

答:
The problem is that you have localhost as the database host in the configuration of your jooq plugin in build.gradle.

You have correctly set environment variables for DB_HOST in other places so I assume you understand that name of the service is the DNS name that you can use to refer to other services when they are connected to a common network. You should change

```<code>url = 'jdbc:postgresql://localhost:5432/yurldb'
</code>```

to

```<code>url = 'jdbc:postgresql://yurldb:5432/yurldb'
</code>```

or you can get the host of db in environment variable for application service and then read it from build.gradle :

```<code>def db = System.getenv('DB_HOST')
url = "jdbc:postgresql://${db}:5432/yurldb"
</code>```

Body:
I have a Dockerfile that uses gradle to build my Spring boot application just before coping it into the container and trigger it. This is how it looks:

FROM gradle:5.4.1-jdk8-alpine AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle build --no-daemon

FROM openjdk:8-jdk-alpine
EXPOSE 8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/*.jar yurlapp.jar
ENTRYPOINT ["java","-jar" , "/yurlapp.jar"]

It's quite simple, it will execute Gradle and the jar will be added into the docker container. So far so good. This Dockerfile will be used inside a docker-compose.yml once the database is provided(the DB is required for the app to work). This is how that docker-compose.yml looks like:

version: '2.1'
services:
  yurldb:
    image: postgres:11
    container_name: yurldb
    networks:
      - yunet
    ports:
      - 5432:5432
    environment:
      - POSTGRES_DB=yurldb
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=somepassword
    volumes:
      - ./init.sql:/docker-entrypoint-initdb.d/
      - yudata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 10s
      retries: 5
  flyway:
    image: boxfuse/flyway
    command: -url=jdbc:postgresql://yurldb:5432/yurldb -schemas=public -user=postgres -password=somepassword migrate
    networks:
      - yunet
    volumes:
      - .:/flyway/sql
    depends_on:
      yurldb:
        condition: service_healthy
  yurlapp:
    container_name: yurlapp
    image: javing/yurlapp:0.0.1
    build:
      context: .
      dockerfile: Dockerfile
    networks:
      - yunet
    ports:
      - 8080:8080
    environment:
      - DB_HOST=yurldb #the name of the DB container is used as url
    depends_on:
      yurldb:
        condition: service_healthy
      flyway:
        condition: service_healthy
networks:
  yunet:
volumes:
  yudata:

As you can see the app image be built last, once the database image is ready and also after flyway performs the migrations. The problem that I have happens during the building of the app.
So once gradle starts it will do all it has to do. But at one point it requires Jooq, to autogenerate some classes based on the existing tables on the database. And in here something goes wrong. The build blows up and tells me this:

Task :generateSampleJooqSchemaSource FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '/home/gradle/src/build.gradle' line: 81

* What went wrong:
Execution failed for task ':generateSampleJooqSchemaSource'.
> jOOQ source code generation failed:

  Jun 01, 2020 7:37:39 PM org.jooq.tools.JooqLogger info
  INFO: Initialising properties  : /home/gradle/src/build/tmp/generateSampleJooqSchemaSource/config.xml
  Jun 01, 2020 7:37:39 PM org.jooq.tools.JooqLogger error
  SEVERE: Cannot read /home/gradle/src/build/tmp/generateSampleJooqSchemaSource/config.xml. Error : Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
  org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:285)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
    at org.postgresql.Driver.makeConnection(Driver.java:459)
    at org.postgresql.Driver.connect(Driver.java:261)
    at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:342)
    at org.jooq.codegen.GenerationTool.run(GenerationTool.java:221)
    at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:216)
    at org.jooq.codegen.GenerationTool.main(GenerationTool.java:188)
  Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:81)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:93)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
    ... 8 more

It says that it can't connect to the database. Why is that? This is the Jooq configuration I have in my build.gradle file

jooq {
    sample(sourceSets.main) {
        jdbc {
            driver = 'org.postgresql.Driver'
            url = 'jdbc:postgresql://localhost:5432/yurldb'
            user = 'postgres'
            password = 'somepassword'
        }
        generator {
            database() {
                name = 'org.jooq.meta.postgres.PostgresDatabase'
                inputSchema = 'public'
                includes = '.*'
            }
            target {
                packageName = 'com.javing.yurl'
                directory = 'build/generated/java'
            }
        }
    }
}

tasks.generateSampleJooqSchemaSource.with {
    def out = new ByteArrayOutputStream()
    javaExecSpec = { JavaExecSpec s ->
        s.standardOutput = out
        s.errorOutput = out
        s.ignoreExitValue = true
        s.jvmArgs '-Xmx512M'
    }
    execResultHandler = { ExecResult r ->
        if (r.exitValue != 0) {
            throw new RuntimeException('jOOQ source code generation failed:\n\n' + out.toString())
        }
    }
}

I am very confused, I am not sure I understand what is happening. If I was to use docker-compose to just boot the database image just by itself and then I run gradle manually from my terminal(not the gradle from docker), those classes will be generated without problem. So I don't know when the gradle is used from the Dockerfile Jooq fails to find the DB. Any idea?
Do i also need to trigger Jooq maybe from the Dockerfile somehow, in the same way that I triggered gradle? Can someone help me with this please, I am a bit stuck.

Update
I tried changing the url in the jooq config to use yurldb instead of localhost since maybe when networking inside the container the url resloves to the name of the container, but that didn't work. What happens is this:

FAILURE: Build failed with an exception.

* Where:
Build file '/home/gradle/src/build.gradle' line: 81

* What went wrong:
Execution failed for task ':generateSampleJooqSchemaSource'.
> jOOQ source code generation failed:

  Jun 01, 2020 8:29:57 PM org.jooq.tools.JooqLogger info
  INFO: Initialising properties  : /home/gradle/src/build/tmp/generateSampleJooqSchemaSource/config.xml
  Jun 01, 2020 8:30:08 PM org.jooq.tools.JooqLogger error
  SEVERE: Cannot read /home/gradle/src/build/tmp/generateSampleJooqSchemaSource/config.xml. Error : The connection attempt failed.
  org.postgresql.util.PSQLException: The connection attempt failed.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:297)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:211)
    at org.postgresql.Driver.makeConnection(Driver.java:459)
    at org.postgresql.Driver.connect(Driver.java:261)
    at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:342)
    at org.jooq.codegen.GenerationTool.run(GenerationTool.java:221)
    at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:216)
    at org.jooq.codegen.GenerationTool.main(GenerationTool.java:188)
  Caused by: java.net.SocketTimeoutException: connect timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:81)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:93)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
    ... 8 more

Body:
The problem is that you have localhost as the database host in the configuration of your jooq plugin in build.gradle.

You have correctly set environment variables for DB_HOST in other places so I assume you understand that name of the service is the DNS name that you can use to refer to other services when they are connected to a common network. You should change

url = 'jdbc:postgresql://localhost:5432/yurldb'

to

url = 'jdbc:postgresql://yurldb:5432/yurldb'

or you can get the host of db in environment variable for application service and then read it from build.gradle :

def db = System.getenv('DB_HOST')
url = "jdbc:postgresql://${db}:5432/yurldb"


问:
How to attach the VSCode debugger to the Brave browser?
When I open my web application in the Chrome browser I can attach the VSCode debugger to it.

The debugger configuration is:

```<code>{
    "name": "Attach to Chrome",
    "type": "chrome",
    "request": "attach",
    "port": 9222,
    "url": "http://localhost:4200/*",
    "webRoot": "${workspaceFolder}",
},
</code>```

But when I open the web application in the Brave browser I cannot attach the VSCode debugger.

The web application is an Angular one opened at http://localhost:4200/users

I'm running:

```<code>Chrome Version 70.0.3538.102 (Build officiel) (64 bits)
Brave Version 0.56.12 Chromium: 70.0.3538.77 (Build officiel) (64 bits)
VSCode Version 1.23.0
</code>```

on a Lubuntu 16.04 box.

Is the Brave browser not yet ready for debugging ? Or is there some port restriction I should remove ? I have put the shiled down for this web application. But VSCode still does not attach to it.

答:
As mentioned in the other answers, you need to add a "runtimeExecutable" field in the launch.json file of your project that will point to the executable of Brave Browser.

... but ...

You also need to launch the browser with the following option : --remote-debugging-port=9222

You have 2 ways to do it :

Launching Brave with the option (Windows : Right click the Brave shortcut, and select properties, and in the "target" field, append --remote-debugging-port=9222, MacOS / linux : execute <path to brave>/brave --remote-debugging-port=9222) (reminder : don't forget to relaunch Brave)

Following Cornelius suggestion, you can simply add the following to your launch.json :

"runtimeArgs": [ "--remote-debugging-port=9222" ]
```

This second option applies ONLY if you have the request: "launch" option, not the request: "attach" one, and if you want to use the "lauch" option, it will open another Brave window, not a new tab. So you'll probably want to use the first method in the long run.

Body:
When I open my web application in the Chrome browser I can attach the VSCode debugger to it.

The debugger configuration is:

{
    "name": "Attach to Chrome",
    "type": "chrome",
    "request": "attach",
    "port": 9222,
    "url": "http://localhost:4200/*",
    "webRoot": "${workspaceFolder}",
},

But when I open the web application in the Brave browser I cannot attach the VSCode debugger.

The web application is an Angular one opened at http://localhost:4200/users

I'm running:

Chrome Version 70.0.3538.102 (Build officiel) (64 bits)
Brave Version 0.56.12 Chromium: 70.0.3538.77 (Build officiel) (64 bits)
VSCode Version 1.23.0

on a Lubuntu 16.04 box.

Is the Brave browser not yet ready for debugging ? Or is there some port restriction I should remove ? I have put the shiled down for this web application. But VSCode still does not attach to it.

Body:
As mentioned in the other answers, you need to add a "runtimeExecutable" field in the launch.json file of your project that will point to the executable of Brave Browser.

... but ...

You also need to launch the browser with the following option : --remote-debugging-port=9222

You have 2 ways to do it :

Launching Brave with the option (Windows : Right click the Brave shortcut, and select properties, and in the "target" field, append --remote-debugging-port=9222, MacOS / linux : execute <path to brave>/brave --remote-debugging-port=9222) (reminder : don't forget to relaunch Brave)

Following Cornelius suggestion, you can simply add the following to your launch.json :

"runtimeArgs": [ "--remote-debugging-port=9222" ]

This second option applies ONLY if you have the request: "launch" option, not the request: "attach" one, and if you want to use the "lauch" option, it will open another Brave window, not a new tab. So you'll probably want to use the first method in the long run.


问:
Validation with html form only gives if statement
No matter how many characters I enter, it only gives the if statement and not the else.
is there a typo I entered somewhere I am not seeing, or does the function not work if there are two inputs?

function valid_Function(){
    var x, text;

    x = document.getElementById("name").value;

    if (isNaN(x) || x < 1 || x > 10) {
        text = "Input not valid";
    }
    else {
        text = "Input OK";
    }
    document.getElementById("valid").innerHTML = text;
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>form input {
    display: block;
    margin-top: 10px;
}
form [type="submit"] {
    padding: 5px;
    border-radius: 5px;
    border: none;
    background: skyblue;
    transition: .5s ease;
}
form [type="submit"]:hover {
    box-shadow: 0 2px 5px 2px rgba(92, 228, 252, 0.8);
}</code>```

<form action="#">
        <input for="fname" id="name" placeholder="First Name" type="text">
        <input for="lname" id="name" placeholder="Last Name" type="text">
        <input onclick="valid_Function()" type="submit" value="Submit">
    </form>

```

答:
No matter how many characters I enter, it only gives the if statement and not the else

Yes because isNaN will always return true if you give it a non number string and that's what is happening with you, if you try and input a number between 1 and 9 then your else will be executed.

Your validation works with number type inputs but since you want to validate a text input(name) then it can be done like this

your if statement

```<code>if (isNaN(x) || x < 1 || x > 10) {
    text = "Input not valid";
}
</code>```

should be

```<code>if(x === "" || x.length > 10) {
    text = "Input not valid";
}
</code>```

because you need to check if the input is empty and if it is larger than 10 chars, besides I noticed you have two inputs with the same id!, the id is something unique it's not like classes, so pls change your HTML code

Body:
No matter how many characters I enter, it only gives the if statement and not the else.
is there a typo I entered somewhere I am not seeing, or does the function not work if there are two inputs?

function valid_Function(){
    var x, text;

    x = document.getElementById("name").value;

    if (isNaN(x) || x < 1 || x > 10) {
        text = "Input not valid";
    }
    else {
        text = "Input OK";
    }
    document.getElementById("valid").innerHTML = text;
}

form input {
    display: block;
    margin-top: 10px;
}
form [type="submit"] {
    padding: 5px;
    border-radius: 5px;
    border: none;
    background: skyblue;
    transition: .5s ease;
}
form [type="submit"]:hover {
    box-shadow: 0 2px 5px 2px rgba(92, 228, 252, 0.8);
}

<form action="#">
        <input for="fname" id="name" placeholder="First Name" type="text">
        <input for="lname" id="name" placeholder="Last Name" type="text">
        <input onclick="valid_Function()" type="submit" value="Submit">
    </form>

Body:
No matter how many characters I enter, it only gives the if statement and not the else

Yes because isNaN will always return true if you give it a non number string and that's what is happening with you, if you try and input a number between 1 and 9 then your else will be executed.

Your validation works with number type inputs but since you want to validate a text input(name) then it can be done like this

your if statement

if (isNaN(x) || x < 1 || x > 10) {
    text = "Input not valid";
}

should be

if(x === "" || x.length > 10) {
    text = "Input not valid";
}

because you need to check if the input is empty and if it is larger than 10 chars, besides I noticed you have two inputs with the same id!, the id is something unique it's not like classes, so pls change your HTML code


问:
Logon failed, use ctrl+c to cancel basic credential prompt to Git in Azure DevOps
When cloning a git repository sitting up in Azure Repos into my local machine clone succeeds but I get a line that says:

```<code>Logon failed, use ctrl+c to cancel basic credential prompt
</code>```

Not sure what this is referring to, any ideas?

I'm using PAT token to authenticate my clone, command is:

```<code>git clone https://*************PAT*************@dev.azure.com/orgname/projectname/_git/reponame
</code>```

答:
Git http.extraheader & bearer

Manual 's answer helped put me on the right track.

YAML style Pipelines can use the preset variable System.AccessToken.  After examining the formal 'Checkout ...' step at the beginning of the Pipeline I found this step to work in my script:

```<code>- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" clone --depth 1 https://my-org@dev.azure.com/my-org/my-proj/_git/my-repo'
</code>```

Note that Azure DevOps job authorization scope may affect this

Body:
When cloning a git repository sitting up in Azure Repos into my local machine clone succeeds but I get a line that says:

Logon failed, use ctrl+c to cancel basic credential prompt

Not sure what this is referring to, any ideas?

I'm using PAT token to authenticate my clone, command is:

git clone https://*************PAT*************@dev.azure.com/orgname/projectname/_git/reponame

Body:
Git http.extraheader & bearer

Manual 's answer helped put me on the right track.

YAML style Pipelines can use the preset variable System.AccessToken.  After examining the formal 'Checkout ...' step at the beginning of the Pipeline I found this step to work in my script:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" clone --depth 1 https://my-org@dev.azure.com/my-org/my-proj/_git/my-repo'

Note that Azure DevOps job authorization scope may affect this


问:
How to make function?
```<code>plt.figure(1)
plt.subplot(121)
sns.distplot(df['Age'])
plt.subplot(122)
df['Age'].plot.box(figsize=(16,5))
plt.show()
</code>```

The only changes from one plot to another is the variable name (Age, Day_Scheduled...).  You could create a function that accepts the dataframe df and the variable's name as arguments and creates a plot. This way, every time you need to do this exact same plot, but using different variables, you can do just by calling this custom function, using something like

function_name(dataframe = df, variable = "Day_Scheduled")

答:
Well... you could do just that!</p>

```<code>def my_plotting_function(df, variable):
    plt.figure(1)
    plt.subplot(121)
    sns.distplot(df[variable])
    plt.subplot(122)
    df[variable].plot.box(figsize=(16,5))
    plt.show()
</code>```

Title: How to make function?

Body:
plt.figure(1)
plt.subplot(121)
sns.distplot(df['Age'])
plt.subplot(122)
df['Age'].plot.box(figsize=(16,5))
plt.show()

The only changes from one plot to another is the variable name (Age, Day_Scheduled...).  You could create a function that accepts the dataframe df and the variable's name as arguments and creates a plot. This way, every time you need to do this exact same plot, but using different variables, you can do just by calling this custom function, using something like

function_name(dataframe = df, variable = "Day_Scheduled")

Body:
Well... you could do just that!

def my_plotting_function(df, variable):
    plt.figure(1)
    plt.subplot(121)
    sns.distplot(df[variable])
    plt.subplot(122)
    df[variable].plot.box(figsize=(16,5))
    plt.show()


问:
How can I make the background of an HTML5 page an image with a link?
I have been creating a webpage teaching about Mars, and I wanted to see if I could make the background of an HTML5 page an image instead of a boring white colour. I do want this with a link, so teaching with a .jpg will not be useful. Here is some code I have tried:

```<code><!DOCTYPE HTML>
    <html>
        <head>
            <title>My Webpage</title>
            <style>
                body {
                background: url(https://phys.org/news/2020-05-astrobiologists-mars-rover-life-detecting-equipment.html);
                }
            </style>
        </head>
        <body>
            My text here...
        </body>
   </html>
</code>```

I am not the most experienced programmer, as you can see from this, but any help (even if it is just a little) will be much appreciated. Thank you for your time and have a great rest of your day.

--

isharief

答:
use the link to the jpg file in the src attribute instead of the html link, for this case,</p>

```<code><style>
                body {
                    background: url(https://scx1.b-cdn.net/csz/news/800/2020/astrobiologi.jpg);
                    background-repeat: no-repeat;
                    background-size: cover;
                    background-position: center;
                    height: 100vh;
                    width: 100vw;
                    overflow: hidden
                }
            </style>
</code>```

Body:
I have been creating a webpage teaching about Mars, and I wanted to see if I could make the background of an HTML5 page an image instead of a boring white colour. I do want this with a link, so teaching with a .jpg will not be useful. Here is some code I have tried:

<!DOCTYPE HTML>

            <title>My Webpage</title>

            My text here...

I am not the most experienced programmer, as you can see from this, but any help (even if it is just a little) will be much appreciated. Thank you for your time and have a great rest of your day.

--

isharief

Body:
use the link to the jpg file in the src attribute instead of the html link, for this case,

<style>
                body {
                    background: url(https://scx1.b-cdn.net/csz/news/800/2020/astrobiologi.jpg);
                    background-repeat: no-repeat;
                    background-size: cover;
                    background-position: center;
                    height: 100vh;
                    width: 100vw;
                    overflow: hidden
                }
            </style>


问:
Better way to summarize multiple groups in same dataframe
I'm not sure a better way to phrase this for the title, which is probably impeding me being able to search for the answer.

I have a dataframe that looks like this:

```<code>example_df <- data.frame(
  ID = c('A', 'A', 'A', 'B', 'B', 'C', 'C', 'C'),
  location = c('park 1', 'park 1', 'park 2', 'park 3', 'park 1', 'park 4', 'park 1', 'park 5'),
  sample_2000 = c(1, 5, 0, 2, 3, 1, 0, 8),
  sample_2001 = c(2, 1, 1, 3, 5, 6, 4, 2),
  sample_2003 = c(1, 2, 5, 8, 11, 1, 0, 7)
  )

  ID location sample_2000 sample_2001 sample_2003
1  A   park 1           1           2           1
2  A   park 1           5           1           2
3  A   park 2           0           1           5
4  B   park 3           2           3           8
5  B   park 1           3           5          11
6  C   park 4           1           6           1
7  C   park 1           0           4           0
8  C   park 5           8           2           7

</code>```

I want to sum all the values for each year by location and end up with the results in the same dataframe. I'm currently using group_by() and summarize on each year individually and then joining everything back together:

```<code>library(dplyr)

summarize1 <- group_by(example_df, location) %>% dplyr::summarize(sample_2000 = sum(sample_2000))
summarize2 <- group_by(example_df, location) %>% dplyr::summarize(sample_2001 = sum(sample_2001))
summarize3 <- group_by(example_df, location) %>% dplyr::summarize(sample_2003 = sum(sample_2003))

all_summarized <- Reduce(function(x, y) merge(x, y, all=TRUE), list(summarize1, summarize2, summarize3))

</code>```

Desired output (which I receive from the above) looks like this:

```<code>
  location sample_2000 sample_2001 sample_2003
1   park 1           9          12          14
2   park 2           0           1           5
3   park 3           2           3           8
4   park 4           1           6           1
5   park 5           8           2           7

</code>```

Surely there's a better method. My attempt at a for-loop returns the following:

'Error in sum(paste0("sample_", i)) :
  invalid 'type' (character) of argument'

```<code>
year_list <- c(2000, 2001, 2003)

for (i in year_list) {

  test <- group_by(example_df, location) %>% dplyr::summarize(paste0("sample_", i)) = sum(paste0("sample_", i))

}

</code>```

Thank you!

答:
If we want to use a similar approach to Reduce/merge, then we can make use of map/reduce from purrr

```<code>library(dplyr)
library(purrr)
map(names(example_df)[3:5], ~
   example_df %>%
        select(location, .x) %>%
        group_by(location) %>%
        summarise_at(vars(starts_with('sample')), sum)) %>%
   reduce(full_join)
</code>```

Or with summarise/across (in the new version of dplyr), we can get the same output (though not sure if the example is for a general case or something related to sum only)

```<code>example_df %>%
      group_by(location) %>%
      summarise(across(starts_with('sample'), sum))
</code>```

Or with summarise_at from stable version of dplyr (could be deprecated in the future)

```<code>example_df %>%
    group_by(location) %>%
    summarise_at(vars(starts_with('sample')), sum)
</code>```

Body:
I'm not sure a better way to phrase this for the title, which is probably impeding me being able to search for the answer.

I have a dataframe that looks like this:

example_df <- data.frame(
  ID = c('A', 'A', 'A', 'B', 'B', 'C', 'C', 'C'),
  location = c('park 1', 'park 1', 'park 2', 'park 3', 'park 1', 'park 4', 'park 1', 'park 5'),
  sample_2000 = c(1, 5, 0, 2, 3, 1, 0, 8),
  sample_2001 = c(2, 1, 1, 3, 5, 6, 4, 2),
  sample_2003 = c(1, 2, 5, 8, 11, 1, 0, 7)
  )

  ID location sample_2000 sample_2001 sample_2003
1  A   park 1           1           2           1
2  A   park 1           5           1           2
3  A   park 2           0           1           5
4  B   park 3           2           3           8
5  B   park 1           3           5          11
6  C   park 4           1           6           1
7  C   park 1           0           4           0
8  C   park 5           8           2           7

I want to sum all the values for each year by location and end up with the results in the same dataframe. I'm currently using group_by() and summarize on each year individually and then joining everything back together:

library(dplyr)

summarize1 <- group_by(example_df, location) %>% dplyr::summarize(sample_2000 = sum(sample_2000))
summarize2 <- group_by(example_df, location) %>% dplyr::summarize(sample_2001 = sum(sample_2001))
summarize3 <- group_by(example_df, location) %>% dplyr::summarize(sample_2003 = sum(sample_2003))

all_summarized <- Reduce(function(x, y) merge(x, y, all=TRUE), list(summarize1, summarize2, summarize3))

Desired output (which I receive from the above) looks like this:

  location sample_2000 sample_2001 sample_2003
1   park 1           9          12          14
2   park 2           0           1           5
3   park 3           2           3           8
4   park 4           1           6           1
5   park 5           8           2           7

Surely there's a better method. My attempt at a for-loop returns the following:

'Error in sum(paste0("sample_", i)) :
  invalid 'type' (character) of argument'

year_list <- c(2000, 2001, 2003)

for (i in year_list) {

  test <- group_by(example_df, location) %>% dplyr::summarize(paste0("sample_", i)) = sum(paste0("sample_", i))

}

Thank you!

Body:
If we want to use a similar approach to Reduce/merge, then we can make use of map/reduce from purrr

library(dplyr)
library(purrr)
map(names(example_df)[3:5], ~
   example_df %>%
        select(location, .x) %>%
        group_by(location) %>%
        summarise_at(vars(starts_with('sample')), sum)) %>%
   reduce(full_join)

Or with summarise/across (in the new version of dplyr), we can get the same output (though not sure if the example is for a general case or something related to sum only)

example_df %>%
      group_by(location) %>%
      summarise(across(starts_with('sample'), sum))

Or with summarise_at from stable version of dplyr (could be deprecated in the future)

example_df %>%
    group_by(location) %>%
    summarise_at(vars(starts_with('sample')), sum)


问:
Removing password_digest from API json?
I'm using Sinatra to make a simple little API. I have not been able to figure out a way to remove the 'password_digest' field from the JSON I'm outputting. Well, I know of a long way that I can do it, but I have a feeling there is a much simpler way.

```<code>get "/users/all" do
content_type :json
@users = User.all

response = @users.map do |user|
  user = user.to_h
  user.delete("password_digest")
  user
end
response.to_json
</code>```

end

All I'm trying to do is remove the password_digest field from the output. Is there a simple way to do this? I've tried searching with no luck.

答:
You should be able to do this:

  get "/users/all" do
    content_type :json
    @users = User.all

    response = @users.map do |user|
      user = user.to_h  # If your data is already a hash, you don't need this line.
      user.delete(:password_digest) # <-- If your keys are symbolized
      user.delete("password_digest") # <-- If your keys are strings
      user
    end
    response.to_json
  end
```

Title: Removing password_digest from API json?

Body:
I'm using Sinatra to make a simple little API. I have not been able to figure out a way to remove the 'password_digest' field from the JSON I'm outputting. Well, I know of a long way that I can do it, but I have a feeling there is a much simpler way.

get "/users/all" do
content_type :json
@users = User.all

response = @users.map do |user|
  user = user.to_h
  user.delete("password_digest")
  user
end
response.to_json

end

All I'm trying to do is remove the password_digest field from the output. Is there a simple way to do this? I've tried searching with no luck.


问:
C++ Template specialization for constant variables
I am currently trying to have a compile-time constant variable that is template specialized for several types. Currently, I am using constant expressions such as the following generalized example:

template<typename T>
constexpr T GENERAL_CONSTANT = T(0.01);

template<> constexpr float GENERAL_CONSTANT<float> = float(0.02);

template<> constexpr double GENERAL_CONSTANT<double> = double(0.03);
```

<p>This code however only seems to work on some compilers/linkers. It will compile and work correctly for Clang 9.0.0 for Windows 10, Clang 6.0.0 for Windows 10, Clang 6.0.0 for Ubuntu 18.04, and GCC for Ubuntu 18.04. But has given the similar multiple redefinition errors in several other configurations such as Clang 10.0.0 on Windows 10 or Clang 10.0.0 on Unix, as well as a few others. The errors will often look similar to this:</p>

```/usr/bin/ld: <some path to a.cpp> multiple definition of `GENERAL_CONSTANT<double>'; <some path to a.cpp>: first defined here
/usr/bin/ld: <some path to a.cpp> multiple definition of `GENERAL_CONSTANT<float>'; <some path to a.cpp>: first defined here
```

Where 'a.cpp' is the file that uses the constant, but does not define them. So given that this error is happening inconsistently depending on compiler and machine, I was curious if this is a non-standard approach to this problem, and if that is true, what approach should I take instead?

答:
const qualification of a variable template (and constexpr does makes an object const) does not imply internal linkage, [basic.link]/p3:

A name having namespace scope has internal linkage if it is the name of

a variable, variable template, function, or function template that is explicitly declared static; or

a non-template variable of non-volatile const-qualified type, unless [...]

It seems to be a recent change (CWG 2387):

Notes from the December, 2018 teleconference:

CWG felt that a const type should not affect the linkage of a variable template or its instances.

and that explains the difference that you observed in Clang-10.

As a solution, mark the variable template and its specializations either static or inline. The former forces internal linkage, while the latter excludes the variable template instances from the one definition rule allowing for multiple definitions provided they are in separate translation units.

Body:
I am currently trying to have a compile-time constant variable that is template specialized for several types. Currently, I am using constant expressions such as the following generalized example:

template<typename T>
constexpr T GENERAL_CONSTANT = T(0.01);

template<> constexpr float GENERAL_CONSTANT<float> = float(0.02);

template<> constexpr double GENERAL_CONSTANT<double> = double(0.03);

This code however only seems to work on some compilers/linkers. It will compile and work correctly for Clang 9.0.0 for Windows 10, Clang 6.0.0 for Windows 10, Clang 6.0.0 for Ubuntu 18.04, and GCC for Ubuntu 18.04. But has given the similar multiple redefinition errors in several other configurations such as Clang 10.0.0 on Windows 10 or Clang 10.0.0 on Unix, as well as a few others. The errors will often look similar to this:

/usr/bin/ld: <some path to a.cpp> multiple definition of `GENERAL_CONSTANT<double>'; <some path to a.cpp>: first defined here
/usr/bin/ld: <some path to a.cpp> multiple definition of `GENERAL_CONSTANT<float>'; <some path to a.cpp>: first defined here

Where 'a.cpp' is the file that uses the constant, but does not define them. So given that this error is happening inconsistently depending on compiler and machine, I was curious if this is a non-standard approach to this problem, and if that is true, what approach should I take instead?


问:
how to debug macro?
having this code:

```<code>#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

#define check(x) ({int _val = (x); (_val ==-1? \
    ({fprintf(stderr, "Error (" __FILE__ ":%d) -- " \
    "%s\n",__LINE__,strerror(errno)); \
    exit(-1);-1;}) : _val); })

int main (int argc, char **argv) {

    if (argc!=2){
        fprintf(stderr, "usage: %s <filename>\n", argv[0]);
        exit(-1);
    }

    int fd;
    fd=open(argv[1], O_RDONLY);

    if(fd<0){
        perror("open");
        fprintf(stderr,"errno = %s\n",strerror(errno));
        exit(-1);
    }

    for(char c;check(read(fd,&c,1))>0;) //macro "check(x)" HERE
        fputc(c,stdout);

    return 0;
}
</code>```

It compiles without an error, but I can see the macro does not output error messeges (__FILE__, neither __LINE__), as define it the macro. How to fix that? (And for general, how to debug macro, how at least output some error for it)?

$cc -pedantic a.c

```<code>a.c: In function ‘main’:
a.c:10:2: warning: ISO C forbids braced-groups within expressions [-Wpedantic]
  ({fprintf(stderr, "Error (" __FILE__ ":%d) -- " \
  ^
a.c:30:13: note: in expansion of macro ‘check’
  for(char c;check(read(fd,&c,1))>0;)
             ^~~~~
a.c:9:18: warning: ISO C forbids braced-groups within expressions [-Wpedantic]
 #define check(x) ({int _val = (x); (_val ==-1? \
                  ^
a.c:30:13: note: in expansion of macro ‘check’
  for(char c;check(read(fd,&c,1))>0;)
</code>```

not single mention about for loop (only its location, because the macro is in there, but that is not error) statment. Only about macro. So please focus on macro problem and not about the for loop.

EDIT1:
the macro actually comes from this guy:
youtube tutorial (at the end of the video), well he uses clang, so I do not know what clang uses as a preprocessor (and therefor it works for him).

EDIT2 (output from a.i - preprocessed output):

```<code># 304 "/usr/include/fcntl.h" 3 4

# 8 "a.c" 2

# 14 "a.c"
int main (int argc, char **argv) {
</code>```

I have deleted all the noise. But you can see between #include <fcntl.h> and int main, there is nothing. But there should be the #define check(x).... So it does not tell me WHY is it missing.

答:
how to debug macro?

Read more about C, in particular the Modern C book then this site.

Most C compilers have a way to show the preprocessed form of a translation unit.

Read the documentation of your C compiler.

For GCC, see this. For Clang, see that. The GCC preprocessor is documented here.

If you use gcc as your C compiler on file foo.c run it as gcc -C -E -H -Wall foo.c > foo.i to obtain into foo.i the preprocessed form of foo.c (but most comments are kept, and you could add more of them). Then look with a pager or an editor (I recommend GNU emacs, but feel free to use vim, gedit, more, less, most etc...) into that generated foo.i  file.

I can see the macro does not output error messeges

A macro is not outputting any messages, it is just expanded.

If you use a build automation tool such as GNU make or ninja, read its documentation.

If you use some IDE, read its documentation. Many IDEs offer a way to show the preprocessed form, and some might even make the macro expansion on the fly.

Don't forget that in some cases, you may want to use some other preprocessor, such as GPP or GNU m4, or generate some C code programmatically (like GNU bison, or lemon, or SWIG does). Many transpilers (such as Chicken-Scheme or Bigloo) are generating C code, and in Bismon I am doing that at run time, then dynamically loading the generated plugin, using dlopen(3). In RefPerSys we want to generate C++ code at runtime, and later use libgccjit.

You can find lots of open source C preprocessors, even standalone ones like mcpp. You could study their source code and improve them for your needs. And tinycc or nwcc is a small enough open source C compiler (with their preprocessor embedded inside) that you could improve in a few days.

If you use a recent GCC, you could extend it with your own plugin, perhaps adding your own _Pragma (used in your macros) which would display things after preprocessing.

Some clever debuggers (e.g. a suitably configured recent GDB) are capable of macro expansion (thrn compile your C code with gcc -O0 -g3 -Wall)

In Bismon, I use lots of quite long C macros. They might be inspirational. And so is the container-macros library. And also GTK whose macros are very readable.

My experience: to debug a macro, remove many lines from it, till you are satisfied with its expansion. Grow that macro in small steps. Use git on your source code.

```<code>$cc -pedantic a.c
</code>```

I recommend using gcc -Wall -Wextra -g3 -H -pedantic a.c on Linux then use a recent gdb.

Title: how to debug macro?

Body:
having this code:

#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

#define check(x) ({int _val = (x); (_val ==-1? \
    ({fprintf(stderr, "Error (" __FILE__ ":%d) -- " \
    "%s\n",__LINE__,strerror(errno)); \
    exit(-1);-1;}) : _val); })

int main (int argc, char **argv) {

    if (argc!=2){
        fprintf(stderr, "usage: %s <filename>\n", argv[0]);
        exit(-1);
    }

    int fd;
    fd=open(argv[1], O_RDONLY);

    if(fd<0){
        perror("open");
        fprintf(stderr,"errno = %s\n",strerror(errno));
        exit(-1);
    }

    for(char c;check(read(fd,&c,1))>0;) //macro "check(x)" HERE
        fputc(c,stdout);

    return 0;
}

It compiles without an error, but I can see the macro does not output error messeges (__FILE__, neither __LINE__), as define it the macro. How to fix that? (And for general, how to debug macro, how at least output some error for it)?

$cc -pedantic a.c

a.c: In function ‘main’:
a.c:10:2: warning: ISO C forbids braced-groups within expressions [-Wpedantic]
  ({fprintf(stderr, "Error (" __FILE__ ":%d) -- " \
  ^
a.c:30:13: note: in expansion of macro ‘check’
  for(char c;check(read(fd,&c,1))>0;)
             ^~~~~
a.c:9:18: warning: ISO C forbids braced-groups within expressions [-Wpedantic]
 #define check(x) ({int _val = (x); (_val ==-1? \
                  ^
a.c:30:13: note: in expansion of macro ‘check’
  for(char c;check(read(fd,&c,1))>0;)

not single mention about for loop (only its location, because the macro is in there, but that is not error) statment. Only about macro. So please focus on macro problem and not about the for loop.

EDIT1:
the macro actually comes from this guy:
youtube tutorial (at the end of the video), well he uses clang, so I do not know what clang uses as a preprocessor (and therefor it works for him).

EDIT2 (output from a.i - preprocessed output):

# 304 "/usr/include/fcntl.h" 3 4

# 8 "a.c" 2

# 14 "a.c"
int main (int argc, char **argv) {

I have deleted all the noise. But you can see between #include <fcntl.h> and int main, there is nothing. But there should be the #define check(x).... So it does not tell me WHY is it missing.

Body:
how to debug macro?

Read more about C, in particular the Modern C book then this site.

Most C compilers have a way to show the preprocessed form of a translation unit.

Read the documentation of your C compiler.

For GCC, see this. For Clang, see that. The GCC preprocessor is documented here.

If you use gcc as your C compiler on file foo.c run it as gcc -C -E -H -Wall foo.c > foo.i to obtain into foo.i the preprocessed form of foo.c (but most comments are kept, and you could add more of them). Then look with a pager or an editor (I recommend GNU emacs, but feel free to use vim, gedit, more, less, most etc...) into that generated foo.i  file.

I can see the macro does not output error messeges

A macro is not outputting any messages, it is just expanded.

If you use a build automation tool such as GNU make or ninja, read its documentation.

If you use some IDE, read its documentation. Many IDEs offer a way to show the preprocessed form, and some might even make the macro expansion on the fly.

Don't forget that in some cases, you may want to use some other preprocessor, such as GPP or GNU m4, or generate some C code programmatically (like GNU bison, or lemon, or SWIG does). Many transpilers (such as Chicken-Scheme or Bigloo) are generating C code, and in Bismon I am doing that at run time, then dynamically loading the generated plugin, using dlopen(3). In RefPerSys we want to generate C++ code at runtime, and later use libgccjit.

You can find lots of open source C preprocessors, even standalone ones like mcpp. You could study their source code and improve them for your needs. And tinycc or nwcc is a small enough open source C compiler (with their preprocessor embedded inside) that you could improve in a few days.

If you use a recent GCC, you could extend it with your own plugin, perhaps adding your own _Pragma (used in your macros) which would display things after preprocessing.

Some clever debuggers (e.g. a suitably configured recent GDB) are capable of macro expansion (thrn compile your C code with gcc -O0 -g3 -Wall)

In Bismon, I use lots of quite long C macros. They might be inspirational. And so is the container-macros library. And also GTK whose macros are very readable.

My experience: to debug a macro, remove many lines from it, till you are satisfied with its expansion. Grow that macro in small steps. Use git on your source code.

$cc -pedantic a.c

I recommend using gcc -Wall -Wextra -g3 -H -pedantic a.c on Linux then use a recent gdb.


问:
multiple AND conditions for a single column in where clause
I have a table with column ID, datatype Integer, now my requirement is to select data from table that matches certain values like

```<code>ID
1
2
3
4
</code>```

Possible conditons:

if ID = 1 and ID = 2 then retrive the dataset, if ID = 1 and ID = 5 then don't return result set.

now here is the whole issue:

I am not sure how to write this condition with And clause

If I write

```<code>select ID where ID = 1 and ID =2
</code>```

this doesn't return any rows.

Not sure how to write query for this particular condition, Also I can't use OR because my requirement is table should contain both the values then return the result set.

答:
I understand that you want to return whole dataset when all conditions are met, nothing otherwise. If so you can count distinct matching id:

```<code>select *
  from t
  where (select count(distinct id) from t where id in (1, 2)) = 2;
</code>```

or use exists twice / multiple times:

```<code>select id
  from t
  where exists (select null from t where id = 1)
    and exists (select null from t where id = 2);
</code>```

If you want only matching rows, when both values exists in table add and id in (1, 2) condition to where clause.

dbfiddle

Body:
I have a table with column ID, datatype Integer, now my requirement is to select data from table that matches certain values like

ID
1
2
3
4

Possible conditons:

if ID = 1 and ID = 2 then retrive the dataset, if ID = 1 and ID = 5 then don't return result set.

now here is the whole issue:

I am not sure how to write this condition with And clause

If I write

select ID where ID = 1 and ID =2

this doesn't return any rows.

Not sure how to write query for this particular condition, Also I can't use OR because my requirement is table should contain both the values then return the result set.

Body:
I understand that you want to return whole dataset when all conditions are met, nothing otherwise. If so you can count distinct matching id:

select *
  from t
  where (select count(distinct id) from t where id in (1, 2)) = 2;

or use exists twice / multiple times:

select id
  from t
  where exists (select null from t where id = 1)
    and exists (select null from t where id = 2);

If you want only matching rows, when both values exists in table add and id in (1, 2) condition to where clause.

dbfiddle


问:
How to solve the error Invalid update: incorrect number of items in section 0 in the collection View on iOS12?
All error text:

Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (0) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).

The method by which this error occurs (only when deleting, when creating or updating an item from the collection there is no error), this error occurs only on iOS12, on iOS13 and > there is no error.

```<code> var cards: [Card] = []

 item = self.cards[itemIndex]
 self.collectionView.performBatchUpdates({
   // here is a request to firebase

   self.db.collection(K.FStore.collectionName!).document((item?.idCard)!).delete() { err in
      if err != nil {
         print("err")
      } else {
         // here removal from the array, which is directly related to CollectionView
         self.cards.remove(at: itemIndex)
      }
    }
 }) {(finished) in
    self.collectionView.reloadData()
 }

 //collection method
 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int   {
 // This is where the application crashes. That is, the method above works out completely, but I don’t understand how it works on ios 13, but not on ios 12 ..
     return cards.count
 }
</code>```

For anyone who wants to send a question to "Duplicate" or throw a link with the words "SAME RESPONSE"
The purpose of the resource is to help with programming questions, and it so happened that I am new to Swift, I really saw and tried to solve my question BEFORE I asked my own.

But no answers gave a result that would fix the error.
I ask people with a higher skill to help me, thanks!

答:
Where are the batch updates (plural)?

You don't need performBatchUpdates, the method is only useful for multiple simultaneous updates. Delete the card in the database, on success remove the card from the data source array and delete the item – animated – in the collection view.

My suggestion assumes that the current index path is available which itemIndex derives from

```<code>item = self.cards[itemIndex]

self.db.collection(K.FStore.collectionName!).document((item?.idCard)!).delete() { err in
   if let error = err {
      print("An error occurred", error)
   } else {
      self.cards.remove(at: itemIndex)
      self.collectionView.deleteItems(at: [indexPath])
   }
}
</code>```

Body:
All error text:

Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (0) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).

The method by which this error occurs (only when deleting, when creating or updating an item from the collection there is no error), this error occurs only on iOS12, on iOS13 and > there is no error.

 var cards: [Card] = []

 item = self.cards[itemIndex]
 self.collectionView.performBatchUpdates({
   // here is a request to firebase

   self.db.collection(K.FStore.collectionName!).document((item?.idCard)!).delete() { err in
      if err != nil {
         print("err")
      } else {
         // here removal from the array, which is directly related to CollectionView
         self.cards.remove(at: itemIndex)
      }
    }
 }) {(finished) in
    self.collectionView.reloadData()
 }

 //collection method
 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int   {
 // This is where the application crashes. That is, the method above works out completely, but I don’t understand how it works on ios 13, but not on ios 12 ..
     return cards.count
 }

For anyone who wants to send a question to "Duplicate" or throw a link with the words "SAME RESPONSE"
The purpose of the resource is to help with programming questions, and it so happened that I am new to Swift, I really saw and tried to solve my question BEFORE I asked my own.

But no answers gave a result that would fix the error.
I ask people with a higher skill to help me, thanks!

Body:
Where are the batch updates (plural)?

You don't need performBatchUpdates, the method is only useful for multiple simultaneous updates. Delete the card in the database, on success remove the card from the data source array and delete the item – animated – in the collection view.

My suggestion assumes that the current index path is available which itemIndex derives from

item = self.cards[itemIndex]

self.db.collection(K.FStore.collectionName!).document((item?.idCard)!).delete() { err in
   if let error = err {
      print("An error occurred", error)
   } else {
      self.cards.remove(at: itemIndex)
      self.collectionView.deleteItems(at: [indexPath])
   }
}


问:
python strftime without leading 0
It worked in last 20 days where i had two numbers in day

Now :

```<code>time data 'Jun  1 2020 12:00AM' does not match format '%B %d %Y %I:%M%p'
</code>```

So the code which goes like

```<code> #last_run_db = 'Jun  1 2020 12:00AM'
 last_run_date = datetime.strptime(last_run_db, "%B %d %Y %I:%M%p")
</code>```

I tried with

```<code>  %-d
  %e
  %#d
</code>```

答:
Your problem is not related to leading 0 in the %d, but is due to the abbreviated month.

Use %b (for "Jun"), not %B (for "June").

Title: python strftime without leading 0

Body:
It worked in last 20 days where i had two numbers in day

Now :

time data 'Jun  1 2020 12:00AM' does not match format '%B %d %Y %I:%M%p'

So the code which goes like

 #last_run_db = 'Jun  1 2020 12:00AM'
 last_run_date = datetime.strptime(last_run_db, "%B %d %Y %I:%M%p")

I tried with

  %-d
  %e
  %#d


问:
Getting the name of the snapshot from a specific VM?
How can I get the name of the snapshot that the particular machine is using?

I have tried:

```<code>Get-VM -Name vdix-test-01 | Get-Snapshot
</code>```

but it returns blank..

答:
You're using the correct cmdlets, maybe the VM doesn't have any snapshots?

If you want to see all the VMs that do have a snapshot, you can use this one-liner

Get-VM | Get-Snapshot | ft VM, Name -AutoSize

Body:
How can I get the name of the snapshot that the particular machine is using?

I have tried:

Get-VM -Name vdix-test-01 | Get-Snapshot

but it returns blank..


问:
html button in asp.net
i am using html in asp page where i have to use html button. but the problem is i want to do the coding on html button in c#. but by using html button i cant do that.. is there any other way to do so..i am using html button as:

```<code> <button id="MyButton" runat="server" onserverclick="MyButton_ServerClick" >
   </button>
</code>```

if i double-click on the html button from .aspx page it generates the code as function under script as:

```<code> function MyButton_onclick() {

        }
</code>```

what can i do for this..

答:
Make AJAX request like this :</p>

```<code>$('#Button').click(function() {
    $.ajax( {
    type:'Get',
    url:'http://mysite.com/mywebservice',
    success:function(data) {
     alert(data);
    }

    })

});
</code>```

Title: html button in asp.net

Body:
i am using html in asp page where i have to use html button. but the problem is i want to do the coding on html button in c#. but by using html button i cant do that.. is there any other way to do so..i am using html button as:

 <button id="MyButton" runat="server" onserverclick="MyButton_ServerClick" >
   </button>

if i double-click on the html button from .aspx page it generates the code as function under script as:

 function MyButton_onclick() {

        }

what can i do for this..

Body:
Make AJAX request like this :

$('#Button').click(function() {
    $.ajax( {
    type:'Get',
    url:'http://mysite.com/mywebservice',
    success:function(data) {
     alert(data);
    }

    })

});