Implementing Convolutional Neural Network - Problems

Question: Recently I have started to implement my own Convolutional Neural Network. I have few questions. I will talk with reference to an example, so that we all remain on the same page. Suppose,
input: 64X64X1 that is gray-channel only.------------Output - 64X64X1
C1: 5X5X6 that is 6 conv_maps, each of size 5X5-Output - 60X60X6
P1: Max-Pooling - non_overlapping size = 2X2--Output - 30X30X6
C2: 9X9X8 - 8 conv_maps, each of size 9X9--------Output - 22X22X48//Subject_To_Change
P2: Max-Pooling - Non_overlapping size = 2X2--Output - 11X11X48//Subject_To_Change
Ok, Now following are the questions:

ReLU

As I understand, ReLU is applied to every neuron. That is, in C1,
first time 5X5 patch is moved over input - Then the sum of
convolution has to pass through transform_function. And no transform_function at Pooling layer. Am I correct in understanding it?
Which function to use as transfer_function?Softplus? Noisy one? Leaky one?
Also, same transfer function should be used for FeedForward part, right? Or can I change to sigmoid there?

Convolution-Feature_Map Connections

How to carry out next convolution? The P1 layer has 6 maps of 30X30. There are going to be 8 convolutional kernels, each of size 9X9. But I have NEVER seen this producing 6*8 maps. Specifically, LeNet has output of 16 maps. How to produce those maps is given in this paper on page 8. After reading it again and again I DO NOT get how to generate next feature maps. Are they doing it like this -->
Also, isn't the method mentioned in the paper specific to 'OCR'? I am very confused about how to write program for them in a user-friendly way. For e.g. if I want to see the output of different architecture, how to define these rules of connections programmatically?
I definitely did not understand "It forces a break of symmetry .." thing from the above mentioned paper. Please if you could elaborate. I am not able to visualize problem of symmetry here.

About Bias

Initially I thought bias as a window of kernel size, but now I think its just a number between 0-1. But How do I add a bias? If I treat kernel as a matrix, say 5X5, then how possibly I can add a single number to matrix? We get the sum after the convolution, I think I am supposed to add the bias to this sum and then apply the transform function. Right?
Answer: Convolution with a kernel is done on all input maps and their summation is taken. In the input layer it is obvious since there is only one feature (input map). However, after first convolution, the later comvolutions are summuation of kernel operation on all feature maps. Hence, instead of 48 output feature map at C2, there should be 8 maps. this link explains the network and its back-prop in a clear way.
Use $ f(x) = max(0,x)$ as activation(transform) function. After successful implementation, you can use the others too. You should use the same function for both 'feedforward' and 'back-prop'.
I haven't read the paper, but breaking symmetry is about selecting weight from a random distribution. If the weights are the same on feature maps, back propagated error will be the same. As a result network learns the same filters which is not desirable.
Rule of connections are already defined as mathematical expressions. The number of kernels, number of layers, kernelsize etc. should be defined symbolically and they sould be assigned in main section of the code.
You should add bias before applying activation function. A single bias, most commonly used, is added to feature map. Summing a scalar with a matrix is simply adding the scalar at each indexes of the matrix.
If you didn't write a code for NN before, It would be better to start with it.


dynamic taging node with keywords(terms) is body

