问:
Turbolinks and 3d party plugins issue?
I have website
http://www.optimapo.ru/
and I have some 3d party scripts installed:
live chat (https://www.jivochat.com/) and yandex analitics.
But because of turbolinks they don't work properly.
For example live chat appears only on main page. But when we go to another page which is loaded using turbolinks it dissapears.

I include scripts in my code before closing body tag

```<code><!-- BEGIN JIVOSITE CODE {literal} -->
<script type='text/javascript'>
(function(){ var widget_id = '2qq06akKwZ';var d=document;var w=window;function l(){
var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = '//code.jivosite.com/script/widget/'+widget_id; var ss = document.getElementsByTagName('script')[0]; ss.parentNode.insertBefore(s, ss);}if(d.readyState=='complete'){l();}else{if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})();</script>
<!-- {/literal} END JIVOSITE CODE -->
<!-- Yandex.Metrika counter --> <script type="text/javascript"> (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter39034390 = new Ya.Metrika({ id:39034390, clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true, trackHash:true, ut:"noindex" }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); </script> <noscript><div><img src="https://mc.yandex.ru/watch/39034390?ut=noindex" style="position:absolute; left:-9999px;" alt="" /></div></noscript> <!-- /Yandex.Metrika counter -->

</body>
</code>```

So what do I do to make scripts work with turbolinks?

答:
I've managed to find a solution that actually works in Turbolinks 5. I've added this piece of code s.setAttribute('data-turbolinks-track', 'reload'); in between existing code, like this:

```<code>s.type = 'text/javascript'; s.setAttribute('data-turbolinks-track', 'reload'); s.async = true;
</code>```

Side note: I've also submitted a PR with this solution to Turbolinks Compatability repository

Title: Turbolinks and 3d party plugins issue?

Body:
I have website
http://www.optimapo.ru/
and I have some 3d party scripts installed:
live chat (https://www.jivochat.com/) and yandex analitics.
But because of turbolinks they don't work properly.
For example live chat appears only on main page. But when we go to another page which is loaded using turbolinks it dissapears.

I include scripts in my code before closing body tag

So what do I do to make scripts work with turbolinks?

Body:
I've managed to find a solution that actually works in Turbolinks 5. I've added this piece of code s.setAttribute('data-turbolinks-track', 'reload'); in between existing code, like this:

s.type = 'text/javascript'; s.setAttribute('data-turbolinks-track', 'reload'); s.async = true;

Side note: I've also submitted a PR with this solution to Turbolinks Compatability repository


来源: stackexchange

问:
No such module 'Alamofire' When adding multiple schemes
I am trying to create multiple schemes for production/qa/staging ect. I have installed Alamofire using Cocoapods. I have copied the working configuration and changed the name. I have changed the build configuration to match the newly added configuration. When I run the project I get "No such module 'Alamofire'". The original scheme still works fine. What Am I missing?</p>

答: try run pod install this will create some .xcconfig files

ContentLicense: CC BY-SA 3.0


问:
UIDatePicker does not show everything
Here is My Image....

The UIDatePicker seems to not show everything on the screen.
Any solutions on making the font size smaller?

答:
According to Apple doc, I guess we cannot.

You cannot customize the appearance of date
  pickers.

A workaround is you can customize a UIPickerView work as a date picker and then change the font size by using UIPickerViewDelegate something like:

```<code>    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
        var label: UILabel

        if let view = view as? UILabel {
            label = view
        } else {
            label = UILabel()
        }

        label.textColor = .black
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 30)

        label.text = recheckDayOptions[row].toString()

        return label
    }
</code>```

ContentLicense: CC BY-SA 4.0

Title: UIDatePicker does not show everything

Body:
According to Apple doc, I guess we cannot.

You cannot customize the appearance of date
  pickers.

A workaround is you can customize a UIPickerView work as a date picker and then change the font size by using UIPickerViewDelegate something like:

    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
        var label: UILabel

        if let view = view as? UILabel {
            label = view
        } else {
            label = UILabel()
        }

        label.textColor = .black
        label.textAlignment = .center
        label.font = UIFont.systemFont(ofSize: 30)

        label.text = recheckDayOptions[row].toString()

        return label
    }


问:
how to send push notification when user posts a new message in firebase?
I am using Ionic and firebase. I store all the post from users in ('/posts'). I came across this plug-in. https://github.com/fechanique/cordova-plugin-fcm. There is this part where it has an option to subscribe to topic.

```<code>FCMPlugin.subscribeToTopic('topicExample');
</code>```

but i think this is not for the database. how can I subscribe to my posts ('/post'). to send push notifications?

答:
It has been a while since I last worked with firebase, but if I remember correctly, you can't directly send push notifications by changing the db. You need firebase functions for that.

Basically what you have to do is write a firebase function that gets triggered when you write to your /post list. You can then send a notification inside that function.

The whole process is described here, including code samples:
https://aaronczichon.de/2017/03/13/firebase-cloud-functions/

Body:
I am using Ionic and firebase. I store all the post from users in ('/posts'). I came across this plug-in. https://github.com/fechanique/cordova-plugin-fcm. There is this part where it has an option to subscribe to topic.

FCMPlugin.subscribeToTopic('topicExample');

but i think this is not for the database. how can I subscribe to my posts ('/post'). to send push notifications?


问:
How to manually number posts to appear first in Wordpress, then sort the rest alphabetically?
I am trying to create a page that lists custom post types alphabetically.  However, I want to be able to manually number some posts so that they appear first, in their numbered order, at the top of the page, and are then followed by the remaining, un-numbered posts, in alphabetical order by their title.  I know how to sort the posts alphabetically, it's combining this with the manual ordering that I don't know how to approach.

Does anyone know what the best way to tackle this would be?  Any help would be much appreciated.

答:
Number In sense Do You Want It To Order By Dates
it Can Be Done By Selecting Order Type And it That Date

or Else

If You Want To Drag And Drop The Order You Can Go With Some Plugins Present In Plugin Store
https://wordpress.org/plugins/intuitive-custom-post-order/


问:
Catching exception in Play for Scala method
This Play for Scala method (that should return Future[play.api.mvc.Result]) invokes another method run that is a future that may throw an exception. If run doesn't throw an exception, then the method should return a Json with ret equals 0.  If run does throw an exception, then the method should retun a Json with ret equals 1.

Problem is that the OnComplete is throwing a compilation error:

type mismatch; found : Unit required:
  scala.concurrent.Future[play.api.mvc.Result]

how to fix this?

```<code>   def test (req:Int) : Future[play.api.mvc.Result] = {

       val future = run(req)
       future.map {
          result =>
               val json = JsObject(Seq(
                          "rs" -> Json.toJson(result),
                          "ret" -> JsString("0")
                      ))
               Ok(json)
           }

       future.onComplete { // <-- compilation error
              case Success(_) => // do nothing
              case Failure(ex) => {
                  val json = JsObject(Seq(
                         "msg" -> JsString(ex.getMessage),
                         "ret" -> JsString("1")
                    ))
                  Ok(json)
              }
            }

   }
</code>```

答:
In Scala result of last expression in a method becomes return value of the method. U)(implicitexecutor:scala.concurrent.ExecutionContext):Unit" rel="nofollow noreferrer">future.onComplete returns a Unit, which makes function body "return" a Unit.

What you actually want is :T](pf:PartialFunction[Throwable,U])(implicitexecutor:scala.concurrent.ExecutionContext):scala.concurrent.Future[U]" rel="nofollow noreferrer">recover

```<code>def test (req:Int) : Future[play.api.mvc.Result] = {
    run(req)
        .map(result => Ok(JsObject("rs" -> ..., "ret" -> 0)))
        .recover({ case NonFatal(ex) =>
            Ok(JsObject(Seq("msg" -> ..., "ret" -> 1))
        })
}
</code>```

Also, note that map returns new future, so in your example you're attaching onComplete callback to the future returned by run, which does not include that json processing; so failure in the map call will not be captured by onComplete Failure(ex) branch. As you can see I've corrected that in the snippet above.

Body:
This Play for Scala method (that should return Future[play.api.mvc.Result]) invokes another method run that is a future that may throw an exception. If run doesn't throw an exception, then the method should return a Json with ret equals 0.  If run does throw an exception, then the method should retun a Json with ret equals 1.

Problem is that the OnComplete is throwing a compilation error:

type mismatch; found : Unit required:
  scala.concurrent.Future[play.api.mvc.Result]

how to fix this?

   def test (req:Int) : Future[play.api.mvc.Result] = {

       val future = run(req)
       future.map {
          result =>
               val json = JsObject(Seq(
                          "rs" -> Json.toJson(result),
                          "ret" -> JsString("0")
                      ))
               Ok(json)
           }

       future.onComplete { // <-- compilation error
              case Success(_) => // do nothing
              case Failure(ex) => {
                  val json = JsObject(Seq(
                         "msg" -> JsString(ex.getMessage),
                         "ret" -> JsString("1")
                    ))
                  Ok(json)
              }
            }

   }

Body:
In Scala result of last expression in a method becomes return value of the method. future.onComplete returns a Unit, which makes function body "return" a Unit.

What you actually want is recover

