问:
How to change Tkinter option menu based on list
I have tried solutions from this post and this post to no avail. I am able to populate the options but am not able to actually select them. Here is a simplified version of my code:

```<code>
import tkinter as tk

class FrameHolder(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        container = tk.Frame(self)
        container.pack(expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        self.frames["TeacherSetDetentionFrame"] = TeacherSetDetentionFrame(parent=container, controller=self)
        self.frames["TeacherSetDetentionFrame"].grid(row=0, column=0, sticky="NESW")

        self.ShowFrame("TeacherSetDetentionFrame")

    def ShowFrame(self, FrameName):
        frame = self.frames[FrameName]
        frame.tkraise()

class TeacherSetDetentionFrame(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller

        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        self.FormStatus = tk.StringVar()
        self.FormStatus.set("7A")

        self.DefaultStudent = tk.StringVar()
        self.DefaultStudent.set("Select Student")

        self.DefaultGround = tk.StringVar()
        self.DefaultGround.set("Select a Ground")

        self.StudentsList = self.GetStudents( self.FormStatus.get() )

        self.StudentLabel = tk.Label(self, text="Student", font=(None,15))
        self.StudentLabel.grid(row=0,column=0,sticky="E")

        self.StudentDrop  = tk.OptionMenu(self,  self.DefaultStudent, *self.StudentsList )
        self.StudentDrop.grid(row=0, column=1, sticky="W")

        self.FormLabel = tk.Label(self, text="Form", font=(None,15))
        self.FormLabel.grid(row=1,column=0,sticky="E")

        self.FormDrop  = tk.OptionMenu(self, self.FormStatus, "7A","7B","8A","8B", command=lambda x: self.UpdateStudents( self.FormStatus.get() ) )
        self.FormDrop.grid(row=1,column=1, sticky="W")

    def GetStudents(self, Form):
        StudentList7A = ["Max","Kelly","Andrew"]
        StudentList8A = ["Steven","Harry","Kyle"]
        StudentList7B = ["Lilly", "Tim"]
        StudentList8B = ["Mike"]
        if Form == "7A":
            return StudentList7A
        elif Form == "8A":
            return StudentList8A
        elif Form == "7B":
            return StudentList7B
        else:
            return StudentList8B

    def UpdateStudents(self, Form):
        menu = self.StudentDrop["menu"]
        menu.delete(0, "end")
        ListStudents = self.GetStudents( Form )
        for Student in ListStudents:
            menu.add_command(label=Student, command=lambda: self.StudentsList.append(Student) )

if __name__ == "__main__":
    app = FrameHolder()
    app.geometry("640x360")
    app.mainloop()
</code>```

GetStudents returns a list of students based on the form option selected. Apologies if I have missed anything obvious from the linked posts.
Edit: Further simplified code.

答:
Try this:

```<code>
import tkinter as tk

class FrameHolder(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        container = tk.Frame(self)
        container.pack(expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        self.frames["TeacherSetDetentionFrame"] = TeacherSetDetentionFrame(parent=container, controller=self)
        self.frames["TeacherSetDetentionFrame"].grid(row=0, column=0, sticky="NESW")

        self.ShowFrame("TeacherSetDetentionFrame")

    def ShowFrame(self, FrameName):
        frame = self.frames[FrameName]
        frame.tkraise()

class TeacherSetDetentionFrame(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller

        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        self.FormStatus = tk.StringVar()
        self.FormStatus.set("7A")

        self.DefaultStudent = tk.StringVar()
        self.DefaultStudent.set("Select Student")

        self.DefaultGround = tk.StringVar()
        self.DefaultGround.set("Select a Ground")

        self.StudentsList = self.GetStudents( self.FormStatus.get() )

        self.StudentLabel = tk.Label(self, text="Student", font=(None,15))
        self.StudentLabel.grid(row=0,column=0,sticky="E")

        self.StudentDrop  = tk.OptionMenu(self,  self.DefaultStudent, *self.StudentsList )
        self.StudentDrop.grid(row=0, column=1, sticky="W")

        self.FormLabel = tk.Label(self, text="Form", font=(None,15))
        self.FormLabel.grid(row=1,column=0,sticky="E")

        self.FormDrop  = tk.OptionMenu(self, self.FormStatus, "7A","7B","8A","8B", command=lambda x: self.UpdateStudents( self.FormStatus.get() ) )
        self.FormDrop.grid(row=1,column=1, sticky="W")

    def GetStudents(self, Form):
        StudentList7A = ["Max","Kelly","Andrew"]
        StudentList8A = ["Steven","Harry","Kyle"]
        StudentList7B = ["Lilly", "Tim"]
        StudentList8B = ["Mike"]
        if Form == "7A":
            return StudentList7A
        elif Form == "8A":
            return StudentList8A
        elif Form == "7B":
            return StudentList7B
        else:
            return StudentList8B

    def student_selector(self, student):
        def inner():
            self.StudentsList.append(student)
            self.DefaultStudent.set(student)

        return inner

    def UpdateStudents(self, Form):
        menu = self.StudentDrop["menu"]
        menu.delete(0, "end")
        ListStudents = self.GetStudents( Form )
        for Student in ListStudents:
            menu.add_command(label=Student, command=self.student_selector(Student))

if __name__ == "__main__":
    app = FrameHolder()
    app.geometry("640x360")
    app.mainloop()
</code>```

You were missing updating your DefaultStudent StringVar when the option was selected, so the option box remained blank.

Body:
I have tried solutions from this post and this post to no avail. I am able to populate the options but am not able to actually select them. Here is a simplified version of my code:

import tkinter as tk

