问:
Refreshing a JS coutndown timer after pressing the back button?
My server runs some database maintenance scripts each night at midnight.  In order to prevent interference from the end user all sessions are terminated a few minutes before execution.  So that the user isn't rudely interrupted in the middle of doing something important, a countdown timer shows the remaining time.  This is done by exporting the server time during preprocessing (php) to a JS variable and cycling down the seconds in a simple looping display routine.

This works as intended most of the time, however, if the user navigates to the page by pressing the back button the time displayed will be out of sync.  Is there a way I can make sure the script is getting the most current server time each time the page is viewed, even when being viewed after having pressed the back button?

It's very simple...

```<code>var seconds = <?php echo $time_left; ?>;
function display_timer ()
{
    seconds--;
    minutes = parseInt((seconds / 60) % 60);
    hours = parseInt(seconds / 3600);

    ds = seconds % 60;
    ds = ds > 9 ? ds.toString() : '0' + ds.toString();
    dm = minutes > 9 ? minutes.toString() : '0' + minutes.toString();
    dh = hours > 9 ? hours.toString() : '0' + hours.toString();

    document.getElementById('countdown').innerHTML = 'Time left: ' + dh + ':' + dm + ':' + ds;

    if (seconds)
    {
        setTimeout("display_timer()", 1000);
    }
}

display_timer();
</code>```

答: You can use Ajax call to refresh (Sync) time at client side with server. All you need to do is to identify the best time interval after which you will send Ajax call to sync time.</p>

Body:
My server runs some database maintenance scripts each night at midnight.  In order to prevent interference from the end user all sessions are terminated a few minutes before execution.  So that the user isn't rudely interrupted in the middle of doing something important, a countdown timer shows the remaining time.  This is done by exporting the server time during preprocessing (php) to a JS variable and cycling down the seconds in a simple looping display routine.

This works as intended most of the time, however, if the user navigates to the page by pressing the back button the time displayed will be out of sync.  Is there a way I can make sure the script is getting the most current server time each time the page is viewed, even when being viewed after having pressed the back button?

It's very simple...

var seconds = <?php echo $time_left; ?>;
function display_timer ()
{
    seconds--;
    minutes = parseInt((seconds / 60) % 60);
    hours = parseInt(seconds / 3600);

    ds = seconds % 60;
    ds = ds > 9 ? ds.toString() : '0' + ds.toString();
    dm = minutes > 9 ? minutes.toString() : '0' + minutes.toString();
    dh = hours > 9 ? hours.toString() : '0' + hours.toString();

    document.getElementById('countdown').innerHTML = 'Time left: ' + dh + ':' + dm + ':' + ds;

    if (seconds)
    {
        setTimeout("display_timer()", 1000);
    }
}

display_timer();


来源: stackexchange

问:
What is the rationale behind the `std::unique_XXX` naming convention?
It seems like there was a mini-trend to name things std::unique_XXX at some point. It makes sense that std::unique_ptr is a smart pointer that is only meant to be handled by one consumer, and therefore "unique" in this case makes sense.

But at least one other class got the unique moniker and I'm not really sure why. Why is std::unique_lock called that? As opposed to std::lock_guard, which is not any less or more unique, right?

I think I'm missing something.

I can't recall what other classes followed suit but I seem to remember we have more. Maybe it was just std::unique_lock; I forget. But if there are other std::unique_XXX class names, why are they named that?

答:
A lock guard is locked on creation and unlocked on destruction. You can't move it or copy it, so you can't transfer or share access to the locked resource.

A std::unique_lock is (among other things) movable (not copyable). So you can transfer access to the underlying resource. Much like you transfer ownership of a std::unique_ptr.

While I can't really comment on why the naming scheme was picked as I wasn't there and haven't read the papers / discussion on the topic... the similarities between the two are at least apparent enough for me to say "yeah I get why they did that." :)

ContentLicense: CC BY-SA 4.0


问:
Flutter Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic> JSON request
I'm a beginner in flutter and i have problem with my app when i wanna take the values from the JSON.

The problem comes from my http request when i call GetCommands() and i don't know to solve it.
I already did it once in another app with other data(JSON too) and it worked...

Here is the main code :

```<code>  var commandsGet = new List<Value>();

  Future<void> GetCommands() async {
    await GET.url(urlTest).then((response) {
      setState(() {
        Iterable list2 = json.decode(response.body);
        commandsGet = list2.map((model) => Value.fromJson(model)).toList();
      });
    });
  }

  Future<void> wait2() async {
    await GetCommands();
  }

  onChange2(commandsData user) {
    setState(() {
      commandselection = user;
      // TEST
      wait2().then((result) {
        print("This is a test");
      });
      // TEST
    });
  }
</code>```

Here is my Value class :

```<code>class Value {
  String device;
  int origin;
  List<Readings> readings;

  Value({
    this.device,
    this.origin,
    this.readings,
  });

  Value.fromJson(Map<String, dynamic> json) {
    device = json['device'];
    origin = json['origin'];
    if (json['readings'] != null) {
      readings = new List<Readings>();
      json['readings'].forEach((v) {
        readings.add(new Readings.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data2 = new Map<String, dynamic>();
    data2['device'] = this.device;
    data2['origin'] = this.origin;
    if (this.readings != null) {
      data2['readings'] = this.readings.map((v) => v.toJson()).toList();
    }
    return data2;
  }
}
</code>```

And here is the the Debug console errors :

```<code>[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>'
#0      _MyListScreenState.GetCommands.<anonymous closure>.<anonymous closure>
package:chat/main.dart:92
#1      State.setState
package:flutter/…/widgets/framework.dart:1164
#2      _MyListScreenState.GetCommands.<anonymous closure>
#3      _rootRunUnary  (dart:async/zone.dart:1134:38)
#4      _CustomZone.runUnary  (dart:async/zone.dart:1031:19)
#5      _FutureListener.handleValue  (dart:async/future_impl.dart:140:18)
#6      Future._propagateToListeners.handleValueCallback  (dart:async/future_impl.dart:682:45)
#7      Future._propagateToListeners  (dart:async/future_impl.dart:711:32)
#8      Future._completeWithValue  (dart:async/future_impl.dart:526:5)
#9      _AsyncAwaitCompleter.complete  (dart:async-patch/async_patch.dart:34:15)
#10     _completeOnAsyncReturn  (dart:async-patch/async_patch.dart:293:13)
#11     _withCl<…>
</code>```

Here is the JSON data :

```<code>{
    "device": "Random-Integer-Generator01",
    "origin": 1581956092184,
    "readings": [
        {
            "origin": 1581956092183,
            "device": "Random-Integer-Generator01",
            "name": "RandomValue_Int8",
            "value": "23"
        }
    ]
}
</code>```

Thanks a lot for your help.

答:
I think the problem is response.body, what is the type? If the response.body is map of String and dynamic already, you dont need to use json.decode, just Value.fromJson(model)

Try to modify, removing decode and parsing direct response.body to list like this:

```<code>(response.body as List).map((item) => Value.fromJson(item)).toList()
</code>```

If not work, please, pass what package do you use to make http call.

I've tested with this url http://www.mocky.io/v2/5e4b0ef82f000000bc97d6ee and Dio package.

Body:
I'm a beginner in flutter and i have problem with my app when i wanna take the values from the JSON.

The problem comes from my http request when i call GetCommands() and i don't know to solve it.
I already did it once in another app with other data(JSON too) and it worked...

Here is the main code :

  var commandsGet = new List<Value>();

  Future<void> GetCommands() async {
    await GET.url(urlTest).then((response) {
      setState(() {
        Iterable list2 = json.decode(response.body);
        commandsGet = list2.map((model) => Value.fromJson(model)).toList();
      });
    });
  }

  Future<void> wait2() async {
    await GetCommands();
  }

  onChange2(commandsData user) {
    setState(() {
      commandselection = user;
      // TEST
      wait2().then((result) {
        print("This is a test");
      });
      // TEST
    });
  }

Here is my Value class :

class Value {
  String device;
  int origin;
  List<Readings> readings;

  Value({
    this.device,
    this.origin,
    this.readings,
  });