def test (req:Int) : Future[play.api.mvc.Result] = {
    run(req)
        .map(result => Ok(JsObject("rs" -> ..., "ret" -> 0)))
        .recover({ case NonFatal(ex) =>
            Ok(JsObject(Seq("msg" -> ..., "ret" -> 1))
        })
}

Also, note that map returns new future, so in your example you're attaching onComplete callback to the future returned by run, which does not include that json processing; so failure in the map call will not be captured by onComplete Failure(ex) branch. As you can see I've corrected that in the snippet above.


问:
Compiling with icc -static issue
I have been using ICC to compile a program I wrote for my research (nothing impressive just a lot of floating point calculations) and I can compile it just fine using:

```<code> g++ -O3 mixingModel.cpp configFile.cpp -o mixingModel
</code>```

or

```<code> icc -O3 -ipo -static mixingModel.cpp configFile.cpp -o mixingModel
</code>```

However, as soon as I add -static the compiler just hangs. This issue first crept up when I wanted to use -fast and the compiler just sat there compiling away forever. The process that is running is called mcpcom and it takes 99% of my cpu (so its one thread) and hardly any memory. I have let it sit there for over 30 minutes before (usual compile time without -fast is under one minutes).

I then went ahead and wrote a small hello world program in c++ and tried compiling it with the -fast flag and it again showed the same MO. Sat there with 99% cpu used and the process called is mcpcom.

Note: I am compiling on 64bit Linux with ICC version 11.1 20100806

Thank you,

Patrick

答: This is likely due to icc's inter-procedural optimization. It considers all object files, which can be a lot when doing static linking. So I recommend to drop -ipo. Apparently, this is an old problem.

ContentLicense: CC BY-SA 2.5

Title: Compiling with icc -static issue

Body:
I have been using ICC to compile a program I wrote for my research (nothing impressive just a lot of floating point calculations) and I can compile it just fine using:

 g++ -O3 mixingModel.cpp configFile.cpp -o mixingModel

or

 icc -O3 -ipo -static mixingModel.cpp configFile.cpp -o mixingModel

However, as soon as I add -static the compiler just hangs. This issue first crept up when I wanted to use -fast and the compiler just sat there compiling away forever. The process that is running is called mcpcom and it takes 99% of my cpu (so its one thread) and hardly any memory. I have let it sit there for over 30 minutes before (usual compile time without -fast is under one minutes).

I then went ahead and wrote a small hello world program in c++ and tried compiling it with the -fast flag and it again showed the same MO. Sat there with 99% cpu used and the process called is mcpcom.

Note: I am compiling on 64bit Linux with ICC version 11.1 20100806

Thank you,

Patrick


问:
'AudioAttributes()' not public in 'android.media.AudioAttributes'. Cannot be accessed from outside package
I'm getting an error mentioned below when I try to instantiate AudioAttributes for setting AudioAttributes inside the sound pool.

'AudioAttributes()' not public in 'android.media.AudioAttributes'.
  Cannot be accessed from outside package

```<code>AudioAttributes attributes = new AudioAttributes  ().Builder().build();
</code>```

I need help setting AudioAttributes in SoundPool

答:
The constructor for AudioAttributes is not public, you need to use Builder class which is a subclass nested inside AudioAttributes. Change your assignment to below

```<code>AudioAttributes audioAttributes= new AudioAttributes.Builder().build();
</code>```

Body:
I'm getting an error mentioned below when I try to instantiate AudioAttributes for setting AudioAttributes inside the sound pool.

'AudioAttributes()' not public in 'android.media.AudioAttributes'.
  Cannot be accessed from outside package

AudioAttributes attributes = new AudioAttributes  ().Builder().build();

I need help setting AudioAttributes in SoundPool

Body:
The constructor for AudioAttributes is not public, you need to use Builder class which is a subclass nested inside AudioAttributes. Change your assignment to below

AudioAttributes audioAttributes= new AudioAttributes.Builder().build();


问:
how to check whether a string has exactly n words in mysql
Like my table consist of name street and city .
My query is to find customer name whose street address match any string of 1)exactly 3 character 2)at least 3 character</p>

答:
You can use String function - Length.

```<code>1)Exactly 3 character
SELECT customer_name,street_address FROM TABLE WHERE LENGTH(street_address ) = 3

2)At least 3 character
SELECT customer_name,street_address FROM TABLE WHERE LENGTH(street_address ) >= 3
</code>```

Hope this helps.

Body:
You can use String function - Length.

1)Exactly 3 character
SELECT customer_name,street_address FROM TABLE WHERE LENGTH(street_address ) = 3

2)At least 3 character
SELECT customer_name,street_address FROM TABLE WHERE LENGTH(street_address ) >= 3

Hope this helps.


问:
How to display many differents values splitted by a new line in one cell
I'been trying to figure this out but can't.
I've got a model which has let's say a one-to-many relationship.

```<code>        public virtual IList<ListModels.listaIdInstrumentos> listaIdInstrumentos { get; set; }
</code>```

A pretty plane controller:

```<code>        public ActionResult Index()
    {
        informeModelContext db = new informeModelContext();
        var model = db.Informe.ToList();
        return View(model);
    }
</code>```

And a scaffolded View:

```<code> @foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.listaCalibracion)
        </td>
</code>```

...

The "listaCalibracion" is a List of string that for example could be something like 2 strings named "ABC" and "XYZ"
although i CAN display the values correctly in my page, it will display ("ABCXYZ") and what i want to show is (ABC /n/n XYZ) meaning one under another.

Sorry if i can't make myself clear. English is not my first Lenguage.
Could you help me?

Thanks!

答:
```<code>@foreach (var item in Model)
{
    @foreach (var subItem in item.listaCalibracion)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => subItem )
            </td>
</code>```

Body:
I'been trying to figure this out but can't.
I've got a model which has let's say a one-to-many relationship.

        public virtual IList<ListModels.listaIdInstrumentos> listaIdInstrumentos { get; set; }

A pretty plane controller:

        public ActionResult Index()
    {
        informeModelContext db = new informeModelContext();
        var model = db.Informe.ToList();
        return View(model);
    }

And a scaffolded View:

 @foreach (var item in Model)
{

            @Html.DisplayFor(modelItem => item.listaCalibracion)

...

The "listaCalibracion" is a List of string that for example could be something like 2 strings named "ABC" and "XYZ"
although i CAN display the values correctly in my page, it will display ("ABCXYZ") and what i want to show is (ABC /n/n XYZ) meaning one under another.

Sorry if i can't make myself clear. English is not my first Lenguage.
Could you help me?

Thanks!


问:
celery worker raise sock setsockopt TCP_SYNCNT [Errno 22] Invalid argument
I am using celery with rabbitmq, But I recently get this error sock.setsockopt(SOL_TCP, opt, val), [Errno 22] Invalid argument,

detail,

```<code>{1: 1, 2: 16396, 3: 0, 4: 60, 5: 10, 6: 9, 7: 0, 8: 30, 9: 0, 10: 81059, 12: 1}
(6, 1, 1)
(6, 2, 16396)
(6, 3, 0)
(6, 4, 60)
(6, 5, 10)
(6, 6, 9)
(6, 7, 0)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/celery/app/task.py", line 535, in apply_async
    **options
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/celery/app/base.py", line 737, in send_task
    amqp.send_task_message(P, name, message, **options)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/celery/app/amqp.py", line 558, in send_task_message
    **properties
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/messaging.py", line 181, in publish
    exchange_name, declare,
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 527, in _ensured
    errback and errback(exc, 0)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 419, in _reraise_as_library_errors
    sys.exc_info()[2])
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 414, in _reraise_as_library_errors
    yield
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 515, in _ensured
    reraise_as_library_errors=False,
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 405, in ensure_connection
    callback)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/utils/functional.py", line 333, in retry_over_time
    return fun(*args, **kwargs)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 261, in connect
    return self.connection
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 802, in connection
    self._connection = self._establish_connection()
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 757, in _establish_connection
    conn = self.transport.establish_connection()
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 130, in establish_connection
    conn.connect()
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/amqp/connection.py", line 294, in connect
    self.transport.connect()
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/amqp/transport.py", line 122, in connect
    self.socket_settings, self.read_timeout, self.write_timeout,
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/amqp/transport.py", line 174, in _init_socket
    self._set_socket_options(socket_settings)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/amqp/transport.py", line 205, in _set_socket_options
    self.sock.setsockopt(SOL_TCP, opt, val)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
kombu.exceptions.OperationalError: [Errno 22] Invalid argument
</code>```

(6, 7, 0) is the output of print(SOL_TCP, opt, val) which I add in _set_socket_options

after referring to _socket.pi, I get this:

6, SOL_TCP = 6

7, TCP_SYNCNT = 7 (I think...)

0, val

that all I know, I assume that it has something with system setting, it work well with other system with same code and package.But I knows little about TCP_SYNCNT, any help is appreciated!

BTW, Here are my environments

celery 4.0.2 (latentcall)

rabbitmq-server-3.6.6-1.el6.noarch

erlang-19.1.6-1.el6.x86_64

CentOS release 6.4 (Final)

python2.7.11 with pyenv

pip freeze

```<code>amqp==2.1.4
billiard==3.5.0.2
celery==4.0.2
chardet==3.0.4
Django==1.10.3
django-redis==4.8.0
djangorestframework==3.6.3
httplib2==0.10.3
kombu==4.0.2
netifaces==0.10.6
psutil==5.2.2
py==1.4.34
pyasn1==0.2.3
pyftpdlib==1.5.2
pyrabbit==1.1.0
pytest==3.0.6
pytz==2017.2
redis==2.10.5
rsa==3.4.2
six==1.10.0
vine==1.1.3
xlrd==1.0.0
</code>```

答: Solved by set net.ipv4.tcp_syn_retries = 1, somebody set it to 0 which maybe means never send syn before ESTABLISHED.

Body:
I am using celery with rabbitmq, But I recently get this error sock.setsockopt(SOL_TCP, opt, val), [Errno 22] Invalid argument,

detail,

{1: 1, 2: 16396, 3: 0, 4: 60, 5: 10, 6: 9, 7: 0, 8: 30, 9: 0, 10: 81059, 12: 1}
(6, 1, 1)
(6, 2, 16396)
(6, 3, 0)
(6, 4, 60)
(6, 5, 10)
(6, 6, 9)
(6, 7, 0)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/celery/app/task.py", line 535, in apply_async
    **options
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/celery/app/base.py", line 737, in send_task
    amqp.send_task_message(P, name, message, **options)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/celery/app/amqp.py", line 558, in send_task_message
    **properties
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/messaging.py", line 181, in publish
    exchange_name, declare,
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 527, in _ensured
    errback and errback(exc, 0)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 419, in _reraise_as_library_errors
    sys.exc_info()[2])
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 414, in _reraise_as_library_errors
    yield
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 515, in _ensured
    reraise_as_library_errors=False,
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 405, in ensure_connection
    callback)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/utils/functional.py", line 333, in retry_over_time
    return fun(*args, **kwargs)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 261, in connect
    return self.connection
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 802, in connection
    self._connection = self._establish_connection()
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/connection.py", line 757, in _establish_connection
    conn = self.transport.establish_connection()
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 130, in establish_connection
    conn.connect()
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/amqp/connection.py", line 294, in connect
    self.transport.connect()
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/amqp/transport.py", line 122, in connect
    self.socket_settings, self.read_timeout, self.write_timeout,
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/amqp/transport.py", line 174, in _init_socket
    self._set_socket_options(socket_settings)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/site-packages/amqp/transport.py", line 205, in _set_socket_options
    self.sock.setsockopt(SOL_TCP, opt, val)
  File "/app/pyenv/versions/2.7.11/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
