TesorFlow Keras GRU layer invalid argument error - 'expected to be a double tensor but is a float tensor'

Question: I am currently working on an RNN in TensorFlow (and Keras) to generate moving object data. My RNN model is defined as follows:
if tf.test.is_gpu_available():
    my_gru = tf.keras.layers.CuDNNGRU
else:
    import functools
    my_gru = functools.partial(
        tf.keras.layers.GRU, recurrent_activation='sigmoid')

def build_model(internal_units, batch_size):
    model = tf.keras.Sequential([
        my_gru(internal_units, return_sequences=True, recurrent_initializer='glorot_uniform', stateful=True, batch_input_shape=[batch_size, None, 3]),
        tf.keras.layers.Dense(3)
    ])
    return model

INTERNAL_UNITS = 1024
model = build_model(internal_units=INTERNAL_UNITS, batch_size=BATCH_SIZE)

I get the following summary for the model, which is all well and good:
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
cu_dnngru_2 (CuDNNGRU)       (64, None, 1024)          3161088
_________________________________________________________________
dense_4 (Dense)              (64, None, 3)             3075
=================================================================
Total params: 3,164,163
Trainable params: 3,164,163
Non-trainable params: 0
_________________________________________________________________

When I try to run the model for a single prediction before training, just to see if it generally works and the output has the correct shape, I get an error.
This is how I run the model ...
for input_example_batch, target_example_batch in dataset.take(1):
    example_batch_predictions = model(input_example_batch)
    print(example_batch_predictions.shape, "# (batch_size, sequence_length, n_features)")

... and this is the error I get ...
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-52-dd1ea240c0d1> in <module>()
      1 for input_example_batch, target_example_batch in dataset.take(1):
----> 2     example_batch_predictions = model(input_example_batch)
      3     print(example_batch_predictions.shape, "# (batch_size, sequence_length, n_features)")

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, inputs, *args, **kwargs)
    755       if not in_deferred_mode:
    756         self._in_call = True
--> 757         outputs = self.call(inputs, *args, **kwargs)
    758         self._in_call = False
    759         if outputs is None:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/sequential.py in call(self, inputs, training, mask)
    227   def call(self, inputs, training=None, mask=None):
    228     if self._is_graph_network:
--> 229       return super(Sequential, self).call(inputs, training=training, mask=mask)
    230
    231     outputs, _ = self._call_and_compute_mask(

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/network.py in call(self, inputs, training, mask)
    843     outputs, _ = self._run_internal_graph(inputs,
    844                                           training=training,
--> 845                                           mask=masks)
    846     return outputs
    847

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/network.py in _run_internal_graph(self, inputs, training, mask)
   1029                     computed_tensor, **kwargs)
   1030               else:
-> 1031                 output_tensors = layer.call(computed_tensor, **kwargs)
   1032                 if hasattr(layer, 'compute_mask'):
   1033                   output_masks = layer.compute_mask(computed_tensor,

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/cudnn_recurrent.py in call(self, inputs, mask, training, initial_state)
    107       # Reverse time axis.
    108       inputs = K.reverse(inputs, 1)
--> 109     output, states = self._process_batch(inputs, initial_state)
    110
    111     if self.stateful:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/cudnn_recurrent.py in _process_batch(self, inputs, initial_state)
    297         params=params,
    298         is_training=True,
--> 299         rnn_mode='gru')
    300
    301     if self.stateful or self.return_state:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_cudnn_rnn_ops.py in cudnn_rnn(input, input_h, input_c, params, rnn_mode, input_mode, direction, dropout, seed, seed2, is_training, name)
    142           input_mode=input_mode, direction=direction, dropout=dropout,
    143           seed=seed, seed2=seed2, is_training=is_training, name=name,
--> 144           ctx=_ctx)
    145     except _core._NotOkStatusException as e:
    146       if name is not None:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_cudnn_rnn_ops.py in cudnn_rnn_eager_fallback(input, input_h, input_c, params, rnn_mode, input_mode, direction, dropout, seed, seed2, is_training, name, ctx)
    184   "is_training", is_training)
    185   _result = _execute.execute(b"CudnnRNN", 4, inputs=_inputs_flat,
--> 186                              attrs=_attrs, ctx=_ctx, name=name)
    187   _execute.record_gradient(
    188       "CudnnRNN", _inputs_flat, _attrs, _result, name)

/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     64     else:
     65       message = e.message
---> 66     six.raise_from(core._status_to_exception(e.code, message), None)
     67   # pylint: enable=protected-access
     68   return tensors

/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: cannot compute CudnnRNN as input #1(zero-based) was expected to be a double tensor but is a float tensor [Op:CudnnRNN]

The input I use (input_example_batch) looks as follows:
tf.Tensor(
[[[ 1.04234461  4.66466794 -4.32528214]
  [ 1.04244826  4.49530966 -4.42294239]
  [ 1.04256889  4.47099585 -4.51911731]
  ...
  [ 1.05549699 -0.64915764  0.67451403]
  [ 1.05559893 -0.7788313   0.66355975]
  [ 1.05570257 -0.88502956  0.65223413]]

 [[-0.83849063 -0.47476892 -0.22299478]
  [-0.8383632  -0.41943403 -0.22782209]
  [-0.83830883 -0.41635987 -0.24527468]
  ...
  [-0.82015615  0.05482504  0.681198  ]
  [-0.8200627  -0.04187127  0.69233796]
  [-0.81995906 -0.13493448  0.66615907]]

 [[-1.27264128  0.12441285 -0.48032767]
  [-1.27256143  0.29544794 -0.714081  ]
  [-1.27247477  0.46871879 -0.97197089]
  ...
  [-1.25435437  3.47832158  0.72724314]
  [-1.25427451  3.90674772  0.63255355]
  [-1.25418956  4.28934093  0.49219015]]

 ...

 [[ 1.01251773  1.16012535 -2.9933152 ]
  [ 1.01263666  1.16906836 -2.99554319]
  [ 1.0127505   0.99943062 -2.95135471]
  ...
  [ 1.02650943 -0.42362607  0.46805359]
  [ 1.02661308 -0.49377282  0.42702143]
  [ 1.02666575 -0.49544963  0.42739276]]

 [[-1.34049978 -0.01029126  0.5430626 ]
  [-1.34038934 -0.04690171  0.52078269]
  [-1.34029419  0.07857991  0.52895199]
  ...
  [-1.3289751   1.94152097  1.03489148]
  [-1.32888165  1.51113855  0.94372954]
  [-1.32878311  1.16208164  0.76511898]]

 [[ 0.57716585 -1.38779448  0.0469634 ]
  [ 0.57728308 -1.44536512 -0.01542033]
  [ 0.57734255 -1.49846425 -0.02581762]
  ...
  [ 0.58594146 -0.63183055 -0.03621491]
  [ 0.58603491 -0.60136842 -0.04419854]
  [ 0.58613855 -0.63015374 -0.07204842]]], shape=(64, 100, 3), dtype=float64)

All of this is running in a Google Colab environment.
I have already tried forcing it to use the normal GRU layer, which leads to pretty much the same error. A notable difference, though, with the normal GRU layer is that it claims to expect a float tensor instead of a double tensor (exactly the other way around as the error I copied into this post).
My entire code basically the same as an example given on the TensorFlow website. I modified the model slightly and changed the input data to have 3 features instead of having as many features as the alphabet is long. The original TensorFlow example works just fine for me.
Please excuse the long post and ask for more information, if you need any. I tried to be thorough, but you never know. I appreciate every help.
EDIT:
Here you can find a short example Notebook on Google Colab that you can use to reproduce the error yourself.
Comment: Can you share a self-contained notebook that reproduces the problem?
Comment: I added a link to my post that leads to a Colab Notebook. It's a much smaller example, but it does produce the same error for me.
Answer: So I found a solution that seems to work for me. When I call model.input I get the following output that suggests that the GRU layer requires its input to be a float tensor.
<DeferredTensor 'gru_input' shape=(64, ?, 3) dtype=float32>

Using the line
x = tf.cast(x, dtype=tf.float32)

(TensorFlow documentation) I can cast my input data to be a float tensor. Using this float tensor, the model works just fine.
I hope this helps someone with the same problem. According to this post float64 compatibility is a known issue with TensorFlow.


how to set multiple value for same name in option tag?

Question: I want to set multiple values of same id or same names in option tag. In my form contains Subjects Field that with Plus(+) and Minus Button(-) to add or remove fields(fields are not constant).
I have attached Image for your refernce @ http://s26.postimg.org/n59ryciah/Stack_cip_subject.png
If i choose Class Name,subjects Fields are automatically filled by AJAX. In this above Picture i set same id,names for all subject fileds. How to set values for all fields.
My Code:
JSP:
<select class="form-control" name="subjects" id="subjectSelect" ></select>

Javascript:
subjectSelect += "<option selected=\"selected\" disabled>Select a Subject</option>";
_.each(jsonResponse,function(row){
subjectSelect += "<option value="+row.id+">"+row.subjectName+"</option>";
});
$("#subjectSelect").html(subjectSelect);

My problem This id will set for first field only. I want to set values for all fields. How to set it?
Comment: id values must be unique.
Comment: ok. how to set values for all fields?
Answer: i have a bit different answer, but it would do similar thing:
in your html:
  <button onclick="addId(); return false;">Add Id</button>

this where you want to add your buttons:

between  tags:
var answers = 0,
write = document.getElementById('buttons');

function addID() {
     write.innerHTML += '<input type="text" id="answer"' + answers + '/>
';
answers++;
}


Returning "-1" from int main shows "return value 4294967295" in the console why?

Question: I am using Windows-11, 64-bit, and Dev-C++ (Bloodshed v5.11); the following is the simple code snippet:-
#include<stdio.h>

int main()
{
    return -1;
}

I am getting the following output in the console:-

Process exited after 0.2015 seconds with return value 4294967295
Press any key to continue . . .

In the output, I do recognize that 4294967295 (2^32 - 1) is the max value of the unsigned 4-byte integer, but I cannot understand why this value is returned instead of "-1".
Comment: It's the *same* bit pattern `0xFFFFFFFF` (in 2's complement representation) and `unsigned` must be how the shell interprets it.
Comment: This is a behavior of the console or command line program, not your program.
Comment: It is a mismatch between the C language specification and the [operating system](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodeprocess).  Which uses DWORD for the exit status, an unsigned integer type.  No biggie, but it is best to reserve negative values for program aborts.
Comment: Hi, Weather Vane, Sorry but I do not understand what you tried to explain, can you elaborate or suggest some text to read, and why the question is closed ?
Comment: Everything in the computer is a number, and what that number means depends on context. The `0xFFFFFFFF` returned was `-1`  to the function that returned it, and `4294967295` to the function that received it, for some reason of the implementation. They are the same set of bits, treated in a different context.
Answer: -1 in two's complement signed number format (assuming 4 bytes long integers) is 0xffffffff which is the maximum unsigned value that can be stored in the 4 bytes.  Two's complement format is used by almost all computers used nowadays (including your PC, Mac and any mobile phone)
Your shell is displaying the program return value as unsigned integer. The decimal representation of the 0xffffffff hex number is 4294967295
Comment: Not a 2's complement issue. -1 encode as a non-2's complement, when assigned to a 32-bit unsigned would still have the value 4294967295.  This is a _signed_ versus _unsigned_ type issue, not an encoding one.
Comment: @chux-ReinstateMonica you assume that shell was written in C and it has assigned the variable. But if the language is not following the C rules or code in shell simple memcpy the return value. Then -1, if ones complement is used, will be 4294967294. You do not know what shell is doing with the return value. So I do not agree with your comment as it covers only one of many possibilities