Question: I have some vocabulary and I want to tag the content automatically  with  keywords types in body of content.
Example my body is :
"Drupal is lovely content management system that provide good api to developer"
and
Drupal,content management system are in vocabulary1
api,developer are in vocabulary2
How can I extract my vocabulary tags auto from body of contents?
Comment: There is a Hashtags module (http://drupal.org/project/hashtags) that does this if you enter things like #drupal, so, while it doesn't do exactly what you want, it might be a good start for some custom coding on your behalf.
Comment: As mentioned, it might be a good start for some custom coding as the mechanics of adding taxonomy terms based upon text in the body are in that module.  So, with that already written, you could cycle through your various vocabularies and their terms looking for matches and then when found, creating links, applying the terms, etc, using already written code.  Just realize that natural language is pretty difficult to codify.  Eg, what do you do when you find `Drupal` and `Drupal Content Management System` and have both as terms and come across the `Drupal` term first.  Just lots to think about.
Comment: But it is more limitation , like cant tag 2 word(separated by space) terms
Comment: Give me few minutes to time travel. I'm sure I've done this before.
Answer: You can do this by writing a custom module that analyzes the node content in a hook_node_presave hook and check if the terms from a particular vocabulary is present in the node.
I created a small custom module that just works if you enter the correct parameters.
https://github.com/Ayesh/drupal-node-auto-tag
Download a tarball or clone it, and set the node type, field names and vocabulary ID in top of the .module and enable the module.
Good luck!
Comment: you tell analyzes node content, but you suppose that node have 5000 word,how you parse word? did you method efficient?
Comment: It doesn't really analyze the content to an algorithm. It just gets all words to an array, remove duplicates and gets the intersection of terms and words(both stemmed). If any, they will be added to the taxonomy field.
Answer: After some searching and pay time I found the great module rule autotag,it is great,of course it is not completely which I want but extract tag from body very good with good  performance


difficulty with chord spelling and voicing in Neumeyer's Hindemith analysis

Question: This post is in reference to David Neumeyer's The Music of Paul Hindemith.
Please refer to the third chord of m.1 in example 3.12 (below). I see this chord spelled as C E E Bb. Having said that, I doubt myself because I see an Eb note in the first chord here, and I am not sure what that means for the E note we are looking at here. Adding to my doubt, we have the fact that the harmonic symbol that corresponds to this chord is a "VI" with an upward sloping line crossing through the I. We know from ex. 3.4 that this corresponds with the 6th scale degree, which would be a C note in Eb.
Neumeyer says,

Note that the 'VI-with-upward-sloping-line-through-'I'', despite its duration, becomes the weakest link in the harmony because its correct root lies high and contradicts the stereotype of the minor-minor seventh chord.

I would like to know why this is being called a minor-minor seventh chord (wouldn't this be the root, m3, 5, and m7: C Eb G b?), but that is not even my main concern: The lowest tone in this voicing is the root of the chord, the C note, so what is this about how "[the chord's] correct root lies high"
Comment: Related question: [Paul Hindemith & Omitted Fifths](https://music.stackexchange.com/questions/59179/paul-hindemith-omitted-fifths).
Answer: I see this chord spelled as C E E Bb. Having said that, I doubt myself because I see an Eb note in the first chord here, and I am not sure what that means for the E note we are looking at here.
The notation follows the standard convention that accidentals carry through the measure. Thus, the chord is C E♭ E♭ B♭. See also Understanding alternate key signature in Neumeyer's Hindemith analysis.
Adding to my doubt, we have the fact that the harmonic symbol that corresponds to this chord is a "VI" with an upward sloping line crossing through the I.
The VI-with-upward-slash means that the root of the chord is the "naturally occurring" sixth degree of the major scale. A downward slash means that the root comes from the minor scale (i.e., a flat 6 or its enharmonic equivalent). This is illustrated in Example 3.4, in which VI-with-downward-slash is positioned at the 8th semitone in the diagram (i.e., minor sixth above the root), and the VI-with-upward-slash is positioned at the 9th (i.e., major sixth above the root).

I would like to know why this is being called a minor-minor seventh chord
A minor-minor seventh chord, also called just "minor seventh" chord, is spelled m3 M3 m3. Thus, with root on C, the (complete) chord is spelled C E♭ G B♭. Here, however, the fifth is missing from the chord, which is a common alteration. See E7 chord at 5th fret missing a B note.
The name "minor-minor" means "minor triad plus a minor seventh above the root". There is also a "minor-major" seventh chord, which is a minor triad plus a major seventh above the root (C-E♭-G-B); and the dominant seventh chord is sometimes called a "major-minor" seventh, because it's a major triad plus a minor seventh above the root.
The lowest tone in this voicing is the root of the chord, the C note, so what is this about how "[the chord's] correct root lies high"
The asterisk next to the chord symbol in Example 3.12 indicates a chord with a root other than what is apparent. Note the specific mention of minor-minor seventh chords.

A chord with a root other than that of the best interval (for example, certain presentations of the major-minor or minor-minor seventh chords). (p. 54. See also image below.)

Unfortunately, Neumeyer's specific meaning is unclear from based on the material provided. He seems to mean that while the chord presents as a VI chord, the "real" root of the chord is not C, but it's not clear what he believes the "real" root is.
An educated guess in that he considers the root to be E♭; that is, this is functionally a I chord. This is because I-VII-I is a common prolongation of tonic harmony, and since the following chord is IV, a tonic prolongation makes sense.
The alternatives would be either:

It's some kind of V (B♭) chord, which seems unlikely given that only one chord tone is present and it's unusually for a predominant harmony to follow the dominant, or
The "true" root isn't present in the chord.
Comment: I suspect the "correct" root, in Neumeyer's mind, for the third chord of measure 1 is actually E♭. Reasons include a possible sense of persistence of the lowest note of the first chord; and maybe more strongly, the V-I relationship this "real" root would create with the following chord.
Comment: @ToddWilcox That explanation makes a lot of sense, and is further supported by the doubled E-flat that is persistent through the entire measure and into the next.
Comment: @286642 "explained" was probably a poor word to choose; "illustrated" might be better. Perhaps it would be more clear to say "note that the VI-with-downward-slash is positioned  at the 8th semitone in the diagram, and the VI-with-upward-slash is positioned at the 9th."
Comment: "The VI-with-upward-slash means that the root of the chord is the "naturally occurring" sixth degree of the major scale. A downward slash means that the root comes from the minor scale (i.e., a flat 6 or its enharmonic equivalent). This is explained in Example 3.4"  Is this explained?  There was no mention of "naturally occurring" or "the root comes from the minor scale" that I recall.  Confusion regarding the symbols is the exact reason i've had difficulty with this book.  Thank you for your thorough answer!!
Comment: @ToddWilcox I was revisiting your comment, and I definitely agree, particularly considering the surrounding harmonies. I've updated the post to reflect. Thanks for the insigtful comment.


Is there any way to disable write-access to source code from within Xcode?

Question: Is there any easy solution to prevent Xcode from writing to source files in a project? I want to edit source files externally and only use Xcode for debugging and so I want to prevent any accidental modifications getting saved via xcode. (Obviously I want Xcode to pickup external changes to files when I build/debug)
One possible solution that I thought of was to enable app sandbox entitlements on xcode and manually maintain a list of directories that it should not write to. Is this feasible? Any other ideas?
On the sandboxing thing, I'm not sure if Xcode is disqualified as per  Apple's Sandboxing Requirements.
Comment: Set up source control. When xcode messes with your stuff, simply reset.
Comment: Thanks for your comment, but my problem isn't that I have no way of reverting those changes. I do. I'd like to avoid the modifications in the first place for reasons out of scope for the question.
Comment: This feels like it should really be asked on SO.  The general rule of thumb is if you're in front of your IDE ask it on SO, if you're in front of a white board ask it on Programmers.  I've voted to migrate.
Answer: I don't think there's any way to prevent XCode from getting all into your source, writing temp files and whatnot.
One option would be to create a simple shell script that pushes your source to a directory for XCode to use.  Since you're not using XCode for development (debugging only), just copy your entire project tree into a temporary directory and then open that in XCode.
Something like (push_to_xcode.sh):
#!/bin/bash

#first, wipe existing project from your temp directory

rm -rf /tmp/xcode_temp_code

#then, copy your existing project into the temp folder

cp -R /path/to/your/project/myProject /tmp/xcode_temp_code

#lastly, launch the project

open /tmp/xcode_temp_code/myProject.xcodeproj

Once you've created the script, change it to executable by typing chmod +x push_to_xcode.sh
Then open a terminal, cd to the directory where you saved the script, and type ./push_to_xcode.sh or double click on it in finder.
That will launch Xcode with this project.  No changes you make in XCode, either purposefully or accidentally, will affect your original code.
Comment: That is exactly what I am doing now. It is a pre-build task so its all automated. But it just adds to the build times because I have large resource asset files and now I either have to write my own program to compare for changes or add some other unneeded complexity to the build chain.
Comment: Wow...I have an app with about 650MB of resources that I tested with the above script and it took less than 15 seconds to copy everything and launch XCode.  Perhaps only copying what has been changed would be the way to go, but that seems like a lot of unneeded complexity, as you said.  Personally, I'd just start the copy and then go make some tea.


How to save node form data in form_values using drupal_execute

Question: I want to save $form_values in the session table in the submit handler when a node type (eg page) is saved.
How can I reuse this $form_values to create this node again using drupal_execute after some time (say tomorrow)?
I've tried creating it but it isn't working out:
function abcdonations_entry() {
  if (isset($_SESSION['form_id'])) {
    $fs = $_SESSION['form_id'];
    $form_id = $fs['values']['form_id'];
    module_load_include('inc', 'node', 'node.pages');
    $node = array('type' => 'person');
    drupal_execute($form_id, $fs,(object)$node);
    print "Written successfully";
  }
}

Then I save it in this function:
function anu_general_form_person_node_form_submit(&$form, &$form_state) {
  $_SESSION['form_id'] = $form_state;
}

Answer: If I understand right you basically want to clone a node later? If this is the case than you can just:
$nid = $the_nid_of_the_old_node;  //get the $nid of the old node
$new_node = node_load($nid);      //load the old node object
$new_node->nid = NULL;            //unset nid to tell node_save that this is a new node
// do what ever you need to the new node
node_save($new_node);             //save the new node

That should do it.
Comment: Have you tried the function [confirm_node](http://api.drupal.org/api/drupal/modules--system--system.module/function/confirm_form/6)? This basically redirects the user (on submission) to a confirmation page where you can show him the duplicated nodes (if any).
Comment: Isn't what [hook_form_alter](http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_form_alter/7) is for? I have to say that I never tried this but it should work by altering the form like this. And, may I say, it's a clean solution because you can do it in your own custom module. You don't have to mess with Drupal's core.
Comment: hook_form_alter isn't for this.
Comment: @Aga Altering a form is exactly what `hook_form_alter` is for. Forms are not classes in Drupal and as such don't have a constructor so I think there's some confusion here. `hook_form_alter` works fine to alter multistep forms (even those that live in core), I've done it many times
Comment: @Clive then please tell me how to use confirm_form to ask for confirmation when user saves a page node for example. That is any form whose form construction code lies in the Drupal core.
Comment: @Aga I didn't say you can use `confirm_form`. `hook_form_alter()` is user to alter the form. You could very easily alter the node form to ask for confirmation on save, but that doesn't mean using `confirm_form` you'd need to roll your own logic
Comment: I don't know if `confirm_form` would really help you as it only adds some default confirmation structure to your form but as @Clive said you could use multistep forms. Take a look at [this](http://www.andrewyager.com/blog/2008-06-03/drupal-6-multistep-forms) link. And you can use multistep form only if there is duplicated content for the current node. To hook into the node processing immediately after the user submitted changes on it you could use [hook_nodeapi](http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_nodeapi/6)(more precisely $op:validate)
Comment: @AgA are you also looking solution for the same problem?


Mysterious Ruby Block behavior: █ vs. {block.call}

Question: When writing a helper for printing javascript that can be used from both other helpers and views, I stumbled upon the following problem:
def javascript(print_tag = false, &block)
  content_for(:javascript) do
    if print_tag
      javascript_tag(&block)          # does not work
      javascript_tag { block.call }   # does work
    else
      capture(&block)
    end
  end
end

This helper should be called with javascript { "alert('hurray'); }.
In the first alternative - which I expected to work - the Rails javascript_tag helper renders an empty  tag.
The second alternative, however, works as expected.
What's going on there? How can that be different?
Answer: You say you are doing this on your views, right?
<%= javascript { "alert('hurray');" } %>

But for content_tag(&block) to work, you should call javascript the way content_tag is intended to be used in views, which is:
<% javascript do %>
  alert('hurray');
<% end %>

content_tag's behavior is different depending on where it's called from, see the function block_called_from_erb? in the source code. In the first case this function returns true because the block does come from an erb (and then it's concated, you don't want that!), in the second returns false (you re-created the block from scratch) and content_tag simply returns the string content, which is what you want.
# ./action_view/helpers/javascript_helper.rb
tag = content_tag(:script, javascript_cdata_section(content), html_options.merge(:type => Mime::JS))
if block_called_from_erb?(block)
  concat(tag)
else
  tag
end

Comment: Ough... what a tricky implementation! Actually I am using Haml:     `- javascript(true) { fire_flash } if flash_message.present?` and I don't want to write that in 4 lines if it is fine in 1 line. But, thank you very much!


df.to_sql gives TypeError with dtype=sqlalchemy.timestamp(timezone=True)

Question: I'm trying to use DataFrame().to_sql to input a time aware dataframe series. Here is an example of my code.
times = ['201412120154', '201412110254']

df = pd.DataFrame()
df['time'] = pd.to_datetime(times, utc=True)

df.time.to_sql('test', engine,
         dtype={'time': sqlalchemy.TIMESTAMP(timezone=True)})

The error I recieve is:
TypeError: issubclass() arg 1 must be a class

The following code works but obviously results in a postgresql column that is not timezone aware.
times = ['201412120154', '201412110254']

df = pd.DataFrame()
df['time'] = pd.to_datetime(times, utc=True)

df.time.to_sql('test', engine,
               dtype={'time': sqlalchemy.TIMESTAMP})

I'm using python 2.7, pandas 0.15.2, postsgresql 9.3 and SQLAlchemy 0.9.7
Comment: Can you report this at the issue tracker? https://github.com/pydata/pandas/issues
Comment: Ok, added to the issue tracker, If it's solved over there I'll be sure to update it here. https://github.com/pydata/pandas/issues/9083
Comment: joris was kind enough to supply a workaround until this bug is fixed, slated for pandas 0.16.0 looks like. https://github.com/pydata/pandas/issues/9083
Answer: Update: this is fixed in 0.16
This is a bug in pandas 0.15.2 that hinders you from providing an instantiated sqlalchemy type with arguments (like TIMESTAMP(timezone=True) instead of TIMESTAMP). This will be fixed in a next version, but for now you can use the patch below.

I will post the workaround here as well. If you run this, you will be able to specify sqlalchemy types instantiated with arguments to the dtype keyword in to_sql:
from pandas.io.sql import SQLTable

def to_sql(self, frame, name, if_exists='fail', index=True,
           index_label=None, schema=None, chunksize=None, dtype=None):
    """
    patched version of https://github.com/pydata/pandas/blob/v0.15.2/pandas/io/sql.py#L1129
    """
    if dtype is not None:
        from sqlalchemy.types import to_instance, TypeEngine
        for col, my_type in dtype.items():
            if not isinstance(to_instance(my_type), TypeEngine):
                raise ValueError('The type of %s is not a SQLAlchemy '
                                 'type ' % col)

    table = SQLTable(name, self, frame=frame, index=index,
                     if_exists=if_exists, index_label=index_label,
                     schema=schema, dtype=dtype)
    table.create()
    table.insert(chunksize)

pd.io.sql.SQLDatabase.to_sql = to_sql


Como pesquisar telefones com Autofilter em VBA

Question: Estou usando VBA para aplicar um filtro na coluna de números de telefone.
Os números de telefones são tratados de forma personalizada para ficar no modelo (XX) XXXXX-XXXX ou (XX) XXXX-XXXX
Eu pego o valor de uma célula e uso como o valor para a busca do filtro.
Segue o código:
If Not IsEmpty(Range("B7")) Then
Range("A12").AutoFilter Field:=2, Criteria1:=Range("B7").Value

End If

Não recebo retorno quando o valor possui formatação
Comment: Qual o comportamento que você esperava? O código não inclui nada que tenha relação com estar ou não formatado da forma X ou Y. O que esse trecho de código faz é apenas o seguinte: se a célula B7 não estiver vazia, vá ao filtro existente que abrange a célula A12, pegue a segunda coluna e configure para mostrar apenas os valores equivalentes a B7. Ele se comporta de alguma forma diferente desta? Dá alguma mensagem de erro?
Comment: Além disso, falta um "=" no parâmetro ```Criteria1```. Era pra ser ```Criteria1:=Range("B7").Value```
Comment: @CésarRodriguez Correto! Na verdade estou tentando encontrar uma forma de fazer a pesquisa para filtrar os valores com a formatação personalizada, eu tentei usar o NumberFormat mas também não obtive resultado pois ele estava retornando FALSE e não o numero formatado.
O resultado que obtenho é um filtro sem os símbolos que são utilizados na formatação personalizada, mas ainda não encontrei uma maneira de resolver isto.
Answer: Após mais um pouco de pesquisa encontrei essa solução usando o Strings.Format, ele retorna uma string então dessa forma o VBA passa o valor exato com todos os símbolos no AutoFilter.
Dim NumTelefone As String
NumTelefone = Range("B7")
If Len(NumTelefone) > 10 Then
NumTelefone = Strings.Format(NumTelefone, "[<=9999999999] (##)#####-####")
Else
NumTelefone = Strings.Format(NumTelefone, "[<=9999999999] (##)####-####")
End If


deserialize json object in javascript

Question: I am developing asp.net mvc application, Java script will call controller for every 3 seconds and it should return list of json objects.I need to show the list of objects in table.Here, I am getting [object Object].should we deserialize that objects,if yes,then how to deserialize them.
Below is my java script code

below is controller
public JsonResult FirstAjax()
{
    var listt = AlgoLegsClass.DataGridAlgos;
    JavaScriptSerializer js = new JavaScriptSerializer();
    string ss =  js.Serialize(listt);
    return Json(ss, JsonRequestBehavior.AllowGet);
}

Output- After every 3 seconds the timer call the controller and it returns list of objects.In alert box it is displaying like "Parameter name":"Value".How can i get these values as i need to append this list to table
Answer: Since you specified dataType: "json" in your ajax options, jQuery will already have done the deserialising of the JSON string back into a JavaScript object for you automatically.
What you're seeing is just what alert() does with JavaScript objects/arrays by default when trying to make them visual as text.
Try
alert(JSON.stringify(response));

instead. This will print a version of your object which is serialised back to a JSON string and thus make it more human-readable.
Or you can just look in the Response section of the ajax call's entry in your Network tab (in the browser's Developer Tools).
Also if you're using a JsonResult (i.e. return Json...) you do not need to serialise the object beforehand - MVC will do it for you. So chances are you're getting double-serialised nonsense.
Simply
return Json(listt, JsonRequestBehavior.AllowGet);

should work no problem.
Comment: I have changed my code as you specified above, I am getting output as [{"parameter _1":"value","parameter_2":"value","parameter_3":"value"}].
Comment: Ok. Well it's valid JSON, so that's good. What were you expecting to see? I don't know what's in your `listt` variable.
Comment: my list contains employee list, i need to get all employee details one by one with their fields like name,salary etc.
Comment: Ok but a description of your object is no good to anyone, a list of employees could have 100 different structures. Show the definition of whatever is the datatype of `DataGridAlgos` , and / or the actual values contained in this object at the time you run your code.
Comment: class Employee { Name {set;get;} Id {set;get;} salary {get;set;} . DataGridAlgos contains List of employees.Now we need to show all employee details one by one in alert box.
Comment: So `DataGridAlgos` is defined like `public List DataGridAlgos { get; set; }` in the `AlgoLegsClass` object? Because if it is, I see no way your JSON would end up serialised like that. What's the real definition of it? What do you mean by a "list" exactly?
Comment: public static List DataGridAlgos = new List(); Employee emp1 = new Employee(); emp1.Id = 1; emp1.Name = "ABC";emp1.salary = 2000; DataGridAlgos.Add(emp1); This way I am adding employee details in list
Comment: See https://dotnetfiddle.net/uSQYDH - I don't see how it's possible for the code you've described to produce the result you mention. You've obviously described something wrongly or omitted some important detail.
Comment: same way I did and I got the same output.But I need to get single parameter like we do in c#. foreach(var item in listt) { string name = item.name; }
Comment: Please tell me how to get each parameter seperately
Comment: Don't you know how to write a `for` loop in Javascript? What you've got is a JavaScript array containing some objects. Google how to loop through an array of objects and also how to display a specific property of an object. e.g. https://stackoverflow.com/a/40416380/5947043 is a simple example. There are hundreds and hundreds of others, on this site alone never mind the rest of the web.
Comment: Here length property is not coming for array, so I am unable to iterate through loop
Comment: See the JSFiddle again: https://dotnetfiddle.net/uSQYDH . Can't see your code so I don't know what you did wrong, but perhaps you didn't understand how to write the `for` loop. I included an example, it's not very complicated. And here is an alternative using `forEach`: https://dotnetfiddle.net/yDcpnr

deserialize json object in javascript


Python - Criando programa que altere ele mesmo

Question: Gostaria de criar um programa que seja capaz de alterar ele mesmo, ou seja, eu executo o script, e ele muda o próprio script.py, criando uma espécie de marcador.
O grande problema é que não consigo alterar o programa quando ele está rodando, como fiz abaixo:
<code>arq = open("./01_programa_alterar.py")
lines = arq.readlines()

x = False  # lines[4] = "x = True\n"

if x:
    print("Você Alterou o script")
else:
    print("Script não alterado")

#----mudar script----
lines[4] = "x = True\n"  # Pulo do gato

for line in lines:
    arq.write(line)
#--------------------

arq.close()
</code>
Gostaria de saber se existe algum módulo que faça essa alteração :(
Comment: Já tentou colocar o `arq.close()` antes do `x = False` ?
Comment: primeiro li o arquivo no modo 'r' depois fechei, então depois abri novamente no modo "w"
Answer: Consegui fazer funcionar da seguinte maneira:
<code>#Ler arquivo
arq = open(__file__, 'r')
lines = arq.readlines() #Leremos por aqui
arq.close()

x = False

if x:
    print("Você Alterou o script")
else:
    print("Script não alterado")

#Escrever arquivo (Não ler linhas)
arq = open(__file__, 'w')

#----mudar script----
lines[5] = "x = True\n"

for line in lines:
    arq.write(line)
#--------------------

arq.close()
</code>
Eu estava esquecendo de fechar o arquivo e depois abrir ele novamente com, só que no como "w" open(file,'w') ...
Comment: Como eu tinha dito.


Password reset is not enabled. Set the EnablePasswordReset property of the membership provider to true

Question: I want to reset current user pasword and get new password. I'm newbie. How do i solve this problem?
My code :
public static string ResetCurrentUserPassword(string userName)
{
    MembershipProvider p = (MembershipProvider)Membership.Providers["Default"];
    MembershipUser obj = Membership.GetUser(userName);
    return obj.ResetPassword();
}

Web.config :
<siteMap defaultProvider="SitefinitySiteMap">
    <providers>
        <add name="SitefinitySiteMap" type="Telerik.Sitefinity.Web.SitefinitySiteMap, Telerik.Sitefinity" enablePasswordReset="true" taxonomyProvider="OpenAccessDataProvider" pageTaxonomy="Pages" rootNode="FrontendSiteMap" pageProvider="OpenAccessDataProvider"/>
    </providers>
</siteMap>
<roleManager enabled="false"/>
<membership defaultProvider="Default">
    <providers>
        <clear/>
        <add name="Default" type="Telerik.Sitefinity.Security.Data.SitefinityMembershipProvider, Telerik.Sitefinity"  enablePasswordReset="true"/>
    </providers>
</membership>

Answer: have a look at the following link: Telerik EnablePasswordReset
The important part is following:
There are two properties of the membership provider that should also be changed in the web.config file. The enablePasswordReset should be set to true, and the requiresQuestionAndAnswer to false.
I think you have to enhance your web.config with the following Parameter:
<add name="Default" enablePasswordReset="true" .....

gretz noone
Comment: try to restart your IIS Service:
cmd -> resetiis
Comment: be sure that you edited the right web.config i.e.:
if you are running your own Website follow the path in the IIS Settings for exapmle: "c:\inetpub\wwwroot\[yourapplicationnname]\web.config" then reset your IIS and it should work.
be sure that you edited the write XML-tree: "<membership " is the right one.
I dont have any more thoughts :) iam sorry. maybe you should ask in the telerik Forum for help (admins are answering rly fast there).


Function does not reduce in Pandas

Question: I have a problem with Pandas aggregate.
I have 4 columns with "int" type and one as a string.
I want those with int to sum, that one with string to get unique.
I have used next function:
df = df.groupby(['Time', 'Id', 'Object', 'Alias', 'Type'],as_index=False).agg(lambda x : x.sum() if x.dtype=='int' else x.unique())

But I'm getting next error:
ValueError: Function does not reduce

I have found some similar questions but each of them has only one operation in an aggregate function. Not sure how to use any advice in my case.
Comment: Where's your data?
Comment: Maybe you are looking for `x.nunique()` ?
Answer: unique is not an aggregating function. Aggregating functions reduce the dimension of the data, e.g. sum reduces a list of numbers to a single number, whereas unique reduces a list to a potentially smaller list.
my_series = pd.Series([1, 2, 1, 3])  # 1-D
my_series.sum()  # 7, a scalar
my_series.unique()  # [1, 2, 3] still 1-D

Function does not reduce in Pandas


Building iOS static library

Question: I have a static library that depends on some of the Apple frameworks though when I include it as a target dependency I still need to add the frameworks it depends on to the application project. Is there some way to setup the project such that the dependencies only have to be specified in the static library target?
Answer: While I'm sure it is possible, you really don't want to do that. I'm not sure you'd be able to get accepted if you did that. The static library is linking against dynamic library, the symbols are not included in it like the .m files are. That is the whole point of dynamic libraries.
One solution is to use an xcconfig file.
http://developer.apple.com/library/ios/#recipes/xcode_help-project_editor/Articles/BasingBuildConfigurationsonConfigurationFiles.html
In this scenario you create a sharable xcconfig file that accompanies the static library. Then in your application project you copy the xcconfig file and base your application configuration on it.
<code>OTHER_LDFLAGS = $(SHARED_LDFLAGS) -framework AssetsLibrary -framework AudioToolbox ...
</code>
Comment: Yes thats more or less what I was looking for. I didn't really mean to statically link the dynamic libraries just a way for the application project to not have to manually add them all, but this config file seems like it can work well enough
Comment: Following this question, I created a new config file and added just the line that is mentioned in the answer. The static library that I am building compiles successfully but I still have to import the MapKit framework in my application project that uses my static library..Am I doing it wrong?
Comment: Even if you link against a library, you still have to import the appropriate header files.

Building iOS static library


How do I edit the CSS based on node, page, or placement on page?

Question: I've been learning how to navigate around and edit my global.css file, but am confused as to how to edit specific elements. I've come across answers to this question that don't specifically describe how to do this
To clarify, say that I have 3 pages on my site titled Red, Blue, and Black. If I want to edit just the h1 headers on page Red, how do I go about doing that? Is there a way to do this without PHP or installing extra modules?
Currently, whenever I try to edit the h1 header on supposed Red page, every single h1 header on my site is updated and edited.
Sorry if this is a duplicate, I honestly couldn't find any answer to my question while I was searching
Answer: This isnt a Drupal API question. It's more of a CSS and how does that work in the browser question. That being said there are docs on how to theme drupal 6 and 7. Since drupal is a web application they cover topics such as:

Working with CSS
Standard Drupal Core Styles and Classes

Within (2) it describes the .node and .node-title CSS classes:

.node
A wrapper div around all of a node, including its title.
.node-title
The title of the node.

Depending on the theme your using you may or may not have those exact classes, every theme is slightly different. Basically in your theme you want to use Firebug or Chrome Developer Tools to look at the HTML markup and CSS classes and IDs attached to things. You can then target a page or node title, and create a rule to target specific page urls if need be. As an example Drupal page (using AdaptiveTheme subtheme):

The  tag has a million css classes on it including page-node-2 that specific CSS class would target only this node (by its NID). You can inject other more useful body classes into any theme using hook functions and template files -- but thats beyond this writings scope.
In this case you can also see the node title has an ID of h1#page-title
A general CSS rule to target this 1 page's title you could put in global.css is body.page-node-2 h1#page-title { color: red; }
For your theme it would be the same process:

examine the body tag in your Theme and find a useful CSS class to specifically target the page(s) with a CSS rule.
examine the Section Header tags within the page to find the exact CSS classes/ids to target just that element as well.

Lastly, I dont think every theme has a global.css file ... though most probably do. My exact CSS rules herein will likely not work for your usecase, they're just examples of what you could do. See the documentation pages listed above to better understand Drupal Themeing.
Comment: Thanks for the reply. I'm using Omega on my site, so there is a global.css file that I'm trying to edit. And how do I find the page node name? How do I find the equivalent of "body.page-node-2" in my css files? And how do I give elements an ID? I'm trying to figure out where the HTML files would be, but to no avail
Comment: you view the source-code in your browser window or using browser developer tools in the browser like Firebug for Firefox. you dont find `body.page-node-2` in your CSS, it's in the rendered HTML.


erro ao gerar o build do angular

Question: eu tenho um projeto angular que roda normalmente no ambiente de producao, mas estou querendo gerar o build dele e estou obtendo o seguinte erro ao usar o comando npm run build:

ERROR in Error: Type ImageCropperComponent in C:/d/Workspaces/Curso
  Java
  Workspace/pk2-angular-v1.0.0/node_modules/ng2-img-cropper/src/imageCropperComponent.d.ts
  is part of the declarations of 2 modules: AppModule in
  C:/d/Workspaces/Curso Java
  Workspace/pk2-angular-v1.0.0/src/app/app.module.ts and
  ImageCropperModule in C:/d/Workspaces/Curso Java
  Workspace/pk2-angular-v1.0.0/node_modules/ng2-img-cropper/src/imageCropperModule.d.ts!
  Please consider moving ImageCropperComponent in C:/d/Workspaces/Curso
  Java
  Workspace/pk2-angular-v1.0.0/node_modules/ng2-img-cropper/src/imageCropperComponent.d.ts
  to a higher module that imports AppModule in C:/d/Workspaces/Curso
  Java Workspace/pk2-angular-v1.0.0/src/app/app.module.ts and
  ImageCropperModule in C:/d/Workspaces/Curso Java
  Workspace/pk2-angular-v1.0.0/node_modules/ng2-img-cropper/src/imageCropperModule.d.ts.
  You can also create a new NgModule that exports and includes
  ImageCropperComponent in C:/d/Workspaces/Curso Java
  Workspace/pk2-angular-v1.0.0/node_modules/ng2-img-cropper/src/imageCropperComponent.d.ts
  then import that NgModule in AppModule in C:/d/Workspaces/Curso Java
  Workspace/pk2-angular-v1.0.0/src/app/app.module.ts and
  ImageCropperModule in C:/d/Workspaces/Curso Java
  Workspace/pk2-angular-v1.0.0/node_modules/ng2-img-cropper/src/imageCropperModule.d.ts.

Ao ler o erro vi que esta lib que estou usando é parte de declaracao de dois modulos (não entendi oque que isso significa) mas vamos lá. no meu app.module que acusa o erro eu estou importando ele:
<code>import { ImageCropperComponent } from 'ng2-img-cropper';
</code>
e declarei no meu declarations so @NgModule.
Alguem sabe me dizer como resolver?
Comment: Conssegui resolver, eu estava importando o component em declarations, mas o correto é importar o modulo em imports
Answer: Você está declarando seu componente no 'declarations' (que são os componentes  e diretivas que pertencem a ele) ao invés do 'imports' (que são os que ele usa).

erro ao gerar o build do angular


Select and Checkbox components-> multiple options but with a maximum choice?

Question: I want to use the Select and Checkbox components with MUI with the multiple props , so the users can pick multiples options. However, I want , that they are limited to 3 options maximum . I can't find this props to set the min and maximum choice . Is it possible ?! I would be really happy if so .
Here is my code :
const languages = [
  "Anglais",
  "Arabe",
  "Espagnol",
  "Italien",
  "Français",
  "Mandarin",
  "Hebreu",
  "Russe",
  "Portugais",
  "Autre",
];

 <FormControl className={classes.formControl}>
            <Select
              multiple={true}
              value={language}
              onChange={handleChange}
              MenuProps={MenuProps}
            >
              {languages.map((language) => (
                <MenuItem key={language} value={language}>
                  {language}
                </MenuItem>
              ))}
            </Select>
          </FormControl>

Thanks !
Answer: This should help you make it for yourself.

const languages = [
  "Anglais",
  "Arabe",
  "Espagnol",
  "Italien",
  "Français",
  "Mandarin",
  "Hebreu",
  "Russe",
  "Portugais",
  "Autre",
];

const App = () => {
  const [selectedItem , setSelectedItem] = React.useState([]);
  const selectHandler = (e) => {
    const select = e.currentTarget.value;
    if(selectedItem.length <3)
      setSelectedItem((prev)=> [...prev,select])
  }
  return (

{selectedItem.map((item)=>item+"-")}

        <select onChange={selectHandler}>
          {languages.map((language) => (
            <option key={language} value={language}>
              {language}
            </option>
          ))}
        </select>

  );
};

ReactDOM.render(<App />, document.getElementById("react"));

In your case, just pass selectedItem as a value to the Select component solve the problem.
Answer: <Select
  multiple={true}
  value={language}
  onChange={handleChange}
  MenuProps={MenuProps}
>
  {languages.map((lang) => (
    <MenuItem
       key={lang}
       disabled={language.length >= 3 && !language.includes(lang)}
       value={lang}
    >
      {language}
    </MenuItem>
  ))}
</Select>

Had to change the map parameter since it's name is the same as the state variable.
This will disable any non-selected items when state (language) has 3 or more items.
Comment: Actually it was not working with your snippet , the select was empty  . So i changed the name of my state and the name of the array and it's finally work


Convert BufferedImage into byte[] without I/O

Question: Hi I have a BufferedImage instance in memory and want to convert it into byte[] to encode as base64 string without I/O operation for performance consideration. I was using the following API:
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
ImageIO.write(image,"png",baos);
return baos.toByteArray();

However, this API still implicitly writes the image to the OS temp directory, which will lead to failure in case that the underlying OS temp directory is full and the temp file cannot be created.
Stack Trace:
Caused by: java.io.IOException: No space left on device
    at java.io.RandomAccessFile.write(RandomAccessFile.java:493)
    at javax.imageio.stream.FileCacheImageOutputStream.write(FileCacheImageOutputStream.java:134)
    at javax.imageio.stream.ImageOutputStreamImpl.write(ImageOutputStreamImpl.java:66)
    at com.sun.imageio.plugins.png.PNGImageWriter.write_magic(PNGImageWriter.java:376)
    at com.sun.imageio.plugins.png.PNGImageWriter.write(PNGImageWriter.java:1115)
    at javax.imageio.ImageWriter.write(ImageWriter.java:628)
    at javax.imageio.ImageIO.write(ImageIO.java:1480)
    at javax.imageio.ImageIO.write(ImageIO.java:1554)

Is there an efficient (like in-memory conversion or efficient I/O) way to do the conversion without I/O? Please advise.
Comment: I am...surprised that this happens.
Comment: This is almost certainly a bug in the JVM. Have you tried the latest version?
Comment: @PeterLawrey: why do you consider this a bug? There is a whole class [`FileCacheImageOutputStream`](http://docs.oracle.com/javase/7/docs/api/javax/imageio/stream/FileCacheImageOutputStream.html). However I wasn't aware of this mechanism in `ImageIO` at all.
Comment: IMHO, A disk cache shouldn't automagically write data until it fills your drive. When was the last time your browser crashed because it filled your drive. ;)
Comment: Is there a way that we can do this without using ImageIO?  I'm having a similar problem but I would like to use an alternative because of performance reasons
Comment: The OS temp directory was filled by other application dump. hence the disk write error occures. I set the cache flag as false. However, ImageIO still takes fair amount of time. The invocation takes around 100ms for small images. Is there another efficient way to do this?
Answer: Disable the ImageIO cache through the ImageIO.setUseCache() method:
ImageIO.setUseCache(false);

It is on by default according to the javadoc:

Sets a flag indicating whether a disk-based cache file should be used when creating ImageInputStreams and ImageOutputStreams.
When reading from a standard InputStream>, it may be necessary to save previously read information in a cache since the underlying stream does not allow data to be re-read. Similarly, when writing to a standard OutputStream, a cache may be used to allow a previously written value to be changed before flushing it to the final destination.
The cache may reside in main memory or on disk. Setting this flag to false disallows the use of disk for future streams, which may be advantageous when working with small images, as the overhead of creating and destroying files is removed.
On startup, the value is set to true.
Answer: Both mentions of ImageIO.setUseCache(false) is correct. However, if you don't like to disable disk caching for ImageIO globally, an alternative is to explicitly wrap the stream in a MemoryCacheImageOutputStream (which does in-memory caching instead of disk caching):
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
ImageOutputStream stream = new MemoryCacheImageOutputStream(baos);
ImageIO.write(image, "png", stream);
stream.close();
return baos.toByteArray();

Comment: Indeed. Thank you very much!
Comment: Seems, it doesn't true anymore, at least in 1.8. `com.sun.imageio.spi.OutputStreamImageOutputStreamSpi#createOutputStreamInstance` doesn't check the type of the stream but does check the `useCache` parameter.
Anyway, it would be really nice to have a way to disable caching locally.
Comment: @sedovav The above solution does indeed provide a way for "locally" disabling the disk cache. When you create the MemoryCacheImageOutputStream directly like that you never hit the Spi, so whatever it does is irrelevant. PS: Note that ImageOutputSream is not a subclass of OutputStream, despite its name. And there's a separate overload of ImageIO.write for this.
Answer: ImageIO by default writes it's cache to disk even when you only use streams. Try disabling the cache with:
ImageIO.setUseCache(false);

Answer: ((DataBufferByte)img.getRaster().getDataBuffer()).getData() automatically returns a byte array if your image was in a byte format. No need for any IO at all.


Mail From Outlook/Exchange Sent to Destination Spam

Question: I have a unique problem and I am hoping someone may have some direction to provide me.
We have a Windows environment with an Exchange 2007 Server.  For some reason when a user sends an email from Outlook to a destination, it finds its way into the SPAM box of the recipient.  Now, I know there could be a 100 reasons why this is happening, but I have found a resolution to the problem and it is the resolution that is confusing me..
If I remove the mailbox profile from the user's computer, then re-add the mailbox profile, the mail is no longer sent to the recipient's Spam folder.
This also means that if I find a user that is having this issue but log into OWA with their account, the email does NOT go to the recipient's Spam box, but if I send an email from their computer using Outlook, it DOES go to the recipient's Spam box.
To test this, I am having users send email to my private Gmail account. This has been the main form of testing that I have been using.  I should specify that if I look at the original message (headers of the message) sent from the user, there is no indication that the message should be treated as Spam.
We changed our self-signed certificate yesterday so I am assuming it has something to do with that, but now I am just trying to figure out why exactly this is happening and how to resolve it (other than going around to EVERY computer and re-adding the mailbox profile for their computer).  Does anyone have any suggestions?
Any help or information is greatly appreciated!
Answer: My guess based on what you are saying would be that something in their original profile had a plug-in/add-in that was causing the email headers to tag it different than would be with OWA or the new profile.
The cert shouldn't matter, unless you are using it for TLS and even then it shouldn't work for TLS if it is self-signed.  Plus, OWA would be using that same cert.
If you can compare the message headers of one that doesn't go to the spam box vs. one that does, that would probably tell you where the difference lies.  I know you said you have looked at the original message header but did you compare a good vs. spam one?
Comment: I will re-compare tomorrow. The OWA access (IIS) uses a wildcard certificate while our Exchange services (currently) utilize the self-signed one.  I just don't understand how removing and re-adding the mail profile triggers a fix to this problem.
Comment: If the mail profile was associated with a certain add-in...but that's the only thing I can think of as well.


How can I have non-exact locations on a map?

Question: I'm using GMap to help users find other people in their area. But I'd like to let users have some privacy only making their city and zip code available in the map, but still have the full address in the database for mailing purposes. How can I do this? The position of the pin on the map should also be only based on city and zip, as obviously it could be pretty precise as to location.
For example, let's say the president registers on our site. He enters his full address, 1600 Pennsylvania Ave NW, Washington D.C., DC 20500. An administrator can now look that up and mail him our newsletter.
Another user in the D.C. area is looking for people to meet up with. They look and see a pin on the map for a user POTUS. The click on the pin and it only displays a partial address, Washington D.C., DC 20500. And the pin's location isn't exact, so the user can't tell from its placement the exact address of POTUS. But it is enough that the user knows they are nearby, so they send a user to user message to get in touch.
Any solutions for non-exact pin locations would be fine. If it was slightly randomized. Or perhaps all pins in a zip-code are grouped into one with a link for "# users in the 20500 area" which takes the user to a full list.
If this can be done with something other than GMap, that is fine.
Answer: I had a similar problem, and this is how I solved it:

Add another 'location' field to you content type; call it, e.g., 'public user location'.
Build up your custom module, and in the hook_form_alter() implementation, hide the new location field, so the user cant edit it.
Now you need to get the 'non-exact' location for the first location; I do this with a Google geocode.

It's up to you to do it via JavaScript when the first location is set (the way im doing it), or to do the geolocation when the form is submitted to 'manually' add the 'non-exact' location.
If you use a geocode on the partial address, Google Geocode will give you the coordinates in the middle of the area you searched.
Please note that, for more specific geocoding, you could even use the Geonames API.
If you choose the second way (create the 'non-exact' location when the form is submitted), maybe this can help you about the location creation: Creating nodes programmatically in Drupal (including cck and location fields).
As side note, I am not using the Gmap module anymore because my needs were a bit complex and were not fit by this module; if you'll find some trouble, I recommend you building your own small module using Google API v3.
This will let you, for example, show the 'public location' in the map with a circle around, as Google Latitude does.
Answer: That pin on the map is going to be the center (usually geometric center) of the zip code (with a few exceptions, such as a zip code that only refers to a single building).

Or perhaps all pins in a zip-code are grouped into one with a link for "# users in the 20500 area" which takes the user to a full list.

This is a better solution than putting 20 pins all on top of each other at the center of 20500 zip code.


Rudin Question (Integration of Complex Functions) [pg.325]

Question: I was reading Rudin and I stumbled upon a proof that I do not seem to understand. It is on page 325 of Baby Rudin $3^{rd}$ edition.
In case you do not have a copy I shall write some background information:
Suppose $\mu$ is a measure on $X$, and $f$ is a complex measurable function on $X$. Then,
$$\int |f|\;d\mu < +\infty$$
and we define
$$\int f \;d\mu = \int u \; d\mu  + i\int v \; d\mu$$.
Now onto, my question. He wants to prove the following
$$ \left| \int f \; d\mu \right| \leq \int |f| \; d\mu. $$
He begins as follows:
If $f \in \mathscr{L}(\mu)$, there is a complex number $c$, $|c| =1$, such that
$$ c\int f \; d\mu \geq 0 $$
Put $g = cf = u +iv$ where $u$ and $v$ are real.Then
$$ \left| \int f \; d\mu \right| = c\int f \;d\mu =  \int g \;d\mu = \int u \;d\mu \leq \int |f| \; d\mu.$$
The thing that bothers me is the following equality
$$\int g \;d\mu = \int u\;d\mu  .$$
How are these two functions equal? If we had assumed that $g = u +iv$, so should not g be
$$\int g \;d\mu = \int u \; d\mu  + i\int v \; d\mu?$$.
Comment: $\left | \int f d \mu \right |$ is real so $\int v$ has to be zero otherwise you get something complex on the RHS.
Comment: What's $\mathscr L (\mu)$?
Comment: @MattN. If I remember correctly from my reading of Rudin's textbook, then I believe that $\cal L(\mu)$ is the $L^1$-space of the positive measure $\mu$. I think Rudin's notation is not standard in this regard.
Comment: @AmiteshDatta Cool, thank you very much!
Answer: $$ \left | \int f d \mu \right |$$ is real so $$ \left| \int f \; d\mu \right| = \int u \; d\mu  + i\int v \; d\mu$$
has to be real too, which means that $\int v d \mu $ has to vanish.


Question on Non-Lipschitz Functions

Question: I have a question about non-Lipschitz functions. Let $f_1,f_2,...f_n$ be some collection of Holder continuous non-Lipschitz scalar functions defined on a compact subset of $\mathbb{R}^n$. My questions are of the type:
When does there exist a function $h$ s.t $h>0$ and $\sum_i hf_i$ or better all $hf_i$ are Lipschitz or all $hf_i$ are Lipschitz with respect to some of the chosen variables (in case $n>1$)
Any keywords regarding such issues topics or any branches that you know of which studies such things is welcome. Thanks
Comment: Don't you want your $f_i$'s continuous, or at least $\sum f_i$? Since the function $h \cdot (\sum f_i)$ continuous would have the same zero set as $\sum f_i$.
Comment: Sorry yes in fact they can be taken Holder continuous in my case infact
Comment: The sum $\sum f_i$ could just as well be one function $f$, since all we know about this some is that it's Holder. If $f$ is strictly positive, you can just let $h=1/f$.
Comment: Sorry that was the simplest case I had in mind, I forgot to add the others. I think I lack in examples. All examples of non-Lipschitz functions I have in mind are differentiable functions which have singularities on their derivatives (they blowup) and themselves are usually 0 somewhere or functions which are non-Lipschitz on the whole $\mathbb{R}^n$ but are Lipschitz on every compact subset. Interesting articles or sources about `non-usual` non-Lipschitz functions are also welcome.
Answer: To make a single function $f$ Lipschitz, one can multiply if by $h(x) = \operatorname{dist}(x,f^{-1}(0)) / f(x)$. (Define $h=1$ on the zero set of $f$. The result is just a signed distance function to the zero set of $f$, which is $1$-Lipschitz.
I would not expect to be able to  do this for two or more functions at once, unless they are tightly related in some way.  It would take some very specific assumptions. It's better to just work with the functions you have than try to come up with a set of conditions.
Finally, I would not expect there to be articles on "how to make a non-Lipschitz function Lipschitz by multiplication". This just does not sound like a topic of a research paper. As a general reference for Lipschitz functions, I find Lipschitz Analysis by Heinonen useful.
Comment: Actually similiar but not exactly the same techniques play some role in integrability of continuous distributions and vector fields but the conditions there are a bit more complex (yet more relaxed, some form of weak lipschitz continuity). I am taking this just as a simpler but stronger starting point to think about such things. Thanks for the reference.
Comment: Well it seems the stronger condition is not so useful (in the sense that it can not be derived meaningful condition) so I will have to think about the weaker notions. So I take this as the correct answer.

Question on Non-Lipschitz Functions


ElasticSearch including or vs database?

Question: I am trying to understand what ElasticSearch exactly does when it comes to persistence.
When I index documents in ElasticSearch, I also within this step save them within ElasticSearch. Though the reason I index my documents with ElasticSearch is to be able to search for them using the API and certain search algorithms.
Then, within for the rest of my application, I also have a relational database where I store a lot of stuff concerning my application. Within the relational database I also have the same documents I index in ElasticSearch.
As a result I have the documents saved in both ElasticSearch and the relational database. I learend about ElasticSearch to get extended search abilities, but now I wonder whether the step of saving the documents in ElasticSearch and the relational database isn't a bit redundant.
Would it be wise to delete the documents from the relational database and use the indexed documents in ElasticSearch as the data source?
Answer: Maybe. This is a design decision that our friends over at DBA Stack Exchange may have more to say about. Sometimes you make redundant copies because of different search or reporting needs, or database engines with different characteristics.
As a part of this design, understand the safety of Elasticsearch especially as it is a distributed system. The Jepsen report is particularly interesting. Network partitions can result in document loss in some scenarios:

My recommendations for Elasticsearch users are unchanged: store your
data in a database with better safety guarantees, and continuously
upsert every document from that database into Elasticsearch. If your
search engine is missing a few documents for a day, it's not a big
deal; they'll be reinserted on the next run and appear in subsequent
searches. Not using Elasticsearch as a system of record also insulates
you from having to worry about ES downtime during elections.

A practical example, I know of an enterprise with a sprawling MediaWiki who built a search engine in Elasticsearch. The wiki and other sources have their own DBMSes supporting lots of CRUD applications. Then tens of millions of documents of all kinds are stuffed into the search engine, so people can usually find things.

ElasticSearch including or vs database?


C program stuck on uninterruptible wait while performing disk I/O on Mac OS X Snow Leopard

Question: One line of background: I'm the developer of Redis, a NoSQL database. One of the new features I'm implementing is Virtual Memory, because Redis takes all the data in memory. Thanks to VM Redis is able to transfer rarely used objects from memory to disk, there are a number of reasons why this works much better than letting the OS do the work for us swapping (redis objects are built of many small objects allocated in non contiguous places, when serialized to disk by Redis they take 10 times less space compared to the memory pages where they live, and so forth).
Now I've an alpha implementation that's working perfectly on Linux, but not so well on Mac OS X Snow Leopard. From time to time, while Redis tries to move a page from memory to disk, the redis process enters the uninterruptible wait state for minutes. I was unable to debug this, but this happens either in a call to fseeko() or fwrite(). After minutes the call finally returns and redis continues working without problems at all: no crash.
The amount of data transfered is very small, something like 256 bytes. So it should not be a matter of a very big amount of I/O performed.
But there is an interesting detail about the swap file that's target of the write operation. It's a big file (26 Gigabytes) created opening a file with fopen() and then enlarged using ftruncate(). Finally the file is unlink()ed so that Redis continues to take a reference to it, but we are sure that when the Redis process will exit the OS will really free the swap file.
Ok that's all but I'm here for any further detail. And BTW you can even find the actual code in the Redis git, but it's not trivial to understand in five minutes given that's a fairly complex system.
Thank you very much for any help.
Comment: More info: now trying with a smaller swap file (256 MB) the bug disappeared, even if data is written exactly in the same locations and in the same number of pages.

Given this and the other guesses in the answers, it seems a lot like what happens is that the operating system after a few writes appears to try to physically allocate the huge file in the filesystem, and this takes minutes given the size.

I can "fix" this writing a few random bytes on startup in order to force the physical allocation ASAP maybe, at least as an option.

Thank you very much. will pust updates here.
Answer: As I understand it, HFS+ has very poor support for sparse files. So it may be that your write is triggering a file expansion that is initializing/materializing a large fraction of the file.
For example, I know mmap'ing a new large empty file and then writing at a few random locations produces a very large file on disk with HFS+. It's quite annoying since mmap and sparse files are an extremely convenient way of working with data, and virtually every other platform/filesystem out there handles this gracefully.
Is the swap file written to linearly? Meaning we either replace an existing block or write a new block at the end and increment a free space pointer? If so, perhaps doing more frequent smaller ftruncate calls to expand the file would result in shorter pauses.
As an aside, I'm curious why redis VM doesn't use mmap and then just move blocks around in an attempt to concentrate hot blocks into hot pages.
Comment: Hello Jason. Yes this was my idea too: that for some reason after the ftruncate() and after a few writes, at some point the HFS+ implementation thinks it's time to materialize a huge part of the file.

The pages are allocated incrementally. I use an algorithm similar to the one of the Linux Kernel. I try to allocate incrementally up to a given number of pages, than I return to the start of the file from time to time searching for free contiguous blocks.

So incremental ftruncates() are a good idea AFAIK. I thought at it but avoid it to tell "out of space" at startup on full disk needed.
Comment: I wonder, does ftruncate() actually reserve the filespace even on systems that support sparse files?

Also: I've heard that Apple has started work on a new filesystem, not derived from HFS. Until they do so OSX will never be usable for servers, and will be annoying for developers deploying to linux/solaris/etc.
Comment: After trying with a smaller file, the bug disappeared. So I think your answer is right, after ftruncate the first writes are probably materializing the file. Given that everybody runs Redis on Linux for production this is not a big problem, but it's better to know :) Thanks
Answer: antirez, I'm not sure I'll be much help since my Apple experience is limited to the Apple ][, but I'll give it a shot.
First thing is a question. I would have thought that, for virtual memory, speed of operation would be a more important measure than disk space (especially for a NoSQL DB where speed is the whole point, otherwise you'd be using SQL, no?). But, if your swap file is 26G, maybe not :-)
Some things to try (if possible).

Try to actually isolate the problem to the seek or write. I have a hard time believing a seek could take that long since, at worst, it should be a buffer pointer change. Still, I didn't write OSX so I can't be sure.
Try adjusting the size of the swap file to see if that's what is causing the problem.
Do you ever dynamically expand the swap file (as opposed to pre-allocation)? If you do, that may be what is causing the problem.
Do you always write as low in the file as you can? It may be that creating a 26G file may not actually fill it with data but, if you create it then write to the last byte, the OS may have to zero out the bytes before then (deferring the initialization, if any).
What happens if you just pre-allocate the entire file (write to every byte) and not unlink it? In other words, leave the file there between runs of your program (creating it if it doesn't already exist of course). Then in your startup code for Redis, just initialize the file (pointers and such). This may get rid of any problems like those in point 4 above.
Ask on the various BSD sites as well. I'm not sure how much Apple changed under the covers but OSX is just BSD at the lowest level (Pax ducks for cover).
Also consider asking on the Apple sites (if you haven't already done so).

Well, that's my small contribution, hopefully it'll help. Good luck with your project.
Comment: Hello, your comment is great! Thank you very much for it.

About the size, indeed the whole point is the speed, but there are many datasets where just 5% of the whole dataset is usually actively used, so a big swap file can be handy sometimes. In Redis the user is able to configure both the swap file size (the page size, and the number of pages actually) and the amount of RAM that Redis can use, so it's a matter of tuning very well the system for your dataset.

Btw: 1) good idea. 2) indeed, this may confirm if is actual file allocaiton time. 3) it's hard to recover from out of space but...
Comment: (continue) I'll try with 4 too. 5) start up time could be too large, I could like to do it incrementally, and given that with Linux it works, and is the first deployment paltform... 6 & 7) good ideas as well.

Wonderful comment and help. Thanks!

At this point my best guess is that's just mac os x trying to allocate the file on disk after the few writes, and given that's a 26 GB file it takes ages.
Comment: antirez, re "5) startup time could be too large": I was suggesting you do this *once* the first time you run the program and leave the swap file there in between runs. That way, subsequent runs won't have to create the file. They'd still have to initialize it but hopefully that would be a case of just writing a few pointer-type values or zero counts into the start of it.
Comment: That way, you always have a swap file when your program starts - there's no possibility that the OS will lazy-create bits of the file as you're using it. You still need code to expand the swap if you run out of space but that is the case no matter what. The swap maintains it's largest size ever achieved (if you want to reduce it, just delete the file either outside Redis so that it's recreated when you run, or have an option to let Redis re-create on startup whetegher or not the swap file exists).
Comment: Oh, got it, this is also viable indeed. The swap file does not need any initialization at all as the pages table is taken in memory for performances. So actually Redis could just check if the file is there. Also the current approach is lame as it creates the swap file in /tmp. The user want it to be created where there is a fast drive like an SSD or something alike. So... actually "named" swap file is better. vm-swap-file <...>. Thanks for the good idea!
Answer: Have you turned off file caching for your file? i.e. fcntl(fd, F_GLOBAL_NOCACHE, 1)
Comment: No, It's a good idea of the OS cache can cache the file when there is free memory in the system. Actually one of the legitimate usages is to trade CPU cycles for memory, as data stored in VM is much smaller but slower to access.

So in theory it should be be a normal file, but if you think this could be the problem I can try it actually. I'll report back my findings. Thanks for the answer.
Answer: Have you tried debugging with DTrace and or Instruments (Apple's experimental dtrace front-end)?
Exploring Leopard with DTrace
Debugging Chrome on OS X
Comment: I tried dtruss in order to see the calls, without too succes, no hints about why it takes so long. Probably it's some blocking thing the OS is doing like materializing part of the file on disk after the ftruncate? I'll try more and thanks for the links and the answer.
Answer: As Linus said once on the Git mailing list:
"I realize that OS X people have a hard time accepting it, but OS X
filesystems are generally total and utter crap - even more so than
Windows."
Comment: Amusing, but not a helpful answer.


How to print typed parse tree

Question: -dparsetree can be used to print untyped parse tree, but how can one print typed AST in OCaml? I looked into the typing directory in the source code, it seems that some functions can do this.
Answer: Use -dtypedtree.  It is a newer feature than -dparsetree and introduced from 4.01.0. You need to upgrade your compiler if ocamlc does not have it.
Unfortunately -dtypedtree does not show the type information of the typed AST.  I am afraid there is no option or tool to print it with type information currently.  Probably since printing all the type info attached to the subnodes is too hard to read, I am afraid. For example, even a simple code let f x = x + 1 has the following typed AST:
let (f : int -> int) =
  (fun (x : int) ->
    (( ( (+) : int -> int -> int) (x : int) : int -> int) (1 : int) : int) : int -> int)

The best way is to write your own printer of typed AST which only prints types of your interest.
Comment: Thx! seems that -dtypedtree does not carry type information. For example, by looking at what ``-dtypedtree`` prints out, I cannot know "let f x = x + 1" has type ``val f: int -> int``. Is there a way to see the parse tree as well as type information? simply let compiler to infer ``.mli`` file cannot do this.
Comment: Yes, `-dtypedtree` unfortunately drops inferred types.  I extended my answer.

How to print typed parse tree


Is the linear approximation of the product of two functions the same as the product of the linear approximations of the two functions?

Question: I have just seen a lecture about linear approximation, in which it was established that when $x$ is near $0$:

The linear approximation of $e^x$ is $1+x$

The linear approximation of $(1+x)^r$ is $1+rx$

Afterwards, the lecturer explained how to find—using 1 and 2—the linear approximation of:
$e^{-3x} \times (1+x)^{-1/2}$.
His next line is:
$(1-3x)(1-0.5x)$
So it seems that he was acting under the assumption that the linear approximation of the product of two functions is the product of the linear approximations of the functions.
Is that true in general for any order of approximations? Maybe just for linear ones? Maybe just when x is near zero? Maybe only when the approximation is linear and x near 0?
Here is a link to the lecture. The comments were made at 26:30.
Comment: Sorry -- I meant to be dismissive of the professor, not of your question. You're right to be skeptical of this, because it's incorrect (though, as an answer now points out, it _is_ correct up to first order. That is, if you take a linear approximation to this approximation, you get a correct linear approximation of the original function).
Comment: This is always correct. If we approximate $f$ and $g$ near $a$ by $f(a) + f'(a)x$ and $g(a) + g'(a)x$ respectively, then the product of these approximations is $f(a)g(a) + (f(a) g'(a) + f'(a) g(a)) x + f'(a)g'(a)x^2$. You can see the linear term agrees with the formula for the product rule, which is the "correct" way to compute the linear approximation.
Comment: $(1-3x)(1-0.5x) = 1.5x^2 -3.5x+1$ is a _quadratic_ approximation. The correct linear approximation is given by the [product rule](https://en.wikipedia.org/wiki/Product_rule)
Comment: thanks for the correction, but I still don't understand why is it allowed to take the product of the linear approximations of the inner functions as any order approximations of the whole function.
Comment: $(1-3x)(1-0.5x) = 1.5x^2 -3.5x+1$ and the linear approximation is $ -3.5x+1$.  So the question in the title has answer "no".  But we can multiply and then drop extra terms, so this is a fast method to do it.  As remarked by Halia, it is the same result as using the product rule.
Comment: @HallaSurvivor  is it (" if you take a linear approximation to this approximation, you get a correct linear approximation of the original function") true generally, or only at this case?
Answer: This is commonly used, and that is because the difference between the two is negligible.
In general, if we have a function $f(x)$ approximated by $f(x_0)+f'(x_0)(x-x_0)$ and another function $g(x)$ approximated the same then you can do some algebra to multiply the two approximations in a part and multiply the two functions then approximate in the other part and compare the results, it won't be the same but the difference would be pretty negligible as long as $x$ is close to $x_0$ so you can use the two methods interchangeably, to be exact the difference would be $f'(x_0)g'(x_0)(x-x_0)^2$.
Comment: thanks for your input! I do not understand it, though. what do you mean by "in a part"? I find it all hard to follow.
Answer: Let's consider the function in question, $f(x)=e^{-3x} \cdot (1+x)^{-1/2}$. To find the linear approximation we need to compute $f(0)$ and $f'(0)$:

$f(0)=1$
Using the product rule, we find that $$f'(x)=-\frac{e^{-3x}(6x+7)}{2(1+x)^{3/2}} \, .$$Hence, $f'(0)=-7/2$.

The linear approximation formula is $$f(a+h) \approx f(a)+f'(a)h \, .$$ At $a=0$, it is
\begin{align}
f(h)&\approx f(0)+f'(0)h \\
f(h)&\approx 1-\frac{7}{2}h \, .
\end{align}
Since you used the variable $x$ in your question, we'll rewrite this as $f(x) \approx 1-\frac{7}{2}x$. This is not the same as the approximation given in the lecture. As HallaSurvivor notes in the comments, the approximation given is a quadratic approximation. If we expand the brackets, it is
$$
f(x) \approx 1.5x^2 - 3.5x + 1 \, .
$$
But this approximation is only very rough and ready. If we use the formula
$$
f(a+h) \approx f(a) + f'(a)h + \frac{f''(a)}{2}h^2
$$
we obtain a different result, which is better than the one obtained by the lecturer. Still, the quadratic approximation obtained by the lecturer is better than the linear approximation we computed earlier.
Comment: thanks! it did make sense to me that the product of the linear approximation will give a good approximation, but now that I know that it is not the best quadratic approximation, it all makes more sense to me.
Answer: You can prove that the approximation at each order, is exactly equal:
Let $H(x)=f(x)g(x)$, by approximating $f$ and $g$ by their taylor series:
$$H(x)\approx \left(f(x_0)+f^{\prime}(x_0)(x-x_0)+\frac{f^{\prime \prime}(x_0)}{2}(x-x_0)^2+\dots\right)\left(g(x_0)+g^{\prime}(x_0)(x-x_0)+\frac{g^{\prime \prime}(x_0)}{2}(x-x_0)^2+\dots\right)$$
Multiplying and grouping by $(x-x_0)^k$:
$$H(x)\approx f(x_0)g(x_0)+(x-x_0)\left(f(x_0)g^{\prime}(x_0)+f^{\prime}(x_0)g(x_0)\right)+(x-x_0)^2\left(\frac{f(x_0)g^{\prime\prime}(x_0)}{2}+\frac{g(x_0)f^{\prime\prime}(x_0)}{2}+f^{\prime}(x_0)g^{\prime}(x_0)\right)$$ which, using the product rule, you can check that equals the taylor expansion of $H(x)$.
So, yes, approximating each function separately up to order $k$ and then multiplying them will give you the same answer as approximating the function as a whole up to the same order $k$. In your example, you are approximating the functions up to linear terms, therefore, your approximation of $e^{-3x}(1+x)^{-1/2}$ will be correct up to linear terms, and the quadratic one will be incorrect and should be discarded.
Comment: nice, really what I was looking for. I think the professor should have talked about that - I hate it when those kinds of steps are skipped.
Answer: The linear approximation of a product equals the product of the linear approximations modulo terms of degree $2$.
Define the operator $M_1$ that takes a differentiable function and giving the linear approximation of it:
$$
M_1 f(x) := f(0) + f'(0) x
$$
Then,
$$\begin{align}
M_1 f(x) \, M_1 g(x)
&= (f(0)+f'(0)x)(g(0)+g'(0)x) \\
&= f(0)g(0) + f(0)g'(0)x + f'(0)g(0)x + f'(0)g'(0)x^2 \\
&= (fg)(0) + (fg)'(0)x + f'(0)g'(0)x^2 \\
&= M_1(fg)(x) + O(x^2)
.
\end{align}$$


Intuition behind Modern Idea of Differential Calculus of several variables

Question: I have read that The modern idea of differential calculus of several variables is it tries to approximate increment in dependent variable by a linear map acting on independent variable.
What is the Intuition behind approximating something by a linear map?Also why the linear map has to act on increment in independent variable?
Comment: Yes, the fundamental strategy of calculus is to take a nonlinear function $f$ (difficult) and approximate it locally by a linear function (easy). When you do this, calculations tend to be greatly simplified, and the approximation is often accurate enough that the result is still useful.
Comment: Because the error is zero when the increment is. You could phrase things in terms of [affine maps](https://en.wikipedia.org/wiki/Affine_transformation) instead if you don't want that focus.
Comment: I'd say we've come to realize linear algebra is immensely powerful and surprisingly "complete", so it's a very solid foundation to build other theories on top of. Of course, you have to appreciate linear algebra to appreciate this conceptual framework.
Comment: Why the linear map has to act on increment in independent variable
Answer: $\newcommand{\Reals}{\mathbf{R}}\newcommand{\Vec}[1]{\mathbf{#1}}$Though calculus may appear to be a study of "variables", the modern mathematical viewpoint is really that calculus studies functions or mappings, i.e., causal relationships between variables. (Causal here means that in a functional relationship $\Vec{y} = f(\Vec{x})$, each value of $\Vec{x}$ uniquely determines a value of $\Vec{y}$. Relationship between variables refers to the fact that the derivative is a property of $f$, not of $\Vec{x}$ or $\Vec{y}$. This is not the explicit stance in all quantitative fields, and may not even be widely recognized by students of mathematics.)
In mathematics, a functional relationship $\Vec{y} = f(\Vec{x})$ is given by a formula or other deterministic specification in the input variable(s) $\Vec{x}$. In the sciences, "laws of nature" are assumed to have the character of functional relationships (e.g., the current state $\Vec{x}$ of a system uniquely determines the future state $\Vec{y}$), but all we are able to do is prepare isolated values of $\Vec{x}$, perform experiments, and measure outcomes $\Vec{y}$.
To "explore" a law of nature, a good experimenter will prepare a system depending on a finite number of numerical quantities, say $\Vec{x} = (x_{1}, x_{2}, \dots, x_{n})$, and then make a number of numerical measurements of $\Vec{y} = (y_{1}, y_{2}, \dots, y_{m})$ by (i) changing the variables one at a time (or controlling the variables) (ii) by small amounts.
The simplest systems are those for which increments have independent effects on the output. These are precisely linear (or really, affine) mappings. In more detail, suppose our "initial" system is in a state represented by the values $\Vec{x}_{0}$, and write $\Vec{y}_{0} = f(\Vec{x}_{0})$. Suppose $\Delta\Vec{x}_{1}$ and $\Delta\Vec{x}_{2}$ are "changes in the input variable", and write
\begin{align*}
  \Delta\Vec{y}_{1} &= f(\Vec{x}_{0} + \Delta\Vec{x}_{1}) - f(\Vec{x}_{0}), \\
  \Delta\Vec{y}_{2} &= f(\Vec{x}_{0} + \Delta\Vec{x}_{2}) - f(\Vec{x}_{0}).
\end{align*}
To say increments have independent effects is to say that for all real parameters $t_{1}$ and $t_{2}$,
\begin{multline*}
  f(\Vec{x}_{0} + t_{1}\, \Delta\Vec{x}_{1} + t_{2}\, \Delta\Vec{x}_{2}) - f(\Vec{x}_{0}) \\
  \begin{aligned}
  &= \underbrace{\bigl[f(\Vec{x}_{0} + t_{1}\, \Delta\Vec{x}_{1} + t_{2}\, \Delta\Vec{x}_{2}) - f(\Vec{x}_{0} + t_{2}\, \Delta\Vec{x}_{2})\bigr]}_{t_{1}\, \Delta\Vec{y}_{1}}
  + \bigl[f(\Vec{x}_{0} + t_{2}\, \Delta\Vec{x}_{2}) - f(\Vec{x}_{0})\bigr] \\
  &= t_{1}\, \Delta\Vec{y}_{1} + t_{2}\, \Delta\Vec{y}_{2}.
  \end{aligned}
\end{multline*}
(The underbraced quantity manifests independence, i.e., the increment in the output is the same regardless of where that increment is applied.)
By induction on the number of increments, the same is true for any finite number of increments. Formally, $f(\Vec{x}_{0} +\;\cdot\;) - f(\Vec{x}_{0})$ distributes over linear combinations of increments in the input.
In reality, laws of nature tend not to be so simple. Nonetheless, it is an empirical fact that many phenomena are approximately linear for small changes in the input. And that leads us to define differentiable mappings to be approximately linear.
Precisely, if $f$ is an $\Reals^{m}$-valued mapping defined in a neighborhood of $\Vec{x}_{0}$ in $\Reals^{n}$, we say $f$ is differentiable at $\Vec{x}_{0}$ if there exists a linear transformation $Df(\Vec{x}_{0}):\Reals^{n} \to \Reals^{m}$ and an $\Reals^{m}$-valued mapping $E$ such that
$$
f(\Vec{x}_{0} + \Delta\Vec{x}) = f(\Vec{x}_{0}) + Df(\Vec{x}_{0})\, \Delta\Vec{x} + E(\Delta\Vec{x}),\qquad
\lim_{\Delta\Vec{x} \to \Vec{0}} \frac{\|E(\Delta\Vec{x})\|}{\|\Delta\Vec{x}\|} = 0.
$$


Git/EGit doesn't seem to exist within eclipse?

Question: Hi I installed Egit from the eclipse market place...

...But when it doesn't appear in the Team drop down? I can't see it anywhere?

I've tried uninstalling and I received:

"Java implementation of Git" cannot be fully uninstalled because other
  installed software requires it.  The parts that are not required will
  be uninstalled.
"Eclipse Git Team Provider" cannot be fully uninstalled because other
  installed software requires it.  The parts that are not required will
  be uninstalled.

Any ideas?
FYI

Eclipse Version: Luna Service Release 1 (4.4.1)
Mac OSx Yosemite
Java 8
Answer: A simple reinstall of eclipse was all that was needed. I hope this helps someone else.


Regularly applying oil to a guitar's fingerboard: how necessary is it?

Question: Reading this question about how to apply lemon oil to a guitar's fingerboard got me thinking, how necessary is this practice?
Checking around forums, seems that some people argue that it makes no difference at all, while others argue that it carries many benefits. Some of them are opinion-based, but are there actual objective, pragmatic, reasons for applying oils (normally lemon oil) to the fingerboard?
So, is this moisturing really necessary? What are the consequences of skipping the oiling maintenance step?
Comment: I've never heard about this and so never used it.
Comment: I think you'll find two types of musicians: those that treat their guitars like work of art, and those that treat them like tools. I'm of the second kind and I may do a little cleanup when changing strings, but in the end.. it sounds the same. If you look at it like an art piece, then I believe there will be a lot of almost religious opinions about how it should be taken care of but it's still wood with a treatment on it and many things will clean it. When I clean something, it's paper towel with water and I've never had problems with it.
Comment: Never use full strength pure lemon oil.  It is too intense for porous wood and could damage it.  Products specifically made for guitars often contain lemon oil as one of their ingredients, but it is diluted.  Never use furniture polish on your guitar.  I have ten acoustic guitars and rarely ever apply any oil to the fretboard unless I do a fret dress or clean the fretboard during a string change (thereby wiping off any oil that exists).  The oil from my fingers keeps my regular "players" fretboards oiled enough.
Answer: It depends on multiple factors. When you store your guitar in a room that isn't too humid or dry, it might not be necessary at all. It also depends on the type of wood. You don't want to oil a maple fretboard. Rosewood fretboards can benefit from it.
You can tell by the color of the wood when it tends to dry out. I've used Dunlop's product on my Fender Jazz bass before, and it did make the wood (after settling) a bit darker.
If your fretboard is varnished, I wouldn't use any kind of product on it.
Do mind that using these kind of products, will dirt up your neck and strings (and thus turning them dead) faster.
Comment: @Lyd A maple fretboard is either finished, in which case oil will do nothing, or it is unfinished, in which case oil will cause dirt to be picked up. The latter case isn't a concern with dark fretboards because the dirt is not visible like it is with maple
Answer: I choose to oil the fingerboard and bridge of the guitars that I own, and those that I build. I find that it adds to the look of the instrument, and less so but still relevant, the feel. This is purely opinion/personal. I use a 33/66 mineral oil/beeswax mixture and use it very sparingly (almost as a polish). Mineral oil = lemon oil and I have used mineral oil in the past.
I've never had a fretboard dry out to the point that oil would have saved it, but I keep my guitars humidified and taken care of. If your fingerboard is cracking, it's either 1) ebony or 2) so dry that the top has already cracked.
1) Ebony (or blackwood or other esoteric/exotic) fingerboards tend to be less stable than rosewood/maple. That being said, if you own a guitar with an ebony fingerboard (they are expensive nowadays), then you likely paid enough that you're going to humidify/care for your guitar.
2) A solid spruce top guitar will crack at the top due to dryness far before the fingerboard cracks from the same factors. If you let it get to the point where the fingerboard (rosewood/maple) also cracks, you likely have damage that is irreparable simply with oil. A luthier will have to fix it. I would hope one would notice and take the guitar for repair/advise before this point.
Answer: Generally, if you have a guitar that you regularly play and take care of, it's largely unnecessarily. Nicer guitars where the fretboard is made of rosewood and ebony, tight-grained oily woods, generally don't need it no matter what
On the other hand, many of cheaper guitars, particularly those made before say the 1990s, have fretboards made of all kinds of wood, poplar or maple or who knows what. And often these guitars are stored away in places with wild temperature swings, low humidity, and generally neglected.
These sorts of guitars benefit a LOT from a light oiling--it'll bring the color back into the overly dry wood and tighten up the grain so it looks less like a barn door and more like a fretboard.
TLDR nice guitars that are played and cared for rarely need it. Cheap abandoned guitars often can use some oiling.


Getting error while joining two tables

Question: Here is query which is, I am using
$query = db_select('users','u');
$query->join('users_roles', 'u.uid = users_roles.uid'); // JOIN users_roles with users
$query->fields('users', array('name','uid')) // SELECT the field name from users
    ->condition('users_roles.rid', 5);

  $results = $query->execute();

Actually i want the user name and id for that those user who are under role id = 5

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1066
  Not unique table/alias: 'u': SELECT users.name AS name, users.uid AS
  uid FROM {users} u INNER JOIN {users_roles} u.uidusers_roles.uid WHERE
  (users_roles.rid = :db_condition_placeholder_0) ; Array (
  [:db_condition_placeholder_0] => 5 ) in user_assign_list() (line 80 of
  C:\xampp\htdocs\nic\sites\all\modules\user_assign\user_assign.module).

This error shown on the browser. Actually i am creating the custom module file for this requirement. Is there any need to include sql connection for those custom module?
here is .module file
<?php
function user_assign_permission() {
  return array(
    'submit user_assign' => array(
      'title' => t('Submit user_assign'),
      'description' => t('Submit the user_assign form'),
    ),
    'access user_assign list' => array(
      'title' => t('Access user_assign list'),
      'description' => t('Access the user_assign submissions'),
    ),

  );
}
function user_assign_menu() {
  $items = array();

   $items['users-list'] = array(
    'title' => t('User Assign'),
    'page callback' => 'user_assign_list',
    'access callback' => TRUE,
    'access arguments' => array('access user_assign list'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function user_assign_theme($existing, $type, $theme, $path) {
  return array(
    'user_assign_function' => array(
      'variables' => array('rows' => NULL),
    ),
    'user_assign_template' => array(
      'variables' => array('rows' => NULL),
      'template' => 'user_assign_template',
    ),

  );
}

function theme_user_assign_function($variables)
{
    $output = '';

//   print_r($variables);
    foreach($variables['items'] as $row) {

     $output .= '

'.$row[1].'&nbsp'.$row[2].'

';

    }

    return $output;
}

function user_assign_list() {
 // $query = db_select('users', 'n');

//  $query->condition('n.empname', '%' . db_like($_GET['empname']). '%','LIKE');

 // $query->fields('n', array('fe_id', 'empcode','empname','empphoto','empemail','empdesignation'))
  //    ->limit(4)
  //    ->addTag('node_access')
  //    ->groupBy('n.fe_id');
$query = db_select('users','u');
$query->join('users_roles', 'u.uid = users_roles.uid'); // JOIN users_roles with users
$query->fields('users', array('name','uid')) // SELLECT the field name from users
    ->condition('users_roles.rid', 5);

  $results = $query->execute();
     $rows = array();
  foreach($results as $result)
  {
    $rows[] = array(
        $result->uid,
        $result->name,
        );

  }
  $output = theme('user_assign_function', array('items' => $rows));
  return $output;
}

?>

Answer: Hi Sumit check the below query and it not showing any error.
Use Query coder module to create any query in drupal format
Query coder Convert SQL query to Drupal Database abstraction layer code.
$query = db_select('users','u');
$query->join('users_roles', 'r', 'u.uid = r.uid'); // JOIN users_roles with users
$query->fields('u', array('name','uid')) // SELECT the field name from users
    ->condition('r.rid', 5);
$results = $query->execute();
     $rows = array();
foreach($results as $result)
  {
$rows[] = array(
    $result->uid,
    $result->name,
    );

}

Getting error while joining two tables


Windows Filesystem Minifilter Drivers: can I monitor and prevent FS operations using them?

Question: I need to:
1. Monitor operations on certain drives/paths
2. Prevent read and/or write operations on certain drives/paths
For example:
C://Users
D:

Can this be done using Windows Filesystem Minifilter Drivers ?
I am mostly interested in step 2. In other words can a minifilter cancel a IRP ?
Answer: Yes this is all possible with a filesystem mini filter driver.
For #1 you don't need a mini filter driver you could use a Win32 API like ReadDirectoryChangesW.
For #2 you can not only do that but you can also modify what gets read/written, even of different size.
You can get started here.
Comment: ty. my reasons for using minifilters for 1. is that ReadDirectoryChangesW reports access operations delayed by 1d (xp) or 1h (vista+)
Answer: Raymond Chen, who is a long-time Windows developer, addressed a version of this question on his blog - he would recommend using ACLs for preventing operations rather than trying to get code to run to stop it.  See his post on this for some thoughts...
Comment: [professional sollutions](http://www.pgp.com/products/endpoint/index.html) seem to use divers. also setting ACLs on endpoints programmatically is [hard-ish](http://diaryproducts.net/about/operating_systems/windows/disable_usb_sticks), and setting ACLs on, say, USB Disks conditionally by serial number and other factors seems only doable by drivers.
Answer: I would suggest using Detours library to handle this task.


Socket fix error TypeError: an integer is required

Question: I have to
 Connect to alien server ('localhost', 10000),
Then send USER followed by aliensignal
But I get an error message that's mean that the format of my .send is incorrecte.
Do you know what's the good way to send two differents string in one .send?
import socket
clientsocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
clientsocket.connect (('localhost', 10000))
clientsocket.send('USER:','aliensignal')

Traceback (most recent call last):
File "/tmp/usercode.py", line 15, in <module>
clientsocket.send('USER:','aliensignal')
TypeError: an integer is required

Comment: The signature of the send function is as follows, where the last parameter passed to send function is an integer. You are passing 'aliensignal', which is a string  as the last parameter

def send(self, data, flags=0)
Answer: [Python 3.Docs]: socket.send(bytes[, flags])'s (optional) flags argument must be an integer (normally you shouldn't use it, but if you want more details check [man7]: RECV(2)).
As for your current case, you can either:

Call send twice (once for each of them):
clientsocket.send(b"USER:")
clientsocket.send(b"aliensignal")

Concatenate the strings (bytes) and send them both at once:
clientsocket.send(b"USER:aliensignal")

Answer: The docs for socket.send() say the second positional argument(s) are int, not str.  It further states more information about this argument can be found in recv(2) of a Unix manual.  Here, at least, is a Linux man page for recv(2)
Answer: send only takes a string and option integer flags that normally aren't used.  TCP is just a byte stream and there are no message boundaries.  The protocol for what makes a complete message must be defined.  Your alien server needs to be a bit more specific.
You can do:
clientsocket.send(b'USER:aliensignal')

but you can also do variations of the following.  The bytes are just entered into the transmit buffer in the same order.
clientsocket.send(b'USE')
clientsocket.send(b'R:a')
clientsocket.send(b'liens')
clientsocket.send(b'ignal')

So how does alien server know you've sent a complete message?  Here are some possible ways:

Close the client connection.  The server can keep reading bytes until it recv returns 0, which means the client closed the connection.
Use a delimiter.  Send a newline \n character at the end of the message.  The server can read until it finds a newline and know that it has the complete message.  If it reads beyond the newline, it can save the excess as part of the next incoming message.
Send the length in bytes of the message, then the message.  send(b'\x16User:aliensignal') for example.  For longer messages, the protocol can agree on the length and endianness of the message, e.g. 32-bit (4-byte) big-endian length.


How/Can I dynamically set Contexts in CircleCi

Question: I have a circle CI environment in which I'd like to assign context dynamically to deploy to 4 different environments.
Ideally I'd like to set the context using a pipeline parameter, any ideas how I can achieve this?
Example how I'd expect to achieve this:
parameters:
  test-contxt:
    type: string
    default: "staging"

build-test-on-prod-pr:
    jobs:
      - build-api:
          context:
            - "<< pipeline.parameters.test-context >>"
      - test-api:
          context:
            - "<< pipeline.parameters.test-context >>"
      - deploy-api:
          context:
            - "<< pipeline.parameters.test-context >>"

Trying this approach results in this error:
#!/bin/sh -eo pipefail
# Error calling workflow: 'build-test-on-prod-pr'
# Unknown variable(s): test-context

Answer: So the sample I posted in my question does actually work, the mistake I was making was a typo in the parameter. However I'll leave this question up just in case its helpful. I also removed the quotes, but I don't think that matters.
parameters:
  test-context:
    type: string
    default: "staging"

build-test-on-prod-pr:
    jobs:
      - build-api:
          context:
            - << pipeline.parameters.test-context >>
      - test-api:
          context:
            - << pipeline.parameters.test-context >>
      - deploy-api:
          context:
            - << pipeline.parameters.test-context >>

Comment: Yeah, I think it would. As right now, both the question and answer have the same code. OR whatever info you feel is needed for the question.
Comment: What is the typo?
Comment: It's been a while since I did this, I did edit the question at some point and changed the code before I managed to get it working.

1.  The question originally posted used code copy pasted from my 1st attempt

2.  Made some changes locally and got a different error (unknown variables)

3.  Updated my question with changes + new error. Likely did this manually without copy pasting so didn't duplicate my typo from local config to the post

4.  Realised the second issue was a typo, but the config I had provided served as a correct example for the question I'd asked originally
Comment: I appreciate that this makes the post a little confusing, do you think it would be helpful to change the example in the question to include the typo that I had made in the original question?