kombu.exceptions.OperationalError: [Errno 22] Invalid argument

(6, 7, 0) is the output of print(SOL_TCP, opt, val) which I add in _set_socket_options

after referring to _socket.pi, I get this:

6, SOL_TCP = 6

7, TCP_SYNCNT = 7 (I think...)

0, val

that all I know, I assume that it has something with system setting, it work well with other system with same code and package.But I knows little about TCP_SYNCNT, any help is appreciated!

BTW, Here are my environments

celery 4.0.2 (latentcall)

rabbitmq-server-3.6.6-1.el6.noarch

erlang-19.1.6-1.el6.x86_64

CentOS release 6.4 (Final)

python2.7.11 with pyenv

pip freeze

amqp==2.1.4
billiard==3.5.0.2
celery==4.0.2
chardet==3.0.4
Django==1.10.3
django-redis==4.8.0
djangorestframework==3.6.3
httplib2==0.10.3
kombu==4.0.2
netifaces==0.10.6
psutil==5.2.2
py==1.4.34
pyasn1==0.2.3
pyftpdlib==1.5.2
pyrabbit==1.1.0
pytest==3.0.6
pytz==2017.2
redis==2.10.5
rsa==3.4.2
six==1.10.0
vine==1.1.3
xlrd==1.0.0


问:
Cakephp 3: How to do an aggregate select statement within an inner join using Cakephp's Query Builder?
Well I just can't seem to figure this out. I'm on day two of messing around with this and it's time to enlist some help.

Here's the SQL that works:

```<code>SELECT rt1.request_id, rt1.status
FROM request_transactions rt1
INNER JOIN (
    SELECT max(id) AS max_id
    FROM request_transactions
    GROUP BY request_id
) AS rt2 ON rt1.id = rt2.max_id;
</code>```

How in the world do I write this using the Cakephp 3 query builder? I'm completely stuck in regards to the inner join with an aggregate function (max).

Many thanks in advance.

EDIT: Here's the table columns and data, if that helps:

```<code>SELECT id, user_id, created, modified FROM requests;

 id | user_id |       created       |      modified
----+---------+---------------------+---------------------
 94 |     101 | 2017-07-04 18:20:47 | 2017-07-04 18:21:26
 95 |     101 | 2017-07-04 18:48:14 | 2017-07-04 18:48:14
 96 |     101 | 2017-07-04 18:48:40 | 2017-07-04 18:48:40
(3 rows)

SELECT id, status, created, request_id FROM request_transactions;

 id  |  status  |       created       | request_id
-----+----------+---------------------+------------
 127 | created  | 2017-07-04 18:20:47 |         94
 128 | read     | 2017-07-04 18:21:03 |         94
 129 | rejected | 2017-07-04 18:21:26 |         94
 130 | created  | 2017-07-04 18:48:14 |         95
 131 | created  | 2017-07-04 18:48:40 |         96
(5 rows)

SELECT rt1.request_id, rt1.status
FROM request_transactions rt1
INNER JOIN (
    SELECT max(id) AS max_id
    FROM request_transactions
    GROUP BY request_id
) AS rt2 ON rt1.id = rt2.max_id;

 request_id |  status
------------+----------
         96 | created
         94 | rejected
         95 | created
(3 rows)
</code>```

答:
You can try this:

```<code>$result = $this->$requestTransactionsModel->find('all')->join(
    ['requests'=>[
      'table'=>'requests',
      'alias'=>'r',
      'type'=>'inner',
      'conditions'=>['request_transactions.id = r.max_id'],
      ])->group('request_transactions.request_id');
</code>```

Body:
Well I just can't seem to figure this out. I'm on day two of messing around with this and it's time to enlist some help.

Here's the SQL that works:

SELECT rt1.request_id, rt1.status
FROM request_transactions rt1
INNER JOIN (
    SELECT max(id) AS max_id
    FROM request_transactions
    GROUP BY request_id
) AS rt2 ON rt1.id = rt2.max_id;

How in the world do I write this using the Cakephp 3 query builder? I'm completely stuck in regards to the inner join with an aggregate function (max).

Many thanks in advance.

EDIT: Here's the table columns and data, if that helps:

SELECT id, user_id, created, modified FROM requests;

 id | user_id |       created       |      modified
----+---------+---------------------+---------------------
 94 |     101 | 2017-07-04 18:20:47 | 2017-07-04 18:21:26
 95 |     101 | 2017-07-04 18:48:14 | 2017-07-04 18:48:14
 96 |     101 | 2017-07-04 18:48:40 | 2017-07-04 18:48:40
(3 rows)

SELECT id, status, created, request_id FROM request_transactions;

 id  |  status  |       created       | request_id
-----+----------+---------------------+------------
 127 | created  | 2017-07-04 18:20:47 |         94
 128 | read     | 2017-07-04 18:21:03 |         94
 129 | rejected | 2017-07-04 18:21:26 |         94
 130 | created  | 2017-07-04 18:48:14 |         95
 131 | created  | 2017-07-04 18:48:40 |         96
(5 rows)

SELECT rt1.request_id, rt1.status
FROM request_transactions rt1
INNER JOIN (
    SELECT max(id) AS max_id
    FROM request_transactions
    GROUP BY request_id
) AS rt2 ON rt1.id = rt2.max_id;

 request_id |  status
------------+----------
         96 | created
         94 | rejected
         95 | created
(3 rows)

Body:
You can try this:

$result = $this->$requestTransactionsModel->find('all')->join(
    ['requests'=>[
      'table'=>'requests',
      'alias'=>'r',
      'type'=>'inner',
      'conditions'=>['request_transactions.id = r.max_id'],
      ])->group('request_transactions.request_id');


问:
wicket - page expired when click previous button
I use wicket 7 with Stateful pages and every i change to new page i always use code like this:

```<code>PageParameters pageParameters = new PageParameters();
setResponsePage(new SecondPage(pageParameters));
</code>```

Every i change page, a new page version is created and the page ID is increased by one.
But when I'm trying to load the previous page, i click the previous button from the browser, the page always expired.

i found the problem when i use this getApplication in my program i cant load the previous page. if i exclude getApplication i can load the previous page.

```<code>public class BasePage extends WebPage {

  private ServletContext servletContext;
  private boolean developmentMode;

  public BasePage() {

    NextApp app = (NextApp) getApplication();
    servletContext = app.getServletContext();
    developmentMode = app.usesDevelopmentConfig();

    /** other code **/
   }
}
</code>```

Please help me, how to use getApplication and i can load the previous page too?

答:
PageExpiredException's javadoc says:

```<code> Thrown when a {@link Page} instance cannot be found by its id in the page stores. The page may be
 * missing because of reasons like:
 * <ul>
 * <li>the page have never been stored there, e.g. an error occurred during the storing process</li>
 * <li>the http session has expired and thus all pages related to this session are erased too</li>
 * <li>the page instance has been erased because the store size exceeded</li>

 * @see HttpSession#setMaxInactiveInterval(int)
 * @see org.apache.wicket.settings.StoreSettings#setMaxSizePerSession(org.apache.wicket.util.lang.Bytes)
 * @see NotSerializableException
</code>```

Check whether any of these is true.

Also I'd recommend you to use: setResponsePage(SecondPage.class,
 new PageParameters());

Body:
I use wicket 7 with Stateful pages and every i change to new page i always use code like this:

PageParameters pageParameters = new PageParameters();
setResponsePage(new SecondPage(pageParameters));

Every i change page, a new page version is created and the page ID is increased by one.
But when I'm trying to load the previous page, i click the previous button from the browser, the page always expired.

i found the problem when i use this getApplication in my program i cant load the previous page. if i exclude getApplication i can load the previous page.

public class BasePage extends WebPage {

  private ServletContext servletContext;
  private boolean developmentMode;

  public BasePage() {

    NextApp app = (NextApp) getApplication();
    servletContext = app.getServletContext();
    developmentMode = app.usesDevelopmentConfig();

    /** other code **/
   }
}

Please help me, how to use getApplication and i can load the previous page too?

Body:
PageExpiredException's javadoc says:

 Thrown when a {@link Page} instance cannot be found by its id in the page stores. The page may be
 * missing because of reasons like:
 * <ul>
 * <li>the page have never been stored there, e.g. an error occurred during the storing process</li>
 * <li>the http session has expired and thus all pages related to this session are erased too</li>
 * <li>the page instance has been erased because the store size exceeded</li>

 * @see HttpSession#setMaxInactiveInterval(int)
 * @see org.apache.wicket.settings.StoreSettings#setMaxSizePerSession(org.apache.wicket.util.lang.Bytes)
 * @see NotSerializableException

Check whether any of these is true.

Also I'd recommend you to use: setResponsePage(SecondPage.class,
 new PageParameters());


问:
Replacing a pandas dataframe column
I have some code which is pulling data into a pandas dataframe.

```<code>df = df[["date","high","low","open","close"]]
</code>```

The data looks like this:

```<code>       date         high          low        open       close
0  1499140800  2615.390000  2600.000000  2610.58000  2603.00000
1  1499155200  2618.785462  2582.002100  2615.00000  2607.00000
2  1499169600  2617.674406  2550.314214  2607.00000  2554.55010
3  1499184000  2572.962113  2519.967440  2554.55010  2519.96744
4  1499198400  2595.654622  2516.000000  2519.96744  2580.00000
</code>```

I am wanting to convert the unix timestamp column with an actual datetime. Earlier in my code am having to import

```<code>from datetime import datetime
</code>```

and it seems to be giving me an error when I try to use datetime.datetime to convert. I can't just use import datetimebecause this gives me an error on my previous import which I need. So my question is twofold. How can I convert the timestamp into a datetime (possibly without using the datetime module?) and how can I overwrite the date column with the new date time before I save into a file?I have tried several approaches but none seem to be giving me any luck..

答:
As @Vinicius Aguiar said in the comment, you can also use pd.to_datetime().

```<code>df['date'] = pd.to_datetime(df['date']).dt.strftime('%Y-%m-%d %H:%M:%S')
</code>```