  Value.fromJson(Map<String, dynamic> json) {
    device = json['device'];
    origin = json['origin'];
    if (json['readings'] != null) {
      readings = new List<Readings>();
      json['readings'].forEach((v) {
        readings.add(new Readings.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data2 = new Map<String, dynamic>();
    data2['device'] = this.device;
    data2['origin'] = this.origin;
    if (this.readings != null) {
      data2['readings'] = this.readings.map((v) => v.toJson()).toList();
    }
    return data2;
  }
}

And here is the the Debug console errors :

[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>'
#0      _MyListScreenState.GetCommands.<anonymous closure>.<anonymous closure>
package:chat/main.dart:92
#1      State.setState
package:flutter/…/widgets/framework.dart:1164
#2      _MyListScreenState.GetCommands.<anonymous closure>
#3      _rootRunUnary  (dart:async/zone.dart:1134:38)
#4      _CustomZone.runUnary  (dart:async/zone.dart:1031:19)
#5      _FutureListener.handleValue  (dart:async/future_impl.dart:140:18)
#6      Future._propagateToListeners.handleValueCallback  (dart:async/future_impl.dart:682:45)
#7      Future._propagateToListeners  (dart:async/future_impl.dart:711:32)
#8      Future._completeWithValue  (dart:async/future_impl.dart:526:5)
#9      _AsyncAwaitCompleter.complete  (dart:async-patch/async_patch.dart:34:15)
#10     _completeOnAsyncReturn  (dart:async-patch/async_patch.dart:293:13)
#11     _withCl<…>

Here is the JSON data :

{
    "device": "Random-Integer-Generator01",
    "origin": 1581956092184,
    "readings": [
        {
            "origin": 1581956092183,
            "device": "Random-Integer-Generator01",
            "name": "RandomValue_Int8",
            "value": "23"
        }
    ]
}

Thanks a lot for your help.

Body:
I think the problem is response.body, what is the type? If the response.body is map of String and dynamic already, you dont need to use json.decode, just Value.fromJson(model)

Try to modify, removing decode and parsing direct response.body to list like this:

(response.body as List).map((item) => Value.fromJson(item)).toList()

If not work, please, pass what package do you use to make http call.

I've tested with this url http://www.mocky.io/v2/5e4b0ef82f000000bc97d6ee and Dio package.


问:
Why Laravel simple paginate doesn't working?
This this my controller

```<code>  class PageController extends Controller
  {

   public function showImageUrl (Request $req){

   $directory = '/public/testukas/';

   $files = collect(Storage::files($directory))->simplePaginate(8);

   return view('welcome')->with('files',$files);

  }
</code>```

and this code from my appServiceprovider

```<code>  if (!Collection::hasMacro('simplePaginate')) {

        Collection::macro('simplePaginate',
            function ($perPage = 15, $page = null, $options = []) {
            $page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
            return (
                new Paginator(
                    $this->forPage($page, $perPage),
                    $perPage,
                    $page,
                    $options
                )
            )->withPath('');
        });
    }
</code>```

In blade template i use this to call links

```<code> {!! $files->render() !!}
</code>```

So my question is how to make it work, links doesn't show. Thanks for help.

答:
Hello you need to put

```<code>{{ $files->links() }}
</code>```

into your blade file.

The links method will render the links to the rest of the pages in the
  result set. Each of these links will already contain the proper page
  query string variable. Remember, the HTML generated by the links
  method is compatible with the Bootstrap CSS framework.
  source: https://laravel.com/docs/5.8/pagination#displaying-pagination-results

The Illuminate\View\View::render() returns the string contents of the view.

Body:
This this my controller

  class PageController extends Controller
  {

   public function showImageUrl (Request $req){

   $directory = '/public/testukas/';

   $files = collect(Storage::files($directory))->simplePaginate(8);

   return view('welcome')->with('files',$files);

  }

and this code from my appServiceprovider

  if (!Collection::hasMacro('simplePaginate')) {

        Collection::macro('simplePaginate',
            function ($perPage = 15, $page = null, $options = []) {
            $page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
            return (
                new Paginator(
                    $this->forPage($page, $perPage),
                    $perPage,
                    $page,
                    $options
                )
            )->withPath('');
        });
    }

In blade template i use this to call links

 {!! $files->render() !!}

So my question is how to make it work, links doesn't show. Thanks for help.

Body:
Hello you need to put

{{ $files->links() }}

into your blade file.

The links method will render the links to the rest of the pages in the
  result set. Each of these links will already contain the proper page
  query string variable. Remember, the HTML generated by the links
  method is compatible with the Bootstrap CSS framework.
  source: https://laravel.com/docs/5.8/pagination#displaying-pagination-results

The Illuminate\View\View::render() returns the string contents of the view.


问:
How to relocate DDEV project that was moved to different directory?

Scenario

DDEV project has been moved from /home/old-path/project-name to /home/new-path/project-name

executing ddev start in new location shows the following error

Unable to get project(s): stat /home/old-path/project-name: no such
  file or directory

Question

Which steps are required in order to "relocate" the directory and get DDEV up and running again?

答:
There is a file named global_config.yaml that resides in your user's home .ddev folder
(on my windows machine it is C:\Users\username\.ddev).

Inside this file you will find the section project_info: that lists your projects and their paths. If you moved the project files you can enter the new path here.

If you moved the files to another disk you also have to go to docker Settings>Resources>File Sharing and make sure the new disk is enabled here and cab be bind mounted.


问:
Vim helptag generation
I use pathogen and have an update script that downloads the latest versions of all the vim plugins I use from vim.org, github, or wherever else they may be. However, this script does not currently update the vim helptags. In order to do so, I have to go to each updated plugin in vim and execute ":helptags doc/". It would be great if I could do so with my update script, but in order to do so I need to run the vim ":helptags" command from a script. Is this possible?

Thanks!

答: In recent enough versions, :helptags ALL will work.

ContentLicense: CC BY-SA 2.5

Title: Vim helptag generation


问:
Tensorflow slice issue with unknown batch size
I am attempting to get a slice of the input data, source. The input shape is [?, 512, 6] and has this shape as it is fed into an LSTM layer, the batch size is unspecified. My neural network, NN, is non-sequential and I require another layer using a subset of the original input data. Specifically, I want to obtain source[:, :, feature] where feature is a integer variable.

I can use raw = Reshape((512*6,))(source) and pass raw into a dense layer and the network will assemble, compile and train. However, when compiling using a subset of the source array I get the following error:

```<code>AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
</code>```

I have tried a few different things. The original data type of source is a numpy array. One attempt was to use:

```<code>raw = source[:,:,feature]
</code>```

I believe that tf.slice should be able to handle this. I have obtained the error as well when using:

```<code>raw = tf.slice( source, [0,0,feature], [-1,512,1] )
</code>```

I have attempted to use type() to try and determine which is the NoneType object with no success. How do I obtain a working slice?

Edit:
I have been able to obtain the slice and successfully added to the model using:

```<code>raw = Lambda(lambda x: x[:,:,feature])(source)
</code>```

and

```<code>raw = Lambda(lambda x: tf.slice(x, [0,0,feature], [-1,512,1]))(source)
</code>```

While this works and the model compiles, upon attempting to save I get the error:

```<code>TypeError: Not JSON Serializable
</code>```

I have found some links discussing this issue and they state that the issue is that one of the layers is not a Keras layer. Their solutions involve using a Lambda layer to resolve the issue. I believe that I have been able to isolate the problem layer to be the Lambda layer, which as far as I can tell is a Keras layer. It is imported using:

```<code>from keras.layers import Lambda
</code>```

答:
I have found a solution through trial and error. I do not currently know why it works though. Let source be the input array to the network and have the shape [?,width,height] and the individual feature element of interest be between 0 and height. First we need to flatten source such that it has one dimension. I believe the key to solving the problem is in the Flatten layer as it must be making the nature of flat different from source some how despite the type of source and flat being the same (<class 'tensorflow.python.framework.ops.Tensor'>). Now we can use a Lambda layer to select the feature that we want based on it's new position within flat.

```<code>flat = Flatten()(source)
subsection = Lambda(lambda x: x[:,feature*width:(1+feature)*width])(flat)
</code>```

The new tensor subsection can now be fed into some layer and the network will both compile as well as save correctly.

Body:
I am attempting to get a slice of the input data, source. The input shape is [?, 512, 6] and has this shape as it is fed into an LSTM layer, the batch size is unspecified. My neural network, NN, is non-sequential and I require another layer using a subset of the original input data. Specifically, I want to obtain source[:, :, feature] where feature is a integer variable.

I can use raw = Reshape((512*6,))(source) and pass raw into a dense layer and the network will assemble, compile and train. However, when compiling using a subset of the source array I get the following error:

AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

I have tried a few different things. The original data type of source is a numpy array. One attempt was to use:

raw = source[:,:,feature]

I believe that tf.slice should be able to handle this. I have obtained the error as well when using:

raw = tf.slice( source, [0,0,feature], [-1,512,1] )

I have attempted to use type() to try and determine which is the NoneType object with no success. How do I obtain a working slice?

Edit:
I have been able to obtain the slice and successfully added to the model using:

raw = Lambda(lambda x: x[:,:,feature])(source)

and

raw = Lambda(lambda x: tf.slice(x, [0,0,feature], [-1,512,1]))(source)

While this works and the model compiles, upon attempting to save I get the error:

TypeError: Not JSON Serializable

I have found some links discussing this issue and they state that the issue is that one of the layers is not a Keras layer. Their solutions involve using a Lambda layer to resolve the issue. I believe that I have been able to isolate the problem layer to be the Lambda layer, which as far as I can tell is a Keras layer. It is imported using:

from keras.layers import Lambda

Body:
I have found a solution through trial and error. I do not currently know why it works though. Let source be the input array to the network and have the shape [?,width,height] and the individual feature element of interest be between 0 and height. First we need to flatten source such that it has one dimension. I believe the key to solving the problem is in the Flatten layer as it must be making the nature of flat different from source some how despite the type of source and flat being the same (<class 'tensorflow.python.framework.ops.Tensor'>). Now we can use a Lambda layer to select the feature that we want based on it's new position within flat.

flat = Flatten()(source)
subsection = Lambda(lambda x: x[:,feature*width:(1+feature)*width])(flat)

The new tensor subsection can now be fed into some layer and the network will both compile as well as save correctly.


问:
Age verification based on birthdate and current date
So, I need to calculate age by subtracting "todays" date from the converted date of an input field, entered by the user. Although it needs cleaned up, the below code works, I had to get creative as RN uses a different JS execution environment... see here.

My question, without adding the "+1" to this snippet "b.getMonth() + 1", the math on the date subtraction comes back 1 month off every time. When I add the "+1" it works like a charm, why? If it's a logical fix, I don't mind keeping the "+1," but I would surely like to know why the "+1" is necessary.

Also, totally open to improved solutions to this problem, keep in mind I had a much simpler function that worked great while debugger was open, once closed, it did not work, see the link above.

```<code>getVerifyBirthday(birthday) {
    const b = new Date();
    var verify = birthday.length;

    const utc2 = Date.UTC(b.getFullYear(), b.getMonth() + 1, b.getDate());

    if (verify === 10) {
      const splitBirth = birthday.split('-');
      var mydate = new Date(splitBirth[2], splitBirth[0], splitBirth[1]);

      const a = mydate;
      const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());

      const diffTime = Math.abs(utc2 - utc1);
      const diffYears = (diffTime / (3.15576e+10));

      this.setState({ diffYears: diffYears});

      return diffYears >= 13;
    } else {}
  }
</code>```

Update

I ended up refactoring my original function, leaving the (+1) on months due to months starting at 0, as mentioned below. I still had to split both dates, when I didn't split both, my age came back NaN/Undefined; not sure if this goes back to the RN execution environment vs browser, but I digress.

答:
Months are zero-based in JavaScript Date objects. However, if you get a formatted string, they start from 1:

const date = new Date(2020, 1, 17); // 17th of February 2020

console.log("getMonth:", date.getMonth());     //month is 1
console.log("formatted:", date.toISOString()); //month is 2```
</div>
</div>
</p>

<p>So, actually what happens is that you're <em>shifting both dates a month forward</em>. This sort of works:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const originDate = new Date(2020, 1, 17); // 17th of February 2020
const originString = "2020-02-17".split("-");

const dateFromDate = new Date(originDate.getFullYear(), originDate.getMonth() + 1, originDate.getDate())
const dateFromString = new Date(originString[0], originString[1], originString[2])

console.log("dateFromDate:", dateFromDate);     //month is 3
console.log("dateFromString:", dateFromString); //month is 3</code>```

When you do the subtraction it evens out but you can still run into an overflow of the date for months with different number of days:

const originDate = new Date(2020, 0, 31);   // 31st of January 2020

const dateFromDate = new Date(originDate.getFullYear(), originDate.getMonth() + 1, originDate.getDate())

console.log("dateFromDate:", dateFromDate); // 1st of March 2020```
</div>
</div>
</p>

<p>This still works logically for most cases, however you are bound to run into a problem at some point if you shift months forward. So, instead you should be doing the opposite and <em>subtracting</em> <code>1</code> when converting a 1-based number into a Date object:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>const originString = "2020-02-17".split("-");

const dateFromString = new Date(originString[0], originString[1] - 1, originString[2])

console.log("dateFromString:", dateFromString); //month is 2</code>```

Body:
So, I need to calculate age by subtracting "todays" date from the converted date of an input field, entered by the user. Although it needs cleaned up, the below code works, I had to get creative as RN uses a different JS execution environment... see here.

My question, without adding the "+1" to this snippet "b.getMonth() + 1", the math on the date subtraction comes back 1 month off every time. When I add the "+1" it works like a charm, why? If it's a logical fix, I don't mind keeping the "+1," but I would surely like to know why the "+1" is necessary.

Also, totally open to improved solutions to this problem, keep in mind I had a much simpler function that worked great while debugger was open, once closed, it did not work, see the link above.

getVerifyBirthday(birthday) {
    const b = new Date();
    var verify = birthday.length;

    const utc2 = Date.UTC(b.getFullYear(), b.getMonth() + 1, b.getDate());

    if (verify === 10) {
      const splitBirth = birthday.split('-');
      var mydate = new Date(splitBirth[2], splitBirth[0], splitBirth[1]);

      const a = mydate;
      const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());

      const diffTime = Math.abs(utc2 - utc1);
      const diffYears = (diffTime / (3.15576e+10));

      this.setState({ diffYears: diffYears});

      return diffYears >= 13;
    } else {}
  }

Update

I ended up refactoring my original function, leaving the (+1) on months due to months starting at 0, as mentioned below. I still had to split both dates, when I didn't split both, my age came back NaN/Undefined; not sure if this goes back to the RN execution environment vs browser, but I digress.

Body:
Months are zero-based in JavaScript Date objects. However, if you get a formatted string, they start from 1:

const date = new Date(2020, 1, 17); // 17th of February 2020

console.log("getMonth:", date.getMonth());     //month is 1
console.log("formatted:", date.toISOString()); //month is 2

So, actually what happens is that you're shifting both dates a month forward. This sort of works:

const originDate = new Date(2020, 1, 17); // 17th of February 2020
const originString = "2020-02-17".split("-");

const dateFromDate = new Date(originDate.getFullYear(), originDate.getMonth() + 1, originDate.getDate())
const dateFromString = new Date(originString[0], originString[1], originString[2])

console.log("dateFromDate:", dateFromDate);     //month is 3
console.log("dateFromString:", dateFromString); //month is 3

When you do the subtraction it evens out but you can still run into an overflow of the date for months with different number of days:

const originDate = new Date(2020, 0, 31);   // 31st of January 2020

const dateFromDate = new Date(originDate.getFullYear(), originDate.getMonth() + 1, originDate.getDate())

console.log("dateFromDate:", dateFromDate); // 1st of March 2020

This still works logically for most cases, however you are bound to run into a problem at some point if you shift months forward. So, instead you should be doing the opposite and subtracting 1 when converting a 1-based number into a Date object:

const originString = "2020-02-17".split("-");

const dateFromString = new Date(originString[0], originString[1] - 1, originString[2])

console.log("dateFromString:", dateFromString); //month is 2


问:
Computing BITMAPINFOHEADER biCompression value for monochrome BMP
Hopefully someone has an answer, and it's not TOO complex.  I'm working on a C++ dll (no C# or .Net, fully static DLL).

Anyhow, its woring on buildin monochrome bitmaps.  I have all of it working EXCEPT the resolution. I get the Device Context, Get Compatible Device Context, build bitmap, draw what I need to (as black/white), and can save.  All this works fine.  However, I can't figure out how to set the resolution of the bitmap.

While doing some testing from another utility under C#, I can create a bitmap and set the resolution.  In doing so, I ran a routine to generate the same file content with a parameter from 1 to 300 for the resolution.  Each image came out exactly the same EXCEPT for the values in the "biCompression" DWORD property.  The default is the screen resolution of 96x96, but need to obviously change for printers of 300x300, and even some at 203x203 resolution.

答: Are you absolutely sure?  The description of the behavior you observe sounds fishy to me and I would suspect the code that you're using to write your bitmaps or your code that reads them back in.</p>

OwnerDisplayName: Don

LastEditorDisplayName: plinth

ContentLicense: CC BY-SA 3.0

OwnerDisplayName: plinth


问:
What's the jquery syntax for click function of submit button
my form has a submit button that's been defined this way:

```<code><input type="submit" name="submit-reg" value="Register" class="submit button">
</code>```

What is the syntax to call the button's jquery click() function?
I've tried:

```<code>$('#submit-reg').click(function()...
</code>```

But it's not working.

答:
```<code><input type="submit"  name="submit-reg"
      value="Register" class="submit button">
</code>```

you can select by name

$('input[name=submit-reg]').click(...

DEMO

here is a useful link

Body:
my form has a submit button that's been defined this way:

<input type="submit" name="submit-reg" value="Register" class="submit button">

What is the syntax to call the button's jquery click() function?
I've tried:

$('#submit-reg').click(function()...

But it's not working.

Body:
<input type="submit"  name="submit-reg"
      value="Register" class="submit button">

you can select by name

$('input[name=submit-reg]').click(...

DEMO

here is a useful link


问:
Overloading a function using templates
I am trying to define a function using templates and I want the typename to be either int or anEnum (a specific enum I had defined). I have tried the following but I have failed:

```<code>template <int | anEnum T> // or <int T, anEnum T> or <int, anEnum T>
bool isFunction(const T &aVariable){}
</code>```

What I am trying to do is to use templates, instead of defining two overloaded functions.
I'd prefer the function to be called as the following, without the programmer having to consider the type

```<code>isFunction(aVariable) // and not isFunction<int> (aVariable) nor isFunction<anEnum> (aVariable)
</code>```

Basically, I want this function to be templated for int and aNum types. I have searched for this, but could not find the answer. What may I be missing? Thank you,

答:
What about this solution? A code with the function will be compiled if the type T is satisfied your requrements. Otherwise, the static assertion failed.</p>

```<code>#include <type_traits>
enum anEnum {
    //
};

template <typename T, bool defined = std::is_same<T, int>::value ||
                                     std::is_same<T, anEnum>::value>
bool isFunction(const T& aVariable)
{
    static_assert(defined, "Invalid specialization");

    bool result = false;
    // Put your code here
    return result;
}
</code>```

Title: Overloading a function using templates

Body:
I am trying to define a function using templates and I want the typename to be either int or anEnum (a specific enum I had defined). I have tried the following but I have failed:

template <int | anEnum T> // or <int T, anEnum T> or <int, anEnum T>
bool isFunction(const T &aVariable){}

What I am trying to do is to use templates, instead of defining two overloaded functions.
I'd prefer the function to be called as the following, without the programmer having to consider the type

isFunction(aVariable) // and not isFunction<int> (aVariable) nor isFunction<anEnum> (aVariable)

Basically, I want this function to be templated for int and aNum types. I have searched for this, but could not find the answer. What may I be missing? Thank you,

Body:
What about this solution? A code with the function will be compiled if the type T is satisfied your requrements. Otherwise, the static assertion failed.

#include <type_traits>
enum anEnum {
    //
};

template <typename T, bool defined = std::is_same<T, int>::value ||
                                     std::is_same<T, anEnum>::value>
bool isFunction(const T& aVariable)
{
    static_assert(defined, "Invalid specialization");

    bool result = false;
    // Put your code here
    return result;
}


问:
Most efficent way to calculate CRC64 with reflected input
I need to calculate a CRC-64 using this setup into this wonderful website: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html

As you can see I require "input reflected" and that means that I need to reverse the bit order of any byte (a bit annoying).
For the moment, I implemented this with a lookup table (for example 0x55 -> 0xAA), but I was wondering if there is any property of CRC which can be used to be more efficient.

This is my code (in C):

```<code>static const unsigned long long CRC64_TABLE[256] = {
    0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, 0x493366450E42ECDF, 0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A,
    0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B, 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4,
    0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A, 0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285,
    0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, 0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B,
    0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0x0B6BD3C3DBFD506B, 0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4,
    0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, 0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A,
    0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B,
    0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A, 0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5,
    0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645,
    0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324, 0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB,
    0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, 0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA,
    0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB, 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14,
    0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144, 0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B,
    0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA, 0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0x0A3B7B1923564425,
    0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB, 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874,
    0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, 0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA,
    0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78, 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7,
    0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6, 0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19,
    0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97, 0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648,
    0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329, 0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6,
    0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6, 0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879,
    0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18, 0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7,
    0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149, 0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96,
    0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7, 0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x020905D88D03A2BB, 0x40F9E43324E99428,
    0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57, 0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288,
    0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9, 0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36,
    0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8, 0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767,
    0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206, 0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9,
    0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589, 0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956,
    0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37, 0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8,
    0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066, 0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9,
    0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8, 0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507
};

static const unsigned char REVERSE_BITS_TABLE[256] = {
    // 0     1     2     3     4     5     6     7     8     9     A     B     C     D     E     F
    0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
    0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
    0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
    0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
    0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
    0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
    0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
    0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
    0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
    0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
    0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
    0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
    0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
    0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
    0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
    0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};

unsigned long long calculateCRC64(unsigned char* data, unsigned long size)
{
    unsigned long long myCRC64 = 0;

    for(unsigned long i = 0; i < size; i++)
        myCRC64 = CRC64_TABLE[((myCRC64 >> 56) ^ REVERSE_BITS_TABLE[data[i]]) & 0xFF] ^ (myCRC64 << 8);

    return myCRC64;
}
</code>```

Thanks in advance for any help!

Update: actually I'm wondering if some properties of CRC allow me to get the same result using reflected table, opposite shifting, reciprocal / reverse polynomial... etc. That would let skip the step of reversing bits.

Solution: using reflected table, changing shift direction and reversing bits just of the very last result:

```<code>static const unsigned long long CRC64_TABLE_REF[256] = {
    0x0000000000000000, 0xB32E4CBE03A75F6F, 0xF4843657A840A05B, 0x47AA7AE9ABE7FF34, 0x7BD0C384FF8F5E33, 0xC8FE8F3AFC28015C, 0x8F54F5D357CFFE68, 0x3C7AB96D5468A107,
    0xF7A18709FF1EBC66, 0x448FCBB7FCB9E309, 0x0325B15E575E1C3D, 0xB00BFDE054F94352, 0x8C71448D0091E255, 0x3F5F08330336BD3A, 0x78F572DAA8D1420E, 0xCBDB3E64AB761D61,
    0x7D9BA13851336649, 0xCEB5ED8652943926, 0x891F976FF973C612, 0x3A31DBD1FAD4997D, 0x064B62BCAEBC387A, 0xB5652E02AD1B6715, 0xF2CF54EB06FC9821, 0x41E11855055BC74E,
    0x8A3A2631AE2DDA2F, 0x39146A8FAD8A8540, 0x7EBE1066066D7A74, 0xCD905CD805CA251B, 0xF1EAE5B551A2841C, 0x42C4A90B5205DB73, 0x056ED3E2F9E22447, 0xB6409F5CFA457B28,
    0xFB374270A266CC92, 0x48190ECEA1C193FD, 0x0FB374270A266CC9, 0xBC9D3899098133A6, 0x80E781F45DE992A1, 0x33C9CD4A5E4ECDCE, 0x7463B7A3F5A932FA, 0xC74DFB1DF60E6D95,
    0x0C96C5795D7870F4, 0xBFB889C75EDF2F9B, 0xF812F32EF538D0AF, 0x4B3CBF90F69F8FC0, 0x774606FDA2F72EC7, 0xC4684A43A15071A8, 0x83C230AA0AB78E9C, 0x30EC7C140910D1F3,
    0x86ACE348F355AADB, 0x3582AFF6F0F2F5B4, 0x7228D51F5B150A80, 0xC10699A158B255EF, 0xFD7C20CC0CDAF4E8, 0x4E526C720F7DAB87, 0x09F8169BA49A54B3, 0xBAD65A25A73D0BDC,
    0x710D64410C4B16BD, 0xC22328FF0FEC49D2, 0x85895216A40BB6E6, 0x36A71EA8A7ACE989, 0x0ADDA7C5F3C4488E, 0xB9F3EB7BF06317E1, 0xFE5991925B84E8D5, 0x4D77DD2C5823B7BA,
    0x64B62BCAEBC387A1, 0xD7986774E864D8CE, 0x90321D9D438327FA, 0x231C512340247895, 0x1F66E84E144CD992, 0xAC48A4F017EB86FD, 0xEBE2DE19BC0C79C9, 0x58CC92A7BFAB26A6,
    0x9317ACC314DD3BC7, 0x2039E07D177A64A8, 0x67939A94BC9D9B9C, 0xD4BDD62ABF3AC4F3, 0xE8C76F47EB5265F4, 0x5BE923F9E8F53A9B, 0x1C4359104312C5AF, 0xAF6D15AE40B59AC0,
    0x192D8AF2BAF0E1E8, 0xAA03C64CB957BE87, 0xEDA9BCA512B041B3, 0x5E87F01B11171EDC, 0x62FD4976457FBFDB, 0xD1D305C846D8E0B4, 0x96797F21ED3F1F80, 0x2557339FEE9840EF,
    0xEE8C0DFB45EE5D8E, 0x5DA24145464902E1, 0x1A083BACEDAEFDD5, 0xA9267712EE09A2BA, 0x955CCE7FBA6103BD, 0x267282C1B9C65CD2, 0x61D8F8281221A3E6, 0xD2F6B4961186FC89,
    0x9F8169BA49A54B33, 0x2CAF25044A02145C, 0x6B055FEDE1E5EB68, 0xD82B1353E242B407, 0xE451AA3EB62A1500, 0x577FE680B58D4A6F, 0x10D59C691E6AB55B, 0xA3FBD0D71DCDEA34,
    0x6820EEB3B6BBF755, 0xDB0EA20DB51CA83A, 0x9CA4D8E41EFB570E, 0x2F8A945A1D5C0861, 0x13F02D374934A966, 0xA0DE61894A93F609, 0xE7741B60E174093D, 0x545A57DEE2D35652,
    0xE21AC88218962D7A, 0x5134843C1B317215, 0x169EFED5B0D68D21, 0xA5B0B26BB371D24E, 0x99CA0B06E7197349, 0x2AE447B8E4BE2C26, 0x6D4E3D514F59D312, 0xDE6071EF4CFE8C7D,
    0x15BB4F8BE788911C, 0xA6950335E42FCE73, 0xE13F79DC4FC83147, 0x521135624C6F6E28, 0x6E6B8C0F1807CF2F, 0xDD45C0B11BA09040, 0x9AEFBA58B0476F74, 0x29C1F6E6B3E0301B,
    0xC96C5795D7870F42, 0x7A421B2BD420502D, 0x3DE861C27FC7AF19, 0x8EC62D7C7C60F076, 0xB2BC941128085171, 0x0192D8AF2BAF0E1E, 0x4638A2468048F12A, 0xF516EEF883EFAE45,
    0x3ECDD09C2899B324, 0x8DE39C222B3EEC4B, 0xCA49E6CB80D9137F, 0x7967AA75837E4C10, 0x451D1318D716ED17, 0xF6335FA6D4B1B278, 0xB199254F7F564D4C, 0x02B769F17CF11223,
    0xB4F7F6AD86B4690B, 0x07D9BA1385133664, 0x4073C0FA2EF4C950, 0xF35D8C442D53963F, 0xCF273529793B3738, 0x7C0979977A9C6857, 0x3BA3037ED17B9763, 0x888D4FC0D2DCC80C,
    0x435671A479AAD56D, 0xF0783D1A7A0D8A02, 0xB7D247F3D1EA7536, 0x04FC0B4DD24D2A59, 0x3886B22086258B5E, 0x8BA8FE9E8582D431, 0xCC0284772E652B05, 0x7F2CC8C92DC2746A,
    0x325B15E575E1C3D0, 0x8175595B76469CBF, 0xC6DF23B2DDA1638B, 0x75F16F0CDE063CE4, 0x498BD6618A6E9DE3, 0xFAA59ADF89C9C28C, 0xBD0FE036222E3DB8, 0x0E21AC88218962D7,
    0xC5FA92EC8AFF7FB6, 0x76D4DE52895820D9, 0x317EA4BB22BFDFED, 0x8250E80521188082, 0xBE2A516875702185, 0x0D041DD676D77EEA, 0x4AAE673FDD3081DE, 0xF9802B81DE97DEB1,
    0x4FC0B4DD24D2A599, 0xFCEEF8632775FAF6, 0xBB44828A8C9205C2, 0x086ACE348F355AAD, 0x34107759DB5DFBAA, 0x873E3BE7D8FAA4C5, 0xC094410E731D5BF1, 0x73BA0DB070BA049E,
    0xB86133D4DBCC19FF, 0x0B4F7F6AD86B4690, 0x4CE50583738CB9A4, 0xFFCB493D702BE6CB, 0xC3B1F050244347CC, 0x709FBCEE27E418A3, 0x3735C6078C03E797, 0x841B8AB98FA4B8F8,
    0xADDA7C5F3C4488E3, 0x1EF430E13FE3D78C, 0x595E4A08940428B8, 0xEA7006B697A377D7, 0xD60ABFDBC3CBD6D0, 0x6524F365C06C89BF, 0x228E898C6B8B768B, 0x91A0C532682C29E4,
    0x5A7BFB56C35A3485, 0xE955B7E8C0FD6BEA, 0xAEFFCD016B1A94DE, 0x1DD181BF68BDCBB1, 0x21AB38D23CD56AB6, 0x9285746C3F7235D9, 0xD52F0E859495CAED, 0x6601423B97329582,
    0xD041DD676D77EEAA, 0x636F91D96ED0B1C5, 0x24C5EB30C5374EF1, 0x97EBA78EC690119E, 0xAB911EE392F8B099, 0x18BF525D915FEFF6, 0x5F1528B43AB810C2, 0xEC3B640A391F4FAD,
    0x27E05A6E926952CC, 0x94CE16D091CE0DA3, 0xD3646C393A29F297, 0x604A2087398EADF8, 0x5C3099EA6DE60CFF, 0xEF1ED5546E415390, 0xA8B4AFBDC5A6ACA4, 0x1B9AE303C601F3CB,
    0x56ED3E2F9E224471, 0xE5C372919D851B1E, 0xA26908783662E42A, 0x114744C635C5BB45, 0x2D3DFDAB61AD1A42, 0x9E13B115620A452D, 0xD9B9CBFCC9EDBA19, 0x6A978742CA4AE576,
    0xA14CB926613CF817, 0x1262F598629BA778, 0x55C88F71C97C584C, 0xE6E6C3CFCADB0723, 0xDA9C7AA29EB3A624, 0x69B2361C9D14F94B, 0x2E184CF536F3067F, 0x9D36004B35545910,
    0x2B769F17CF112238, 0x9858D3A9CCB67D57, 0xDFF2A94067518263, 0x6CDCE5FE64F6DD0C, 0x50A65C93309E7C0B, 0xE388102D33392364, 0xA4226AC498DEDC50, 0x170C267A9B79833F,
    0xDCD7181E300F9E5E, 0x6FF954A033A8C131, 0x28532E49984F3E05, 0x9B7D62F79BE8616A, 0xA707DB9ACF80C06D, 0x14299724CC279F02, 0x5383EDCD67C06036, 0xE0ADA17364673F59
};

unsigned long long calculateCRC64(unsigned char* data, unsigned long size)
{
    unsigned long long myCRC64 = 0;

    for(unsigned long i = 0; i < size; i++)
        myCRC64 = CRC64_TABLE_REF[(myCRC64 ^ data[i]) & 0xFF] ^ (myCRC64 >> 8);

    unsigned long long tmp = myCRC64;
    myCRC64 = 0;
    for (int i = 0; i < 64; i++) {
        myCRC64 = (myCRC64 << 1) | (tmp & 1);
        tmp >>= 1;
    }

    return myCRC64;
}
</code>```

Thanks to everybody for the help!

答:
The code just needs to switch from a left shifting CRC to a right shifting CRC, with the polynomial bits reversed. The "#if 0" is used to select between two common polynomials, in this case, "#if 0" will use CRC64 ecma, which is what is shown in the question's CRC table. (0x42F0E1EBA9EA3693 bit reversed == 0xC96C5795D7870F42).

```<code>uint64_t crctbl[256];

void gentbl(void)
{
uint64_t crc;
uint64_t b;
uint64_t c;
uint64_t i;
    for(c = 0; c < 0x100; c++){
        crc = c;
        for(i = 0; i < 8; i++){
            b = crc&1;
            crc >>= 1;
#if 0
            crc ^= (0 - b) & 0xd800000000000000ull; // crc64 iso
#else
            crc ^= (0 - b) & 0xc96c5795d7870f42ull; // crc64 ecma
#endif
        }
        crctbl[c] = crc;
    }
}

uint64_t crc64c(uint64_t crc64, uint8_t * bfr, size_t size)
{
uint64_t crc = crc64;
    while(size--)
        crc = (crc >> 8) ^ crctbl[(crc & 0xff)^*bfr++];
    return(crc);
}
</code>```

"Most efficient way" - if running on X86 X64 with carryless multiply, a really fast CRC, over 20 times as fast as the table method shown above (For a CRC of 256 MB of data, Intel Core i7-10510U .475 seconds table, .015 seconds pclmulqdq, 31.5 times as fast) , can be performed using pclmulqdq instruction and xmm registers. Link to a zip of a 520+ line assembly file, for Visual Studio's MASM (ML64.EXE), for 64 bit reflected CRC, with the same "if 0" as the gentbl() function above to choose between the two CRC polynomials.

http://rcgldr.net/misc/crc64ra.zip

Intel document explaining the algorithm for a 32 bit CRC:

https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf

A carryless multiply of two 64 bit non-reflected operands produces a 127 bit product in bits 126 (msb) to bit 0 (lsb). For reflected operands, a carryless multiply effectively multiplies the product by 2, which is taken into account with the constants. For 64 bit CRC, the poly is 65 bits, so some adjustments are also needed to handle that.

Body:
I need to calculate a CRC-64 using this setup into this wonderful website: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html

As you can see I require "input reflected" and that means that I need to reverse the bit order of any byte (a bit annoying).
For the moment, I implemented this with a lookup table (for example 0x55 -> 0xAA), but I was wondering if there is any property of CRC which can be used to be more efficient.

This is my code (in C):

static const unsigned long long CRC64_TABLE[256] = {
    0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5, 0x493366450E42ECDF, 0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A,
    0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B, 0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4,
    0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A, 0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285,
    0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4, 0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B,
    0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0x0B6BD3C3DBFD506B, 0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4,
    0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5, 0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A,
    0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584, 0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B,
    0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A, 0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5,
    0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A, 0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645,
    0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324, 0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB,
    0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75, 0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA,
    0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB, 0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14,
    0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144, 0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B,
    0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA, 0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0x0A3B7B1923564425,
    0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB, 0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874,
    0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15, 0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA,
    0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78, 0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7,
    0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6, 0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19,
    0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97, 0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648,
    0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329, 0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6,
    0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6, 0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879,
    0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18, 0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7,
    0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149, 0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96,
    0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7, 0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x020905D88D03A2BB, 0x40F9E43324E99428,
    0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57, 0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288,
    0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9, 0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36,
    0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8, 0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767,
    0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206, 0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9,
    0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589, 0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956,
    0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37, 0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8,
    0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066, 0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9,
    0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8, 0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507
};

static const unsigned char REVERSE_BITS_TABLE[256] = {
    // 0     1     2     3     4     5     6     7     8     9     A     B     C     D     E     F
    0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
    0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
    0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
    0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
    0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
    0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
    0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
    0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
    0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
    0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
    0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
    0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
    0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
    0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
    0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
    0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};

unsigned long long calculateCRC64(unsigned char* data, unsigned long size)
{
    unsigned long long myCRC64 = 0;

    for(unsigned long i = 0; i < size; i++)
        myCRC64 = CRC64_TABLE[((myCRC64 >> 56) ^ REVERSE_BITS_TABLE[data[i]]) & 0xFF] ^ (myCRC64 << 8);

    return myCRC64;
}

Thanks in advance for any help!

Update: actually I'm wondering if some properties of CRC allow me to get the same result using reflected table, opposite shifting, reciprocal / reverse polynomial... etc. That would let skip the step of reversing bits.

Solution: using reflected table, changing shift direction and reversing bits just of the very last result:

static const unsigned long long CRC64_TABLE_REF[256] = {
    0x0000000000000000, 0xB32E4CBE03A75F6F, 0xF4843657A840A05B, 0x47AA7AE9ABE7FF34, 0x7BD0C384FF8F5E33, 0xC8FE8F3AFC28015C, 0x8F54F5D357CFFE68, 0x3C7AB96D5468A107,
    0xF7A18709FF1EBC66, 0x448FCBB7FCB9E309, 0x0325B15E575E1C3D, 0xB00BFDE054F94352, 0x8C71448D0091E255, 0x3F5F08330336BD3A, 0x78F572DAA8D1420E, 0xCBDB3E64AB761D61,
    0x7D9BA13851336649, 0xCEB5ED8652943926, 0x891F976FF973C612, 0x3A31DBD1FAD4997D, 0x064B62BCAEBC387A, 0xB5652E02AD1B6715, 0xF2CF54EB06FC9821, 0x41E11855055BC74E,
    0x8A3A2631AE2DDA2F, 0x39146A8FAD8A8540, 0x7EBE1066066D7A74, 0xCD905CD805CA251B, 0xF1EAE5B551A2841C, 0x42C4A90B5205DB73, 0x056ED3E2F9E22447, 0xB6409F5CFA457B28,
    0xFB374270A266CC92, 0x48190ECEA1C193FD, 0x0FB374270A266CC9, 0xBC9D3899098133A6, 0x80E781F45DE992A1, 0x33C9CD4A5E4ECDCE, 0x7463B7A3F5A932FA, 0xC74DFB1DF60E6D95,
    0x0C96C5795D7870F4, 0xBFB889C75EDF2F9B, 0xF812F32EF538D0AF, 0x4B3CBF90F69F8FC0, 0x774606FDA2F72EC7, 0xC4684A43A15071A8, 0x83C230AA0AB78E9C, 0x30EC7C140910D1F3,
    0x86ACE348F355AADB, 0x3582AFF6F0F2F5B4, 0x7228D51F5B150A80, 0xC10699A158B255EF, 0xFD7C20CC0CDAF4E8, 0x4E526C720F7DAB87, 0x09F8169BA49A54B3, 0xBAD65A25A73D0BDC,
    0x710D64410C4B16BD, 0xC22328FF0FEC49D2, 0x85895216A40BB6E6, 0x36A71EA8A7ACE989, 0x0ADDA7C5F3C4488E, 0xB9F3EB7BF06317E1, 0xFE5991925B84E8D5, 0x4D77DD2C5823B7BA,
    0x64B62BCAEBC387A1, 0xD7986774E864D8CE, 0x90321D9D438327FA, 0x231C512340247895, 0x1F66E84E144CD992, 0xAC48A4F017EB86FD, 0xEBE2DE19BC0C79C9, 0x58CC92A7BFAB26A6,
    0x9317ACC314DD3BC7, 0x2039E07D177A64A8, 0x67939A94BC9D9B9C, 0xD4BDD62ABF3AC4F3, 0xE8C76F47EB5265F4, 0x5BE923F9E8F53A9B, 0x1C4359104312C5AF, 0xAF6D15AE40B59AC0,
    0x192D8AF2BAF0E1E8, 0xAA03C64CB957BE87, 0xEDA9BCA512B041B3, 0x5E87F01B11171EDC, 0x62FD4976457FBFDB, 0xD1D305C846D8E0B4, 0x96797F21ED3F1F80, 0x2557339FEE9840EF,
    0xEE8C0DFB45EE5D8E, 0x5DA24145464902E1, 0x1A083BACEDAEFDD5, 0xA9267712EE09A2BA, 0x955CCE7FBA6103BD, 0x267282C1B9C65CD2, 0x61D8F8281221A3E6, 0xD2F6B4961186FC89,
    0x9F8169BA49A54B33, 0x2CAF25044A02145C, 0x6B055FEDE1E5EB68, 0xD82B1353E242B407, 0xE451AA3EB62A1500, 0x577FE680B58D4A6F, 0x10D59C691E6AB55B, 0xA3FBD0D71DCDEA34,
    0x6820EEB3B6BBF755, 0xDB0EA20DB51CA83A, 0x9CA4D8E41EFB570E, 0x2F8A945A1D5C0861, 0x13F02D374934A966, 0xA0DE61894A93F609, 0xE7741B60E174093D, 0x545A57DEE2D35652,
    0xE21AC88218962D7A, 0x5134843C1B317215, 0x169EFED5B0D68D21, 0xA5B0B26BB371D24E, 0x99CA0B06E7197349, 0x2AE447B8E4BE2C26, 0x6D4E3D514F59D312, 0xDE6071EF4CFE8C7D,
    0x15BB4F8BE788911C, 0xA6950335E42FCE73, 0xE13F79DC4FC83147, 0x521135624C6F6E28, 0x6E6B8C0F1807CF2F, 0xDD45C0B11BA09040, 0x9AEFBA58B0476F74, 0x29C1F6E6B3E0301B,
    0xC96C5795D7870F42, 0x7A421B2BD420502D, 0x3DE861C27FC7AF19, 0x8EC62D7C7C60F076, 0xB2BC941128085171, 0x0192D8AF2BAF0E1E, 0x4638A2468048F12A, 0xF516EEF883EFAE45,
    0x3ECDD09C2899B324, 0x8DE39C222B3EEC4B, 0xCA49E6CB80D9137F, 0x7967AA75837E4C10, 0x451D1318D716ED17, 0xF6335FA6D4B1B278, 0xB199254F7F564D4C, 0x02B769F17CF11223,
    0xB4F7F6AD86B4690B, 0x07D9BA1385133664, 0x4073C0FA2EF4C950, 0xF35D8C442D53963F, 0xCF273529793B3738, 0x7C0979977A9C6857, 0x3BA3037ED17B9763, 0x888D4FC0D2DCC80C,
    0x435671A479AAD56D, 0xF0783D1A7A0D8A02, 0xB7D247F3D1EA7536, 0x04FC0B4DD24D2A59, 0x3886B22086258B5E, 0x8BA8FE9E8582D431, 0xCC0284772E652B05, 0x7F2CC8C92DC2746A,
    0x325B15E575E1C3D0, 0x8175595B76469CBF, 0xC6DF23B2DDA1638B, 0x75F16F0CDE063CE4, 0x498BD6618A6E9DE3, 0xFAA59ADF89C9C28C, 0xBD0FE036222E3DB8, 0x0E21AC88218962D7,
    0xC5FA92EC8AFF7FB6, 0x76D4DE52895820D9, 0x317EA4BB22BFDFED, 0x8250E80521188082, 0xBE2A516875702185, 0x0D041DD676D77EEA, 0x4AAE673FDD3081DE, 0xF9802B81DE97DEB1,
    0x4FC0B4DD24D2A599, 0xFCEEF8632775FAF6, 0xBB44828A8C9205C2, 0x086ACE348F355AAD, 0x34107759DB5DFBAA, 0x873E3BE7D8FAA4C5, 0xC094410E731D5BF1, 0x73BA0DB070BA049E,
    0xB86133D4DBCC19FF, 0x0B4F7F6AD86B4690, 0x4CE50583738CB9A4, 0xFFCB493D702BE6CB, 0xC3B1F050244347CC, 0x709FBCEE27E418A3, 0x3735C6078C03E797, 0x841B8AB98FA4B8F8,
    0xADDA7C5F3C4488E3, 0x1EF430E13FE3D78C, 0x595E4A08940428B8, 0xEA7006B697A377D7, 0xD60ABFDBC3CBD6D0, 0x6524F365C06C89BF, 0x228E898C6B8B768B, 0x91A0C532682C29E4,
    0x5A7BFB56C35A3485, 0xE955B7E8C0FD6BEA, 0xAEFFCD016B1A94DE, 0x1DD181BF68BDCBB1, 0x21AB38D23CD56AB6, 0x9285746C3F7235D9, 0xD52F0E859495CAED, 0x6601423B97329582,
    0xD041DD676D77EEAA, 0x636F91D96ED0B1C5, 0x24C5EB30C5374EF1, 0x97EBA78EC690119E, 0xAB911EE392F8B099, 0x18BF525D915FEFF6, 0x5F1528B43AB810C2, 0xEC3B640A391F4FAD,
    0x27E05A6E926952CC, 0x94CE16D091CE0DA3, 0xD3646C393A29F297, 0x604A2087398EADF8, 0x5C3099EA6DE60CFF, 0xEF1ED5546E415390, 0xA8B4AFBDC5A6ACA4, 0x1B9AE303C601F3CB,
    0x56ED3E2F9E224471, 0xE5C372919D851B1E, 0xA26908783662E42A, 0x114744C635C5BB45, 0x2D3DFDAB61AD1A42, 0x9E13B115620A452D, 0xD9B9CBFCC9EDBA19, 0x6A978742CA4AE576,
    0xA14CB926613CF817, 0x1262F598629BA778, 0x55C88F71C97C584C, 0xE6E6C3CFCADB0723, 0xDA9C7AA29EB3A624, 0x69B2361C9D14F94B, 0x2E184CF536F3067F, 0x9D36004B35545910,
    0x2B769F17CF112238, 0x9858D3A9CCB67D57, 0xDFF2A94067518263, 0x6CDCE5FE64F6DD0C, 0x50A65C93309E7C0B, 0xE388102D33392364, 0xA4226AC498DEDC50, 0x170C267A9B79833F,
    0xDCD7181E300F9E5E, 0x6FF954A033A8C131, 0x28532E49984F3E05, 0x9B7D62F79BE8616A, 0xA707DB9ACF80C06D, 0x14299724CC279F02, 0x5383EDCD67C06036, 0xE0ADA17364673F59
};

unsigned long long calculateCRC64(unsigned char* data, unsigned long size)
{
    unsigned long long myCRC64 = 0;

    for(unsigned long i = 0; i < size; i++)
        myCRC64 = CRC64_TABLE_REF[(myCRC64 ^ data[i]) & 0xFF] ^ (myCRC64 >> 8);

    unsigned long long tmp = myCRC64;
    myCRC64 = 0;
    for (int i = 0; i < 64; i++) {
        myCRC64 = (myCRC64 << 1) | (tmp & 1);
        tmp >>= 1;
    }

    return myCRC64;
}

Thanks to everybody for the help!

Body:
The code just needs to switch from a left shifting CRC to a right shifting CRC, with the polynomial bits reversed. The "#if 0" is used to select between two common polynomials, in this case, "#if 0" will use CRC64 ecma, which is what is shown in the question's CRC table. (0x42F0E1EBA9EA3693 bit reversed == 0xC96C5795D7870F42).

uint64_t crctbl[256];

void gentbl(void)
{
uint64_t crc;
uint64_t b;
uint64_t c;
uint64_t i;
    for(c = 0; c < 0x100; c++){
        crc = c;
        for(i = 0; i < 8; i++){
            b = crc&1;
            crc >>= 1;
#if 0
            crc ^= (0 - b) & 0xd800000000000000ull; // crc64 iso
#else
            crc ^= (0 - b) & 0xc96c5795d7870f42ull; // crc64 ecma
#endif
        }
        crctbl[c] = crc;
    }
}

uint64_t crc64c(uint64_t crc64, uint8_t * bfr, size_t size)
{
uint64_t crc = crc64;
    while(size--)
        crc = (crc >> 8) ^ crctbl[(crc & 0xff)^*bfr++];
    return(crc);
}

"Most efficient way" - if running on X86 X64 with carryless multiply, a really fast CRC, over 20 times as fast as the table method shown above (For a CRC of 256 MB of data, Intel Core i7-10510U .475 seconds table, .015 seconds pclmulqdq, 31.5 times as fast) , can be performed using pclmulqdq instruction and xmm registers. Link to a zip of a 520+ line assembly file, for Visual Studio's MASM (ML64.EXE), for 64 bit reflected CRC, with the same "if 0" as the gentbl() function above to choose between the two CRC polynomials.

http://rcgldr.net/misc/crc64ra.zip

Intel document explaining the algorithm for a 32 bit CRC:

https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf

A carryless multiply of two 64 bit non-reflected operands produces a 127 bit product in bits 126 (msb) to bit 0 (lsb). For reflected operands, a carryless multiply effectively multiplies the product by 2, which is taken into account with the constants. For 64 bit CRC, the poly is 65 bits, so some adjustments are also needed to handle that.


问:
Publish Jekyll Site To Git Repository
Every time I run Jekyll it destroys the entire contents of the destination folder.  The problem with this is that my destination directory is a small git repo from which I use to push to my actual server.  Is there a way to stop Jekyll deleting the Git files so that I don't have to generate the contents then copy them over?</p>

答:
Have you had a look at the Deployment section of the Jekyll wiki? - https://github.com/mojombo/jekyll/wiki/Deployment. It clearly explains Jekyll deployment steps.

And why are you pushing from the destination? That is bad! Push it from some other clone.

Title: Publish Jekyll Site To Git Repository


问:
Using pqxx cursors
I am trying to learn how to use cursors in pqxx.

I found pqxx::cursor_base in the reference and there are several subclasses that derive from pqxx::cursor_base.

After Googling the topic for hours, I can't find any sample code or anything explaining how to use pqxx cursors.

Any suggestions?

答:
There are surprisingly few cursor examples to be found.  Here's what I use:</p>

```<code>      const std::conStr("user=" + opt::dbUser + " password=" + opt::dbPasswd + " host=" + opt::dbHost + " dbname=" + opt::dbName);

      pqxx::connection conn(connStr);
      pqxx::work txn(conn);
      std::string selectString = "SELECT id, name FROM table_name WHERE condition";

      pqxx::stateless_cursor<pqxx::cursor_base::read_only, pqxx::cursor_base::owned>
      cursor(txn, selectString, "myCursor", false);

      //cursor variables
      size_t idx = 0;       //starting location
      size_t step = 10000;  //number of rows for each chunk
      pqxx::result result;
      do{
        //get next cursor chunk and update the index
        result = cursor.retrieve( idx, idx + step );
        idx += step;

        size_t records = result.size();
        cout << idx << ": records pulled = " << records << endl;

        for( pqxx::result::const_iterator row : result ){
          //iterate over cursor rows
        }
      }
      while( result.size() == step ); //if the result.size() != step, we're on our last loop
      cout << "Done!" << endl;
</code>```

Title: Using pqxx cursors

Body:
There are surprisingly few cursor examples to be found.  Here's what I use:

      const std::conStr("user=" + opt::dbUser + " password=" + opt::dbPasswd + " host=" + opt::dbHost + " dbname=" + opt::dbName);

      pqxx::connection conn(connStr);
      pqxx::work txn(conn);
      std::string selectString = "SELECT id, name FROM table_name WHERE condition";

      pqxx::stateless_cursor<pqxx::cursor_base::read_only, pqxx::cursor_base::owned>
      cursor(txn, selectString, "myCursor", false);

      //cursor variables
      size_t idx = 0;       //starting location
      size_t step = 10000;  //number of rows for each chunk
      pqxx::result result;
      do{
        //get next cursor chunk and update the index
        result = cursor.retrieve( idx, idx + step );
        idx += step;

        size_t records = result.size();
        cout << idx << ": records pulled = " << records << endl;

        for( pqxx::result::const_iterator row : result ){
          //iterate over cursor rows
        }
      }
      while( result.size() == step ); //if the result.size() != step, we're on our last loop
      cout << "Done!" << endl;


问:
Scrapy: select one immediate following sibling, and return empty string if not present
I have this HTML structure:

```<code><div>
    <h2>First title</h2>
    <p>First paragraph</p>

    <h2>Second title</h2>

    <h2>Third title</h2>
    <p>Third paragraph</p>
</div>
</code>```

I need to select the paragraph after a specific title, for example, the first paragraph:

```<code>response.xpath(".//h2[contains(text(), 'First title')]/following-sibling::p/text()").extract()[0]
</code>```

This gives me 'First paragraph'. However, if I need to select the text under Second title, I would get 'Third paragraph', instead of an empty string.

Is there a way to do this?

答:
You are getting 'Third paragraph' because the statement you are using is getting the first coming occurrence of
 after
Second title
.
You could do something like the following.

```<code>paragraphs = []
for e in response.xpath(".//h2[contains(text(), 'title')]/following-sibling::*[1]"):
  if '<p>' in e.get():
    # there is a paragraph after the current title
    paragraphs.append(e.xpath('.//text()')[0].get())
  else:
    # there is no paragraph after the current title
    paragraphs.append('')
</code>```

Body:
I have this HTML structure:

First title

First paragraph

Second title

Third title

Third paragraph

I need to select the paragraph after a specific title, for example, the first paragraph:

response.xpath(".//h2[contains(text(), 'First title')]/following-sibling::p/text()").extract()[0]

This gives me 'First paragraph'. However, if I need to select the text under Second title, I would get 'Third paragraph', instead of an empty string.

Is there a way to do this?

Body:
You are getting 'Third paragraph' because the statement you are using is getting the first coming occurrence of <p> after <h2>Second title</h2>.
You could do something like the following.

paragraphs = []
for e in response.xpath(".//h2[contains(text(), 'title')]/following-sibling::*[1]"):
  if '<p>' in e.get():
    # there is a paragraph after the current title
    paragraphs.append(e.xpath('.//text()')[0].get())
  else:
    # there is no paragraph after the current title
    paragraphs.append('')


问:
where and how to put a picture closing button in my html page
I am stuck. I have a site where people can check my lists, and can click on a code and see a larger picture in a window that opens after. I'd like this larger picture to have a closing option (an "X") somewhere up right. And can not find the place in my HTML page to do it.

Is there anyone who can help me?

Thanks! Tomas http://www.patentesantiguas.com.ar/galeria/repetidas.html

答:
I feel this is more appropriate as a comment, but I couldnt comment. On your button, you navigate to the image URL (eg. http://www.patentesantiguas.com.ar/galeria/250/E3G.JPG), which from what I know, could not have a button on top of it.

You will need to make a page or overlay with the html image element,

So your current page button will navigate you to the new html or open the overlay instead of opening the image.

Then your page will have

```<code>[![][1]][1]
</code>```

which display the image, then have a button to go back to history (-1) page

```<code> <button onclick="window.history.go(-1); return false;" >Close</button>
</code>```

Hopefully this is helpful

Body:
I feel this is more appropriate as a comment, but I couldnt comment. On your button, you navigate to the image URL (eg. http://www.patentesantiguas.com.ar/galeria/250/E3G.JPG), which from what I know, could not have a button on top of it.

You will need to make a page or overlay with the html image element,

So your current page button will navigate you to the new html or open the overlay instead of opening the image.

Then your page will have

[![][1]][1]

which display the image, then have a button to go back to history (-1) page

 <button onclick="window.history.go(-1); return false;" >Close</button>

Hopefully this is helpful


问:
Wrong behavior of the char arrays after strncpy
I am not a C-dev and I can get something wrong (I am doing the changes in the old code):

There is a function called strncpySafe (it is just a wrapper on strncpy as I can see):

```<code>void    strncpySafe(char *strDest, const char *strSource, int count)
{
    strncpy(strDest, strSource, count-1);
    strDest[count-1] = '\0';
}
</code>```

The step by itself, where is a copy from source A to source B with an offset:

```<code>void Foo(const char *message) {
char line[1024];
...
strncpySafe(line, &message[message_offset], count);
</code>```

In the last step they are modifying a line[] that was copied (the message[] should stay the same):

```<code>line[N] = 0;
</code>```

On the last step I can see from a VSCode debugger that line[N] is being changed and in the same time the message[N] also modifies.

I am using Ubuntu /g++-8, -march=x86-64, -std=c++11.

Is it something about the same pointers? Is it the wrong usage of the strncpy?

Thank you.

ps: the same code is being used inside a game client for windows and linux and I can say that on windows it is not being reproduced (windows was built on an older c-compiler, haven't checked with the same c++11 build yet).

EDIT: to make it clear, the modification of the line and a message happens in the same time when I pass a step with line[N] = 0;

Removed incorrect naming of the message_offset_2. It is a count.

Let me provide an example of the execution:

```<code>strncpySafe(line, &message[5], 10); // It copies 10 elements from 5th
line[5] = 0; // this leads that message[5] also gets 0 for it's element
</code>```

There are no errors with the boundaries (offsets and counters seems alright).

I agree that this code is deprecated and the logic might be unclear (why is that done that way) and I could use std::string. For me it was interesting why does it happen.

答:
Taking into account that the array message is also changed as you wrote in your question then it is evident that you are using the function incorrectly and as a result you have undefined behavior.

For example the third parameter that you named like message_offset_2 specifies the number of characters that should be copied from a string to the the destination character array. So it should not be named like message_offset_2.

Another reason of undefined behavior can be using of overlapped arrays.

So either the third argument is specified incorrectly or there takes place overlapping of character arrays.

But in any case the function is declared and defined badly.

If it is a wrapper around the standard C function strncpy then it should be declared at least like

```<code>char * strncpySafe( char * restrict s1, const char * restrict s2, size_t n );
</code>```

Or if it is declared as a C++ function then

```<code>char * strncpySafe( char * s1, const char * s2, size_t n );
</code>```

If the function is designed to copy n characters then the body of the function should look like

```<code>if ( n )
{
    strncpy( s1, s2, n );
    s1[n] = '\0';
}

return s1;
</code>```

So the destination array shall have at least n + 1 elements.

And (the C Standard, 7.23.2.4 The strncpy function )

If copying takes place between objects that overlap, the behavior is
  undefined.

Body:
I am not a C-dev and I can get something wrong (I am doing the changes in the old code):

There is a function called strncpySafe (it is just a wrapper on strncpy as I can see):

void    strncpySafe(char *strDest, const char *strSource, int count)
{
    strncpy(strDest, strSource, count-1);
    strDest[count-1] = '\0';
}

The step by itself, where is a copy from source A to source B with an offset:

void Foo(const char *message) {
char line[1024];
...
strncpySafe(line, &message[message_offset], count);

In the last step they are modifying a line[] that was copied (the message[] should stay the same):

line[N] = 0;

On the last step I can see from a VSCode debugger that line[N] is being changed and in the same time the message[N] also modifies.

I am using Ubuntu /g++-8, -march=x86-64, -std=c++11.

Is it something about the same pointers? Is it the wrong usage of the strncpy?

Thank you.

ps: the same code is being used inside a game client for windows and linux and I can say that on windows it is not being reproduced (windows was built on an older c-compiler, haven't checked with the same c++11 build yet).

EDIT: to make it clear, the modification of the line and a message happens in the same time when I pass a step with line[N] = 0;

Removed incorrect naming of the message_offset_2. It is a count.

Let me provide an example of the execution:

strncpySafe(line, &message[5], 10); // It copies 10 elements from 5th
line[5] = 0; // this leads that message[5] also gets 0 for it's element

There are no errors with the boundaries (offsets and counters seems alright).

I agree that this code is deprecated and the logic might be unclear (why is that done that way) and I could use std::string. For me it was interesting why does it happen.

Body:
Taking into account that the array message is also changed as you wrote in your question then it is evident that you are using the function incorrectly and as a result you have undefined behavior.

For example the third parameter that you named like message_offset_2 specifies the number of characters that should be copied from a string to the the destination character array. So it should not be named like message_offset_2.

Another reason of undefined behavior can be using of overlapped arrays.

So either the third argument is specified incorrectly or there takes place overlapping of character arrays.

But in any case the function is declared and defined badly.

If it is a wrapper around the standard C function strncpy then it should be declared at least like

char * strncpySafe( char * restrict s1, const char * restrict s2, size_t n );

Or if it is declared as a C++ function then

char * strncpySafe( char * s1, const char * s2, size_t n );

If the function is designed to copy n characters then the body of the function should look like

if ( n )
{
    strncpy( s1, s2, n );
    s1[n] = '\0';
}

return s1;

So the destination array shall have at least n + 1 elements.

And (the C Standard, 7.23.2.4 The strncpy function )

If copying takes place between objects that overlap, the behavior is
  undefined.


问:
How to enable Masonry animation directly at page load
On the homepage of the masonry library, there is the masonry-effect shown directly at page load. Besides the headline "What is Masonry?" are image-tiles displayed one after another in a beautiful fade effect.

However, running all the examples within the github repo don't animate at page load.

How to archive this?

What i did:

i cloned the repo.

i ran "npm install", "bower install", "grunt"

i opened the example files in the folder "sandbox", one after another.

No error messages are shown in the browser-console. Apparently masonry is working. I can be sure because changes in e.g. the configuration will take effect.

But the effect on page load differs a lot from this one at the homepage of the vendor. There are no animations.

答: This is a very late response to the original question but I was stumped on the same issue. The trick is to init Masonry with no grid items or items that have visibility: hidden. Using the Masonry config option stagger will improve the effect even more. After init, add your grid items or make them visible and they should each appear with a zoom effect. Here's an example I modified from one of David DeSandro's.


问:
Arithmetic overflow error converting money to data type numeric
This is my query I am inserting  a values in the in the temp table, but I am getting the error like this..

Arithmetic overflow error converting
  money to data type numeric.

Query is:

```<code>DECLARE @EBT money
Declare @ConversionRatio money
Declare @TotalRevenues money

insert into #SummarySheet(Item,INR,Dollar,Percentage)
VALUES ('EBT', isnull(@EBT,0), isnull(@EBT,0)/isnull(@ConversionRatio,0),
         isnull(@EBT,0)/isnull(@TotalRevenues,0))

FYR:
</code>```

The values are:

```<code>@TotalRevenues="1.00"
@EBT="-50995944.26"
@ConversionRatio="44.5"
</code>```

How to rectify it....

答:
Arithmetic overflow error

Destination data type do not have
  capacity to handle the space

kindly increase the space

Body:
This is my query I am inserting  a values in the in the temp table, but I am getting the error like this..

Arithmetic overflow error converting
  money to data type numeric.

Query is:

DECLARE @EBT money
Declare @ConversionRatio money
Declare @TotalRevenues money

insert into #SummarySheet(Item,INR,Dollar,Percentage)
VALUES ('EBT', isnull(@EBT,0), isnull(@EBT,0)/isnull(@ConversionRatio,0),
         isnull(@EBT,0)/isnull(@TotalRevenues,0))

FYR:

The values are:

@TotalRevenues="1.00"
@EBT="-50995944.26"
@ConversionRatio="44.5"

How to rectify it....


问:
Java8: Stream merge two lists
I have two lists

```<code>List1 - (1, 2, 3)
List2 - (4, 5, 6,7, 8)
</code>```

Want to merge both the list as  (1, 4, 2, 5, 3, 6, 7, 8) using java streams

First element from List1, List2 and, Second element from list1, list2 ...so on..if any extra elements remain then place at the end.

答:
Other answer has a link to a working solution, but here's another approach:</p>

```<code>    List<Integer> l1 = Arrays.asList(1, 2, 3);
    List<Integer> l2 = Arrays.asList(4, 5, 6, 7, 8);

    List<Integer> combined = IntStream.range(0, Math.max(l1.size(), l2.size()))
            .boxed()
            .flatMap(i -> {
                if (i < Math.min(l1.size(), l2.size()))
                    return Stream.of(l1.get(i), l2.get(i));
                else if (i < l1.size())
                    return Stream.of(l1.get(i));
                return Stream.of(l2.get(i));
            })
            .collect(Collectors.toList());

    System.out.println(combined);
</code>```

Title: Java8: Stream merge two lists

Body:
I have two lists

List1 - (1, 2, 3)
List2 - (4, 5, 6,7, 8)

Want to merge both the list as  (1, 4, 2, 5, 3, 6, 7, 8) using java streams

First element from List1, List2 and, Second element from list1, list2 ...so on..if any extra elements remain then place at the end.

Body:
Other answer has a link to a working solution, but here's another approach:

    List<Integer> l1 = Arrays.asList(1, 2, 3);
    List<Integer> l2 = Arrays.asList(4, 5, 6, 7, 8);

    List<Integer> combined = IntStream.range(0, Math.max(l1.size(), l2.size()))
            .boxed()
            .flatMap(i -> {
                if (i < Math.min(l1.size(), l2.size()))
                    return Stream.of(l1.get(i), l2.get(i));
                else if (i < l1.size())
                    return Stream.of(l1.get(i));
                return Stream.of(l2.get(i));
            })
            .collect(Collectors.toList());

    System.out.println(combined);


问:
mkvirtualenv says "no module named distutils.spawn" when making a venv for non-default python on Raspbian Buster
Raspbian Buster has Python3.7 by default.  I'm trying to make a Python3.6 virtualenv.  I have a fresh install of Raspbian Buster with Desktop (not the version that is with "recommended software") and have already sudo apt-get update; sudo apt-get upgrade'd.

I have run sudo apt-get install python3.6-dev to get Python 3.6.

I then run pip3 install virtualenvwrapper and added the appropriate lines to my .bashrc.

When I run mkvirtualenv --python=/usr/bin/python3.6 venv it gives the following error

```<code>Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/virtualenv.py", line 24, in <module>
    import distutils.spawn
ModuleNotFoundError: No module named 'distutils.spawn'
</code>```

I have searched for answers already and nothing has helped.  Here's what I've done (as far as I can remember).

I tried adding export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.6 to my .bashrc and it didn't help.

I tried python3.6 -m pip install virtualenvwrapper and get another distutils error:

```<code>Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
from pip._internal import main as _main  # isort:skip # noqa
File "/usr/lib/python3/dist-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 17, in <module>
from pip._internal.locations import USER_CACHE_DIR, src_prefix
File "/usr/lib/python3/dist-packages/pip/_internal/locations.py", line 10, in <module>
from distutils import sysconfig as distutils_sysconfig
ImportError: cannot import name 'sysconfig'
</code>```

I can successfully do mkvirtualenv venv but of course that uses Python 3.7 which I don't want.

I tried sudo apt-get install python3-distutils --reinstall but it only seems to install the Python3.7 version.  There is no python3.6-distutils package.

Anyone know anything about how to get this working?

答:
I had the same issue (ModuleNotFoundError: No module named 'distutils.spawn'). The problem was that PIP for python3 was not preinstalled on my system. The venv was created without problem after installing it manualy:

```<code>sudo apt install python3-pip
</code>```

Body:
Raspbian Buster has Python3.7 by default.  I'm trying to make a Python3.6 virtualenv.  I have a fresh install of Raspbian Buster with Desktop (not the version that is with "recommended software") and have already sudo apt-get update; sudo apt-get upgrade'd.

I have run sudo apt-get install python3.6-dev to get Python 3.6.

I then run pip3 install virtualenvwrapper and added the appropriate lines to my .bashrc.

When I run mkvirtualenv --python=/usr/bin/python3.6 venv it gives the following error

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/virtualenv.py", line 24, in <module>
    import distutils.spawn
ModuleNotFoundError: No module named 'distutils.spawn'

I have searched for answers already and nothing has helped.  Here's what I've done (as far as I can remember).

I tried adding export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.6 to my .bashrc and it didn't help.

I tried python3.6 -m pip install virtualenvwrapper and get another distutils error:

Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
from pip._internal import main as _main  # isort:skip # noqa
File "/usr/lib/python3/dist-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 17, in <module>
from pip._internal.locations import USER_CACHE_DIR, src_prefix
File "/usr/lib/python3/dist-packages/pip/_internal/locations.py", line 10, in <module>
from distutils import sysconfig as distutils_sysconfig
ImportError: cannot import name 'sysconfig'

I can successfully do mkvirtualenv venv but of course that uses Python 3.7 which I don't want.

I tried sudo apt-get install python3-distutils --reinstall but it only seems to install the Python3.7 version.  There is no python3.6-distutils package.

Anyone know anything about how to get this working?

Body:
I had the same issue (ModuleNotFoundError: No module named 'distutils.spawn'). The problem was that PIP for python3 was not preinstalled on my system. The venv was created without problem after installing it manualy:

sudo apt install python3-pip


问:
How to stop an Apache 2 HTTP server from a Java program?
I start an Apache HTTP server within my Java program. Unfortunately, I cannot stop the server from the program through the "httpd.exe -k stop" command. The error message is "(OS 5)Access is denied. : Failed to open the Apache2.2 Service". My OS is Windows 7.
How can I stop the server from my Java program? (Stopping manually the server is not an option.) </p>

<p>UPDATE: I cannot change the Windows permissions. </p>

答:
A dirty--but plain java--solution is to call:</p>

```<code>Runtime.getRuntime().exec("taskkill /F /IM httpd.exe");
</code>```

Body:
I start an Apache HTTP server within my Java program. Unfortunately, I cannot stop the server from the program through the "httpd.exe -k stop" command. The error message is "(OS 5)Access is denied. : Failed to open the Apache2.2 Service". My OS is Windows 7.
How can I stop the server from my Java program? (Stopping manually the server is not an option.)

UPDATE: I cannot change the Windows permissions.

Body:
A dirty--but plain java--solution is to call:

Runtime.getRuntime().exec("taskkill /F /IM httpd.exe");


问:
KendoUpload widget duplicate issue
I'm having an kendoUpload widget in a modal window issue - if you close the window and then again open it kendoUpload widget as if makes several instances of some of its part. Thus it will make a as many records and uploads as you open and close the window. What can cause the issue. I tried to destroy the kendoUpload widget each time when the window close but no luck. Maybe because of the wrong syntax ... Any ideas? THX!

Now I close and open the modal window again ->

Now I try to upload a file ->

HTML:

```<code><div id="UploadFiles" style="display: none">
<h3>Upload your files:</h3>
<div class="demo-section k-content">
    <input name="files" id="files" type="file"/>
</div>
<br/>
<h3>Current files on server:</h3>
<div id="CurrentFilesOnServer">
    <ul class="CurrentFilesOnServerList">

    </ul>
</div>
</code>```

Modal window:

```<code>// Modal Window Upload file to server
    var uploadFilesWindow = $("#UploadFiles").kendoWindow({
        width: "350px",
        modal: true,
        title: "Upload file to server:",
        actions: [
            "Pin",
            "Minimize",
            "Maximize",
            "Close"
        ],
        close: function () {

        }
    }).data("kendoWindow");
</code>```

JS Upload section:

```<code>  // upload file on server
    $(".k-grid-upload")
        .click(function () {
           uploadFilesWindow.center().open();

            function upload () {

       $("#files")
              .kendoUpload({
                  async: {
                      saveUrl: "/api/Grid/UploadFileOnServer",
                      removeUrl: "",
                      autoUpload: true
                  }
            }
      });
});
</code>```

C# controller:

```<code>// Upload file on server

    public string UploadFileOnServer()
    {

        var file = HttpContext.Current.Request.Files.Count > 0 ?
   HttpContext.Current.Request.Files[0] : null;

        if (file != null && file.ContentLength > 0)
        {
            var fileName = Path.GetFileName(file.FileName);

            var path = Path.Combine(
                HttpContext.Current.Server.MapPath("~/uploads"),
                fileName
            );

            file.SaveAs(path);
        }

       return  file != null ? "/uploads/" + file.FileName : null;

    }
</code>```

答:
You should Disable Drop Zone, it worked for me, see this link from Kendo Ticket: Disable Drop Zone

kendo.ui.Upload.fn._supportsDrop = function() { return false; }

Before*
After **

Title: KendoUpload widget duplicate issue

Body:
I'm having an kendoUpload widget in a modal window issue - if you close the window and then again open it kendoUpload widget as if makes several instances of some of its part. Thus it will make a as many records and uploads as you open and close the window. What can cause the issue. I tried to destroy the kendoUpload widget each time when the window close but no luck. Maybe because of the wrong syntax ... Any ideas? THX!

Now I close and open the modal window again ->

Now I try to upload a file ->

HTML:

Upload your files:

    <input name="files" id="files" type="file"/>

Current files on server:

Modal window:

// Modal Window Upload file to server
    var uploadFilesWindow = $("#UploadFiles").kendoWindow({
        width: "350px",
        modal: true,
        title: "Upload file to server:",
        actions: [
            "Pin",
            "Minimize",
            "Maximize",
            "Close"
        ],
        close: function () {

        }
    }).data("kendoWindow");

JS Upload section:

  // upload file on server
    $(".k-grid-upload")
        .click(function () {
           uploadFilesWindow.center().open();

            function upload () {

       $("#files")
              .kendoUpload({
                  async: {
                      saveUrl: "/api/Grid/UploadFileOnServer",
                      removeUrl: "",
                      autoUpload: true
                  }
            }
      });
});

C# controller:

// Upload file on server

    public string UploadFileOnServer()
    {

        var file = HttpContext.Current.Request.Files.Count > 0 ?
   HttpContext.Current.Request.Files[0] : null;

        if (file != null && file.ContentLength > 0)
        {
            var fileName = Path.GetFileName(file.FileName);

            var path = Path.Combine(
                HttpContext.Current.Server.MapPath("~/uploads"),
                fileName
            );

            file.SaveAs(path);
        }

       return  file != null ? "/uploads/" + file.FileName : null;

    }