class FrameHolder(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        container = tk.Frame(self)
        container.pack(expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        self.frames["TeacherSetDetentionFrame"] = TeacherSetDetentionFrame(parent=container, controller=self)
        self.frames["TeacherSetDetentionFrame"].grid(row=0, column=0, sticky="NESW")

        self.ShowFrame("TeacherSetDetentionFrame")

    def ShowFrame(self, FrameName):
        frame = self.frames[FrameName]
        frame.tkraise()

class TeacherSetDetentionFrame(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller

        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        self.FormStatus = tk.StringVar()
        self.FormStatus.set("7A")

        self.DefaultStudent = tk.StringVar()
        self.DefaultStudent.set("Select Student")

        self.DefaultGround = tk.StringVar()
        self.DefaultGround.set("Select a Ground")

        self.StudentsList = self.GetStudents( self.FormStatus.get() )

        self.StudentLabel = tk.Label(self, text="Student", font=(None,15))
        self.StudentLabel.grid(row=0,column=0,sticky="E")

        self.StudentDrop  = tk.OptionMenu(self,  self.DefaultStudent, *self.StudentsList )
        self.StudentDrop.grid(row=0, column=1, sticky="W")

        self.FormLabel = tk.Label(self, text="Form", font=(None,15))
        self.FormLabel.grid(row=1,column=0,sticky="E")

        self.FormDrop  = tk.OptionMenu(self, self.FormStatus, "7A","7B","8A","8B", command=lambda x: self.UpdateStudents( self.FormStatus.get() ) )
        self.FormDrop.grid(row=1,column=1, sticky="W")

    def GetStudents(self, Form):
        StudentList7A = ["Max","Kelly","Andrew"]
        StudentList8A = ["Steven","Harry","Kyle"]
        StudentList7B = ["Lilly", "Tim"]
        StudentList8B = ["Mike"]
        if Form == "7A":
            return StudentList7A
        elif Form == "8A":
            return StudentList8A
        elif Form == "7B":
            return StudentList7B
        else:
            return StudentList8B

    def UpdateStudents(self, Form):
        menu = self.StudentDrop["menu"]
        menu.delete(0, "end")
        ListStudents = self.GetStudents( Form )
        for Student in ListStudents:
            menu.add_command(label=Student, command=lambda: self.StudentsList.append(Student) )

if __name__ == "__main__":
    app = FrameHolder()
    app.geometry("640x360")
    app.mainloop()

GetStudents returns a list of students based on the form option selected. Apologies if I have missed anything obvious from the linked posts.
Edit: Further simplified code.

Body:
Try this:

import tkinter as tk

class FrameHolder(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        container = tk.Frame(self)
        container.pack(expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}

        self.frames["TeacherSetDetentionFrame"] = TeacherSetDetentionFrame(parent=container, controller=self)
        self.frames["TeacherSetDetentionFrame"].grid(row=0, column=0, sticky="NESW")

        self.ShowFrame("TeacherSetDetentionFrame")

    def ShowFrame(self, FrameName):
        frame = self.frames[FrameName]
        frame.tkraise()

class TeacherSetDetentionFrame(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller

        self.grid_columnconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        self.FormStatus = tk.StringVar()
        self.FormStatus.set("7A")

        self.DefaultStudent = tk.StringVar()
        self.DefaultStudent.set("Select Student")

        self.DefaultGround = tk.StringVar()
        self.DefaultGround.set("Select a Ground")

        self.StudentsList = self.GetStudents( self.FormStatus.get() )

        self.StudentLabel = tk.Label(self, text="Student", font=(None,15))
        self.StudentLabel.grid(row=0,column=0,sticky="E")

        self.StudentDrop  = tk.OptionMenu(self,  self.DefaultStudent, *self.StudentsList )
        self.StudentDrop.grid(row=0, column=1, sticky="W")

        self.FormLabel = tk.Label(self, text="Form", font=(None,15))
        self.FormLabel.grid(row=1,column=0,sticky="E")

        self.FormDrop  = tk.OptionMenu(self, self.FormStatus, "7A","7B","8A","8B", command=lambda x: self.UpdateStudents( self.FormStatus.get() ) )
        self.FormDrop.grid(row=1,column=1, sticky="W")

    def GetStudents(self, Form):
        StudentList7A = ["Max","Kelly","Andrew"]
        StudentList8A = ["Steven","Harry","Kyle"]
        StudentList7B = ["Lilly", "Tim"]
        StudentList8B = ["Mike"]
        if Form == "7A":
            return StudentList7A
        elif Form == "8A":
            return StudentList8A
        elif Form == "7B":
            return StudentList7B
        else:
            return StudentList8B

    def student_selector(self, student):
        def inner():
            self.StudentsList.append(student)
            self.DefaultStudent.set(student)

        return inner

    def UpdateStudents(self, Form):
        menu = self.StudentDrop["menu"]
        menu.delete(0, "end")
        ListStudents = self.GetStudents( Form )
        for Student in ListStudents:
            menu.add_command(label=Student, command=self.student_selector(Student))

if __name__ == "__main__":
    app = FrameHolder()
    app.geometry("640x360")
    app.mainloop()

You were missing updating your DefaultStudent StringVar when the option was selected, so the option box remained blank.


来源: stackexchange

问:
Django 3.0 — database connections are not closed after async tests
I use Django ORM inside async code. Everything works fine and all tests pass. However, DB connections do not close properly after tests. Here is an example:

```<code>from asgiref.sync import sync_to_async, async_to_sync

@sync_to_async
def count_books():
    return Book.objects.count()

class FooTest(TestCase):
    def setUp(self):
        Book.objects.create(title='Haha')

    def test1(self):
        import asyncio
        c = asyncio.run(count_books())
        self.assertEqual(1, c)

    def test2(self):
        c = async_to_sync(count_books)()
        self.assertEqual(1, c)

</code>```

Postgres error:

```<code>django.db.utils.OperationalError: database "test_mydbname" is being accessed by other users
</code>```

Sqlite error:

```<code>sqlite3.OperationalError: database table is locked: test_mydbname
</code>```

I've tried swapping sync_to_async with database_sync_to_async from django-channels, but this didn't change anything.

How can I fix this?

答:
The issue comes with how your async runloops are interacting with the main thread, handling this yourself can get quite complex.

For testing django-channels I suggest using pytest with pytest-asyncio for testing channels. And of course pytest-django.

This will provide a few useful tools for testing async code.

@pytest.mark.django_db(transaction=True)
@pytest.mark.asyncio
async def test1():
    count = await database_sync_to_async(Book.objects.count)
    ....
```

for some examples of how to test channels code take a look here.

ContentLicense: CC BY-SA 4.0

Body:
I use Django ORM inside async code. Everything works fine and all tests pass. However, DB connections do not close properly after tests. Here is an example:

from asgiref.sync import sync_to_async, async_to_sync

@sync_to_async
def count_books():
    return Book.objects.count()

class FooTest(TestCase):
    def setUp(self):
        Book.objects.create(title='Haha')

    def test1(self):
        import asyncio
        c = asyncio.run(count_books())
        self.assertEqual(1, c)

    def test2(self):
        c = async_to_sync(count_books)()
        self.assertEqual(1, c)

Postgres error:

django.db.utils.OperationalError: database "test_mydbname" is being accessed by other users

Sqlite error:

sqlite3.OperationalError: database table is locked: test_mydbname

I've tried swapping sync_to_async with database_sync_to_async from django-channels, but this didn't change anything.

How can I fix this?

Body:
The issue comes with how your async runloops are interacting with the main thread, handling this yourself can get quite complex.

For testing django-channels I suggest using pytest with pytest-asyncio for testing channels. And of course pytest-django.

This will provide a few useful tools for testing async code.

@pytest.mark.django_db(transaction=True)
@pytest.mark.asyncio
async def test1():
    count = await database_sync_to_async(Book.objects.count)
    ....

for some examples of how to test channels code take a look here.


问:
Filter dates in sharepoint list with REST API
I just created a workflow using Sharepoint Designer 2013 and I getting  the error shown in yellow

What do I have to change in the Call HTTP web Service string builder to make it work?

regards, Elio Fernandes

答:
In SharePoint Designer, you often have to encode the spaces (%20) in the filter so that it knows not to cut off the url. Also, it is generally best practice in ODATA filter comparisons to wrap a datetime value with datetime('somedatestringhere') to ensure it gets interpreted and compared as a date value and not as a text value.

So, your URI should look something like [%Variable: SiteUrl%]_api/web/lists/GetByTitle('<sitelist>')/Items?$filter=Data%20ge%20datetime('[%Variable: DataIni%]')


问:
jqgrid first load filtering
I was wondering if there is a way for jqgrid to pass a certain value/string from a given view to the controller, I have a case where I would like to filter my records at the first load and then allow search. I tried to pass the value in the griddata function alongside the sid and sord ... but it would just pass that string as null, I found a couple of related posts but I couldnt utilize them.

Thanks in advance!

答: In general you should just set filters property of the postData jqGrid parameter and set one more parameter search:true. Look at the answer with the demo. One more answer shows how to construct the filters property.

ContentLicense: CC BY-SA 3.0

Title: jqgrid first load filtering


问:
#<NoMethodError: undefined method `reject' for nil:NilClass> in Rack

I'm using spring rails s to start my server.

It's a Rails 6.0.0 application

Whenever accessing localhost:3000 I'm see this error message:

```<code>2020-02-15 11:31:36 -0800: Rack app error handling request { GET /favicon.ico }
#<NoMethodError: undefined method `reject' for nil:NilClass>
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-2.2.0/lib/rack/request.rb:623:in `reject_trusted_ip_addresses'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-2.2.0/lib/rack/request.rb:363:in `ip'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-mini-profiler-1.1.0/lib/mini_profiler/config.rb:27:in `block (2 levels) in default'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-mini-profiler-1.1.0/lib/mini_profiler/profiler.rb:87:in `user'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-mini-profiler-1.1.0/lib/mini_profiler/profiler.rb:343:in `call'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/webpacker-4.0.7/lib/webpacker/dev_server_proxy.rb:29:in `perform_request'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/railties-6.0.0/lib/rails/engine.rb:526:in `call'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/configuration.rb:228:in `call'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/server.rb:681:in `handle_request'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/server.rb:472:in `process_client'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/server.rb:328:in `block in run'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/thread_pool.rb:134:in `block in spawn_thread'
</code>```

答:
Sadly, I didn't identify the root cause.

After updating rack to 2.2.2 this issue went away so I'm unblocked now.

I believe the source of the problem was that in @env within the rack request there was no HTTP_X_FORWARDED_FOR header being sent.

Body:
I'm using spring rails s to start my server.

It's a Rails 6.0.0 application

Whenever accessing localhost:3000 I'm see this error message:

2020-02-15 11:31:36 -0800: Rack app error handling request { GET /favicon.ico }
#<NoMethodError: undefined method `reject' for nil:NilClass>
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-2.2.0/lib/rack/request.rb:623:in `reject_trusted_ip_addresses'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-2.2.0/lib/rack/request.rb:363:in `ip'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-mini-profiler-1.1.0/lib/mini_profiler/config.rb:27:in `block (2 levels) in default'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-mini-profiler-1.1.0/lib/mini_profiler/profiler.rb:87:in `user'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-mini-profiler-1.1.0/lib/mini_profiler/profiler.rb:343:in `call'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/webpacker-4.0.7/lib/webpacker/dev_server_proxy.rb:29:in `perform_request'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/railties-6.0.0/lib/rails/engine.rb:526:in `call'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/configuration.rb:228:in `call'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/server.rb:681:in `handle_request'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/server.rb:472:in `process_client'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/server.rb:328:in `block in run'
/Users/amirsharif/.rvm/gems/ruby-2.6.1/gems/puma-4.3.1/lib/puma/thread_pool.rb:134:in `block in spawn_thread'


问:
how can I spread these arrays properly?
I need to insert an empty item as the first item in an array of data which will be databound to a dropdown.   My code looks like this:

```<code>      let suppliers = response.data[0];
      let defaultSupplier = [{ SupplierId:0, ContactFirstName:''}];
      suppliers = [...defaultSupplier, suppliers];
</code>```

I was thinking that this code would initialize my array with a default item, and then I could simply spread the retrieved suppliers data into this array.  However, the result of this approach is that I have an array where defaultSupplier is the first item in the array and then the second item in the array is an array of the retrieved supplier data.  What approach do I need to take so that the retrieved suppliers data is appended at the same level as the defaultSupplier?

答:
You have to spread suppliers. But you created new array defaultSupplier with one element and spread this one. Correct variant:

```<code>let suppliers = response.data[0]; // array
let defaultSupplier = { SupplierId:0, ContactFirstName:''};
suppliers = [defaultSupplier, ...suppliers]; // spread array suppliers
</code>```

Title: how can I spread these arrays properly?

Body:
I need to insert an empty item as the first item in an array of data which will be databound to a dropdown.   My code looks like this:

      let suppliers = response.data[0];
      let defaultSupplier = [{ SupplierId:0, ContactFirstName:''}];
      suppliers = [...defaultSupplier, suppliers];

I was thinking that this code would initialize my array with a default item, and then I could simply spread the retrieved suppliers data into this array.  However, the result of this approach is that I have an array where defaultSupplier is the first item in the array and then the second item in the array is an array of the retrieved supplier data.  What approach do I need to take so that the retrieved suppliers data is appended at the same level as the defaultSupplier?

Body:
You have to spread suppliers. But you created new array defaultSupplier with one element and spread this one. Correct variant:

let suppliers = response.data[0]; // array
let defaultSupplier = { SupplierId:0, ContactFirstName:''};
suppliers = [defaultSupplier, ...suppliers]; // spread array suppliers


问:
How to change the color of correct answer using JavaScript when check answer button clicked

Lorem ipsum dolor sit amet, consectetur adipiscing elit
 (A)Lorem ipsum dolor

  (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor
 (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>

Lorem ipsum dolor sit amet, consectetur adipiscing elit

  (A)Lorem ipsum dolor
 (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor
 (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>

Lorem ipsum dolor sit amet, consectetur adipiscing elit
 (A)Lorem ipsum dolor
 (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor

  (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>```

how to change the color of the correct option when 'check answer' button of the question clicked?

答:
Using JQuery, it's pretty easy:

Lorem ipsum dolor sit amet, consectetur adipiscing elit
 (A)Lorem ipsum dolor

  (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor
 (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>

Lorem ipsum dolor sit amet, consectetur adipiscing elit

  (A)Lorem ipsum dolor
 (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor
 (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>

Lorem ipsum dolor sit amet, consectetur adipiscing elit
 (A)Lorem ipsum dolor
 (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor

  (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>

```

Body:
Lorem ipsum dolor sit amet, consectetur adipiscing elit
 (A)Lorem ipsum dolor

  (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor
 (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>

Lorem ipsum dolor sit amet, consectetur adipiscing elit

  (A)Lorem ipsum dolor
 (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor
 (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>

Lorem ipsum dolor sit amet, consectetur adipiscing elit
 (A)Lorem ipsum dolor
 (B)Lorem ipsum dolor
 (C) Lorem ipsum dolor

  (D) Lorem ipsum dolor

<button class="ans-button">check answer</button>

how to change the color of the correct option when 'check answer' button of the question clicked?

Body:
Using JQuery, it's pretty easy:

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit<br> (A)Lorem ipsum dolor<br>
  <span class="correct">(B)Lorem ipsum dolor</span><br> (C) Lorem ipsum dolor<br> (D) Lorem ipsum dolor</p>
<button class="ans-button">check answer</button>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit<br>
  <span class="correct">(A)Lorem ipsum dolor</span><br> (B)Lorem ipsum dolor<br> (C) Lorem ipsum dolor<br> (D) Lorem ipsum dolor</p>
<button class="ans-button">check answer</button>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit<br> (A)Lorem ipsum dolor<br> (B)Lorem ipsum dolor<br> (C) Lorem ipsum dolor<br>
  <span class="correct">(D) Lorem ipsum dolor</span></p>
<button class="ans-button">check answer</button>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
  var a = $(".ans-button").on("click", function() {
    $(this).prev().find(".correct").css("color", "green");
  });
</script>


问:
Faster alternatives to hFileSize to retrieve the size of a file in Haskell?
I am wondering how to get the size of a file in haskell with the least amount of overhead. Right now I have the following code:

```<code>getFileSize :: FilePath -> IO Integer
getFileSize x = do
handle <- openFile x ReadMode
size <- hFileSize handle
hClose handle
return size
</code>```

This seems to be quite slow. I have stumbled across getFileStatus in System.Posix.Files but don't know how it works - at least I only get errors when playing around with it in ghci. Also, I am not sure if this would work on Windows (probably not).

So to reiterate: What is the best (and platform independent) approach to get the size of a file in Haskell?

答:
https://hackage.haskell.org/package/directory-1.3.6.0/docs/System-Directory.html#v:getFileSize</p>

```<code>getFileSize :: FilePath -> IO Integer
</code>```

Body:
I am wondering how to get the size of a file in haskell with the least amount of overhead. Right now I have the following code:

getFileSize :: FilePath -> IO Integer
getFileSize x = do
handle <- openFile x ReadMode
size <- hFileSize handle
hClose handle
return size

This seems to be quite slow. I have stumbled across getFileStatus in System.Posix.Files but don't know how it works - at least I only get errors when playing around with it in ghci. Also, I am not sure if this would work on Windows (probably not).

So to reiterate: What is the best (and platform independent) approach to get the size of a file in Haskell?

Body:
https://hackage.haskell.org/package/directory-1.3.6.0/docs/System-Directory.html#v:getFileSize

getFileSize :: FilePath -> IO Integer


问:
Angular redirects when I hit enter in an input field
I have the following application with an input field. When I type in and hit enter, the app forwards to http://example.org/?. Rather than firing the onEnter event. The onKey event work fine. How can I stop this redirecting happening?

here is the html:

```<code><mat-card>
  <form class="example-form">
    <mat-form-field class="example-full-width">
      <input matInput placeholder="How can I help" (keyup)="onKey($event)">
      <mat-icon matSuffix>?</mat-icon>
    </mat-form-field>
  </form>
</mat-card>
</code>```

and the ts:

```<code>import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {

  onKey(event) {
    console.log(event.target.value)
  }
}
</code>```

答:
This can also be caused by missing FormsModule and HttpModule modules in the app.module.ts

import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,// import FormsModule
    HttpModule,// import HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})```

Body:
I have the following application with an input field. When I type in and hit enter, the app forwards to http://example.org/?. Rather than firing the onEnter event. The onKey event work fine. How can I stop this redirecting happening?

here is the html:

<mat-card>
  <form class="example-form">
    <mat-form-field class="example-full-width">
      <input matInput placeholder="How can I help" (keyup)="onKey($event)">
      <mat-icon matSuffix>?</mat-icon>
    </mat-form-field>
  </form>
</mat-card>

and the ts:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {

  onKey(event) {
    console.log(event.target.value)
  }
}


问:
What is the correct way to start and stop simple Node.js scripts
I'm trying to create a simple Twitter bot to learn some Node.js skills.

It works fine on my local computer. I start the script with node bot.js and then close it with Ctrl + C.

I've uploaded the files to a server (Krystal hosting). I've ssh'd into the server and then used $ source /home/[username]/nodevenv/twitterbot/10/bin/activate. Which I think puts me into a Node environment (I'm not really clear what is happening here).

From here I can run node bot.js. My Twitter bot runs fine and I can leave the terminal. What I've realised now is that I don't know how to stop this script.

Can someone explain how I should be doing this? Is there a command I can enter to stop the original bot.js process? Since looking into this it looks like perhaps I should have used something like pm2 process manager. Is this correct?

Any pointers would be much appreciated.

Thanks,
B

答:
You can kill it externally by nuking the process from an OS command line or in an OS GUI (exact procedure varies by OS).  Ctrl-C from the shell is one version of this, but it can be done without the command shell that it was started in too by nuking the process directly.

Or, you can add a control port (a simple little http server running on a port only accessible locally) that accepts commands that let you do all sorts of things with the server such as extract statistics, shut it down, change the configuration, tell it to clear caches so content updates take effect immediately, etc...  Shutting down the server this way allows for a more orderly shut-down from code within the server.  You can even stop accepting incoming connections, but wait for existing http connections to complete before shutting down, close databases normally, etc...

Or, you can use a monitoring program such as PM2 or forever that in addition to restarting the server automatically if it should ever crash, they also offer commands for shutting it down too (which will just send it certain signals kind of like Ctrl-C does).


问:
How to efficiently convert a multidimensional collection of 2 different types into a multidimensional List
I have the following HashSet, which needs to have TreeSets as elements :

```<code>HashSet<TreeSet<Integer>> hash=new HashSet<TreeSet<Integer>>();
</code>```

I want to be able to store ordered elements into the TreeSet, order is also important hence the choice of a TreeSet. Those elements themselves need to be ordered but not necessarily sorted. But I must return :

```<code>List<List<Integer>>
</code>```

What is the most efficient way to convert my hash into a List of a List of Integers in terms of performance ?

Thank you

答:
You still need to iterate over collection and convert inner sets into lists. Although if performance is of the greatest importance, consider using some third-party libraries, that provide some optimizations.

1. Benchmarks

I have written a couple of simple benchmarks using JMH to compare them with vanilla java solution:

```<code>public class Set2ListTest {

    private static final int SMALL_SET_SIZE = 10;
    private static final int LARGE_SET_SIZE = 1000;

    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder()
                .include(Set2ListTest.class.getSimpleName())
                .forks(1)
                .threads(8)
                .warmupIterations(1)
                .measurementIterations(1)
                .build();
        new Runner(options).run();
    }

    @State(Scope.Benchmark)
    public static class Provider {

        Set<Set<Integer>> smallSet = new HashSet<>(SMALL_SET_SIZE);
        Set<Set<Integer>> largeSet = new HashSet<>(LARGE_SET_SIZE);

        @Setup
        public void setup() {
            fillSet(smallSet, SMALL_SET_SIZE);
            fillSet(largeSet, LARGE_SET_SIZE);
        }

        private void fillSet(Set<Set<Integer>> set, int count) {
            Random random = new Random();
            for (int i = 0; i < count; i++) {
                Set<Integer> innerSet = new TreeSet<>();
                for (int j = 0; j < count; j++) {
                    innerSet.add(random.nextInt(Integer.MAX_VALUE));
                }
                set.add(innerSet);
            }
        }

    }

    @Benchmark
    public void small_plainJava(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(SMALL_SET_SIZE);
        for (Set<Integer> set : provider.smallSet) {
            list.add(new ArrayList<>(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void large_plainJava(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(LARGE_SET_SIZE);
        for (Set<Integer> set : provider.largeSet) {
            list.add(new ArrayList<>(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void small_guava(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(SMALL_SET_SIZE);
        for (Set<Integer> set : provider.smallSet) {
            list.add(com.google.common.collect.Lists.newArrayList(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void large_guava(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(LARGE_SET_SIZE);
        for (Set<Integer> set : provider.largeSet) {
            list.add(com.google.common.collect.Lists.newArrayList(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void small_commons(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(SMALL_SET_SIZE);
        for (Set<Integer> set : provider.smallSet) {
            List<Integer> innerList = new ArrayList<>(SMALL_SET_SIZE);
            CollectionUtils.addAll(innerList, set);
            list.add(innerList);
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void large_commons(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(LARGE_SET_SIZE);
        for (Set<Integer> set : provider.largeSet) {
            List<Integer> innerList = new ArrayList<>(LARGE_SET_SIZE);
            CollectionUtils.addAll(innerList, set);
            list.add(innerList);
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void small_eclipse(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = FastList.newList();
        for (Set<Integer> set : provider.smallSet) {
            list.add(FastList.newList(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void large_eclipse(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = FastList.newList();
        for (Set<Integer> set : provider.largeSet) {
            list.add(FastList.newList(set));
        }
        blackhole.consume(list);
    }

}
</code>```

2. Results

The results are as follows:

```<code>Benchmark                      Mode  Cnt        Score   Error  Units
Set2ListTest.large_commons    thrpt           183.205          ops/s
Set2ListTest.large_eclipse    thrpt           219.068          ops/s
Set2ListTest.large_guava      thrpt           178.478          ops/s
Set2ListTest.large_plainJava  thrpt           148.058          ops/s
Set2ListTest.small_commons    thrpt       2140560.198          ops/s
Set2ListTest.small_eclipse    thrpt       2619862.935          ops/s
Set2ListTest.small_guava      thrpt       2720692.868          ops/s
Set2ListTest.small_plainJava  thrpt       2472748.566          ops/s
</code>```

3. Discussion

Two different sizes of Sets were used to measure performance: 10 sets of size 10 (100 elements) and 1000 sets of 1000 elements (1.000.000 elements).

For the small Set, eclipse collections outperformed the other tools. Plain java seems to be the slowest solution.

In the case of the larger Set, guava provides the best results.

It's obvious, that the size of collections has a great impact on performance and can influence the best choice among those libraries. I don't know the size of your data, but my goal is not to give you the best collections library but to give you a tool to find one.

4. Additional notes

I do not consider myself a specialist in any of the collection frameworks and there might be a better way to use them.

If those results are not satisfactory, you can use primitive collections, so that much less memory has to be allocated. This will result in a huge performance boost.

Note, that if you want to experiment with the benchmarks provided, it's important, that you compare the implementations against each other, not against the results I got, because that might be hardware-related.

Body:
I have the following HashSet, which needs to have TreeSets as elements :

HashSet<TreeSet<Integer>> hash=new HashSet<TreeSet<Integer>>();

I want to be able to store ordered elements into the TreeSet, order is also important hence the choice of a TreeSet. Those elements themselves need to be ordered but not necessarily sorted. But I must return :

List<List<Integer>>

What is the most efficient way to convert my hash into a List of a List of Integers in terms of performance ?

Thank you

Body:
You still need to iterate over collection and convert inner sets into lists. Although if performance is of the greatest importance, consider using some third-party libraries, that provide some optimizations.

1. Benchmarks

I have written a couple of simple benchmarks using JMH to compare them with vanilla java solution:

public class Set2ListTest {

    private static final int SMALL_SET_SIZE = 10;
    private static final int LARGE_SET_SIZE = 1000;

    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder()
                .include(Set2ListTest.class.getSimpleName())
                .forks(1)
                .threads(8)
                .warmupIterations(1)
                .measurementIterations(1)
                .build();
        new Runner(options).run();
    }

    @State(Scope.Benchmark)
    public static class Provider {

        Set<Set<Integer>> smallSet = new HashSet<>(SMALL_SET_SIZE);
        Set<Set<Integer>> largeSet = new HashSet<>(LARGE_SET_SIZE);

        @Setup
        public void setup() {
            fillSet(smallSet, SMALL_SET_SIZE);
            fillSet(largeSet, LARGE_SET_SIZE);
        }

        private void fillSet(Set<Set<Integer>> set, int count) {
            Random random = new Random();
            for (int i = 0; i < count; i++) {
                Set<Integer> innerSet = new TreeSet<>();
                for (int j = 0; j < count; j++) {
                    innerSet.add(random.nextInt(Integer.MAX_VALUE));
                }
                set.add(innerSet);
            }
        }

    }

    @Benchmark
    public void small_plainJava(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(SMALL_SET_SIZE);
        for (Set<Integer> set : provider.smallSet) {
            list.add(new ArrayList<>(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void large_plainJava(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(LARGE_SET_SIZE);
        for (Set<Integer> set : provider.largeSet) {
            list.add(new ArrayList<>(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void small_guava(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(SMALL_SET_SIZE);
        for (Set<Integer> set : provider.smallSet) {
            list.add(com.google.common.collect.Lists.newArrayList(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void large_guava(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(LARGE_SET_SIZE);
        for (Set<Integer> set : provider.largeSet) {
            list.add(com.google.common.collect.Lists.newArrayList(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void small_commons(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(SMALL_SET_SIZE);
        for (Set<Integer> set : provider.smallSet) {
            List<Integer> innerList = new ArrayList<>(SMALL_SET_SIZE);
            CollectionUtils.addAll(innerList, set);
            list.add(innerList);
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void large_commons(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = new ArrayList<>(LARGE_SET_SIZE);
        for (Set<Integer> set : provider.largeSet) {
            List<Integer> innerList = new ArrayList<>(LARGE_SET_SIZE);
            CollectionUtils.addAll(innerList, set);
            list.add(innerList);
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void small_eclipse(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = FastList.newList();
        for (Set<Integer> set : provider.smallSet) {
            list.add(FastList.newList(set));
        }
        blackhole.consume(list);
    }

    @Benchmark
    public void large_eclipse(Provider provider, Blackhole blackhole) {
        List<List<Integer>> list = FastList.newList();
        for (Set<Integer> set : provider.largeSet) {
            list.add(FastList.newList(set));
        }
        blackhole.consume(list);
    }

}

2. Results

The results are as follows:

Benchmark                      Mode  Cnt        Score   Error  Units
Set2ListTest.large_commons    thrpt           183.205          ops/s
Set2ListTest.large_eclipse    thrpt           219.068          ops/s
Set2ListTest.large_guava      thrpt           178.478          ops/s
Set2ListTest.large_plainJava  thrpt           148.058          ops/s
Set2ListTest.small_commons    thrpt       2140560.198          ops/s
Set2ListTest.small_eclipse    thrpt       2619862.935          ops/s
Set2ListTest.small_guava      thrpt       2720692.868          ops/s
Set2ListTest.small_plainJava  thrpt       2472748.566          ops/s

3. Discussion

Two different sizes of Sets were used to measure performance: 10 sets of size 10 (100 elements) and 1000 sets of 1000 elements (1.000.000 elements).

For the small Set, eclipse collections outperformed the other tools. Plain java seems to be the slowest solution.

In the case of the larger Set, guava provides the best results.

It's obvious, that the size of collections has a great impact on performance and can influence the best choice among those libraries. I don't know the size of your data, but my goal is not to give you the best collections library but to give you a tool to find one.

4. Additional notes

I do not consider myself a specialist in any of the collection frameworks and there might be a better way to use them.

If those results are not satisfactory, you can use primitive collections, so that much less memory has to be allocated. This will result in a huge performance boost.

Note, that if you want to experiment with the benchmarks provided, it's important, that you compare the implementations against each other, not against the results I got, because that might be hardware-related.


问:
Airflow SimpleHttpOperator
Hi I am experiencing weird behavior from SimpleHttpOperator.
I have extended this operator like this:

```<code>class EPOHttpOperator(SimpleHttpOperator):
    """
    Operator for retrieving data from EPO API, performs token validity check,
    gets a new one, if old one close to not valid.
    """

    @apply_defaults
    def __init__(self, entity_code, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.entity_code = entity_code
        self.endpoint = self.endpoint + self.entity_code

    def execute(self, context):
        try:
            token_data = json.loads(Variable.get(key="access_token_data", deserialize_json=False))
            if (datetime.now() - datetime.strptime(token_data["created_at"],
                                                   '%Y-%m-%d %H:%M:%S.%f')).seconds >= 19 * 60:

                Variable.set(value=json.dumps(get_EPO_access_token(), default=str), key="access_token_data")

            self.headers = {
                "Authorization": f"Bearer {token_data['token']}",
                "Accept": "application/json"
            }

            super(EPOHttpOperator, self).execute(context)

        except HTTPError as http_err:
            logging.error(f'HTTP error occurred during getting EPO data: {http_err}')
            raise http_err

        except Exception as e:
            logging.error(e)
            raise e
</code>```

And I have written a simple unit test:

```<code>def test_get_EPO_data(requests_mock):
    requests_mock.get('http://ops.epo.org/rest-services/published-data/publication/epodoc/EP1522668',
                      text='{"text": "test"}')
    requests_mock.post('https://ops.epo.org/3.2/auth/accesstoken',
                       text='{"access_token":"test", "status": "we just testing"}')

    dag = DAG(dag_id='test_data', start_date=datetime.now())
    task = EPOHttpOperator(
        xcom_push=True,
        do_xcom_push=True,
        http_conn_id='http_EPO',
        endpoint='published-data/publication/epodoc/',
        entity_code='EP1522668',
        method='GET',
        task_id='get_data_task',
        dag=dag,
    )
    ti = TaskInstance(task=task, execution_date=datetime.now(), )
    task.execute(ti.get_template_context())
    assert ti.xcom_pull(task_ids='get_data_task') == {"text": "test"}
</code>```

Test doesn't pass though, the XCOM value from HttpHook is never pushed as an XCOM, I have checked that code responsible for the push logic in the hook class gets called:

```<code>....
  if self.response_check:
            if not self.response_check(response):
                raise AirflowException("Response check returned False.")
  if self.xcom_push_flag:
     return response.text
</code>```

What did I do wrong? Is this a bug?

答:
So I actually managed to make it work by setting an xcom value to the result of super(EPOHttpOperator, self).execute(context).

```<code>def execute(self, context):
        try:
             .
             .
             .
            self.headers = {
                "Authorization": f"Bearer {token_data['token']}",
                "Accept": "application/json"
            }

            super(EPOHttpOperator, self).execute(context) -> Variable.set(value=super(EPOHttpOperator, self).execute(context),key='foo')
</code>```

Documentation is kind of misleading on this one; or am I doing something wrong after all?

Title: Airflow SimpleHttpOperator

Body:
Hi I am experiencing weird behavior from SimpleHttpOperator.
I have extended this operator like this:

class EPOHttpOperator(SimpleHttpOperator):
    """
    Operator for retrieving data from EPO API, performs token validity check,
    gets a new one, if old one close to not valid.
    """

    @apply_defaults
    def __init__(self, entity_code, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.entity_code = entity_code
        self.endpoint = self.endpoint + self.entity_code

    def execute(self, context):
        try:
            token_data = json.loads(Variable.get(key="access_token_data", deserialize_json=False))
            if (datetime.now() - datetime.strptime(token_data["created_at"],
                                                   '%Y-%m-%d %H:%M:%S.%f')).seconds >= 19 * 60:

                Variable.set(value=json.dumps(get_EPO_access_token(), default=str), key="access_token_data")

            self.headers = {
                "Authorization": f"Bearer {token_data['token']}",
                "Accept": "application/json"
            }

            super(EPOHttpOperator, self).execute(context)

        except HTTPError as http_err:
            logging.error(f'HTTP error occurred during getting EPO data: {http_err}')
            raise http_err

        except Exception as e:
            logging.error(e)
            raise e

And I have written a simple unit test:

def test_get_EPO_data(requests_mock):
    requests_mock.get('http://ops.epo.org/rest-services/published-data/publication/epodoc/EP1522668',
                      text='{"text": "test"}')
    requests_mock.post('https://ops.epo.org/3.2/auth/accesstoken',
                       text='{"access_token":"test", "status": "we just testing"}')

    dag = DAG(dag_id='test_data', start_date=datetime.now())
    task = EPOHttpOperator(
        xcom_push=True,
        do_xcom_push=True,
        http_conn_id='http_EPO',
        endpoint='published-data/publication/epodoc/',
        entity_code='EP1522668',
        method='GET',
        task_id='get_data_task',
        dag=dag,
    )
    ti = TaskInstance(task=task, execution_date=datetime.now(), )
    task.execute(ti.get_template_context())
    assert ti.xcom_pull(task_ids='get_data_task') == {"text": "test"}

Test doesn't pass though, the XCOM value from HttpHook is never pushed as an XCOM, I have checked that code responsible for the push logic in the hook class gets called:

....
  if self.response_check:
            if not self.response_check(response):
                raise AirflowException("Response check returned False.")
  if self.xcom_push_flag:
     return response.text

What did I do wrong? Is this a bug?

Body:
So I actually managed to make it work by setting an xcom value to the result of super(EPOHttpOperator, self).execute(context).

def execute(self, context):
        try:
             .
             .
             .
            self.headers = {
                "Authorization": f"Bearer {token_data['token']}",
                "Accept": "application/json"
            }

            super(EPOHttpOperator, self).execute(context) -> Variable.set(value=super(EPOHttpOperator, self).execute(context),key='foo')

Documentation is kind of misleading on this one; or am I doing something wrong after all?


问:
Can't deploy Rails 6 app to Heroku. ErrorLog included
I've build a Rails 6 app using React via the newly integrated Webpacker for JS and can't seem to get over the final hurdle of deploying to Heroku. I don't quite understand the logs. I did create a Procfile to launch Puma and Webpack server. Would anyone mind looking at the logs and tell me what I might be missing? BTW, the first hurdle was getting rid of a Yarn vs NPM lockfile conflict.

Here are the logs:

```<code>2020-02-15T19:10:42.074186+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.6.0/bin/puma)
2020-02-15T19:10:42.074256+00:00 app[web.1]: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "outages" does not exist
2020-02-15T19:10:42.074256+00:00 app[web.1]: LINE 8:  WHERE a.attrelid = '"outages"'::regclass
2020-02-15T19:10:42.074257+00:00 app[web.1]: ^
2020-02-15T19:10:42.074269+00:00 app[web.1]:
2020-02-15T19:10:42.074271+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:65:in `exec'
2020-02-15T19:10:42.074274+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:65:in `block (2 levels) in query'
2020-02-15T19:10:42.074274+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
2020-02-15T19:10:42.074275+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
2020-02-15T19:10:42.074275+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
2020-02-15T19:10:42.074275+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:64:in `block in query'
2020-02-15T19:10:42.074276+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:718:in `block (2 levels) in log'
2020-02-15T19:10:42.074276+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
2020-02-15T19:10:42.074276+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:717:in `block in log'
2020-02-15T19:10:42.074277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
2020-02-15T19:10:42.074277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:708:in `log'
2020-02-15T19:10:42.074277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `query'
2020-02-15T19:10:42.074277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:817:in `column_definitions'
2020-02-15T19:10:42.074278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:114:in `columns'
2020-02-15T19:10:42.074278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/schema_cache.rb:76:in `columns'
2020-02-15T19:10:42.074278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/schema_cache.rb:82:in `columns_hash'
2020-02-15T19:10:42.074278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/model_schema.rb:490:in `load_schema!'
2020-02-15T19:10:42.074279+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/attributes.rb:247:in `load_schema!'
2020-02-15T19:10:42.074279+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
2020-02-15T19:10:42.074279+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/model_schema.rb:480:in `block in load_schema'
2020-02-15T19:10:42.074279+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/model_schema.rb:477:in `load_schema'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/model_schema.rb:352:in `columns_hash'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1216:in `arel_column'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1203:in `block in arel_columns'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1196:in `each'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1196:in `flat_map'
2020-02-15T19:10:42.074281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1196:in `arel_columns'
2020-02-15T19:10:42.074281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1187:in `build_select'
2020-02-15T19:10:42.074281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1071:in `build_arel'
2020-02-15T19:10:42.074284+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1016:in `arel'
2020-02-15T19:10:42.074284+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/finder_methods.rb:317:in `block in exists?'
2020-02-15T19:10:42.074284+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation.rb:828:in `skip_query_cache_if_necessary'
2020-02-15T19:10:42.074284+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/finder_methods.rb:317:in `exists?'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/querying.rb:21:in `exists?'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/app/controllers/application_controller.rb:3:in `<class:ApplicationController>'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/app/controllers/application_controller.rb:1:in `<main>'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2020-02-15T19:10:42.074286+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2020-02-15T19:10:42.074286+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2020-02-15T19:10:42.074286+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2020-02-15T19:10:42.074286+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:16:in `require'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/app/controllers/dashboard_controller.rb:1:in `<main>'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2020-02-15T19:10:42.074288+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2020-02-15T19:10:42.074288+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:16:in `require'
2020-02-15T19:10:42.074288+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:351:in `const_get'
2020-02-15T19:10:42.074288+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:351:in `block (2 levels) in eager_load'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:685:in `block in ls'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:682:in `foreach'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:682:in `ls'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:346:in `block in eager_load'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:338:in `synchronize'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:338:in `eager_load'
2020-02-15T19:10:42.074290+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:449:in `each'
2020-02-15T19:10:42.074290+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:449:in `eager_load_all'
2020-02-15T19:10:42.074290+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/application/finisher.rb:122:in `block in <module:Finisher>'
2020-02-15T19:10:42.074290+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `instance_exec'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `run'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
2020-02-15T19:10:42.074294+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
2020-02-15T19:10:42.074294+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
2020-02-15T19:10:42.074294+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call'
2020-02-15T19:10:42.074295+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
2020-02-15T19:10:42.074295+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
2020-02-15T19:10:42.074295+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
2020-02-15T19:10:42.074295+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:60:in `run_initializers'
2020-02-15T19:10:42.074296+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/application.rb:363:in `initialize!'
2020-02-15T19:10:42.074296+00:00 app[web.1]: /app/config/environment.rb:5:in `<top (required)>'
2020-02-15T19:10:42.074297+00:00 app[web.1]: config.ru:3:in `require_relative'
2020-02-15T19:10:42.074297+00:00 app[web.1]: config.ru:3:in `block in <main>'
2020-02-15T19:10:42.074315+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `eval'
2020-02-15T19:10:42.074316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `new_from_string'
2020-02-15T19:10:42.074316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:105:in `load_file'
2020-02-15T19:10:42.074316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:66:in `parse_file'
2020-02-15T19:10:42.074316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:321:in `load_rackup'
2020-02-15T19:10:42.074317+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:246:in `app'
2020-02-15T19:10:42.074317+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/runner.rb:155:in `load_and_bind'
2020-02-15T19:10:42.074317+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/single.rb:98:in `run'
2020-02-15T19:10:42.074317+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/launcher.rb:172:in `run'
2020-02-15T19:10:42.074318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/cli.rb:80:in `run'
2020-02-15T19:10:42.074318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/bin/puma:10:in `<top (required)>'
2020-02-15T19:10:42.074318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/bin/puma:23:in `load'
2020-02-15T19:10:42.074318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/bin/puma:23:in `<top (required)>'
2020-02-15T19:10:42.174683+00:00 heroku[web.1]: State changed from starting to crashed
2020-02-15T19:10:42.158245+00:00 heroku[web.1]: Process exited with status 1
2020-02-15T19:10:43.902737+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=tml-dashboard.herokuapp.com request_id=c6f9e222-b62f-47e2-b5eb-5befc8af9ad2 fwd="68.194.85.143" dyno= connect= service= status=503 bytes= protocol=https
2020-02-15T19:10:45.661172+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=tml-dashboard.herokuapp.com request_id=25660d39-0184-411c-8e94-d54fcbd0d7b3 fwd="68.194.85.143" dyno= connect= service= status=503 bytes= protocol=https

</code>```

答:
Your error is actually

```<code>ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "outages" does not exist
</code>```

So it looks like you never ran migrations

```<code>heroku run rake db:migrate
</code>```

or, if you have multiple environments, then add the flag for that env

```<code>heroku run rake db:migrate --remote production
</code>```

or whatever the environment is called.

Body:
I've build a Rails 6 app using React via the newly integrated Webpacker for JS and can't seem to get over the final hurdle of deploying to Heroku. I don't quite understand the logs. I did create a Procfile to launch Puma and Webpack server. Would anyone mind looking at the logs and tell me what I might be missing? BTW, the first hurdle was getting rid of a Yarn vs NPM lockfile conflict.

Here are the logs:

2020-02-15T19:10:42.074186+00:00 app[web.1]: bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.6.0/bin/puma)
2020-02-15T19:10:42.074256+00:00 app[web.1]: ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "outages" does not exist
2020-02-15T19:10:42.074256+00:00 app[web.1]: LINE 8:  WHERE a.attrelid = '"outages"'::regclass
2020-02-15T19:10:42.074257+00:00 app[web.1]: ^
2020-02-15T19:10:42.074269+00:00 app[web.1]:
2020-02-15T19:10:42.074271+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:65:in `exec'
2020-02-15T19:10:42.074274+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:65:in `block (2 levels) in query'
2020-02-15T19:10:42.074274+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
2020-02-15T19:10:42.074275+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
2020-02-15T19:10:42.074275+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
2020-02-15T19:10:42.074275+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:64:in `block in query'
2020-02-15T19:10:42.074276+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:718:in `block (2 levels) in log'
2020-02-15T19:10:42.074276+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
2020-02-15T19:10:42.074276+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:717:in `block in log'
2020-02-15T19:10:42.074277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
2020-02-15T19:10:42.074277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:708:in `log'
2020-02-15T19:10:42.074277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:63:in `query'
2020-02-15T19:10:42.074277+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:817:in `column_definitions'
2020-02-15T19:10:42.074278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:114:in `columns'
2020-02-15T19:10:42.074278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/schema_cache.rb:76:in `columns'
2020-02-15T19:10:42.074278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/schema_cache.rb:82:in `columns_hash'
2020-02-15T19:10:42.074278+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/model_schema.rb:490:in `load_schema!'
2020-02-15T19:10:42.074279+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/attributes.rb:247:in `load_schema!'
2020-02-15T19:10:42.074279+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
2020-02-15T19:10:42.074279+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/model_schema.rb:480:in `block in load_schema'
2020-02-15T19:10:42.074279+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/monitor.rb:230:in `mon_synchronize'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/model_schema.rb:477:in `load_schema'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/model_schema.rb:352:in `columns_hash'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1216:in `arel_column'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1203:in `block in arel_columns'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1196:in `each'
2020-02-15T19:10:42.074280+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1196:in `flat_map'
2020-02-15T19:10:42.074281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1196:in `arel_columns'
2020-02-15T19:10:42.074281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1187:in `build_select'
2020-02-15T19:10:42.074281+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1071:in `build_arel'
2020-02-15T19:10:42.074284+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/query_methods.rb:1016:in `arel'
2020-02-15T19:10:42.074284+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/finder_methods.rb:317:in `block in exists?'
2020-02-15T19:10:42.074284+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation.rb:828:in `skip_query_cache_if_necessary'
2020-02-15T19:10:42.074284+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/relation/finder_methods.rb:317:in `exists?'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/activerecord-6.0.2.1/lib/active_record/querying.rb:21:in `exists?'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/app/controllers/application_controller.rb:3:in `<class:ApplicationController>'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/app/controllers/application_controller.rb:1:in `'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2020-02-15T19:10:42.074285+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2020-02-15T19:10:42.074286+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2020-02-15T19:10:42.074286+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2020-02-15T19:10:42.074286+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2020-02-15T19:10:42.074286+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:16:in `require'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/app/controllers/dashboard_controller.rb:1:in `'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2020-02-15T19:10:42.074287+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2020-02-15T19:10:42.074288+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2020-02-15T19:10:42.074288+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:16:in `require'
2020-02-15T19:10:42.074288+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:351:in `const_get'
2020-02-15T19:10:42.074288+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:351:in `block (2 levels) in eager_load'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:685:in `block in ls'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:682:in `foreach'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:682:in `ls'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:346:in `block in eager_load'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:338:in `synchronize'
2020-02-15T19:10:42.074289+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:338:in `eager_load'
2020-02-15T19:10:42.074290+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:449:in `each'
2020-02-15T19:10:42.074290+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.2.2/lib/zeitwerk/loader.rb:449:in `eager_load_all'
2020-02-15T19:10:42.074290+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/application/finisher.rb:122:in `block in <module:Finisher>'
2020-02-15T19:10:42.074290+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `instance_exec'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:32:in `run'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:228:in `block in tsort_each'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
2020-02-15T19:10:42.074291+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:431:in `each_strongly_connected_component_from'
2020-02-15T19:10:42.074294+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:349:in `block in each_strongly_connected_component'
2020-02-15T19:10:42.074294+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each'
2020-02-15T19:10:42.074294+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `call'
2020-02-15T19:10:42.074295+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:347:in `each_strongly_connected_component'
2020-02-15T19:10:42.074295+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:226:in `tsort_each'
2020-02-15T19:10:42.074295+00:00 app[web.1]: /app/vendor/ruby-2.6.3/lib/ruby/2.6.0/tsort.rb:205:in `tsort_each'
2020-02-15T19:10:42.074295+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/initializable.rb:60:in `run_initializers'
2020-02-15T19:10:42.074296+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/railties-6.0.2.1/lib/rails/application.rb:363:in `initialize!'
2020-02-15T19:10:42.074296+00:00 app[web.1]: /app/config/environment.rb:5:in `<top (required)>'
2020-02-15T19:10:42.074297+00:00 app[web.1]: config.ru:3:in `require_relative'
2020-02-15T19:10:42.074297+00:00 app[web.1]: config.ru:3:in `block in '
2020-02-15T19:10:42.074315+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `eval'
2020-02-15T19:10:42.074316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:116:in `new_from_string'
2020-02-15T19:10:42.074316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:105:in `load_file'
2020-02-15T19:10:42.074316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/rack-2.2.2/lib/rack/builder.rb:66:in `parse_file'
2020-02-15T19:10:42.074316+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:321:in `load_rackup'
2020-02-15T19:10:42.074317+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/configuration.rb:246:in `app'
2020-02-15T19:10:42.074317+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/runner.rb:155:in `load_and_bind'
2020-02-15T19:10:42.074317+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/single.rb:98:in `run'
2020-02-15T19:10:42.074317+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/launcher.rb:172:in `run'
2020-02-15T19:10:42.074318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/lib/puma/cli.rb:80:in `run'
2020-02-15T19:10:42.074318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/puma-4.3.1/bin/puma:10:in `<top (required)>'
2020-02-15T19:10:42.074318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/bin/puma:23:in `load'
2020-02-15T19:10:42.074318+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/bin/puma:23:in `<top (required)>'
2020-02-15T19:10:42.174683+00:00 heroku[web.1]: State changed from starting to crashed
2020-02-15T19:10:42.158245+00:00 heroku[web.1]: Process exited with status 1
2020-02-15T19:10:43.902737+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=tml-dashboard.herokuapp.com request_id=c6f9e222-b62f-47e2-b5eb-5befc8af9ad2 fwd="68.194.85.143" dyno= connect= service= status=503 bytes= protocol=https
2020-02-15T19:10:45.661172+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=tml-dashboard.herokuapp.com request_id=25660d39-0184-411c-8e94-d54fcbd0d7b3 fwd="68.194.85.143" dyno= connect= service= status=503 bytes= protocol=https

Body:
Your error is actually

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "outages" does not exist

So it looks like you never ran migrations

heroku run rake db:migrate

or, if you have multiple environments, then add the flag for that env

heroku run rake db:migrate --remote production

or whatever the environment is called.


问:
MongoDb Full text search eats memory when i search on com and other small words
Thank you for reading this, i have an collection with full text th index size is of the index is 809.7MB (Mongo Compass) but when i search for com or other small words the memory is full (8GB memory).

Its a sharding.

Does anyone know why this is?

答:
if I understand; your text search then must touch every document.

perhaps you have no alternative but the way to do a faster query is to:
a. match to the index
b. text search on the beginning letters i.e. ^ symbol as search the first letters is much more efficient than searching anywhere in the string...

if this is not possible, and text searching is going to be a major component of your application you would consider some strategies:
* create key search words as part of the data input that can be used by the text query process
* delimit the pool of possible docs in some way perhaps a date range, topic, etc - - ultimately you probably would want to index on these and include them in your text query.


问:
Specify the percentColWidth for datagrid column in action script
Tried

```<code>col.setStyle('percentWidth',20) //doesn't work

col.setStyle('percentWidth',0.2)//doesn't work
</code>```

&&

```<code>col.percentWidth //doesnt compile
</code>```

where col is one of the columns in a datagrid

Thanks.

答:
There is no "percentWidth" on data grids (that I'm aware of). You can write some code to do it manually ie: set the width to be .1*dataGrid.width for 10%, but that's obviously a bit annoying. I used this solution in the past.

I did a quick google search and found the following link where a guy has extended the DataGrid class to have the functionality that I think you are sinking. You can check out his article here:

ScalableDataGrid

I haven't tried using this, so I'd be interested to know if it works.

Good luck.

Body:
Tried

col.setStyle('percentWidth',20) //doesn't work

col.setStyle('percentWidth',0.2)//doesn't work

&&

col.percentWidth //doesnt compile

where col is one of the columns in a datagrid

Thanks.


问:
Why does clang require a function to be declared before it's called in a template?
I have the following code example (available online at coliru):

#include <iostream>
#include <utility>

struct Bar {
    int a;
};

template <class T>
void print_arg(const T& arg) {
    std::cout << arg << std::endl;
}

std::ostream& operator<<(std::ostream& os, const Bar& b) {
    os << b.a;
    return os;
}

template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& pair) {
    os << "Pair(" << pair.first << ',' << pair.second << ")";
    return os;
}

int main()
{
    auto bar = Bar{1};
    print_arg(bar);
    print_arg(std::make_pair(bar, bar));
    print_arg(std::make_pair(bar, 1));
    print_arg(std::make_pair(0, 1));
}
```

<p>The last line in the main function is what's giving me trouble. Compilation with g++ works just fine (with the exact same options as below), I launch the executable and it prints everything as expected. However, Clang++ gives me the following error:</p>

```$ clang++ -std=c++17 -O2 -Wall -Werror -Wpedantic main.cpp && ./a.out
main.cpp:10:15: error: call to function 'operator<<' that is neither visible in the template definition nor found by argument-dependent lookup
    std::cout << arg << std::endl;
              ^
main.cpp:29:5: note: in instantiation of function template specialization 'print_arg<std::pair<int, int> >' requested here
    print_arg(std::make_pair(0, 1));
    ^
main.cpp:19:15: note: 'operator<<' should be declared prior to the call site
std::ostream& operator<<(std::ostream& os, const std::pair<T, T>& pair) {
              ^
1 error generated.
```

Furthermore, removing the last line (commenting it out) results in Clang++ compiling everything correctly. Which, as far as I can tell, means that std::pair<int, int> is qualitatively different from other parameter types.

My question is, why does g++ compile it eitherway? And more importantly, why does clang think it is ok to declare operator<<(ostream, pair<Bar, Bar>) later, but it's not ok for operator<<(ostream, pair<int, int>). Is it because the latter only includes standard and basic types?

To me the (somewhat) logical thing seems to be that defining functions only over standard/basic types is UB, but g++ silently ignores it and clang++ gives a weird-looking error message. However, that doesn't make a whole lot of sense to me and I can't find the relevant standard clause.

Note: I understand that moving the declaration up is what clang is asking for, but I don't understand why. I want to provide print_arg function in a separate header and allow the person that includes that header to specialize operator<< while using print_arg.

答:
Look into Language Compatibility : Unqualified lookup in templates section. It explains exactly this case.

The summary is GCC compiles buggy code, while clang follows the standard.

Body:
I have the following code example (available online at coliru):

#include <iostream>
#include <utility>

struct Bar {
    int a;
};

template <class T>
void print_arg(const T& arg) {
    std::cout << arg << std::endl;
}

std::ostream& operator<<(std::ostream& os, const Bar& b) {
    os << b.a;
    return os;
}

template <class T1, class T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& pair) {
    os << "Pair(" << pair.first << ',' << pair.second << ")";
    return os;
}

int main()
{
    auto bar = Bar{1};
    print_arg(bar);
    print_arg(std::make_pair(bar, bar));
    print_arg(std::make_pair(bar, 1));
    print_arg(std::make_pair(0, 1));
}

The last line in the main function is what's giving me trouble. Compilation with g++ works just fine (with the exact same options as below), I launch the executable and it prints everything as expected. However, Clang++ gives me the following error:

$ clang++ -std=c++17 -O2 -Wall -Werror -Wpedantic main.cpp && ./a.out
main.cpp:10:15: error: call to function 'operator<<' that is neither visible in the template definition nor found by argument-dependent lookup
    std::cout << arg << std::endl;
              ^
main.cpp:29:5: note: in instantiation of function template specialization 'print_arg<std::pair<int, int> >' requested here
    print_arg(std::make_pair(0, 1));
    ^
main.cpp:19:15: note: 'operator<<' should be declared prior to the call site
std::ostream& operator<<(std::ostream& os, const std::pair<T, T>& pair) {
              ^
1 error generated.

Furthermore, removing the last line (commenting it out) results in Clang++ compiling everything correctly. Which, as far as I can tell, means that std::pair<int, int> is qualitatively different from other parameter types.

My question is, why does g++ compile it eitherway? And more importantly, why does clang think it is ok to declare operator<<(ostream, pair<Bar, Bar>) later, but it's not ok for operator<<(ostream, pair<int, int>). Is it because the latter only includes standard and basic types?

To me the (somewhat) logical thing seems to be that defining functions only over standard/basic types is UB, but g++ silently ignores it and clang++ gives a weird-looking error message. However, that doesn't make a whole lot of sense to me and I can't find the relevant standard clause.

Note: I understand that moving the declaration up is what clang is asking for, but I don't understand why. I want to provide print_arg function in a separate header and allow the person that includes that header to specialize operator<< while using print_arg.