Title: Replacing a pandas dataframe column

Body:
I have some code which is pulling data into a pandas dataframe.

df = df[["date","high","low","open","close"]]

The data looks like this:

       date         high          low        open       close
0  1499140800  2615.390000  2600.000000  2610.58000  2603.00000
1  1499155200  2618.785462  2582.002100  2615.00000  2607.00000
2  1499169600  2617.674406  2550.314214  2607.00000  2554.55010
3  1499184000  2572.962113  2519.967440  2554.55010  2519.96744
4  1499198400  2595.654622  2516.000000  2519.96744  2580.00000

I am wanting to convert the unix timestamp column with an actual datetime. Earlier in my code am having to import

from datetime import datetime

and it seems to be giving me an error when I try to use datetime.datetime to convert. I can't just use import datetimebecause this gives me an error on my previous import which I need. So my question is twofold. How can I convert the timestamp into a datetime (possibly without using the datetime module?) and how can I overwrite the date column with the new date time before I save into a file?I have tried several approaches but none seem to be giving me any luck..

Body:
As @Vinicius Aguiar said in the comment, you can also use pd.to_datetime().

df['date'] = pd.to_datetime(df['date']).dt.strftime('%Y-%m-%d %H:%M:%S')


问:
Adding android fragment terminates the app
I am a newbie to Android development and I created a blank fragment, which has a textview by default. I tried to add the fragment to my main activity and I am getting following error:

Connected to process 3689 on device samsung-gt_i9300-32305248b97211f9
Application terminated.

Not getting any other exception reason.

```<code> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite"
    tools:context="com.ideasurge.winfertility.AccountActivity">

    <ImageView
        android:id="@+id/titleImageView"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:layout_marginLeft="30dp"
        android:layout_marginStart="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginEnd="30dp"
        android:scaleType="centerInside"
        android:background="@color/colorWhite"
        app:srcCompat="@drawable/wftitleimage" />

    <TextView
        android:id="@+id/fertilityTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your Fertility Companion"
        android:textStyle="bold"
        android:textSize="20sp"
        android:textColor="@color/colorBlack"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:layout_marginTop="20dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/titleImageView"/>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fragmentPlaceholder"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/fertilityTextView">

        <!-- Fragment will go here eventually, but it's not added in the layout -->

    </LinearLayout>

</android.support.constraint.ConstraintLayout>
</code>```

Here is Java code:

```<code> AccountFragment fragment = new AccountFragment();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.fragmentPlaceholder, fragment);
    ft.commit();
</code>```

答: Change you linearLayout to frameLayout . because Fragment is unable to add in LinearLayout.</p>

Body:
I am a newbie to Android development and I created a blank fragment, which has a textview by default. I tried to add the fragment to my main activity and I am getting following error:

Connected to process 3689 on device samsung-gt_i9300-32305248b97211f9
Application terminated.

Not getting any other exception reason.

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite"
    tools:context="com.ideasurge.winfertility.AccountActivity">

    <ImageView
        android:id="@+id/titleImageView"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:layout_marginLeft="30dp"
        android:layout_marginStart="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginEnd="30dp"
        android:scaleType="centerInside"
        android:background="@color/colorWhite"
        app:srcCompat="@drawable/wftitleimage" />

    <TextView
        android:id="@+id/fertilityTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Your Fertility Companion"
        android:textStyle="bold"
        android:textSize="20sp"
        android:textColor="@color/colorBlack"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:layout_marginTop="20dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/titleImageView"/>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fragmentPlaceholder"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/fertilityTextView">

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

Here is Java code:

 AccountFragment fragment = new AccountFragment();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.fragmentPlaceholder, fragment);
    ft.commit();


问:
Env. Variables not set while running Minimal Flask application
I am trying to follow the flask documentation on my windows machine given at the following link:
http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode

Firstly I wrote the code below in a python script:

```<code>from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(debug=True)
</code>```

I saved this in a file called run.py

Then wrote this command in the command window:

```<code>set FLASK_APP = run.py
flask run
</code>```

Upon running this, I am getting the following error:

"Error: Could not locate flask application. You did not provide the FLASK_APP environment variable"

I was expecting to get this instead:

```<code>Running on http://127.0.0.1:5000/
</code>```

Can somebody tell me how to fix this?

答:
Just drop the space around '=' !

After half an hour searching for solution, I finally get what does 'You did not provide the FLASK_APP environment variable' mean. Because what I set is 'FLASK_APP ' variable (with space).

Body:
I am trying to follow the flask documentation on my windows machine given at the following link:
http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode

Firstly I wrote the code below in a python script:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(debug=True)

I saved this in a file called run.py

Then wrote this command in the command window:

set FLASK_APP = run.py
flask run

Upon running this, I am getting the following error:

"Error: Could not locate flask application. You did not provide the FLASK_APP environment variable"

I was expecting to get this instead:

Running on http://127.0.0.1:5000/

Can somebody tell me how to fix this?


问:
Asana - Rest API - Multipart/form image upload times out
I am working on a little tool to upload issues found during development to Asana. I am able to get and use post to create tasks etc, but I am unable to do a proper multipart forum upload.

When I run my image upload post request through an independent perl based cgi script I am getting 200's back and an image saved on my server.

When I target Asana, I get 504 gateway timeouts. I am thinking there must be something strict that the perl script is letting through but I have malformed in my request but I am hard pressed to find it.

Is there a web expert or asana expert out there who might be able to help shed some light on what might be missing.

Note the wireshark capture has an extra field. The Asana docs indicate a task field I have tried with and without that field since it is unclear if the task id encoded in the url satisfies that requirement.

答:
I found the problem!
My boundary= had quotes around the value which was getting through on my cgi / apache setup but not for asana.</p>


问:
HTML5 canvas with freehand line drawing
I am a new learner of canvas in HTML5, and currently trying to make a simple draw line project for kids. I inserted background images into canvas, and try to come up with a freehand line drawing method but up  to no result. Can someone help me fix my below code? Thank you all before. </p>

```<code><!DOCTYPE HTML>
<html>
    <script type="text/javascript">
    var canvas, ctx, flag = false,
        prevX = 0,
        currX = 0,
        prevY = 0,
        currY = 0,
        dot_flag = false;

    var x = "black",
        y = 2;

    function init() {
        canvas = document.getElementById('can');
        ctx = canvas.getContext("2d");
        w = canvas.width;
        h = canvas.height;

        canvas.addEventListener("mousemove", function (e) {
            findxy('move', e)
        }, false);
        canvas.addEventListener("mousedown", function (e) {
            findxy('down', e)
        }, false);
        canvas.addEventListener("mouseup", function (e) {
            findxy('up', e)
        }, false);
        canvas.addEventListener("mouseout", function (e) {
            findxy('out', e)
        }, false);
    }

    function color(obj) {
        switch (obj.id) {
            case "green":
                x = "green";
                break;
            case "blue":
                x = "blue";
                break;
            case "red":
                x = "red";
                break;
            case "yellow":
                x = "yellow";
                break;
            case "orange":
                x = "orange";
                break;
            case "black":
                x = "black";
                break;
            case "white":
                x = "white";
                break;
        }
        if (x == "white") y = 14;
        else y = 2;

    }

    function draw() {
        ctx.beginPath();
        ctx.moveTo(prevX, prevY);
        ctx.lineTo(currX, currY);
        ctx.strokeStyle = x;
        ctx.lineWidth = y;
        ctx.stroke();
        ctx.closePath();
    }

    function erase() {
        var m = confirm("Want to clear");
        if (m) {
            ctx.clearRect(0, 0, w, h);
            document.getElementById("canvasimg").style.display = "none";
        }
    }

    function save() {
        document.getElementById("canvasimg").style.border = "2px solid";
        var dataURL = canvas.toDataURL();
        document.getElementById("canvasimg").src = dataURL;
        document.getElementById("canvasimg").style.display = "inline";
    }

    function findxy(res, e) {
        if (res == 'down') {
            prevX = currX;
            prevY = currY;
            currX = e.clientX - canvas.offsetLeft;
            currY = e.clientY - canvas.offsetTop;

            flag = true;
            dot_flag = true;
            if (dot_flag) {
                ctx.beginPath();
                ctx.fillStyle = x;
                ctx.fillRect(currX, currY, 2, 2);
                ctx.closePath();
                dot_flag = false;
            }
        }
        if (res == 'up' || res == "out") {
            flag = false;
        }
        if (res == 'move') {
            if (flag) {
                prevX = currX;
                prevY = currY;
                currX = e.clientX - canvas.offsetLeft;
                currY = e.clientY - canvas.offsetTop;
                draw();
            }
        }
    }
    </script>
    <body onload="init()" style="background-image: src=c:/WebProgram/Pictures/test1.png;">
        <canvas id="can" width="520" height="700" style="position:absolute;top:10%;left:10%;border:2px solid;"></canvas>
        <div style="position:absolute;top:12%;left:43%;">Choose Color</div>
        <div style="position:absolute;top:15%;left:45%;width:10px;height:10px;background:green;" id="green" onclick="color(this)"></div>
        <div style="position:absolute;top:15%;left:46%;width:10px;height:10px;background:blue;" id="blue" onclick="color(this)"></div>
        <div style="position:absolute;top:15%;left:47%;width:10px;height:10px;background:red;" id="red" onclick="color(this)"></div>
        <div style="position:absolute;top:17%;left:45%;width:10px;height:10px;background:yellow;" id="yellow" onclick="color(this)"></div>
        <div style="position:absolute;top:17%;left:46%;width:10px;height:10px;background:orange;" id="orange" onclick="color(this)"></div>
        <div style="position:absolute;top:17%;left:47%;width:10px;height:10px;background:black;" id="black" onclick="color(this)"></div>
        <div style="position:absolute;top:20%;left:43%;">Eraser</div>
        <div style="position:absolute;top:22%;left:45%;width:15px;height:15px;background:white;border:2px solid;" id="white" onclick="color(this)"></div>
        <img id="canvasimg" style="position:absolute;top:10%;left:52%;" style="display:none;">
        <input type="button" value="save" id="btn" size="30" onclick="save()" style="position:absolute;top:5%;left:10%;">
        <input type="button" value="clear" id="clr" size="23" onclick="erase()" style="position:absolute;top:5%;left:15%;">
    </body>
</html>
</code>```