"Select All That Apply" -- How To Generate a Predictive Model with this Type of Question

Question: For a particular question in a survey, respondents have been asked to select all that apply (i.e. say from a list of books they have read).
I'm wondering if anyone knows how I would be able to build a model that predicts which book they have read based on demographic variables obtained in the survey?
I know it would be possible to construct a model like this using Multinomial Logistic Regression if they were asked to select a single book (i.e. perhaps selecting the last book from the list they have read, if any).
Any suggestions/help would be greatly appreciated.
Thanks!
Answer: I think that in this case, you really have multiple dependent variables captured by the "select all that apply" question.
The way that I would probably approach it would be to create a model for each of the possible responses to the select all that apply question, effectively ending up with a prediction model for each of the possible responses.
Alternatively, you could also create models that capture combinations of the "select all that apply" questions, something of the form "the respondent selected at least one of the first three options is predicted by these explanatory variables."
It really comes down to what your research questions are.
Comment: Thanks for your comment Mike! Yea, I wasn't sure how I would be able to somehow combine all the cases into a single model. Your idea sounds good. Thanks again!


Garland sub-theme color functionality is not working

Question: I have a subtheme in Drupal 7 for Garland theme. below is my my_garland.info file for the sub-theme
name = My Custom Sub Theme
description = Custom sub-theme of Garland
core = 7.x
base theme = garland
stylesheets[all][] = my_garland.css

i have also include some information in the template.php file to help with the color module
function my_garland_process_html(&$vars) {
  // Hook into color.module.
  if (module_exists('color')) {
    _color_html_alter($vars);
  }
}

I have also copied the color and images file from the garland theme therefore the initial blue works perfectly and i can see the color wheel but the total page layout is not changing.
I have also tried to follow this link to see if it will be resolved but all in vain. Thanks in advance for your assistance.
Answer: From Example: Creating a Garland Subtheme That Utilizes the Color Module

That said, even if you do not have a style.css file in your subtheme
  directory, you still must add it to your .info file with
  stylesheets[all][] = style.css
Comment: Thanks @J.Reynolds, but as you are aware if I add style.css to the info file, this will override the style.css from the main theme. hence the whole site will be without the style.css attributes.


Minimum Number of Sets Needed to Generate the Power Set

Question: Take a finite set $A$ with $|A|=n.$ Let $\mathscr{F}$ be the power set of $A$. What is the smallest number of sets needed to generate $\mathscr{F}$? That is, if $\mathscr{C}$ is a set of subsets of $A$, what is the minimum size of $\mathscr{C}$ such that $\sigma (\mathscr{C})=\mathscr{F},$ where $\sigma (\mathscr{C})$ denotes the sigma-field generated by $\mathscr{C}.$
My approach to this is to look at $\mathscr{C}$ being able to generate all the singletons of $A$. So we have an upper bound on the size of $\mathscr{C}$ at $n$, this comes from just letting $\mathscr{C}$ be the set of singletons.
However, looking at the example of $A=\{ 1,2,3\},$ I can get a set that $\mathscr{C}=\{\{1,2\},\{2,3\}\}$ generates $\mathscr{F}$. So I know that $n$ is not the minimal size, but I am unsure how to go about finding the minimal size.
Thanks for any help!
Comment: Your same example gives $|C| = 2$ when $n=4$; remember you are allowed to take complements.
Answer: The minimal such size is $\lceil \log_2 n \rceil$.
To see this, we'll first show that if $|\mathscr{C}| < \lceil \log_2 n \rceil$, then $\mathscr{C}$ cannot generate $\mathscr{F}$. This follows from the fact that $2^{|\mathscr{C}|} < n$, so two elements of $A$ must appear in exactly the same sets of $\mathscr{C}$, so they will appear in exactly the same sets in $\sigma(\mathscr{C})$. However, there exist sets in $\mathscr{F}$ which contain one of these two elements but not the other, hence leading to a contradiction.
On the other hand, we'll show that there is a $\mathscr{C}$ with $|\mathscr{C}| = \lceil \log_2 n \rceil$ that suffices. Let $S_i$ be the subset of $\{0, 1, \dots, n-1\}$ consisting of those elements whose $i$th bit (from the right) equals $1$ (when written in binary), and let $\mathscr{C}$ be the collection of $S_i$ for $1 \leq i \leq \lceil \log_2 n \rceil$. Now, to construct any singleton $\{i\}$, let $X$ equal the set of positions $j$ such that the $j$th bit of $i$ is $1$, and let $Y$ equal the set of positions $j$ such that the $j$th bit of $i$ is $0$. It then follows that
$$\{i\} = \bigcap_{j\in X} S_j \cap \bigcap_{j \in Y} \overline{S_j}$$
and hence this set generates $\mathscr{F}$.
Comment: Thanks for the help. When you say that two elements of $A$ must appear in exactly the same sets of $\mathscr{C}$, do you mean that  there are two elements of $A$, $a$ and $b$, so that $a$ and $b$ only appear in the same elements of $\mathscr{C}$? If so, how do we know this is true?
Comment: @User112358 For every element $a\in A,$ put it in $\textit{a subset X of C},$ which is a set of subsets of $A,$ such that, exactly the sets in X contain $a.$ Then by pigeonhole principle, there are two elements of $A$ that are put in the same X, which means that they are contained in the same sets of $C.$ The $\sigma$ does not affect this property then.
Comment: @awllower In forming $\mathscr{C}$ there is nothing that says every element of $A$ must be in a subset in $\mathscr{C}$. Also if the two elements are not only in the same subsets then set operations does affect that property.
Comment: Let $a$ and $b$ be two elements of $A$. Then the property "$a$ and $b$ only appear in the same elements of $C$" is preserved by the operations of sigma-algebras; namely intersection, union, and complementation.
Comment: @jschnei I understand this, what I do not understand is how you justify that there are two such elements of $A$ if $|\mathscr{C}|<\lceil \log_2 (n)\rceil$. For $m<\lceil \log_2 (n)\rceil$ couldn't you just take $\mathscr{C}$ to be $m$ singletons then there are no two elements of $A$ in all the same elements of $\mathscr{C}$.
Comment: In that case, take two elements $a$ and $b$ that don't appear in any  of the sets in $C$. These elements only appear in the same elements of $C$ (i.e., none of them).
Comment: In particular the formal condition is: for every pair of elements $a, b$ with $a\neq b$, there exists a set $S \in \mathcal{C}$ such that either $a\in S$ and $b \not\in S$ or $a\not \in S$ and $b \in S$.
Comment: @jschnei In the second half of your answer, where you write the example where $|\mathscr{C}|=\lceil \log_2 (n) \rceil$ and $\mathscr{C}$ generates $\mathscr{F}$ I don't know what much of your notation means. What is $[n]$? What does $i$th bit from the right mean?
Comment: $[n]$ is simply shorthand for $\{1, 2, \dots, n\}$ (although it turns out it's actually more convenient to work with $\{0, 1, \dots, n-1\}$; I'll edit the answer). The $i$th bit from the right is simply the $i$th bit from the right when written in binary; for example, the 2nd bit from the right in $13 = 1101_2$ is $0$.


Deleted printers keeps coming back - and multiply

Question: My users are on 2012 R2 RDS Session Host servers.
I've used "Deploy Printers" (from Print Manager) to deploy 4 printers. The last week, I've had a lot of problems where users can't print. If I deleted the printer and added it again, they could print just fine.
Now I've removed all printer deploying from GPO - and I have no printers in any login scripts. I did a gpupdate /force, but all the 4 printers are now listed 3 times...

If I delete the printers and log off and back on, all the printers are popping up again. Sigh! This is driving me nuts.
This script doesn't show any of the "SVFREJA" printers...
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colPrinters = objWMIService.ExecQuery ("Select * From Win32_Printer")

If colPrinters.Count <> 0 Then 'If there are some network printers
    Dim s
    s = ""
        For Each objPrinterInstalled In colPrinters ' For each network printer
        s = s + objPrinterInstalled.Name + chr(13)
        Next
    msgbox s
End if

It gives me this result...

(sry for the big picture)
My problem is not with the "redirected" printers, my problem is that I have several printers with the same name (on SVFREJA) and I can't get rid of them.
Any idea why I can't get rid of the "ophaned" printers??
Answer: I had this exact same problem. After I deleted a Group Policy printers kept coming back all over the place.
The only solution for me was:

Downloading PSTools
Running CMD as administrator
Run the command psexec -i -s c:\windows\regedit.exe (make sure you don't have regedit open already, otherwise it gives an error)
Delete all keys under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SWD\PRINTENUM which contained the printer name that keeps coming back.

You have to use the PStools option, because otherwise you will get an access denied error when deleting the regkeys.
Comment: this was exactly was I did to resolve the same issue.
Comment: We had a ton of printers (like ~100) showing up for everyone logging into an RDS host, and we hadn't deployed most of them via Group Policy anywhere at any point in time. We're wondering if it wasn't because we cloned a server and did a sysprep to build the RDS host. At any rate, this regedit was the solution for us as well, thanks much!
Comment: See "Credit to Herman Brood and Benjamin Chan..." post below
Answer: Looking to see if you found a solution. I'm running into the exact same issue. Definately not redirected printers.
If I look at the events I can see - Kernal-PnP:
Device SWD\PRINTENUM{5251368F-DFD2-4635-8ED1-B37C4AF55D58} was deleted.
Class Guid: {1ed2bbf9-11f0-4084-b21f-ad83a8e6dcdc}
One minute later:
Device SWD\PRINTENUM{5251368F-DFD2-4635-8ED1-B37C4AF55D58} was configured.
Driver Name: PrintQueue.inf
Class Guid: {1ed2bbf9-11f0-4084-b21f-ad83a8e6dcdc}
Driver Date: 06/21/2006
Driver Version: 6.3.9600.16384
Driver Provider: Microsoft
Driver Section: NO_DRV
Driver Rank: 0xFF0000
Matching Device Id: PRINTENUM\PrinterConnection
Outranked Drivers: oem10.inf:lptenum\zebra_technologiesztf670:00FF0001 oem14.inf:lptenum\zebra_technologiesztf670:00FF0001 c_swdevice.inf:SWD\GenericRaw:00FF3001
Device Updated: false
EDIT:
I believe I found my fix here:
http://social.technet.microsoft.com/Forums/windowsserver/en-US/71d06204-3735-4473-8bc9-20be9e19090e/problem-with-multiple-instances-of-shared-printers-being-installed-on-client-computers-when-the?forum=winserverprint
Hate having to dive into the registry but it looks like going into the Client Side Rending Print Provider keys under the HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers\ and cleaning out anywhere there
s a reference to the persistent "zombie" printers.
Comment: See "Credit to Herman Brood and Benjamin Chan..." post below
Answer: Those are printers being redirected from the local computers of the users who have sessions on the RDS server. Those ARE NOT local printers on the RDS server. If you don't want those printers to be redirected from the local computers to the RDS server then disable Printer Redirection on the RDS server.
Comment: I'm sorry for not making myself clear. My problem is not with the printers with (redirected) ... my problem is that I have 3 printers called "HAD - Print 1 på SVFREJA", 4 printers called "TAA - Print 1 på SVFREJA" and 3 printers called "TAA - Print 2 på SVFREJA" ... it's kinda like ophaned printers, but I can't remove them.
Answer: Had this exact problem and drove me crazy for over a week.  To resolve this issue install the Printer Management role (or Printer and Document Service) on the session host.
Answer:
This steps worked for me:
Open "Administrative Tools", then "Print Management"
Select "All Printers"
-Find the printer in question -the status will be something like "Deleting - Offline" and there was 1 pending job. I right-clicked, selected "Cancel All Jobs", and the printer immediately disappeared.
Answer: I ran into this once on some workstations that had been imaged with an older Kaspersky imaging server.  Ended up building a completely brand new Kaspersky image.  Nothing else we did would permanently remove the printers.
Is it possible that your server has gone through one or more OS upgrades?
Answer: Credit to @Herman Brood and @Benjamin Chan, here are the instructions that resolved the issue for me (a merge of what both mentioned above):
Anything under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SWD\PRINTENUM seems to be derived from errant references within HKLM\Software\Microsoft\Windows NT\CurrentVersion\Print\Providers\ and/or HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers\ which therefore need to be deleted to cure the issue.
Find the errant queues in Device Manager.  Since I've fixed the issue, I don't have them anymore, but as an example, refer to the "Location" in the "General" tab of each errant queue:

For me, the location said something similar to:
\Users\S-1-5-21-4#########8-3########4-1#########6-1#####5\Printers\^\^\{print server name}^\{printer name}

Download PSTools
Run CMD as administrator
Run the command
psexec -i -s c:\windows\regedit.exe (make sure you don't have regedit
open already, otherwise it gives an error.  The -s switch allows you to impersonate SYSTEM, which is necessary for permission to delete these keys from the registry.)
Delete all keys under
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Print\Providers\ which
contain each "Location" determined above.
Delete all keys under
HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers\ which
contain each "Location" determined above (I didn't have any, likely because everything is 64 bit).
Uninstall the errant Print Queues:

Cycle the Print Spooler and cross your fingers.  Printers should not return (they didn't for me).

As an aside, deleting keys under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SWD\PRINTENUM seems to work similar (if not equivalent) to uninstalling the queue from Device Manager.  If the keys under HKLM\Software[\Wow6432Node]\Microsoft\Windows NT\CurrentVersion\Print\Providers\ aren't deleted, the errant queues return.
Answer: I have found, that you can create a GPO that runs a Batch file on startup to delete the errant printers. PSEXEC is not necessary as these scripts run under the system account:
if exist c:\printfix.txt goto FIXED
reg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Print\Providers\" /f
reg delete "HKLM\Software\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Print\Providers\" /f
reg delete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\SWD\PRINTENUM" /f

echo fix > c:\printfix.txt
:FIXED


How to enable a payment method as soon as an order is saved in Drupal commerce programmatically?

Question: I am trying to create a membership site using Drupal commerce. I have created a custom form that collects all the billing details of the user and the membership type and then on submit creates and saves a Drupal commerce order (products have already been created).
Now I want to activate the payment system for the order as soon the order is saved but I have not been able to do so. All of this should be happening in the backend and I do not want to redirect the user to a payment page. How do we do that?
Comment: What do you mean by "activate the payment system"? Do you mean you want to enable a payment rule programmatically? Or do you mean you want to programmatically add a payment record to an order?
Comment: Clive, I am not familiar with the terminology of these commerce systems as I am new to them. Usually in a normal shopping cart, once the product has been added to their cart a user moves to the 'pay' button and then goes on to submit their credit card information. My form has all the required fields, and what I want is when the customer clicks on the submit button, an order is created and immediately proceeds to payment using the credit card info they entered earlier. I have enabled the payment method, tried activating the payment system when the order has been created but it is not working.
Comment: What payment processor are you using? On or off-site version?
Comment: I am using authorize.net. I am guessing it is an offsite version
Comment: If it's an offsite payment method you won't be able to do that. You'll need to change to use an insure method if you want to process card details on your own site
Answer: To get it to go onto the review page you can do.
<code>$order = commerce_order_new($uid, 'checkout_review');
</code>
When creating your order that sets the status to checkout_review.
Then you can use the following to driect yourself to the page
<code>drupal_goto('checkout/' . $order->order_id. '/review');
</code>
As the status has been set you go to the review page. I did something similar recently and it is working well.


Java's equals bugging me

Question: I encountered a problem using equals, let me first add the code here :
Operateur o = new Operateur(nom, age, sexe, grade, role);
for(Operateur op : Membre.getOperateurs()){
  if(o.equals((Object)op)){
    already_exists = true;
    break;
  }
}

if(already_exists){
  ret = ">Can't create it : already exists";
  Membre.removeLast();
  o.finalize();
}else{
  ret = ">Created it";
}

Here I check if a new Operateur isn't just a copy of an old one (Membre.getOperateurs gets me the list of all instances of Membre that are actual Operateur).

My problem is that when I run this bit of code, if my Operateur is brand new it appears as already existing (which he should not, since he's brand new).
For instance, when I create the first Operateur ever it evaluates it as a duplicate of an already existing one.
As :
import cmd.*;
import matrice.*;
import persona.*;
import non_grata.non.*;
import non_grata.grata.*;
//all above is importing packages to use all classes required

public class Debug{
  public static void out(String s){
    System.out.println(s);
  }//handy

  public static void main(String[] args){
    Membre.init();//Membre.membre = new ArrayList<Membre>();
    Personnel.init();//Personnel.membre = new ArrayList<Membre>();
    Vaisseau.init();//Vaisseau.vaisseaux = new ArrayList<Vaisseau>();
    MatrixCmd cmd = new MatrixCmd();//Create the command parser

    String parser_input = "afficherMembres";//get some input
    String parser_output = cmd.execCommand(parser_input);//process it
    out(parser_output);//use it
    //empty list, correct since we only initialized it

    parser_input = "newOPsion mikebike 10 o string string";
    parser_output = cmd.execCommand(parser_input);
    out(parser_output);
    //outputs ">Impossible de créer cet Opérateur : Il existe déjà" which it shouldn't
    //since there are no other Operateur and this is only
    //given as output when it founds a similar Operateur

    parser_input = "afficherMembres";
    parser_output = cmd.execCommand(parser_input);
    out(parser_output);
    //outputs an empty list, meaning that there are no Membre created
    //and therefore no Operateur

    parser_input = "newOPsion mikebke 8 f tring sring";//command that will trigger the bit of code above
    parser_output = cmd.execCommand(parser_input);
    out(parser_output);
    //outputs">Impossible de créer cet Opérateur : Il existe déjà" which it shouldn't
  }
}

Comment: I'm sorry Vivick but even if it's not a duplicate, the question quality is a bit low. Firstly the title is terrible - you've blamed Java for your problems rather than an incomplete understanding. Secondly, you've given quite a big code dump rather than creating an [MCVE]. Thirdly you haven't provided evidence of understanding the difference between the `==` `equals`. If you're asking for free help, please spend some time editing your question with the minimum code for what you are trying to achieve, your research so far, and what happens when you debug it.
Comment: @Vivick "It is NOT a duplicate" not necessarily. Current duplicate simply solves one of your problems which we could see based on what you showed us. If it doesn't solve all of problems, it is possible they exist in code which you are not showing us. Like David suggested please take your time and try creating [mcve].
Comment: @Vivick I'm sorry you feel this way, but based on the initial pass over the out-of-context code, that is an issue you need to correct first, correcting this allows you to solve at least one, albeit, obvious issue which may lead you to discovering the real underlying issue. Based on this correction, feel free to ask a new question with the updated code, providing a runnable example which demonstrates the issue you're trying to solve, otherwise, it becomes nothing more than guess game
Comment: Purpose of helper method wasn't to solve *current* problem since honestly it is not clear (at least for me). Its purpose was to limit potential *future* problems when you can simply forget to add casting and end up with problem which you will search potentially for hours. Generally casting is considered as symptom of design problem. Anyway in your edit you reduced your code to only some testing method, but we can't really use it (copy-paste and run on our machines) which prevents us from debugging it, so it is still not proper [MCVE] (a.k.a. [SSCCE](http://sscce.org))
Comment: BTW existence of overloaded `equals(YourClass)` method doesn't look right. It forces you to use `if(o.equals((Object)op))` instead of simply `if(o.equals(op))`. If you really want to have helper method maybe use something like `private boolean equalsHelper(YourClass o){...}`.
Comment: Oh surpise! When someone yells "possible duplicate" question is marked as duplicate automatically whether it is true or not. I know  that because, oh surprise, changing every `==` for `.equals(` in string comparison didn't change a thing \o/. GJ @OliverCharlesworth
Comment: @MadProgrammer : It is NOT a duplicate (see above)
Comment: Helper didn't help either. The problem resides on the fact that `equals` seems to only evaluate to true
Comment: I can't give you 600 lines of code and tell you "it's minimal, complete and verifiable"
Comment: However, there is a part where I say something like (as a comment about  `for(Operateur c : Membre.getOperateurs())`) `browse through every created instance of Operateur` which is the alarm signal. You guys couldn't see, and me neither, that `all` means "CURRENT INCLUDED". Therefore, excluding current solved the problem.
Comment: How about we all get some glasses
Answer: Change return super.equals((Object)o) && this.role==o.role;, Object.equals tests reference identity (and you know the Objects are unique instances). Also, don't use == for comparing reference types (like String). I think you wanted
return this.role.equals(o.role);

Comment: This solution didn't change a single thing

Java's equals bugging me


Moments of a random variable in terms of its cumulative distribution function

Question: Consider a random variable $X$ with distribution function $F(x)$. Calculate the $r$th moment of $X$, $\mathbb E X^r$. I read that the desired moment can be calculated as follows.
$$
\begin{align}
\mathbb E X^r &= \int_0^\infty x^r dF(x) - \int_0^\infty (-x)^r dF(-x) \\[5pt]
&=r \int_0^\infty x^{r-1} \left[ 1-F(x)+(-1)^rF(-x) \right] dx.
\end{align}
$$
Could anyone explain to me why this is true, please? In addition, when do we need to find the moments in this way? Thank you!
Comment: I need to use this formula in a paper I'm writing. Could you provide the reference where you found it?
Answer: Here's a sketch for the continuous case:
For any nonnegative continuous real random variable $X$ and any integer $r\ge 1$,
$$X^r = \int_0^X rx^{r-1}dx = \int_0^\infty r x^{r-1}[X>x]dx
$$
where
$$[X>x] =
\begin{cases}
1  & \text{if }X>x \\
0  & \text{if }X\le x.
\end{cases}$$
Therefore, using Tonelli's theorem and the fact that $E[X>x] = P(X>x)$,
$$E (X^r) = r \int_0^\infty x^{r-1}P(X>x)dx.
$$
Now, for any continuous random variable $X$ (not necessarily nonnegative), we have $X = Y - Z$, where
$Y=X^+$ and $Z=X^-$ are the positive and negative parts of $X$.
Then, since $YZ = 0$, the Binomial Theorem gives
$$X^r = (Y - Z)^r = Y^r +(-Z)^r
$$
and because both $Y$ and $Z$ are nonnegative random variables,
$$\begin{align}
E(X^r) &= E(Y^r) + (-1)^rE(Z^r)\\
&=r\int_0^\infty y^{r-1}P(Y>y)dy + (-1)^r r\int_0^\infty z^{r-1}P(Z>z)dz\\
&=r\int_0^\infty y^{r-1}P(X>y)dy + (-1)^r r\int_0^\infty z^{r-1}P(X<-z)dz\\
&=r\int_0^\infty x^{r-1}\big(P(X>x) + (-1)^r P(X<-x)\big)dx\\
&=r\int_0^\infty x^{r-1}\big(1-F(x) + (-1)^r F(-x)\big)dx.\\
\end{align}
$$
Answer: As to your question "why" this is necessary, many times it is easy to approximate an empirical distribution with some other theoretical cdf. Then this gives a shortcut to investigating the moments of such a distribution if you don't have the time/patience to derive the pdf and then derive the moments from there.
Also, it gives us general albeit significant insight into the relationship between the moments of a distribution and the cdf, where we are used to only seeing it in terms of the expected value with the pdf.


Some strange things in the db table of mysql database

Question: I noticed some weird things in the db table of mysql database in a client's server, after having the Mysql service stopping for no reason

what are the test, and test_% entries?
Why are there two entries for the database AQUA?
Why is there a entry with a blank name?

Should I worry about any of those? What should I do for each specific case? Is it safe to just delete the ones that should not be there, after backing up?
Answer: Question 1. Please remove the two entries test and test_% immediately. The book "MySQL 5.0 Certification Study Guide" (ISBN 0-672-32812-7) Chapter 35 is about Securing the MySQL Installation. It recommends removing these. Notice that all permissions have Y for test and test_% except Grants_priv. With this, I can do malicious things to a test database or any database that start with 'test_' in its name. Here is an example of something malicious that can be done to a test database:
USE test

CREATE TABLE tb (a INT);

INSERT INTO tb VALUES (1);

INSERT INTO tb SELECT * FROM tb; <<-- Do This 30 times

you have an instant 4GB file.
A malicious person can make many of these in a test database.
Worse yet, in some instances a person with these credentials can login to the test database with no password from a default installation of MySQL.
Conclusion: Remove test user immediately !!!
Question 2. This one is OK
There are two different users that has access to the AQUA database
root@localhost
dbcon@localhost
They have different access privileges.
Just run these commands and see the difference in access privileges
SHOW GRANTS FOR root@localhost;

SHOW GRANTS FOR dbcon@localhost;

Question 3. Remove this one too. The same book reference I made in question 1 also highly recommends removing this also. That entry will allow anonymous users to login against any database. In other words, no user and no password is allowed. Remove this one !!!


Modify the file parameters in plupload

Question: I am using plupload. I cannot find a way to edit the name that the upload script sets for the file I am uploading.
Is there a way to change the file name?
Comment: Looks like it's missing from the doc. Asking of SO is good, fixing the problem is better, no? https://github.com/moxiecode/plupload/issues/666
Answer: You can set the name for upload field using file_data_name option. By default is set to file.

Modify the file parameters in plupload


Can something like $\text{Hom}(V,K)$ be visualised?

Question: I have no trouble visualising vector spaces like $\Bbb R^3$ and (e.g.) a subspace of dimension $2$, which would just be a plane through the origin of a $3$-D space, but I'm having trouble visualising something like "$W°$ is a subspace of $V^*$" when you know that:
$V$ is a vector space,
$W$ is a subspace of $V$,
$W°:=\{f\in V^*:W\subseteq \ker f\}$,
$V^*=\operatorname{Hom}_{_K}(V,K)$.
Even visualising $V^*$ is something I don't understand: it's a collection of functions; so how can it be a vector space?
I have the proof, and I understand it, but it seems impossible to intuitively "see" things like that. Is it even possible?
Comment: The tag "continuous homomorphisms" is nonsense (not only here).
Comment: @MartinBrandenburg Not sure what you mean. Even [here](http://math.stackexchange.com/q/11537/462) or [here](http://homepages.math.uic.edu/~rosendal/PapersWebsite/AutomaticContinuity06.pdf)?
Answer: Since $V^*$ is the initial vector space equipped with a homomorphism $V^* \otimes V \to K$, the question is closely connected to this question about geometric pictures for tensor products. But it also has no full answer yet.
I would suggest the following: If $K=\mathbb{R}$ and $V$ is a finite-dimensional vector space equipped with an inner product $\langle-,- \rangle$ (for example $V=\mathbb{R}^n$ with the standard product), then we may identify $V^*$ canonically with $V$ via $v \mapsto \langle v,-\rangle$. The operation $W \mapsto W^o$ corresponds to the orthogonal complement $W \mapsto W^{\perp}$, for which we have a good geometric picture. We have $W \subseteq W'$ iff $W'^\perp \subseteq W^\perp$, and $\dim(W^\perp)=\dim(V)-\dim(W)$. Thus, $\langle -,- \rangle$ makes it possible to define an "inner duality" of $V$ in the sense that $V$ becomes dual to itsself. For example, lines correspond to hyperplanes.
If $K$ is arbitrary and $V$ is a finite-dimensional vector space over $K$, then we have no canonical duality between $V$ and itsself. But $V$ is dual to another vector space, namely its dual vector space $V^*$ (this also motivates the terminology). Thus, there is a non-degenerate bilinear form $V^* \times V \to K$, namely $(\omega,v) \mapsto \omega(v)$ when you construct $V^*$ as $\hom_K(V,K)$. For $W \subseteq V$ we can still define the orthogonal complement $W^\perp \subseteq V^*$ with respect to this form. These orthogonal complements behave as above. Thus we may borrow our geometric intuition from the inner product case.


Taxonomy Terms based on already created content

Question: Ok I have a client that builds homes in subdivision.  I have created a subdivision and homes content type.  What I want to be able to do is attach homes to subdivisions.
What i want to be able to do is when a subdivision is created, it will automatically be available as either a taxonomy term, or as part of a drop down available when the client is creating a new home.
Is there a way that I can achieve this using the taxonomy module?
Thanks in advanced.
Comment: why you need a subdivision to be available as taxonomy term automatically when creating new node? have you tried to use node reference module [references](http://drupal.org/project/references)
Answer: Instead of using taxonomy term use the following options:
Option 1: References module

This project provides D7 versions of the 'node_reference' and 'user_reference' field types.

Option 2: Entity reference module

Provides a field type that can reference arbitrary entities.


Averaging TIFF images in Matlab?

Question: I'm trying to average 8 TIFF images in Matlab, but I've been unable to get a proper result. If I read in the images and divide by a fixed number (the number of images read), I end up with a very dark image instead of an "average image" with even brightness. The code I used is as follows:
i = 0;
R = 0;
A=imread('1.tif');
B=imread('2.tif');
R = imdivide((imadd(A,B)),2);

for i = 3:8
    TEMP = imadd(R,imread(sprintf('%d.tif' ,i)));
    R = imdivide(TEMP,8);
end

imshow(R);
imwrite(R,'AVG.tif','tif');

Is there any way to fix this averaging scheme?
Thanks!
Comment: I don't understand how you are performing your averaging. You seem to be iteratively adding in a new image and then dividing by two, which does not give a true average. See http://en.wikipedia.org/wiki/Moving_average  (EDIT: see @Richante's answer )
Comment: You're right! I hadn't changed the number I was dividing by! It should be updated now.
Answer: Your problem is that summing the images causes overflow (Richante is correct that imadd uses saturating arithmetic when overflow occurs).  You need to change to a data type capable of holding the sum without loss.
e.g.
A = double(imread('1.tif'));

for i = 2:8
    A = A + double(imread(sprintf('%d.tif' ,i)));
end

...
R = uint8(A / 8);

Of course you need to convert back to whatever the original data type was.
Comment: Also, just for the sake of completeness, I used the following [example](http://www.mathworks.com/help/techdoc/creating_plots/f2-1667.html) to convert my datatypes.
Answer: Might be better to do:
R = imdivide(imread('1.tif'), 8);
for i = 2:8
    R = imadd(R,imdivide(imread(sprintf('%d.tif' ,i)), 8));
end

This will avoid saturation, and will add them in the right way (the way use will be an average strongly weighted in favour of the image 8).
Comment: For my application, it's very important that I do not introduce any error.
Answer: Even easier, suppose that X = [X1; X2; X3... X8] is an array with dimensions (rows,columns,8) in which:
X1 = imread('1.tif');
X1 = double(X1);
...
X = cat(3,X1 X2 X3 X4 X5 X6 X7 X8);
R = mean(X,3);

Where R is the average matrix.

Averaging TIFF images in Matlab?


Rectify Heteroskedasticity in R?

Question: library(lmtest)
library(MASS)
library(car)
library(caret)
x      = rep(1:100)
a      = 10
b      = 2
sigma2_2 = x*10
eps    = rnorm(x, mean=0, sd=sqrt(sigma2_2))
y2      = a+b*x + eps
model2    = lm(y2 ~ x)

sigma2_3 = x^2*10
eps    = rnorm(x,mean=0,sd=sqrt(sigma2_3))
y3      = a+b*x + eps
model3    = lm(y3 ~ x)

par(mfcol=c(1,2))
plot(x,y2,main="mild heteroscedasticity")
abline(coef(model2), col="red")
plot(x,y3,main="severe heteroscedasticity")
abline(coef(model3), col="red")
par(mfcol=c(1,1))

bptest(model2)
bptest(model3)

model2_new <- lm(y2~x, weights = 1/sqrt(x*10))
summary(model2_new)
plot(model2_new)
bptest(model2_new)

model3_new <- lm(y3~x, weights = 1/x)
summary(model3_new)
plot(model3_new)
bptest(model3_new)

y2BCMod <- BoxCoxTrans(y2)
print(y2BCMod)
y2_new=predict(y2BCMod, y2)
Mod2_bc <- lm(y2_new ~ x)
bptest(Mod2_bc)

y3BCMod <- BoxCoxTrans(y3+450)
print(y3BCMod)
y3_new=predict(y3BCMod, y3)
Mod3_bc <- lm(y3_new ~ x)
bptest(Mod3_bc)

I want to compare the box-cox transformation and WLS method in solving the heteroskedasticity problem, but no matter how I simulate the data, it seems the bptest always rejected the null hypothsis. I am confused. Is there a problem in choosing the weights or other problem in my code?
Comment: You are simulating models with strong heteroskedasticity, and the `bptest` rejects the null of homoskedasticity, as it should. What is wrong?  Please extend your post by including plots and some output from your code, and explain where you are surprised.
Comment: Box-Cox doesn't attempt to rectify heteroscedasticity, does it?
Answer: The problem you are going through is the same one I had when reading about this topic in most introductory books.
Most books indicate that WLS will address heteroskedasticity by "eliminating" it from the model. This is technically done by using weights equal to 1 over the source of the heteroskedasticity. The alternative is to transform all data accordingly.
What the books do not mention, but we expect, is for heteroskedasticity to now be eliminated.
It happens to be that only with the transformed model can one obtain this result.
For instance, try the following code
   y2t=y2/(10*x)^.5
xt=x/(10*x)^.5
ct=1/(10*x)^.5
model2_new=lm(y2~x, weights = 1/(x*10))
model2_new2=lm(y2t~0+ct+xt)
summary(model2_new)
summary(model2_new2)
bptest(model2_new)
bptest(model2_new2)

You will see that the one with transformed variables does indeed suggest there is no heteroskedasticity in the model
HTH
Comment: Thank you very much.What if I use robust standard error?Do I need to use bptest after using that?
Comment: That is a completely different approach to address heteroskedasticity. Instead of "correcting" for heteroskedasticity, Robust standard errors "account" for heteroskedasticity by estimating the coefficient standard errors assuming some unknown form of heteroskedasticity.  This means. a) if you do a BPTEST, you will still find heteroskedasticity. b) but your standard errors will be correctly estimated, so that t-stats and F-Stats are valid.
Comment: Also. Generally speaking, the "right" procedure should be: 1. test for heteroskedasticity and 2. if you find evidence of it correct it using WLS or Robust standard errors.

Rectify Heteroskedasticity in R?


How to find what server a web service resides on?

Question: I inherited a project with no documentation and I am now in a spot where I need to update a certain web service.  I have a configuration file that contains the url for the web service:
local.scanner.example.com

But I don't know how to determine what server this is.  I tried pinging the url, but when I do that I get an unfamiliar ip address returned to me.  If I drop the url into my browser, nothing it found.
Can anyone point me in the right direction?
UPDATE:
The url I posted is bogus.  Sorry for the confusion.
Comment: That "unfamiliar IP address is where the service lives.
Comment: bogus urls are fine, but use `example.com` to save confusion
Comment: Ok will do, updated.
Answer: Seems to me that you have to find out some more information.
Sounds like perhaps you're developing an app that needs to connect out to that server?
The whois command can help you find out information about a domain or IP. If you're on Linux, OS X, Solaris, or any kind of UNIX, you probably have access to whois in a terminal session. Otherwise, you can search the web for "whois search" and find plenty of web gateways that will perform the query in your browser.
If the domain you gave is the actual domain indicated by your project, however, you are probably going to hit a dead end. Mysite.com is a hosting provider, and accessing http://local.scanner.mysite.com provides a landing page indicating the domain is not in use. This means that the IP you would get from pinging this domain is at a hosting provider and is going to be of little use in your hunt.
I think your only option is to either see if you can figure out who to contact for more information, or you may end up being forced to code a new web service. Hopefully this wouldn't be the case - ideally, you'd be able to somehow get access to the existing code...
Good luck!
Comment: No I posted a bogus URL, sorry for the confusion.  I have the existing code for the web service and I have updated it.  Now I just need to find the spot to deploy it to. I will let you know if I make any progress
Answer: Sounds like a near-impossible situation but there might be a few things to help you.
Is the address actually local.scanner.mysite.com, or did you use this as an example?  If it is, it's probably used as an example or placeholder.  You'll need to use another method to discover the real value to put here.
If not, then you have a Fully Qualified Domain Name which resolves to an IP address that responds to a ping.  You're trying to locate the physical or virtual machine corresponding to that address.  Is the IP in the private address space?  If it is, find or create a network map and trace the server from the switch port it is connected to.
If it's not a private IP, then use fdmillion's suggestion and use whois on the IP address.  This should give you an organisation name, address and phone number.  Take this information around your company until you find someone who knows something about it - start with the accounts dept :)


Primefaces progressBar is not showing up

Question: This is the code in the body of my .xhtml file. The bars were showing before (I don't remember changing anything significant) but now just the value is displayed.

The second bar is derived from this answer but the problem still remains the same.

This is the code from primefaces, which also does not show up as a bar but just as a value.
I would appreciate it you could clarify if I have some major misunderstanding of how the progressBar works.
Answer: Use Firebug or your browser's WebDevelopment Tools to check if the progressbar is properly rendered:

Check for Javascript Errors
Is the right CSS Style applied or are you overwriting primefaces css classes?
Are you using your own JQuery Version? It can come to conflicts between your JQuery and Primefaces' one.


Issabel-Asterisk- How to handle multi-digit inputs on IVR

Question: I have an Issable server running and integrated with Cisco Call Manager correctly.
I am using Issabel server as my IVR system to answer calls without any direct extension callings.
My Scenario is as below:
When callers call my DID number I have defined IVR which plays fine and ask the user to enter '0' for the operator.
Here is the configuration for the main ivr.
<code>
[ivr-4] ; Main-Menu
include => ivr-4-custom
include => from-did-direct-ivr
exten => s,1,Set(TIMEOUT_LOOPCOUNT=0)
exten => s,n,Set(INVALID_LOOPCOUNT=0)
exten => s,n,Set(_IVR_CONTEXT_${CONTEXT}=${IVR_CONTEXT})
exten => s,n,Set(_IVR_CONTEXT=${CONTEXT})
exten => s,n,Set(__IVR_RETVM=)
exten => s,n,GotoIf($["${CDR(disposition)}" = "ANSWERED"]?skip)
exten => s,n,Answer
exten => s,n,Wait(1)
exten => s,n(skip),Set(IVR_MSG=custom/WelcomeMessage)
exten => s,n(start),Set(TIMEOUT(digit)=3)
exten => s,n,ExecIf($["${IVR_MSG}" != ""]?Background(${IVR_MSG}))
exten => s,n,WaitExten(5,)
exten => 291,1,Set(__IVR_DIGIT_PRESSED=291)
exten => 291,n(ivrsel-291),Goto(ext-miscdests,4,1)

exten => 0,1,Set(__IVR_DIGIT_PRESSED=0)
exten => 0,n(ivrsel-0),Goto(ext-miscdests,3,1)
</code>
The above works fine if the caller enters only one digit, and in my case, this is '0' which works correctly. if the caller enters '291' although the "Direct Dial" option is enabled, the call is not passed to CUCM. In other words, the IVR is only able to understand one digit & if there is more than one digit dialed by the caller, the call drops.
I hope you understand my problem since I am new to VOIP services.
Many thanks and best regards
Answer: it is no difference to enter one digit or multiple in IVR, you should look at trunk settings, maybe your DTMF Mode conflicts with providers. Try different modes.
Answer: Fixed the issue by using an outbound route matching 3digit extensions.


Resolving auto-generated typescript-mongodb types for GraphQL output

Question: I'm using the typescript-mongodb plugin to graphql-codegen to generate Typescript types for pulling data from MongoDB and outputting it via GraphQL on Node.
My input GraphQL schema looks like this
type User @entity{
    id: ID @id,
    firstName: String @column @map(path: "first_name"),
...

The generated output Typescript types look correct
export type User = {
   __typename?: 'User',
  id?: Maybe<Scalars['ID']>,
  firstName?: Maybe<Scalars['String']>,
...

And the corresponding DB object
export type UserDbObject = {
  _id?: Maybe<String>,
  first_name: Maybe<string>,
...

The problem is when actually sending back the mongo document as a UserDbObject I do not get the fields mapped in the output. I could write a custom resolver that re-maps the fields back to the User type, but that would mean I'm mapping the fields in two different places.
i.e. I do not get mapped fields from a resolver like this
  userById: async(_root: any, args: QueryUserByIdArgs, _context: any) : Promise<UserDbObject> => {
    const result = await connectDb().then((db) => {
      return db.collection<UserDbObject>('users').findOne({'_id': args.id}).then((doc) => {
        return doc;
      });
    })
    ...
    return result as UserDbObject;
  }
};

Is there a way to use the typescript-mongodb plugin to only have to map these fields in the schema, then use the auto-generated code to resolve them?
Answer: You can use mappers feature of codegen to map between your GraphQL types and your models types.
See:

https://graphql-code-generator.com/docs/plugins/typescript-resolvers#mappers---overwrite-parents-and-resolved-values
https://graphql-code-generator.com/docs/plugins/typescript-resolvers#mappers-object

Since all codegen plugins are independent and not linked together, you should do it manually, something like:
config:
  mappers:
     User: UserDbObject

This will make typescript-resolvers plugin to use UserDbObject at any time (as parent value, or as return value).
If you wish to automate this, you can either use the codegen programmatically (https://graphql-code-generator.com/docs/getting-started/programmatic-usage), or you can also create a .js file instead of .yaml file that will create the config section according to your needs.


Write a function which removes english stop words from a tweet

Question: I want to write a function that removes English stop words from a tweet.
Function Specifications:

It should take a pandas dataframe as input.
Should tokenise the sentences according to the definition in function 6. Note that function 6 cannot be called within this function.
Should remove all stop words in the tokenised list. The stopwords are defined in the stop_words_dict variable defined at the top of this notebook.
The resulting tokenised list should be placed in a column named "Without Stop Words".
The function should modify the input dataframe.
The function should return the modified dataframe.

Here is the twitter dataframe:
twitter_url = 'https://raw.githubusercontent.com/Explore-AI/Public-Data/master/Data/twitter_nov_2019.csv'
twitter_df = pd.read_csv(twitter_url)
twitter_df.head()

Here are the 'stop_words' in a dictionary:
stop_words_dict = {
    'stopwords':[
        'where', 'done', 'if', 'before', 'll', 'very', 'keep', 'something', 'nothing', 'thereupon',
        'may', 'why', ''s', 'therefore', 'you', 'with', 'towards', 'make', 'really', 'few', 'former',
        'during', 'mine', 'do', 'would', 'of', 'off', 'six', 'yourself', 'becoming', 'through',
        'seeming', 'hence', 'us', 'anywhere', 'regarding', 'whole', 'down', 'seem', 'whereas', 'to',
        'their', 'various', 'thereafter', ''d', 'above', 'put', 'sometime', 'moreover', 'whoever', 'although',
        'at', 'four', 'each', 'among', 'whatever', 'any', 'anyhow', 'herein', 'become', 'last', 'between', 'still',
        'was', 'almost', 'twelve', 'used', 'who', 'go', 'not', 'enough', 'well', ''ve', 'might', 'see', 'whose',
        'everywhere', 'yourselves', 'across', 'myself', 'further', 'did', 'then', 'is', 'except', 'up', 'take',
        'became', 'however', 'many', 'thence', 'onto', ''m', 'my', 'own', 'must', 'wherein', 'elsewhere', 'behind',
        'becomes', 'alone', 'due', 'being', 'neither', 'a', 'over', 'beside', 'fifteen', 'meanwhile', 'upon', 'next',
        'forty', 'what', 'less', 'and', 'please', 'toward', 'about', 'below', 'hereafter', 'whether', 'yet', 'nor',
        'against', 'whereupon', 'top', 'first', 'three', 'show', 'per', 'five', 'two', 'ourselves', 'whenever',
        'get', 'thereby', 'noone', 'had', 'now', 'everyone', 'everything', 'nowhere', 'ca', 'though', 'least',
        'so', 'both', 'otherwise', 'whereby', 'unless', 'somewhere', 'give', 'formerly', ''d', 'under',
        'while', 'empty', 'doing', 'besides', 'thus', 'this', 'anyone', 'its', 'after', 'bottom', 'call',
        'n't', 'name', 'even', 'eleven', 'by', 'from', 'when', 'or', 'anyway', 'how', 'the', 'all',
        'much', 'another', 'since', 'hundred', 'serious', ''ve', 'ever', 'out', 'full', 'themselves',
        'been', 'in', "'d", 'wherever', 'part', 'someone', 'therein', 'can', 'seemed', 'hereby', 'others',
        "'s", "'re", 'most', 'one', "n't", 'into', 'some', 'will', 'these', 'twenty', 'here', 'as', 'nobody',
        'also', 'along', 'than', 'anything', 'he', 'there', 'does', 'we', ''ll', 'latterly', 'are', 'ten',
        'hers', 'should', 'they', ''s', 'either', 'am', 'be', 'perhaps', ''re', 'only', 'namely', 'sixty',
        'made', "'m", 'always', 'those', 'have', 'again', 'her', 'once', 'ours', 'herself', 'else', 'has', 'nine',
        'more', 'sometimes', 'your', 'yours', 'that', 'around', 'his', 'indeed', 'mostly', 'cannot', ''ll', 'too',
        'seems', ''m', 'himself', 'latter', 'whither', 'amount', 'other', 'nevertheless', 'whom', 'for', 'somehow',
        'beforehand', 'just', 'an', 'beyond', 'amongst', 'none', "'ve", 'say', 'via', 'but', 'often', 're', 'our',
        'because', 'rather', 'using', 'without', 'throughout', 'on', 'she', 'never', 'eight', 'no', 'hereupon',
        'them', 'whereafter', 'quite', 'which', 'move', 'thru', 'until', 'afterwards', 'fifty', 'i', 'itself', 'n't',
        'him', 'could', 'front', 'within', ''re', 'back', 'such', 'already', 'several', 'side', 'whence', 'me',
        'same', 'were', 'it', 'every', 'third', 'together'
    ]
}

Here is the code I have tried writing:
def stop_words_remover(df):
    df['With Stop Words'] = df['Tweets'].str.split()
    df['With Stop Words']

    stop_words = stop_words_dict.values()
    stop_words

    df['Without Stop Words'] = df['With Stop Words'].replace(stop_words, '')

    df = df[['Tweets', 'Date', 'Without Stop Words']]

    return df

stop_words_remover(twitter_df.copy())

This is the output i got
TypeError                                 Traceback (most recent call last)
C:\Users\DATASC~1\AppData\Local\Temp/ipykernel_5696/4217028502.py in <module>
     15
     16
---> 17 stop_words_remover(twitter_df.copy())
     18 ### END FUNCTION

C:\Users\DATASC~1\AppData\Local\Temp/ipykernel_5696/4217028502.py in stop_words_remover(df)
      4     stop_words = stop_words_dict.values()
      5
----> 6     df['Without Stop Words'] = df['With Stop Words'].replace(stop_words, '', stop_words())
      7
      8     df = df[['Tweets', 'Date', 'Without Stop Words']]

TypeError: 'dict_values' object is not callable

This is the expected output

stop_words_remover(twitter_df.copy())
       Tweets                                           Date                 Without Stop Words
0   @BongaDlulane Please send an email to mediades...   2019-11-29 12:50:54 [@bongadlulane, send, email, firstname.lastname@example.com...
1   @saucy_mamiie Pls log a call on 0860037566          2019-11-29 12:46:53 [@saucy_mamiie, pls, log, 0860037566]
2   @BongaDlulane Query escalated to media desk.        2019-11-29 12:46:10 [@bongadlulane, query, escalated, media, desk.]
3   Before leaving the office this afternoon, head...   2019-11-29 12:33:36 [leaving, office, afternoon,, heading, weekend...
4   #ESKOMFREESTATE #MEDIASTATEMENT : ESKOM SUSPEN...   2019-11-29 12:17:43 [#eskomfreestate, #mediastatement, :, eskom, s...
... ... ... ...
195 Eskom's Visitors Centres' facilities include i...   2019-11-20 10:29:07 [eskom's, visitors, centres', facilities, incl...
196 #Eskom connected 400 houses and in the process...   2019-11-20 10:25:20 [#eskom, connected, 400, houses, process, conn...
197 @ArthurGodbeer Is the power restored as yet?        2019-11-20 10:07:59 [@arthurgodbeer, power, restored, yet?]
198 @MuthambiPaulina @SABCNewsOnline @IOL @eNCA @e...   2019-11-20 10:07:41 [@muthambipaulina, @sabcnewsonline, @iol, @enc...
199 RT @GP_DHS: The @GautengProvince made a commit...   2019-11-20 10:00:09 [rt, @gp_dhs:, @gautengprovince, commitment, e...

Please can someone help me?

Comment: Try this instead of `dict.values`:  `stop_words = stop_words_dict['stopwords']`
Comment: okay i have tried this and it doesn't return the error anymore but returns a dataframe with the stop words still in it
Comment: That's because `replace` doesn't work that way. It needs to find an exact match of the word - both for `from` and `to`.
Comment: You might also need to add `df['With Stop Words'] = df['With Stop Words'].apply(str)` so that each string is stringified with quotes in order to find and replace.
Answer: there a simple way to do this in a single command using apply lambda:
twitter_df["Tweets"].apply(lambda x: " ".join([word for word in x.split() if word not in stop_words_dict["stopwords"]]))

If you prefer create a function to do this, the function could be:
def remove_stop_words(tweet, stop_words_dict):
    sentence = tweet.split()
    output = []
    for word in sentence:
        if word not in stop_words_dict["stopwords"]:
            output.append(word)
    return " ".join(output)

twitter_df["Tweets"].apply(lambda x: remove_stop_words(x, stop_words_dict))

Comment: thanks this works perfectly well, very much appreciated
Comment: Welcome Jeremiah, please, consider to mark my answer as resolved? This stimulates my work.


How to speed up insertion performance in PostgreSQL

Question: I am testing Postgres insertion performance. I have a table with one column with number as its data type. There is an index on it as well. I filled the database up using this query:
insert into aNumber (id) values (564),(43536),(34560) ...

I inserted 4 million rows very quickly 10,000 at a time with the query above. After the database reached 6 million rows performance drastically declined to 1 Million rows every 15 min. Is there any trick to increase insertion performance? I need optimal insertion performance on this project.
Using Windows 7 Pro on a machine with 5 GB RAM.
Comment: It's worth mentioning your Pg version in questions too. In this case it doesn't make tons of difference, but it does for a lot of questions.
Comment: drop the indexes on the table and triggers if any and run the insert script. Once you have completed the bulk load you can recreate the indexes.
Answer: See populate a database in the PostgreSQL manual, depesz's excellent-as-usual article on the topic, and this SO question.
(Note that this answer is about bulk-loading data into an existing DB or to create a new one. If you're interested DB restore performance with pg_restore or psql execution of pg_dump output, much of this doesn't apply since pg_dump and pg_restore already do things like creating triggers and indexes after it finishes a schema+data restore).
There's lots to be done. The ideal solution would be to import into an UNLOGGED table without indexes, then change it to logged and add the indexes. Unfortunately in PostgreSQL 9.4 there's no support for changing tables from UNLOGGED to logged. 9.5 adds ALTER TABLE ... SET LOGGED to permit you to do this.
If you can take your database offline for the bulk import, use pg_bulkload.
Otherwise:

Disable any triggers on the table

Drop indexes before starting the import, re-create them afterwards. (It takes much less time to build an index in one pass than it does to add the same data to it progressively, and the resulting index is much more compact).

If doing the import within a single transaction, it's safe to drop foreign key constraints, do the import, and re-create the constraints before committing. Do not do this if the import is split across multiple transactions as you might introduce invalid data.

If possible, use COPY instead of INSERTs

If you can't use COPY consider using multi-valued INSERTs if practical. You seem to be doing this already. Don't try to list too many values in a single VALUES though; those values have to fit in memory a couple of times over, so keep it to a few hundred per statement.

Batch your inserts into explicit transactions, doing hundreds of thousands or millions of inserts per transaction. There's no practical limit AFAIK, but batching will let you recover from an error by marking the start of each batch in your input data. Again, you seem to be doing this already.

Use synchronous_commit=off and a huge commit_delay to reduce fsync() costs. This won't help much if you've batched your work into big transactions, though.

INSERT or COPY in parallel from several connections. How many depends on your hardware's disk subsystem; as a rule of thumb, you want one connection per physical hard drive if using direct attached storage.

Set a high max_wal_size value (checkpoint_segments in older versions) and enable log_checkpoints. Look at the PostgreSQL logs and make sure it's not complaining about checkpoints occurring too frequently.

If and only if you don't mind losing your entire PostgreSQL cluster (your database and any others on the same cluster) to catastrophic corruption if the system crashes during the import, you can stop Pg, set fsync=off, start Pg, do your import, then (vitally) stop Pg and set fsync=on again. See WAL configuration. Do not do this if there is already any data you care about in any database on your PostgreSQL install. If you set fsync=off you can also set full_page_writes=off; again, just remember to turn it back on after your import to prevent database corruption and data loss. See non-durable settings in the Pg manual.

You should also look at tuning your system:

Use good quality SSDs for storage as much as possible. Good SSDs with reliable, power-protected write-back caches make commit rates incredibly faster. They're less beneficial when you follow the advice above - which reduces disk flushes / number of fsync()s - but can still be a big help. Do not use cheap SSDs without proper power-failure protection unless you don't care about keeping your data.

If you're using RAID 5 or RAID 6 for direct attached storage, stop now. Back your data up, restructure your RAID array to RAID 10, and try again. RAID 5/6 are hopeless for bulk write performance - though a good RAID controller with a big cache can help.

If you have the option of using a hardware RAID controller with a big battery-backed write-back cache this can really improve write performance for workloads with lots of commits. It doesn't help as much if you're using async commit with a commit_delay or if you're doing fewer big transactions during bulk loading.

If possible, store WAL (pg_wal, or pg_xlog in old versions) on a separate disk / disk array. There's little point in using a separate filesystem on the same disk. People often choose to use a RAID1 pair for WAL. Again, this has more effect on systems with high commit rates, and it has little effect if you're using an unlogged table as the data load target.

You may also be interested in Optimise PostgreSQL for fast testing.
Comment: @CraigRinger I've tested RAID-5 vs RAID-10 with SSD's on a Perc H730. RAID-5 is actually faster. Also it might be worth noting that insert/transactions in combination with large bytea's seems to be faster than copy. Overall good advice though.
Comment: Anyone is seeing any major speed improvements with `UNLOGGED`? A quick test shows something like 10-20% improvement.
Comment: Would you agree that the write penalty from RAID 5/6 is somewhat mitigated if good quality SSDs are used? Obviously there is still a penalty, but I think the difference is far less painful than it is with HDDs.
Comment: I haven't tested that. I'd say it's probably less bad - the nasty write amplification effects and (for small writes) need for a read-modify-write cycle still exist, but the severe penalty for excessive seeking should be a non-issue.
Comment: Can we just disable indexes instead of dropping them, for example, by setting `indisvalid` (http://www.postgresql.org/docs/8.3/static/catalog-pg-index.html) to false, then load data and  then bring indexes online by `REINDEX`?
Comment: @FractalizeR Unfortunately it's not that simple. I really don't recommend that approach.
Comment: @CraigRinger Can you please elaborate? Not that I am going to do that, I'm just curious. My current approach is to find (https://gist.github.com/FractalizeR/6c4fd1433611484e6c05), drop and then recreate all indexes.
Comment: @CraigRinger - A related Q, I am inserting about 30 million records. I am inserting this using INSERT into target select * from source. All this is wrapped inside a function. Is COPY likely to improve the performance?
Comment: @Jayadevan `COPY` won't help you for moving data around within the DB, it's for import/export. `INSERT INTO ... SELECT ...` is as good as you are likely to get without going parallel across multiple connections with all the attendant hassle, lack of atomic commit, etc.
Comment: OK. Since many threads about improving performance of inserts suggested COPY, I thought may be COPY has some optimization for bulk data processing. So I tried COPYing data from source to file and COPYing from file target. It did not reduce the load time. I just wanted to confirm I did not miss anything. Thanks.
Comment: @CraigRinger I know this answer is really old, but people are reading this and thinking they can make `COPY` faster by disabling table logging, or setting on asynchronous commits. Could you please clarify in your answer what these optimizations bring to `COPY` and `INSERT`, so people don't think that this speeds up everything magically.
Comment: Async commit won't help with `COPY`; as I said above "this won't help much if you've batched your work into big transactions, though." Using `UNLOGGED` tables _will_, though with the expected safety costs.
Comment: I asked a question here, may be interested in it http://dba.stackexchange.com/q/160807/2639
Comment: @serg It depends on your storage performance: whether WAL and the main tablespace are on different volumes/disks, how good your storage is at concurrent I/O, and a number of other factors. There are non-speed advantages too like reducing AWS EBS iops charges and pool depletion, reducing size of WALs archived for point-in-time recovery / streaming replication data sizes, etc.
Comment: There is a limit for making really big transaction, actually. It's 2^32-2 commands per transaction, and I met this condition once (thanks, osmosis!).
Comment: This answer is likely a good candidate for a topic somewhere under https://stackoverflow.com/documentation/postgresql/topics
Comment: I'm using the hibernate-PostgreSQL stack, but from documents over the internet, it says batch insert will not increase performance if there are related table insertions.How can we handle those cases?
Comment: "documents on the Internet". Links?
Comment: What about removing primary key constraints? These have an index associated with them, so must also result in extra work during an import?
Comment: @CraigRinger: One nitpick regarding: "Use synchronous_commit=off and a huge commit_delay".  Just synchronous_commit=off is enough since   "commit_delay is ignored during an asynchronous commit" Source: https://www.postgresql.org/docs/9.5/static/wal-async-commit.html
Answer: I spent around 6 hours on the same issue today. Inserts go at a 'regular' speed (less than 3sec per 100K) up until to 5MI (out of total 30MI) rows and then the performance sinks drastically (all the way down to 1min per 100K).
I will not list all of the things that did not work and cut straight to the meat.
I dropped a primary key on the target table (which was a GUID) and my 30MI or rows happily flowed to their destination at a constant speed of less than 3sec per 100K.
Comment: You don't have to drop the primary key, as there is another solution: partitions.
If you will create partitioned table, in that case you will have smaller indexes per partition, and because of that insertion speed will be high. Also it simplifies and speed up the deletion of the old data.
Comment: This helped me a lot
Comment: @Dennis so the table you are joining on or grabbing data from doesn't matter, only the table you INSERT INTO?  I definitely just tried this and it is much faster WOW thanks
Answer: Use COPY table TO ... WITH BINARY which is according to the documentation "is somewhat faster than the text and CSV formats." Only do this if you have millions of rows to insert, and if you are comfortable with binary data.
Here is an example recipe in Python, using psycopg2 with binary input.
Comment: Binary mode can be a big time saving on some inputs, such as timestamps, where parsing them is nontrivial. For many data types it doesn't offer much benefit or is can even be slightly slower due to increased bandwidth (e.g. small integers). Good point raising it.
Comment: Does anyone know how much this is relevant for inserting JSON data into `json` or `jsonb` columns?
Answer: In addition to excellent Craig Ringer's post and depesz's blog post, if you would like to speed up your inserts through ODBC (psqlodbc) interface by using prepared-statement inserts inside a transaction, there are a few extra things you need to do to make it work fast:

Set the level-of-rollback-on-errors to "Transaction" by specifying Protocol=-1 in the connection string. By default psqlodbc uses "Statement" level, which creates a SAVEPOINT for each statement rather than an entire transaction, making inserts slower.
Use server-side prepared statements by specifying UseServerSidePrepare=1 in the connection string. Without this option the client sends the entire insert statement along with each row being inserted.
Disable auto-commit on each statement using SQLSetConnectAttr(conn, SQL_ATTR_AUTOCOMMIT, reinterpret_cast<SQLPOINTER>(SQL_AUTOCOMMIT_OFF), 0);
Once all rows have been inserted, commit the transaction using SQLEndTran(SQL_HANDLE_DBC, conn, SQL_COMMIT);. There is no need to explicitly open a transaction.

Unfortunately, psqlodbc "implements" SQLBulkOperations by issuing a series of unprepared insert statements, so that to achieve the fastest insert one needs to code up the above steps manually.
Comment: Large socket buffer size, `A8=30000000` in connection string should also used to speed up inserts.
Answer: If you happend to insert colums with UUIDs (which is not exactly your case) and to add to @Dennis answer (I can't comment yet), be advise than using gen_random_uuid() (requires PG 9.4 and pgcrypto module) is (a lot) faster than uuid_generate_v4()
=# explain analyze select uuid_generate_v4(),* from generate_series(1,10000);
                                                        QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
 Function Scan on generate_series  (cost=0.00..12.50 rows=1000 width=4) (actual time=11.674..10304.959 rows=10000 loops=1)
 Planning time: 0.157 ms
 Execution time: 13353.098 ms
(3 filas)

vs

=# explain analyze select gen_random_uuid(),* from generate_series(1,10000);
                                                        QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------
 Function Scan on generate_series  (cost=0.00..12.50 rows=1000 width=4) (actual time=252.274..418.137 rows=10000 loops=1)
 Planning time: 0.064 ms
 Execution time: 503.818 ms
(3 filas)

Also, it's the suggested official way to do it

Note
If you only need randomly-generated (version 4) UUIDs, consider using the gen_random_uuid() function from the pgcrypto module instead.

This droped insert time from ~2 hours to ~10 minutes for 3.7M of rows.
Answer: For optimal Insertion performance disable the index if that's an option for you. Other than that, better hardware (disk, memory) is also helpful
Answer: I encountered this insertion performance problem as well. My solution is spawn some go routines to finish the insertion work. In the meantime, SetMaxOpenConns should be given a proper number otherwise too many open connection error would be alerted.
db, _ := sql.open()
db.SetMaxOpenConns(SOME CONFIG INTEGER NUMBER)
var wg sync.WaitGroup
for _, query := range queries {
    wg.Add(1)
    go func(msg string) {
        defer wg.Done()
        _, err := db.Exec(msg)
        if err != nil {
            fmt.Println(err)
        }
    }(query)
}
wg.Wait()

The loading speed is much faster for my project. This code snippet just gave an idea how it works. Readers should be able to modify it easily.
Comment: Well, you can say that. But it does reduce the running time from a few hours to several minutes for millions of rows for my case. :)


Como fazer uma regex que ignore caracteres não-alfanuméricos?

Question: Por exemplo:uma regex que ache correpondencia na string "moeda" mas que também ache correspondencia na string (m,.o,e.d...a). Ou seja ela ignora caracteres não alfanuméricos independente da posição ou da quantidade.
OBS:JA SEI FAZER DA SEGUINTE FORMA MAS A IDÉIA É SÓ DIGITAR 1 VEZ.
 #=\W*

m#o#e#d#a
Comment: É uma string apenas ou quer capturar múltiplas palavras em uma string e separa-las?
Answer: Se entendi com o termo "capturar", o que você quer é remover os caracteres não alfanuméricos, use replace, a regex de negação deve ser assim:
[^a-z0-9]

O sinal de ^ dentro de [...] faz negar qualquer caractere, então o replace vai remover todos que não são os que tiverem dentro [^....]
Em JavaScript deve usar com o modificador global chamado /.../g e com o /.../i se necessitar de case-insensitive, exemplo:

var str = "m,.o,e.d...a";
var resposta = str.replace(/[^a-z0-9]/gi, "");
console.log(resposta);

Em PHP seria assim, com preg_replace:
$str = "m,.o,e.d...a";
$resposta = preg_replace('#[^a-z0-9]#', '', $str);

var_dump($resposta);

Exemplo online no ideone
Nota:
É importante perceber que se quiser adicionar mais caráteres para não serem removidos, como espaços, basta adicionar dentro de [^....], exemplo que "captura" os alfanumericos e espaços:

var str = "m,.o,e.d...a ,.n,.a,. ,.,.c,.a,.r,.t,.e,.i,.r,.a";
var resposta = str.replace(/[^a-z0-9\s]/gi, "");
console.log(resposta);

Capturar em um array
Se de fato você quer capturar, então o correto é usar .match em JavaScript e preg_match em PHP, a regx também mudaria, para algo um pouco mais complexo, considerando que é uma string com diferentes palavras e você queira capturar todas, então tem que ser algo assim:
(^|\s)([a-z0-9]*[^\s]*)(\s|$)

Exemplo em JavaScript:

var str = "m,.o,e.d...a ,.n,.a,. ,.,.c,.a,.r,.t,.e,.i,.r,.a";
var respostas = str.match(/(^|\s)([^\s]+?)(\s|$)/gi, "");
var allowAN = /[^a-z0-9]/gi;

for (var i = 0, j = respostas.length; i < j; i++) {
    respostas[i] = respostas[i].trim().replace(allowAN, "");
}

console.log(respostas);
Answer: Use apenas \w+ isso vai casar todos os caracteres no intervalode e A-Za-z0-9 uma ou mais vezes.
console.log('m#o#e#d#a'.match(/\w+/g));
console.log('m,.o,e.d...a'.match(/\w+/g));

Comment: a questão é que eu quero capturar uma determinada string, não genérica, ou seja, eu quero que ele capture a sequencia m-o-e-d-a independente de caracteres alfa-numéricos entre os digitos.
Comment: @FelipePadilha vc está usando alguma linguagem ou editor de texto especifico?
Answer: Utilize essa expressão regular:
[0-9a-zA-Z]

Teste aqui
Comment: a questão é que eu quero capturar uma determinada string, não genérica, ou seja, eu quero que ele capture a sequencia m-o-e-d-a independente de caracteres alfa-numéricos entre os digitos.
Comment: @FelipePadilha você quer dizer caracteres NÃO alfa-numéricos certo?
Comment: @FelipePadilha por exemplo: em uma string "mKoKeKdKa" não deve dar match, porém em uma string como "$m!o#e@d(a" deve dar match certo?
Comment: sim, caracteres não-alfanumericos, perdão
Answer: Não tenho a certeza se entendi o pedido, mas
var s="m.o...e,!d--a";
console.log(s.replace(/\W/g,"").match(/moeda/) ? "y":"n")

(ou seja, retirar primeiro os "não letra" e depois procurar "moeda") pode
ser usado para detetar se uma string contem "moeda".
Answer: Não é possível fazer o que você quer utilizando regex.
Em uma expressão regular você deve designar o que quer encontrar através de uma sequencia lógica de tokens e quantifiers.
No seu caso você quer buscar uma sequencia determinada, porém não quer utilizar quantifiers e nem os tokens para ignorar o que está entre a sequencia (como mencionou no comentário dessa resposta)
Ou seja, o único jeito para isso seria adicionando uma flag global na regex como \x (que ignora espaços em branco nas buscas), entretanto não existe tal flag para o seu caso, pois o resultado que você quer alcançar pode ser obtido através de tokens e quantifiers, eliminando a necessidade de criação de uma flag pra isso.
O resultado que você quer pode ser obtido somente através dessa RegEx:
(m\W*o\W*e\W*d\W*a)

Você pode testa-la aqui
Explicação

() Representa o grupo de captura que sua regex irá retornar caso a condição for satisfeira
m  é o caractere que deve ser encontrado primeiro para iniciar o "match" da regex
\W*representa que pode haver entre 0 e infinitos caracteres que sejam não-alfanuméricos
o outro caractere que deve estar após o "m" para que a condição seja satisfeita
\W* tem o mesmo efeito do anterior
e assim segue a regex até que encontre e d e a mesmo que contenham caracteres não-alfanuméricos entre eles
Comment: infelizmente não há outro jeito de se chegar a isso, não existe nenhum flavour de regex que contenha uma flag global que mude o método de busca como você quer, você pode ler a minha explicação na resposta para ter uma noção melhor do porque @FelipePadilha
Comment: Sim, dessa forma dá certo, mas eu queria uma forma que eu não tenha que digitar entre todo caracter alfanumérico, a idéia era digitar somente uma vez
Comment: @FelipePadilha não entendi, o que você não quer digitar?
Comment: não quero ter de digitar \W*, ou este grupo nomeado, entre todo caracter não alfa numérico
Comment: entre todo caraccter *alfa numérico


Setting default text in WYMEDITOR

Question: I've got a question about using WYMEditor in ASP.NET MVC 3 with jQuery. I'd like to set default text in WYMEditor on my web page. If I'm doing in that way :

And please get rid of this ViewBag as everytime I see it I get sick. Use view models and strongly typed views.
Comment: I've got different view model for it, but this is only quick example. Thx a lot.
Comment: @jacbar, in this case maybe you could consider [marking this as answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work), unless of course you have some issues with it and it wasn't helpful to you.
Comment: I tried to vote up, but without 15 points of reputation I can't

Setting default text in WYMEDITOR


Proof by induction using summation

Question: I'm trying to figure out how to solve this equation by induction and I really don't know where to begin. I have seen some YouTube tutorials, but can't understand how I can go from $k(k+1)$ to $n+1$ in the equation. The task is:
Use induction to show that:
$$\sum_{k=1}^{n} {1 \over k(k+1)} = {n \over n+1}$$
Can someone help me solve this equation? Or give me some tips for where to start? I would really appreciate it.
Thanks in advance!
Comment: Induction aside, familiar with telescoping?
Answer: To prove this you would first check the base case $n = 1$. This is just a fairly straightforward calculation to do by hand.
Then, you assume the formula works for $n$. This is your "inductive hypothesis". So we have
\begin{equation*}
 \sum_{k = 1}^n \frac 1{k(k + 1)} = \frac n{n + 1}.
\end{equation*}
Now we can add $\frac 1{(n + 1)(n + 2)}$ to both sides:
\begin{align*}
 \sum_{k = 1}^{n + 1} \frac 1{k(k + 1)}
  &= \frac n{n + 1} + \frac 1{(n + 1)(n + 2)} \\
  &= \frac{n(n + 2) + 1}{(n + 1)(n + 2)} \\
  &= \frac{(n + 1)^2}{(n + 1)(n + 2)} \\
  &= \frac{(n + 1)}{(n + 1) + 1}
\end{align*}
But this is exactly the same formula again, just with $n$ replaced by $n + 1$. So if the formula works for $n$, it also works for $n + 1$. And then, by induction, we are done.
Answer: The hint is
$$
\sum_{k=1}^{n+1}\frac{1}{k(k+1)}
=\biggl(\,\sum_{k=1}^n\frac{1}{k(k+1)}\biggr)+\frac{1}{(n+1)(n+2)}
$$
which should equal
$$
\frac{n+1}{n+2}
$$
Answer: Define the hypothesis $H_n$ as $$H_n : \sum_{k = 1}^n \frac{1}{k(k+1)} = \frac{n}{n+1} $$
For $n = 1$, we have LHS = $\sum \limits_{k = 1}^1 \frac{1}{k(k+1)} = \frac{1}{2} $ and RHS = $\frac{1}{1 + 1} = \frac{1}{2} $ so $H_1$ is true.
Now suppose $H_m$ is true for some integer $m \geq 1$, that is, we have $\sum \limits_{k = 1}^m\frac{1}{k(k+1)} = \frac{m}{m+1}$ as a given.
Then, consider $$\sum_{k  = 1}^{m+1} \frac{1}{k(k+1)}$$
$$= \frac{1}{ (m+1)(m + 2)} + \sum_{k=1}^m \frac{1}{k(k+1)}$$
By induction hypothesis, we have:
$$ = \frac{1}{ (m+1)(m + 2)} + \frac{m}{m+1}$$
$$ = \frac{1 + m(m+2)}{(m+1)(m+2)}$$
$$ = \frac{(m+1)^2}{(m+1)(m+2)}$$
$$ = \frac{m+1}{(m + 1) + 1}$$
Therefore, $$\sum_{k=1}^{m+1} \frac{1}{k(k+1)} =  \frac{m+1}{(m + 1) + 1} $$
So $H_m \implies H_{m+1}$
Since we had $H_1$ true, by induction, $H_n$ is true for all integers $n \geq 1$

Proof by induction using summation


Destroy clone prefab

Question: I have a problem. In a scene I have a list and when I click on it shows me with some clones prefab the contents of the database. The point is that once generated, no matter how much I select another item from the list, the prefabs do not update me and show the contents of the first selection. I've tried to destroy them. But the most I've managed to do is destroy the original prefab and don't believe me anymore. How can I fix this?
<code>public Transform contentParent;
public List<TablePlayerTransctData> playersTransct;
public GameObject playerTransactItemPrefab;
private Models.Club _club;
public TextMeshProUGUI memberUuid;

public void Start()
{
    GetTablePlayerTransactRequest();
}

private void GetTablePlayerTransactRequest()
{
    _club = TablesManager.Instance.club;

    new LogEventRequest().SetEventKey("Transactions")
        .SetEventAttribute("clubId", _club.id)
        .SetEventAttribute("playerId", memberUuid.text)
        .Send(GetTablePlayerTransactResponse);
}

private void HandleResults()
{
    var cont = 0f;

    Vector3 posicion = new Vector3();

    foreach (TablePlayerTransctData data in playersTransct)
    {
        GameObject item = Instantiate(playerTransactItemPrefab, contentParent);
        PlayerTransact playerTableTransact = item.GetComponent<PlayerTransact>();

        if (cont == 0)
        {
            posicion = playerTableTransact.transform.position;
        }
        else
        {
            posicion.Set(posicion.x, (posicion.y) - 0.5f, posicion.z);
            playerTableTransact.transform.position = posicion;
        }

        playerTableTransact.Setup(data);

        cont++;
    }
}

private void GetTablePlayerTransactResponse(LogEventResponse response)
{
    if (response.HasErrors)
    {
        return;
    }

    GSData scriptData = response.ScriptData;
    var list = scriptData.GetGSDataList("list");
    playersTransct = new List<TablePlayerTransctData>();

    foreach (GSData entry in list)
    {
        TablePlayerTransctData data = new TablePlayerTransctData()
        {
            chips = GSUtil.GetInt(entry, "chips"),
            date = GSUtil.GetDouble(entry, "date"),
        };

        playersTransct.Add(data);
    }

    HandleResults();
}

public class TablePlayerTransctData
{
    public int chips;
    public double date;
}
</code>
I think these prefabs should be reset or removed just before they are re-created. But I don't know how to do this or maybe there's another, more correct way to do it.
Edit:
I changed Start to Update and magically works almost as it should. I don't understand what this miracle is like. Since with starting every time you enter you should cool off on your own. Now all that remains is to remove the leftover prefabs which is what I don't finish doing properly.
Comment: you are only showing how you generate the prefabs, all the select and update stuff where the problem seems to be is not exposed in the question
Comment: he added all the code
Comment: Please use the correct tags! Note that `unityscript` is or better **was** a JavaScript flavor like custom language used by early Unity versions and is long **deprecated** by now! You code is clearly in `c#`
Comment: Ok derHugo, thx
Answer: Before instantiating the new items you could destroy them all like e.g.
<code>// General hint: Make this of the correct type
// - Makes sure that the referenced prefab actually HAS that component
// - Gets rid of some GetComponent calls later since Instantiate already
//   returns the same type as the given prefab has
public PlayerTransact playerTransactItemPrefab;

foreach(Transform child in contentParent)
{
    Destroy(child.gameObject);
}

foreach (var data in playersTransct)
{
    PlayerTransact item = Instantiate(playerTransactItemPrefab, contentParent);
    ...
}
</code>

Alternatively you could of course only create the amount of objects you need and destroy others and instead of destroying and recreating all of them reuse those that already exists like e.g.
<code>// cache the counts
var childCount = contentParent.childCount;
var dataCount = playersTransct.Count;
// we want to iterate the count that is greater
var count = Mathf.Max(childCount, dataCount);

for (var i = 0; i < count; i++)
{
    if (i < dataCount)
    {
        // there is data for this index
        var data = playersTransct[i];

        // so we need a child for it
        PlayerTransact playerTableTransact;

        if (i < childCount)
        {
            // We are still in the range of existing childs -> Re-use a child that already exists
            playerTableTransact = contentParent.GetChild(i).GetComponent<PlayerTransact>();
            posicion = playerTableTransact.transform.position;
        }
        else // i < dataCount && i >= childCount
        {
            // There is still data but no childs left -> create a new one now
            playerTableTransact = Instantiate(playerTransactItemPrefab, contentParent);

            if (i == 0)
            {
                posicion = playerTableTransact.transform.position;
            }
            else
            {
                posicion -= Vector3.up * 0.5f;
                playerTableTransact.transform.position = posicion;
            }
        }

        playerTableTransact.Setup(data);
    }
    else // i < childCount && i >= dataCount
    {
        // There are more childs than data -> destroy the unneeded childs
        Destroy(contentParent.GetChild(i).gameObject);
    }
}
</code>
Comment: I've tried the two codes, but I'm eliminated by the father prefab and it leaves me the invisible clones. I've been told by a colleague, who could make a second list where to save the created objects and remove them from the list before generating new ones. But I don't know very well what you mean.
Comment: In the end, the first solution has helped me. Thx

Destroy clone prefab