答:
The process is quite simple really when you think about it:

First, you take the points (x and y coordinates) of the mouse when clicked (make sure you only take these points when the mouse is being clicked).List item

You then draw lines between the points. This should also be easy. (Remember that the lines should only be drawn when the mouse is down and should begin from the first point at which the user presses the mouse or touches the screen. Pretty much whenever there's input)

Now to save the drawing you

convert the image to a data URL using the canvas' toDataURL() function.

then use this code to convert the dataURL into a Blob.

use URL.createObjectURL(blob) to create a link to the blob.

create an  tag and set it's href to the link previously mentioned. Also set it's download attribute to whatever you want the file to be called (e.g. 'myImage.png'). This should leave you with an  tag that looks something like this Click to Save

This, of course, is how I see you completing this app.

One more thing, please read the following tutorials to learn more:

Learn how to use createBojectURL and Blob in this article by MDN

Check out this amazing demo by William Malone

There's also this tutorial I found on Tuts+ (It has no demo from what I've seen. Haven't actually tried this)

Great day! Hope this helps, sorry for being so lazy and not giving actual code to back up this answer.

Title: HTML5 canvas with freehand line drawing

Body:
I am a new learner of canvas in HTML5, and currently trying to make a simple draw line project for kids. I inserted background images into canvas, and try to come up with a freehand line drawing method but up  to no result. Can someone help me fix my below code? Thank you all before.

<!DOCTYPE HTML>

        <canvas id="can" width="520" height="700" style="position:absolute;top:10%;left:10%;border:2px solid;"></canvas>

Choose Color

Eraser

        <input type="button" value="save" id="btn" size="30" onclick="save()" style="position:absolute;top:5%;left:10%;">
        <input type="button" value="clear" id="clr" size="23" onclick="erase()" style="position:absolute;top:5%;left:15%;">

Body:
The process is quite simple really when you think about it:

First, you take the points (x and y coordinates) of the mouse when clicked (make sure you only take these points when the mouse is being clicked).List item

You then draw lines between the points. This should also be easy. (Remember that the lines should only be drawn when the mouse is down and should begin from the first point at which the user presses the mouse or touches the screen. Pretty much whenever there's input)

Now to save the drawing you

convert the image to a data URL using the canvas' toDataURL() function.

then use this code to convert the dataURL into a Blob.

use URL.createObjectURL(blob) to create a link to the blob.

create an <a> tag and set it's href to the link previously mentioned. Also set it's download attribute to whatever you want the file to be called (e.g. 'myImage.png'). This should leave you with an <a> tag that looks something like this <a href="blob:https://example.com/3d45a4f6-7302-485a-a255-d7f56ecf8074" download="myImage.png">Click to Save</a>

This, of course, is how I see you completing this app.

One more thing, please read the following tutorials to learn more:

Learn how to use createBojectURL and Blob in this article by MDN

Check out this amazing demo by William Malone

There's also this tutorial I found on Tuts+ (It has no demo from what I've seen. Haven't actually tried this)

Great day! Hope this helps, sorry for being so lazy and not giving actual code to back up this answer.


问:
How can I mock up an instance of my main Winform form to test some methods?
I am using Moq (which I am very new too as well as TDD period).  And I wanted to Moq up an instance of my main Winforms form so I could test a few methods on there. Is this possible?  Its constructor takes an object of Assembly().

I was trying the following attempts unsuccessful:

```<code>var mockMainForm = new Mock<MainForm>();
mockMainForm.Setup(x => x.Assembler).Returns(new Assembly());
return mockMainForm.Object;
</code>```

But I can't access any properties or methods on this object once it is returned.  Is this possible to do?

But I get errors that ( failed: System.ArgumentException : Expression is not a method invocation: x => x.Assembler
    at Moq.ExpressionExtensions.ToMethodCall(LambdaExpression expression))

答:
Mocking using Moq will only mock the interfaces and virtual methods of a class. Assembler property needs to be defined as virtual.

In any case Mocking a Windows Form is not a good mocking - it has a big bag of WIN32 stuff which make your tests brittle. If you need to unit test and mock a form, create an interface that your form needs to implement and mock that for objects that need to interact with your form.

```<code>public interface IHasAssembler
{
    Foo Assembler {get; set;}
}

public class MyForm : IHasAssembler
{
     //
}
</code>```

then mock the interface and not the form:

```<code>Mock<IHasAssembler> myMock = new Mock<IHasAssembler>();
</code>```

Body:
I am using Moq (which I am very new too as well as TDD period).  And I wanted to Moq up an instance of my main Winforms form so I could test a few methods on there. Is this possible?  Its constructor takes an object of Assembly().

I was trying the following attempts unsuccessful:

var mockMainForm = new Mock<MainForm>();
mockMainForm.Setup(x => x.Assembler).Returns(new Assembly());
return mockMainForm.Object;

But I can't access any properties or methods on this object once it is returned.  Is this possible to do?

But I get errors that ( failed: System.ArgumentException : Expression is not a method invocation: x => x.Assembler
    at Moq.ExpressionExtensions.ToMethodCall(LambdaExpression expression))

Body:
Mocking using Moq will only mock the interfaces and virtual methods of a class. Assembler property needs to be defined as virtual.

In any case Mocking a Windows Form is not a good mocking - it has a big bag of WIN32 stuff which make your tests brittle. If you need to unit test and mock a form, create an interface that your form needs to implement and mock that for objects that need to interact with your form.

public interface IHasAssembler
{
    Foo Assembler {get; set;}
}

public class MyForm : IHasAssembler
{
     //
}

then mock the interface and not the form:

Mock<IHasAssembler> myMock = new Mock<IHasAssembler>();


问:
Random Lines Appearing in HTML Email on outlook 2016
We've been using mailchimp for creating simple email templates then exporting the code and using it in other clients to send those ones out. The problem im having are these random lines under certain tables and between others. I've tried adding a blank  with black background colour and specific width and heights but that doesn't seem to get rid of the white lines. Here is what the part at the bottom looks like in office 2016:

Ignore the yellow highlight text

This is what it looks like on other email clients and browsers:

Apologies for the poor quality but as you can see there are white lines under the text tables and between the text and buttons. Here is my code:

```<code> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"> <head><!--[if gte mso 15]> <xml> <o:OfficeDocumentSettings> <o:AllowPNG/> <o:PixelsPerInch>96</o:PixelsPerInch> </o:OfficeDocumentSettings> </xml><![endif]--><!--[if gt mso 15]> <![endif]--> <meta charset="UTF-8"> <meta http-equiv="x-ua-compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>An Athena for Every Situation</title> </head> <body> <span class="mcnPreviewText" style="display:none; font-size:0px; line-height:0px; max-height:0px; max-width:0px; opacity:0; overflow:hidden; visibility:hidden; mso-hide:all;">An Athena for Every Situation</span> <center> <table align="center" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="bodyTable"> <tr> <td align="center" valign="top" id="bodyCell"><!--[if gte mso 9]> <table align="center" border="0" cellspacing="0" cellpadding="0" width="600" style="width:600px;"> <tr> <td align="center" valign="top" width="600" style="width:600px;"><![endif]--> <table border="0" cellpadding="0" cellspacing="0" width="100%" class="templateContainer"> <tr> <td valign="top" id="templatePreheader"><table class="mcnTextBlock" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnTextBlockOuter"> <tr> <td class="mcnTextBlockInner" style="padding-top:9px;" valign="top"><!--[if mso]> <table align="left" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100%;"> <tr><![endif]--><!--[if mso]> <td valign="top" width="210" style="width:210px;"><![endif]--> <table style="max-width:210px;" class="mcnTextContentContainer" width="100%" cellspacing="0" cellpadding="0" border="0" align="left" > <tbody><tr> <td class="mcnTextContent" style="padding-top:0; padding-left:18px; padding-bottom:9px; padding-right:18px;" valign="top"> </td></tr></tbody></table><!--[if mso]> </td><![endif]--><!--[if mso]> <td valign="top" width="390" style="width:390px;"><![endif]--> <table style="max-width:390px;" class="mcnTextContentContainer" width="100%" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnTextContent" style="padding-top:0; padding-left:18px; padding-bottom:9px; padding-right:18px;" valign="top"> <a href="" target="_blank">View this email in your browser</a> </td></tr></tbody></table><!--[if mso]> </td><![endif]--><!--[if mso]> </tr></table><![endif]--> </td></tr></tbody> </table></td></tr><tr> <td valign="top" id="templateHeader"><table class="mcnImageBlock" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnImageBlockOuter"> <tr> <td style="padding:0px" class="mcnImageBlockInner" valign="top"> <table class="mcnImageContentContainer" style="min-width:100%; border-collapse: collapse;" width="100%" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnImageContent" style="padding-right: 0px; padding-left: 0px; padding-top: 0; padding-bottom: 0; text-align:center;" valign="top"> <img alt="" src="https://gallery.mailchimp.com/ea957616d7790e5fcf5872a25/images/2dc82f25-c77f-4372-a010-f0788c2f0d37.jpg" style="max-width:900px; padding-bottom: 0; display: inline !important; vertical-align: bottom;" class="mcnImage" width="600" align="middle"> </td></tr></tbody></table> </td></tr></tbody> </table></td></tr><tr> <td valign="top" id="templateBody"><table class="mcnBoxedTextBlock" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0"><!--[if gte mso 9]> <table align="center" border="0" cellspacing="0" cellpadding="0" width="100%"><![endif]--> <tbody class="mcnBoxedTextBlockOuter"> <tr> <td class="mcnBoxedTextBlockInner" valign="top"><!--[if gte mso 9]> <td align="center" valign="top" "><![endif]--> <table style="min-width:100%; border-collapse: collapse;" class="mcnBoxedTextContentContainer" width="100%" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td style="padding-top:9px; padding-left:18px; padding-bottom:9px; padding-right:18px;"> <table class="mcnTextContentContainer" style="min-width: 100% !important;background-color: #000000;border: 20px none;" width="100%" cellspacing="0" cellpadding="18" border="0"> <tbody><tr> <td class="mcnTextContent" style="color: #F2F2F2;font-family: Helvetica;font-size: 14px;font-weight: normal;line-height: 100%;text-align: center;" valign="top"> <span style="font-size:27px"><span style="color: #FFFFFF;"><span style="font-family:merriweather sans,helvetica neue,helvetica,arial,sans-serif">An Athena for <strong>EVERY</strong> situation</span></span></span> </td></tr></tbody></table> </td></tr></tbody></table><!--[if gte mso 9]> </td><![endif]--><!--[if gte mso 9]> </tr></table><![endif]--> </td></tr></tbody> </table><table class="mcnTextBlock" style="min-width:100%; border-collapse: collapse;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnTextBlockOuter"> <tr> <td class="mcnTextBlockInner" style="padding-top:9px;" valign="top"><!--[if mso]> <table align="left" border="0" cellspacing="0" cellpadding="0" width="100%" style="width:100%;"> <tr><![endif]--><!--[if mso]> <td valign="top" width="600" style="width:600px;"><![endif]--> <table style="max-width:100%; min-width:100%;" class="mcnTextContentContainer" width="100%" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnTextContent" style="padding-top:0; padding-right:18px; padding-bottom:9px; padding-left:18px;" valign="top"> <div style="text-align: center;"><span style="color:#FFFFFF">NEW RELEASES OUT NOW</span></div></td></tr></tbody></table><!--[if mso]> </td><![endif]--><!--[if mso]> </tr></table><![endif]--> </td></tr></tbody> </table><table class="mcnImageBlock" style="min-width:100%; border-collapse: collapse;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnImageBlockOuter"> <tr> <td style="padding:9px" class="mcnImageBlockInner" valign="top"> <table class="mcnImageContentContainer" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnImageContent" style="padding-right: 9px; padding-left: 9px; padding-top: 0; padding-bottom: 0; text-align:center;" valign="top"> <img alt="" src="https://gallery.mailchimp.com/ea957616d7790e5fcf5872a25/images/c0528a15-f340-4211-bb27-530086ff99ca.png" style="max-width:1087px; padding-bottom: 0; display: inline !important; vertical-align: bottom;" class="mcnImage" width="564" align="middle"> </td></tr></tbody></table> </td></tr></tbody> </table></td></tr><tr> <td valign="top" id="templateColumns"><!--[if gte mso 9]> <table align="center" border="0" cellspacing="0" cellpadding="0" width="600" style="width:600px;"> <tr> <td align="center" valign="top" width="200" height="95" style="width:200px; height:95px;"><![endif]--> <table align="left" border="0" cellpadding="0" cellspacing="0" width="200" height="95" class="columnWrapper"> <tr> <td valign="top" class="columnContainer"><table class="mcnCaptionBlock" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnCaptionBlockOuter"> <tr> <td class="mcnCaptionBlockInner" style="padding:9px;" valign="top"> <table class="mcnCaptionBottomContent" style="border-collapse: collapse;" width="false" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnCaptionBottomImageContent" style="padding:0 9px 9px 9px;" valign="top" align="center"> <img alt="" src="https://gallery.mailchimp.com/ea957616d7790e5fcf5872a25/images/1810cbf7-1d5c-4fbb-901c-ba3394c2bad0.jpg" style="max-width:106px;" class="mcnImage" width="106"> </td></tr><tr> <td class="mcnTextContent" style="padding:0 9px 0 9px; height:95px;" width="164" height="95" valign="top"> <span style="font-family:helvetica neue,helvetica,arial,verdana,sans-serif"><span style="color:#cc0033"><strong>Athena™ 850</strong></span><br><span style="color:#FFFFFF"><span style="font-size:12px">- Travels while raised<br>- Transportable by trailer<br>- Non marking tracks as standard</span></span></span><br></td></tr><tr><td></td></tr></tbody></table> </td></tr></tbody> </table></td></tr></table><!--[if gte mso 9]> </td><td align="center" valign="top" width="200" style="width:200px;"><![endif]--> <table align="left" border="0" cellpadding="0" cellspacing="0" width="200" class="columnWrapper"> <tr> <td valign="top" class="columnContainer"><table class="mcnCaptionBlock" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnCaptionBlockOuter"> <tr> <td class="mcnCaptionBlockInner" style="padding:9px;" valign="top"> <table class="mcnCaptionBottomContent" style="border-collapse: collapse;" width="false" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnCaptionBottomImageContent" style="padding:0 9px 9px 9px;" valign="top" align="center"> <img alt="" src="https://gallery.mailchimp.com/ea957616d7790e5fcf5872a25/images/1810cbf7-1d5c-4fbb-901c-ba3394c2bad0.jpg" style="max-width:106px;" class="mcnImage" width="106"> </td></tr><tr> <td class="mcnTextContent" style="padding:0 9px 0 9px;" width="164" valign="top"> <span style="font-family:helvetica neue,helvetica,arial,verdana,sans-serif"><span style="color:#cc0033"><strong>Athena™ HE-  New release</strong></span><br><span style="color:#FFFFFF"><span style="font-size:12px">- Fits through a door<br>- Indoor and outdoor use<br>- Self-levels on up to 20 degrees<br>- Transportable by trailer</span></span></span><br>  </td></tr></tbody></table> </td></tr></tbody> </table></td></tr></table><!--[if gte mso 9]> </td><td align="center" valign="top" width="200" style="width:200px;"><![endif]--> <table align="left" border="0" cellpadding="0" cellspacing="0" width="200" class="columnWrapper"> <tr> <td valign="top" class="columnContainer"><table class="mcnCaptionBlock" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnCaptionBlockOuter"> <tr> <td class="mcnCaptionBlockInner" style="padding:9px;" valign="top"> <table class="mcnCaptionBottomContent" style="border-collapse: collapse;" width="false" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnCaptionBottomImageContent" style="padding:0 9px 9px 9px;" valign="top" align="center"> <img alt="" src="https://gallery.mailchimp.com/ea957616d7790e5fcf5872a25/images/1810cbf7-1d5c-4fbb-901c-ba3394c2bad0.jpg" style="max-width:106px;" class="mcnImage" width="106"> </td></tr><tr> <td class="mcnTextContent" style="padding:0 9px 0 9px;" width="164" valign="top"> <span style="font-family:helvetica neue,helvetica,arial,verdana,sans-serif"><span style="color:#cc0033"><strong>Athena™ EVO 10.90 - New release</strong></span><br><span style="color:#FFFFFF"><span style="font-size:12px">- New 10 metre working height<br>- Dynamic and Proactive Levelling capabilities<br>- Drives and self levels while in the air<br>- New larger basket design</span></span></span> </td></tr></tbody></table> </td></tr></tbody> </table></td></tr></table><!--[if gte mso 9]> </td></tr></table><![endif]--> </td></tr><tr> <td valign="top" id="templateFooter"><table class="mcnBoxedTextBlock" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0"><!--[if gte mso 9]> <table align="center" border="0" cellspacing="0" cellpadding="0" width="100%"><![endif]--> <tbody class="mcnBoxedTextBlockOuter"> <tr> <td class="mcnBoxedTextBlockInner" valign="top"><!--[if gte mso 9]> <td align="center" valign="top" "><![endif]--> <table style="min-width:100%; border-collapse: collapse;" class="mcnBoxedTextContentContainer" width="100%" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td style="padding-top:9px; padding-left:18px; padding-bottom:9px; padding-right:18px;"> <table class="mcnTextContentContainer" style="min-width: 100% !important;background-color: #000000;" width="100%" cellspacing="0" cellpadding="18" border="0"> <tbody><tr> <td class="mcnTextContent" style="color: #F2F2F2;font-family: Helvetica;font-size: 14px;font-weight: normal;text-align: center;" valign="top"> <span style="font-size:16px"><strong><span style="color: #CC0033;"><span style="font-family:helvetica neue,helvetica,arial,verdana,sans-serif">CLICK THROUGH TO DOWNLOAD A SPEC SHEET OR TO WATCH THE ATHENA™ IN ACTION</span></span></strong></span> </td></tr></tbody></table> </td></tr></tbody></table><!--[if gte mso 9]> </td><![endif]--><!--[if gte mso 9]> </tr></table><![endif]--> </td></tr></tbody> </table><table class="mcnCaptionBlock" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnCaptionBlockOuter"> <tr> <td class="mcnCaptionBlockInner" style="padding:9px;" valign="top"> <table class="mcnCaptionLeftContentOuter" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td class="mcnCaptionLeftContentInner" style="padding:0 9px ;" valign="top"> <table class="mcnCaptionLeftImageContentContainer" cellspacing="0" cellpadding="0" border="0" align="right"> <tbody><tr> <td class="mcnCaptionLeftImageContent" valign="top"> <a href="http://v3au.zone-secure.net/drive/9982/339883/" title="" class="" target="_blank"> <img alt="" src="athena.jpg" style="max-width:709px;" class="mcnImage" width="264"> </a> </td></tr></tbody></table> <table class="mcnCaptionLeftTextContentContainer" width="264" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnTextContent" valign="top"> <div style="text-align: center;"><span style="font-size:14px"><span style="font-family:helvetica neue,helvetica,arial,verdana,sans-serif"><span style="color: #FFFFFF;">For a full range of ASPAC Specialist Access equipment</span></span></span></div></td></tr></tbody></table> </td></tr></tbody></table> </td></tr></tbody> </table><table class="mcnDividerBlock" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnDividerBlockOuter"> <tr> <td class="mcnDividerBlockInner" style="min-width:100%; padding:18px;"> <table class="mcnDividerContent" style="min-width: 100%;border-top: 2px solid #FFFFFF;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td> <span></span> </td></tr></tbody></table> </td></tr></tbody> </table><table class="mcnCaptionBlock" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnCaptionBlockOuter"> <tr> <td class="mcnCaptionBlockInner" style="padding:9px;" valign="top"> <table class="mcnCaptionLeftContentOuter" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody><tr> <td class="mcnCaptionLeftContentInner" style="padding:0 9px ;" valign="top"> <table class="mcnCaptionLeftImageContentContainer" cellspacing="0" cellpadding="0" border="0" align="right"> <tbody><tr> <td class="mcnCaptionLeftImageContent" valign="top"> <a href="http://www.aspacgroup.com.au" title="" class="" target="_blank"> <img alt="" src="https://gallery.mailchimp.com/ea957616d7790e5fcf5872a25/images/d733278d-2c92-4a9f-9be1-4f0c6b5266a8.jpg" style="max-width:709px;" class="mcnImage" width="264"> </a> </td></tr></tbody></table> <table class="mcnCaptionLeftTextContentContainer" width="264" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td class="mcnTextContent" valign="top"> <div style="text-align: center;"><span style="font-size:14px"><span style="font-family:helvetica neue,helvetica,arial,verdana,sans-serif"><span style="color: #FFFFFF;">For a full range of ASPAC Specialist Access equipment</span></span></span></div></td></tr></tbody></table> </td></tr></tbody></table> </td></tr></tbody> </table><table class="mcnBoxedTextBlock" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0"><!--[if gte mso 9]> <table align="center" border="0" cellspacing="0" cellpadding="0" width="100%"><![endif]--> <tbody class="mcnBoxedTextBlockOuter"> <tr> <td class="mcnBoxedTextBlockInner" valign="top"><!--[if gte mso 9]> <td align="center" valign="top" "><![endif]--> <table style="min-width:100%;" class="mcnBoxedTextContentContainer" width="100%" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody><tr> <td style="padding-top:9px; padding-left:18px; padding-bottom:9px; padding-right:18px;"> <table class="mcnTextContentContainer" style="min-width: 100% !important;background-color: #DA2127;" width="100%" cellspacing="0" cellpadding="18" border="0"> <tbody><tr> <td class="mcnTextContent" style="color: #F2F2F2;font-family: "Helvetica Neue",Helvetica,Arial,Verdana,sans-serif;font-size: 14px;font-weight: normal;text-align: center;" valign="top"> <div style="text-align: center;"><span style="color:#FFFFFF"><span style="font-family:helvetica neue,helvetica,arial,verdana,sans-serif"><strong>After Sales Service: </strong></span></span></div><span style="color:#FFFFFF"><span style="font-family:helvetica neue,helvetica,arial,verdana,sans-serif">Maintenance agreements available 24 hour phone support</span></span> </td></tr></tbody></table> </td></tr></tbody></table><!--[if gte mso 9]> </td><![endif]--><!--[if gte mso 9]> </tr></table><![endif]--> </td></tr></tbody> </table></td></tr><tr> <td valign="top" id="templateFooterSage"> <table class="mcnDividerBlock" style="min-width:100%;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnDividerBlockOuter"> <tr> <td class="mcnDividerBlockInner" style="min-width:100%;padding:18px;"> <table class="mcnDividerContent" style="min-width:100%;border-top:2px solid #EAEAEA;" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td> <span></span> </td></tr></tbody> </table> </td></tr></tbody> </table> <table class="mcnCaptionBlock" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody class="mcnCaptionBlockOuter"> <tr> <td class="mcnCaptionBlockInner" style="padding:9px;" valign="top"> <table class="mcnCaptionRightContentOuter" width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td class="mcnCaptionRightContentInner" style="padding:0 9px;" valign="top"> <table class="mcnCaptionRightImageContentContainer" cellspacing="0" cellpadding="0" border="0" align="left"> <tbody> <tr> <td class="mcnCaptionRightImageContent" valign="top"> <img alt="" src="https://gallery.mailchimp.com/ea957616d7790e5fcf5872a25/images/0d9da147-38d0-4b35-b132-9798550e40f9.jpg" style="max-width:60px;" class="mcnImage" width="60"> </td></tr></tbody> </table> <table class="mcnCaptionRightTextContentContainer" width="396" cellspacing="0" cellpadding="0" border="0" align="right"> <tbody> <tr> <td class="mcnTextContent" valign="top"> <br>info@sagemedia.com.au +61 8 6336 6430 www.sagemedia.com.au <tr> <td style="width:100px; height:20px;"></td></tr><tr class="unsub"> <td valign="top" align="center"><a href="https://www.buildaustralia.com.au/unsubscribe" style="padding: 0px 0px;font-size: 12px; text-decoration:none; font-family: font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; mso-height-rule: exactly; line-height:14px; text-align: right;color: #888888;">click here to unsubscribe</a></td></tr></tr></td></tr></tbody> </table> </td></tr></tbody> </table> </td></tr></tbody> </table> </td></tr></table><!--[if gte mso 9]> </td></tr></table><![endif]--> </td></tr></table> </center> </body> </html>
</code>```

Here is a JSFiddle with formatted html: https://jsfiddle.net/025ox8tp/1/

Thanks for the help. PS I had to minify the code in order to fit everything in.

答: Problem Solved!!! It turns out it was just one computer that had an issue with this email. Other computers using outlook didnt seem to have the problem and after re-installing outlook on his computer. Problem solved </p>

Body:
We've been using mailchimp for creating simple email templates then exporting the code and using it in other clients to send those ones out. The problem im having are these random lines under certain tables and between others. I've tried adding a blank  with black background colour and specific width and heights but that doesn't seem to get rid of the white lines. Here is what the part at the bottom looks like in office 2016:

Ignore the yellow highlight text

This is what it looks like on other email clients and browsers:

Apologies for the poor quality but as you can see there are white lines under the text tables and between the text and buttons. Here is my code:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <meta charset="UTF-8"> <meta http-equiv="x-ua-compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>An Athena for Every Situation</title>   An Athena for Every Situation

  View this email in your browser

  An Athena for EVERY situation

NEW RELEASES OUT NOW

  Athena™ 850
- Travels while raised
- Transportable by trailer
- Non marking tracks as standard

  Athena™ HE-  New release
- Fits through a door
- Indoor and outdoor use
- Self-levels on up to 20 degrees
- Transportable by trailer

  Athena™ EVO 10.90 - New release
- New 10 metre working height
- Dynamic and Proactive Levelling capabilities
- Drives and self levels while in the air
- New larger basket design

  CLICK THROUGH TO DOWNLOAD A SPEC SHEET OR TO WATCH THE ATHENA™ IN ACTION

For a full range of ASPAC Specialist Access equipment

For a full range of ASPAC Specialist Access equipment

After Sales Service:
Maintenance agreements available 24 hour phone support

info@sagemedia.com.au +61 8 6336 6430 www.sagemedia.com.au

 click here to unsubscribe

Here is a JSFiddle with formatted html: https://jsfiddle.net/025ox8tp/1/

Thanks for the help. PS I had to minify the code in order to fit everything in.


问:
Is there a way to use .innerHTML multiple times?
I would like to write two variable values into a div container (with id myDiv) using innerHTML. My Div container is only showing the second value.</p>

```<code><button type="button" onclick="myFunction()">Click me</button>
<input type="text" id="First" name="firstname">
<input type="text" id="Last" name="lastname">

<div id="myDiv"></div>
<script>
function myFunction() {
    var x = document.getElementById("John").value;
    var y = document.getElementById("Mail").value;
    document.getElementById("myDub").innerHTML=x;
    document.getElementById("myDub").innerHTML=y;
}</script>
</code>```

答:
First you need to use correct ids everywhere. Second you can just add x+y in one assignment only like this:

```<code><button type="button" onclick="myFunction()">Click me</button>
<input type="text" id="First" name="firstname">
<input type="text" id="Last" name="lastname">

<div id="myDiv"></div>
<script>
function myFunction() {
    var x = document.getElementById("First").value;
    var y = document.getElementById("Last").value;
    document.getElementById("myDiv").innerHTML= x + y;
}</script>
</code>```

or you can use += for if you want to keep appending to previously assigned value.

```<code>document.getElementById("myDiv").innerHTML = x;
document.getElementById("myDiv").innerHTML += y;
</code>```

Body:
I would like to write two variable values into a div container (with id myDiv) using innerHTML. My Div container is only showing the second value.

<button type="button" onclick="myFunction()">Click me</button>
<input type="text" id="First" name="firstname">
<input type="text" id="Last" name="lastname">

Body:
First you need to use correct ids everywhere. Second you can just add x+y in one assignment only like this:

<button type="button" onclick="myFunction()">Click me</button>
<input type="text" id="First" name="firstname">
<input type="text" id="Last" name="lastname">

<div id="myDiv"></div>
<script>
function myFunction() {
    var x = document.getElementById("First").value;
    var y = document.getElementById("Last").value;
    document.getElementById("myDiv").innerHTML= x + y;
}</script>

or you can use += for if you want to keep appending to previously assigned value.

document.getElementById("myDiv").innerHTML = x;
document.getElementById("myDiv").innerHTML += y;


问:
ExoPlayer2 - How to release from fragment
I have one activity with 2 fragments (not a ViewPager) & want to use ExoPlayer2 in one of the fragments to play content. The initial fragment shows a list of content & when clicked the second fragment is shown to play the selected content. However when I click back to the initial fragment I can still hear the content playing; it's as though the second fragment is still open. I'm (trying to) release the player this way:

```<code>@Override
public void onStop() {
    super.onStop();
    releasePlayer();
}

public void releasePlayer() {

    if (player != null) {
        player.setPlayWhenReady(true);
        player.stop();
        player.release();
        player = null;
        trackSelector = null;
        simpleExoPlayerView.setPlayer(null);
        simpleExoPlayerView = null;
        System.out.println("releasePlayer");
    }
}
</code>```

I read this but it didn't provide much of a solution. Also, read several posts where ExoPlayer is used in ViewPager fragments but not exactly sure how those examples released the player. Followed the releasePlayer() method from the demo app found here but no luck. Called releasePlayer() from onPause(), onDetach(), onDestroyView() but it made no difference.

Here's some logging set up after the listener is added to the player but don't see anything to explain why it's not releasing...

```<code>07-05 19:01:07.216 2529-2643/? V/RenderScript: 0xe0494000 Launching thread(s), CPUs 4
07-05 19:01:11.871 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:11.876 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onTimelineChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onLoadingChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onTimelineChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onLoadingChanged...
07-05 19:01:12.467 3064-3064/? V/MediaCodecInfo: Listener-onTimelineChanged...
07-05 19:01:12.468 3064-3064/? V/MediaCodecInfo: Listener-onTimelineChanged...
07-05 19:01:12.515 3064-3099/? V/SoftFFmpegVideo: got OMX_IndexParamPortDefinition, width: 320, height: 180
07-05 19:01:12.708 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:12.708 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:13.380 3064-3064/? V/MediaCodecInfo: Listener-onLoadingChanged...
07-05 19:01:13.655 3064-3064/? V/MediaCodecInfo: Listener-onLoadingChanged...
07-05 19:01:18.528 3064-3099/? V/SoftFFmpegVideo: ~SoftFFmpegVideo
</code>```

Tried the button click but it failed

```<code>fragmentExoBinding.button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            System.out.println("button click");
            releasePlayer();
        }
    });
</code>```

It was crashing everytime I shut it down (using back press, home or recent) b/c there's no longer a player. Updated the releasePlayer() method with if (player != null) but can still hear the content playing even after button click.

答:
I am using ExoPlayer inside the Activity and I am using a two-step process. onPause I am stopping the playback:

```<code>private SimpleExoPlayer player;
@Override
protected void onPause() {
    super.onPause();

    // Pause video if it's playing
    if (isVideoPlaying()) {
        if (player != null)
            player.setPlayWhenReady(false);
    }
}
</code>```

And onDestroy I release the player

```<code>@Override
protected void onDestroy() {
    releasePlayer();
    super.onDestroy();
}

private void releasePlayer() {
        if (player != null) {
            player.stop();
            player.release();
            player = null;
        }
    }
</code>```

Body:
I have one activity with 2 fragments (not a ViewPager) & want to use ExoPlayer2 in one of the fragments to play content. The initial fragment shows a list of content & when clicked the second fragment is shown to play the selected content. However when I click back to the initial fragment I can still hear the content playing; it's as though the second fragment is still open. I'm (trying to) release the player this way:

@Override
public void onStop() {
    super.onStop();
    releasePlayer();
}

public void releasePlayer() {

    if (player != null) {
        player.setPlayWhenReady(true);
        player.stop();
        player.release();
        player = null;
        trackSelector = null;
        simpleExoPlayerView.setPlayer(null);
        simpleExoPlayerView = null;
        System.out.println("releasePlayer");
    }
}

I read this but it didn't provide much of a solution. Also, read several posts where ExoPlayer is used in ViewPager fragments but not exactly sure how those examples released the player. Followed the releasePlayer() method from the demo app found here but no luck. Called releasePlayer() from onPause(), onDetach(), onDestroyView() but it made no difference.

Here's some logging set up after the listener is added to the player but don't see anything to explain why it's not releasing...

07-05 19:01:07.216 2529-2643/? V/RenderScript: 0xe0494000 Launching thread(s), CPUs 4
07-05 19:01:11.871 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:11.876 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onTimelineChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onLoadingChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onTimelineChanged...
07-05 19:01:11.904 3064-3064/? V/MediaCodecInfo: Listener-onLoadingChanged...
07-05 19:01:12.467 3064-3064/? V/MediaCodecInfo: Listener-onTimelineChanged...
07-05 19:01:12.468 3064-3064/? V/MediaCodecInfo: Listener-onTimelineChanged...
07-05 19:01:12.515 3064-3099/? V/SoftFFmpegVideo: got OMX_IndexParamPortDefinition, width: 320, height: 180
07-05 19:01:12.708 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:12.708 3064-3064/? V/MediaCodecInfo: Listener-onPlayerStateChanged...
07-05 19:01:13.380 3064-3064/? V/MediaCodecInfo: Listener-onLoadingChanged...
07-05 19:01:13.655 3064-3064/? V/MediaCodecInfo: Listener-onLoadingChanged...
07-05 19:01:18.528 3064-3099/? V/SoftFFmpegVideo: ~SoftFFmpegVideo

Tried the button click but it failed

fragmentExoBinding.button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            System.out.println("button click");
            releasePlayer();
        }
    });

It was crashing everytime I shut it down (using back press, home or recent) b/c there's no longer a player. Updated the releasePlayer() method with if (player != null) but can still hear the content playing even after button click.

Body:
I am using ExoPlayer inside the Activity and I am using a two-step process. onPause I am stopping the playback:

private SimpleExoPlayer player;
@Override
protected void onPause() {
    super.onPause();

    // Pause video if it's playing
    if (isVideoPlaying()) {
        if (player != null)
            player.setPlayWhenReady(false);
    }
}

And onDestroy I release the player

@Override
protected void onDestroy() {
    releasePlayer();
    super.onDestroy();
}

private void releasePlayer() {
        if (player != null) {
            player.stop();
            player.release();
            player = null;
        }
    }


问:
INNER JOIN with Table-Valued Function not working
I have a table valued function that returns a table. When I try to JOIN the table-valued function with another table I don't get any results, but when I copy the result of the function into an actual table and do the same join, then I get expected results.

The query looks something like this:

```<code>Select *
From myTable
INNER JOIN fn_function(@parm1, @param2)
ON ....
</code>```

All up I have about 4 such queries and each one has slighly different function, but all the functions produce the same table but different data. For some of these queries the INNER JOIN works, but for others it does not.

Any suggesting why this happens?

答:
I think this should work

```<code>  Select *
    From Animals
    Join dbo.AnimalsTypesIds(900343)
      As AnimalsTypes
      On AnimalsTypes.TypeId = Animals.TypeId
</code>```

In table valued function the return table should have TypeId so that join works on that clause

Body:
I have a table valued function that returns a table. When I try to JOIN the table-valued function with another table I don't get any results, but when I copy the result of the function into an actual table and do the same join, then I get expected results.

The query looks something like this:

Select *
From myTable
INNER JOIN fn_function(@parm1, @param2)
ON ....

All up I have about 4 such queries and each one has slighly different function, but all the functions produce the same table but different data. For some of these queries the INNER JOIN works, but for others it does not.

Any suggesting why this happens?

Body:
I think this should work

  Select *
    From Animals
    Join dbo.AnimalsTypesIds(900343)
      As AnimalsTypes
      On AnimalsTypes.TypeId = Animals.TypeId

In table valued function the return table should have TypeId so that join works on that clause


问:
Is there a perfect algorithm for chess?
I was recently in a discussion with a non-coder person on the possibilities of chess computers.  I'm not well versed in theory, but think I know enough.

I argued that there could not exist a deterministic Turing machine that always won or stalemated at chess.  I think that, even if you search the entire space of all combinations of player1/2 moves, the single move that the computer decides upon at each step is based on a heuristic.  Being based on a heuristic, it does not necessarily beat ALL of the moves that the opponent could do.

My friend thought, to the contrary, that a computer would always win or tie if it never made a "mistake" move (however do you define that?).  However, being a programmer who has taken CS, I know that even your good choices - given a wise opponent - can force you to make "mistake" moves in the end.  Even if you know everything, your next move is greedy in matching a heuristic.

Most chess computers try to match a possible end game to the game in progress, which is essentially a dynamic programming traceback.  Again, the endgame in question is avoidable though.

Edit: Hmm... looks like I ruffled some feathers here.  That's good.

Thinking about it again, it seems like there is no theoretical problem with solving a finite game like chess.  I would argue that chess is a bit more complicated than checkers in that a win is not necessarily by numerical exhaustion of pieces, but by a mate.  My original assertion is probably wrong, but then again I think I've pointed out something that is not yet satisfactorily proven (formally).

I guess my thought experiment was that whenever a branch in the tree is taken, then the algorithm (or memorized paths) must find a path to a mate (without getting mated) for any possible branch on the opponent moves. After the discussion, I will buy that given more memory than we can possibly dream of, all these paths could be found.

答:
As a chess programmer from the 1970's, I definitely have an opinion on this. What I wrote up about 10 years ago, still is basically true today:

"Unfinished Work and Challenges to Chess Programmers"

Back then, I thought we could solve Chess conventionally, if done properly.

Checkers was solved recently (Yay, University of Alberta, Canada!!!) but that was effectively done Brute Force. To do chess conventionally, you'll have to be smarter.

Unless, of course, Quantum Computing becomes a reality. If so, chess will be solved as easily as Tic-Tac-Toe.

In the early 1970's in Scientific American, there was a short parody that caught my attention. It was an announcement that the game of chess was solved by a Russian chess computer. It had determined that there is one perfect move for white that would ensure a win with perfect play by both sides, and that move is: 1. a4!

Title: Is there a perfect algorithm for chess?

LastEditorDisplayName: Dan Dyer

OwnerDisplayName: lkessler


问:
'createPolyglotMiddleware' is not defined
I'm trying to set up redux-polyglot following the instructions here: https://www.npmjs.com/package/redux-polyglot

My problem is that when I add the const polyglotMiddleware = createPolyglotMiddleware( part I get an error telling me it isn't defined. I can't work out where I've gone wrong. Can anyone help?

Here is my Reducer code:

```<code>import { createStore, combineReducers, applyMiddleware } from 'redux';
import { polyglotReducer } from 'redux-polyglot';

const rootReducer = combineReducers({
    polyglot: polyglotReducer
});

const polyglotMiddleware = createPolyglotMiddleware(
    'ACTION_TO_CATCH',
    action => action.payload.locale,
    locale => new Promise(resolve => {
        // perform async here
        resolve({
            hello: 'bonjour',
        });
    }),
)

const store = createStore(rootReducer, {}, applyMiddleware(polyglotMiddleware));

export default store;
</code>```

答:
I think you have forgot to import createPolyglotMiddleware, try the following on top of you module:

```<code>import { polyglotReducer, createPolyglotMiddleware } from 'redux-polyglot';
</code>```

Body:
I'm trying to set up redux-polyglot following the instructions here: https://www.npmjs.com/package/redux-polyglot

My problem is that when I add the const polyglotMiddleware = createPolyglotMiddleware( part I get an error telling me it isn't defined. I can't work out where I've gone wrong. Can anyone help?

Here is my Reducer code:

import { createStore, combineReducers, applyMiddleware } from 'redux';
import { polyglotReducer } from 'redux-polyglot';

const rootReducer = combineReducers({
    polyglot: polyglotReducer
});

const polyglotMiddleware = createPolyglotMiddleware(
    'ACTION_TO_CATCH',
    action => action.payload.locale,
    locale => new Promise(resolve => {
        // perform async here
        resolve({
            hello: 'bonjour',
        });
    }),
)

const store = createStore(rootReducer, {}, applyMiddleware(polyglotMiddleware));

export default store;

Body:
I think you have forgot to import createPolyglotMiddleware, try the following on top of you module:

import { polyglotReducer, createPolyglotMiddleware } from 'redux-polyglot';