How to fix CORS issue between webflow and netlify

Question: I have deployed my first netlify site that simply returns a few records from airtable:
https://codefy-airtable.netlify.app/.netlify/functions/courses
it also works with a redirect I set up:-
https://codefy-airtable.netlify.app/api/courses
However, when I add an axios get function to my header script in webflow to test it I get a CORS error:-

"Access to XMLHttpRequest at
'https://codefy-airtable.netlify.app/.netlify/functions/courses'
from origin 'https://mgl-community.webflow.io' has been blocked by
CORS policy: No 'Access-Control-Allow-Origin' header is present on the
requested resource."

mgl-community.webflow.io
Make Give Live | Community
This is my function:-
   axios.get('https://codefy-airtable.netlify.app/.netlify/functions/courses')
  .then(function (response) {
    console.log('axios ', response);
  })
  .catch(function (error) {
    console.log('Axios ', error);
  });

This is my github repo https://github.com/jonathanlyon/airtable-temp that shows the _header file with:-
/*
Access-Control-Allow-Origin: *

and the .toml file with:
[[headers]]
for = "/*"
[headers.values]
Access-Control-Allow-Origin = "*"

Any idea why I can't use the json data returned from the URL please?
Thanks
Jonathan
Answer: I figured out a way to add headers to my code and now it works. Seems that despite having a _header file and adding headers to the .toml file in Netlify it didn't do the trick.
In my api return I added headers:-
module.exports = (statusCode, body) => {
    return {
        headers: {
          "Access-Control-Allow-Origin": "*"
        },
        statusCode: 200,
        body: JSON.stringify(body)
      };

    };

Comment: So you need `headers` in three parts to solve the `cors`? a) `netlify.toml` b) `_headers` c) `handler function`. There is `handler()` missing which is needed as of today with `import { Handler } from '@netlify/functions'`.
Comment: In my case, one of the three files mentioned in my last comment has to be prepared for `cors` and then it works with `localhost/.netlify..`.
Answer: You have to modify your API,
install cors with:  npm install cors,
then in your middleware:
import cors from 'cors'

app.use (cors ())

Comment: The answer does not help at all, because `express` is not used. Welcome to so.
Answer: I encountered the same problem and found that the problem is due to the limitation "10 second execution limit for synchronous serverless functions" (reference: https://docs.netlify.com/functions/overview/)
My finding is that, after the Netlify function was called after 10 seconds, the Netlify function will continue to run, however, the response contains the body

TimeoutError: Task timed out after 10.00 seconds new TimeoutError
(D:\yourModule\node_modules\netlify-cli\node_modules\lambda-local\build\lib\utils.js:110:28)
Context.
(D:\yourModule\node_modules\netlify-cli\node_modules\lambda-local\build\lib\context.js:110:19)
listOnTimeout (internal/timers.js:554:17) processTimers
(internal/timers.js:497:7)

Body of response (by Postman)
and the header with only keys "x-powered-by", "date", "connection" and "content-length".
Header of response (by Postman)
Since there is no 'Access-Control-Allow-Origin' header, the browser shows the error message

Access to XMLHttpRequest at 'http://localhost:8888/.netlify/functions/yourFunction/' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

In Firefox, the error message is

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8888/.netlify/yourFunction/. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

However, the root cause is not the CORS setting in server. The error message may direct you to the wrong direction.


Quais os tipos de armazenamento para aplicações desktop?

Question: Bom, estou desenvolvendo uma aplicação Java para gerenciar meu extrato bancário, para separar os lançamentos por categorias e data, para futuramente gerar gráficos.
Quais são os meios salvar, modificar e consultar os dados? De forma que eu possa facilmente repassar o aplicativo, sem ter a necessidade de instalar um banco de dados a parte, MySQL por exemplo.
Eu já conheço 4 formas, mas não sei se são praticas a longo prazo:

Manipular um Json.
Manipular um Xml.
Criar um banco de dados com SQL Lite e afins.
Salvar o objeto serializado no Java.

Perguntas:

Quais as vantagens e desvantagens dessas formas?
Qual a mais viável para esse projeto ser fácil de distribuir?
Existe alguma solução melhor que eu poderia adotar?
Comment: Eu acho que a edição tornou a pergunta ampla.
Comment: Seja bem vindo ao StackOverFlow Português. Sua pergunta e baseada em opiniões e ela pode ser fechada. Adote a tecnologia que melhor se adapta a sua necessidade, se vc tiver duvidas (Programação) no decorrer do uso dela, vc pode postar a pergunta aqui que a comunidade lhe vai ajudar.  Lembre-se também de postar seu código.
Comment: O banco de dados da sua aplicação vai ter muitas tabelas?
Comment: é amplo demais..
Answer:
Quais as vantagens e desvantagens dessas formas?

Métodos 1 e 2 são bons para dados somente leitura, pois é fácil carregar e acessar o que se deseja.
Entretanto, considerando que você vai frequentemente querer consultar e filtrar os dados em diferentes formas, acredito que seja mais coerente usar um banco de dados embutido no programa como proposta em 3. Boas alternativas são:

H2 Database
HyperSQL

O item 4 eu nem consideraria como uma forma de armazenamento decente. Isso pode gerar vários problemas se você precisar evoluir sua estrutura de dados.
Outro problema com 1, 2 e 4 é que você terá que manipular tudo em memória e, para evitar perda der dados, fazer flush constante para o disco. Terá também que se preocupar com a integridade dos arquivos, etc.
Por outro lado, se o programa pretende ser simples e não há muita preocupação com consistência dos dados, nem com consultas mais complexas, gerenciar tudo em memória e serializar para o disco em JSON não é uma má ideia.

Qual a mais viável para esse projeto ser fácil de distribuir?

A melhor distribuição hoje em dia seria numa aplicação web. Se precisar fazer uso offline, pode criar um APP que funciona com autonomia, mas é capaz de sincronizar com um servidor remoto usando, por exemplo, uma API REST.
Dá mais trabalho, mas com certeza é melhor do que armazenar um banco de dados ou arquivo localmente, principalmente se a ideia é que os dados sejam acessíveis e modificados de vários locais.
Mover arquivos para lá e para cá pode ser uma dor de cabeça. Um dia você sai de casa e esquece de levar a cópia mais recente do arquivo. Aí você fica impedido de fazer qualquer alteração enquanto não voltar para casa. Outro dia você faz uma alteração e não lembra se o arquivo atual é mesmo o mais recente. Se você esquecer em qual ambiente alterou o arquivo pela última vez, ou fizer alterações em dois ambiente sem querer, como vai garantir que os dados atuais estão consistentes?
Entretanto, se você prefere ainda uma versão puramente desktop, o método mais flexível seria usar o banco a partir de um arquivo no disco. Isso é perfeitamente possível e fácil usando os bancos de dados que citei acima.
Existe alguma solução melhor que eu poderia adotar?
Aplicação web, se possível com um aplicativo mobile para lançamentos simples offline e posterior sincronização.
Considerações
Embora eu tenha procurado me ater bem ao contexto da pergunta, alguns pontos aqui são um tanto opinativos e dependem das necessidades específicas de quem vai usar o programa, além das restrições específicas.
Por exemplo, quem vai usar o programa tem um smartphone? Fica frequentemente sem acesso à internet? Anda sempre com um laptop pessoal?
Comment: A primeira instância, o programa vai ficar sem internet. E apenas em laptop ou computador pessoal.


Trouble installing ruby via rvm

Question: I installed Ubuntu today for an internship and was setting up my environment, which required the use of ruby. I tried installing it following the documentation but I keep getting stuck on one step. I tried fixing it using
rvmsudo rvm get stable --auto-dotfiles
rvm fix-permissions system
But it hasn't worked so far. I've also done this:
rvm group add rvm $USER
as well but still no luck
What should I do now?
the error I'm getting
Comment: You should [contact the RVM experts](https://rvm.io/support).
Answer: I got a similar Error. The Below command works for me,
<code>rvm autolibs disable
</code>
Hope this will work for you.

Trouble installing ruby via rvm


Grid graphs eliminating edges

Question: I have an $m \times n$ grid graph. I'm trying to find the maximum number of edges I can remove from the graph such that two vertices can still be connected in some roundabout way.
I know the total number of edges in a grid graph is $2mn - m - n$
I drew this out using a $2 \times 2$ grid and found I could only remove $1$ edge.
On a $3 \times 3$ grid, on a corner vertex, I can still only remove $1$ edge.
Is the maximum number of edges I can remove just $1$?
Comment: "On a $3 \times 3$ grid, on a corner vertex, I can still only remove 1 edge" - that's incorrect. You can remove at least 3 edges (all but one edge adjacent to the central node).
Comment: @Dmitry youre right i just misinterpreted the problem, i was finding the minimum number of edges I could remove not the maximum
Answer: In general for any connected graph with $m$ edges and $n$ vertices it is possible to remove $m-(n-1)$ edges without disconnecting it. This is because if the graph has more edges it will contain a cycle, and any edge in the cycle can be removed.
In your case the number of edges is $(m-1)n+(n-1)m =2mn-m-n$ and the number of vertices is $nm$. Therefore you can remove $mn-m-n+1$ edges.
Comment: so for my $3 \times 3$ hypothetical, I can remove 4 edges: 3 from the center vertex and one from an edge surrounding?
Comment: Yes, and moreover you don't have to be careful when you do it. As long as you don't immediately make the graph disconnected you can keep going until only $|V|-1$ edges remain (where $|V|$ is the number of vertices). In fact there are various theoretical results which can help you. Try to look at theorems that give various analogous definitions for trees.

Grid graphs eliminating edges


Find $a$ such that $E[(X-a)^4]$ is minimised

Question: Given X is a symmetrical random variable and $E[X^4]$ exists. Find $a$ such that $E[(X-a)^4]$ is minimised.
The fact, X is symmetrical, means the odd central moments are $0$. I expanded the expression, worked out the derivative and set it to $0$. I ended up with an answer of $a^2 = -3E[X^2]$. I'm not sure if this is correct.
Comment: Alternatively, if you differentiate without expanding and set to zero you get $E[(X-a)^3]=0,$ which is clearly zero when $a=0$.
Answer: Your calculation is (almost) correct.
\begin{align}
E[(X-a)^4] &= a^4 + 4a^3E[X]+ 6a^2E[X^2] + 4a^3E[X] + E[X^4] \\
 &= a^4 + 6a^2E[X^2] + E[X^4]
\end{align}
because, as you mention yourself, "the odd central moments are 0", i.e.,
$$
E[X] = E[X^3] = 0
$$
and thus
$$
\frac{d}{da}E[(X-a)^4] = 4a^3 + 12aE[X^2]
$$
This is $0$ only when $a=0$ (the other 2 roots of the cubic polynomial are the complex conjugates you found).
Since the derivative changes sign when $a=0$, this is indeed, an extreme value, and since the change is from negative (function is decreasing) to positive (function is increasing), this is a minimum.
Thus the answer is $a=0$.
Comment: Ah thanks, you're the best!
Comment: here symmetry dictates `E[X]=0`
Comment: @Eli.Z: You are welcome. If your question has been answered to your satisfaction, you should [close it by accepting an answer](https://meta.stackexchange.com/q/5234/215439).
Comment: Thanks again! It's my first time posting.
Comment: @karakfa: yes, both the question and the answer mention that. So?


Time Series: Confused about identification of (possibly?) an ARMA(p,q) model

Question: this is my first ever question on a website i use frequently!
This time series has given me much trouble over the last couple of days even after extensive googling, I suppose with TS theres no two series that look the same, hence my confusion!
I have the following ACF and PACF plots for my data:

After modelling NUMEROUS models in R (ARMA(p,q), with all combinations of p=0,1,2,3,4 and q=0,1,2,3,4) and looking at their theoretical acf plots, it seems R's auto.arima gave the best model with p=q=2.
But in my work, i don't want to just say i used R and inferred nothing from the ACF plots haha!
I understand that the slightly significant PACF at lag 1 indicates an AR component(?) and that as both plots 'slope off' it suggests a ARMA(p,q) model, but is there anything else im missing????
Also; the ts (in my eyes) seems seasonal, however ironically, no amount of differencing makes a difference, the plot still looks the same no matter what d equals. (R also tells me its not seasonal)
In short:

What does the ACF plots tell me (main)
Am i right in not differencing the data

Thanks a bunch!!
Comment: Can you edit your post to include your data, by pasting in the result of `dput()` applied to your series?
Comment: Of course!! Thankyou!!! Hope this works
Comment: What time granularity is your data?
Comment: Its monthly, if that answers your question !
Answer: The ACF plot shows a seasonality with a period of about 12 (note the sinusoidal pattern). So the first plot to do is a seasonplot.
seasonplot(ts(foo,frequency=12))

However, that does not look very promising.
So, let's look at your time series plot once more. We do see the seasonality, but we also see that the peaks alternate between being high and low. So there does not only seem to be a yearly seasonality, but one of length 2 years as well. So let's look at a seasonplot for a period of 24 months:
seasonplot(ts(foo,frequency=12))

This looks much more regular than the one above. So let's work with a frequency argument of 24. If we now fit a model using auto.arima(), R indeed gives us a seasonal ARIMA model:
model <- auto.arima(ts(foo,frequency=24))
plot(forecast(model,h=24))

I would rather trust auto.arima() to create a forecast based on minimizing AIC, than trying the older Box-Jenkins approach of trying to parse (P)ACF plots. Note that forecast() gives you nice prediction intervals. Take a look at ?forecast.Arima (note the capitalization). Finally, note that in-sample fit is not a good guide to out-of-sample accuracy. Instead, consider using a holdout sample.
Comment: You HEROOOOoooo!  i was trying a difference of 24 months but maybe i just didnt trust it. Fantastic.
Comment: Just a side note - the question asks me to write down the formula for model found; when doing this and writing Z_{t} as the white noise, do i state what i found as the white noises standard deviation?? ie.  do i write Z_{t} ~ N(0, sd(model$res)) next to the model, or do i just leave it out and assume its unknown? (if you understand this question lol) Thanks a bunch anyway!
Comment: You would typically write out that $Z_t\sim N(0, \hat{\sigma}^2)$, where the estimate for $\hat{\sigma}$ comes out of `auto.arima()`.
Answer: Trying a list of arima which assume that there are no deterministic structure is frequently inadequate as the correlogram should be calculated from residuals using a model that controls for intervention administration, otherwise the intervention effects are taken to be Gaussian noise, underestimating the actual autoregressive effect. See @AdamO's reflections here @Interrupted Time Series Analysis - ARIMAX for High Frequency Biological Data?.
In a similar ( but different way ) trying to parse/match the original acf/ccf to a set of models (using mid 60's procedures) is also flawed for the same reason ( untreated deterministic structure)
This explains why the following paradigm works well because it integrates both ARIMA (memory) and latent deterministic structure while validating homogeneity/constancy of model parameters and model error variance over time.
https://autobox.com/pdfs/ARIMA%20FLOW%20CHART.pdf
Comment: I see, so basically don't just assume models that have similar looking acfs are accurate. Think about the data!! (added)
Comment: equivalently examine the data to identify structure be it a combination of arima , level shifts, local time trends , seasonal pulses , pulses and possible breakpoints in parameters or model error variance over time.


Why are the Goldberg Variations considered a demanding work?

Question: In print, the Goldbergs (Goldberg Variations) have a quasi-legendary status, a hallmark of technical difficulty.
I was perusing the score and it doesn't look terribly intricate for what's possibly a majority of the variations - certainly less than Bach's 3- or 4-part works.
Aria looks easy-peasy, the first variation has some fun going on with the LH and you have to work on your fingering with the RH and do some thumb-under-ing , but it doesn't look impossible, ditto for 2nd. 5th looks approachable.
18 very much so.
Even 26, 28: lots of notes, but they look like 1-2-1-2-1-2-1-2... with the occasional pinky leap.
Some are in fact very scary, with all the 32th notes and the > 8th leaps and whatnot, but even then they look more like good ol' fashioned keyboard shredding than... um, the really really scary Rachmaninov stuff.
Am I being superficial and ignorant (I am an amateur with little training beyond Old MacDonald Had A Farm), is this stuff deceptively simple or is there, in fact, a significant portion of them that's actually playable?
Answer: The Goldberg Variations are considered infamous / demanding for a few reasons, which I will outline briefly below.  Firstly, the reasons why the work is infamous:

The work is a theme and variations, and to my knowledge there is only one other JS Bach piece that follow suit (see comments below).
The work represents the highest model of Baroque theme and variations.  Many of JS Bach's works represent the highest models of their respective art forms; Bach was a master of all Baroque art forms.
The underlying structure of the piece is incredibly carefully conceived and executed.  Read here under "form" to learn a little bit more about the larger structure of the piece.

Why the piece is demanding

It's long - 30 variations and an aria is no joke; it's a lot of heavy lifting.
One thing that makes Bach notorious (and one of the reasons why he's on almost every audition list for every instrument at every school) is because of how deceptively difficult the music is.  Much like Mozart, you can play the notes and get through it, but you really have to know how to play the notes to make it come alive, especially with Bach; there are so many notes...how will you choose which ones are the most important?
Since it's Bach, you can bet about 1,000,000 other people have studied, performed, and recorded it very well, so you are competing with all of the other interpretations and performances.  What will you do to make yours stand out? How will you make sure you don't miss any notes?
JS Bach did not write music with the intention of it being hard.  He himself was too hard-working, too industrious, and too humble to afford himself that much narcissism.  He wrote music that needed to be written.  Yes, some of it might use 32nd notes, but look at the tempo...is it slow?  Bach wrote music to serve a purpose and he never thought about what would happen to the music after he passed.
Comment: The musical offering is also a theme and variations. Also, the Goldberg Variations are specifically written for double manual harpsichord. Which makes them awkward on the piano since there are many instances of the hands playing in "overlapping" positions.
Comment: To be contrarian, Bach's Aria variata all maniera italiana (BWV 989) is another theme and variations that is less ambitious, but beautiful nonetheless.
Comment: @speedfranklin Thanks for the update; I have studied many Bach works, but not all of them.  Will edit my answer accordingly.
Answer: The theme only looks easy. The hard part is fitting in all the ornaments and getting the result to sound like you were just making it up as you go, but not turning into an incoherent mess. Var 13 and 25 is another two where the notes are easy enough, but it's hard to stop it sounding like a rather boring technical exercise.
The variations that are scariest technically on piano - for example the ones with lots of hand-crossing like 5, 14, 17, 23, 26(!), 29(!!!), are much easier on a double harpsichord, and this is one of the few pieces where Bach explicitly says that's what it was written for. With one hand on each keyboard, either hand can play anywhere from bass to treble without collisions.
Also, there is nothing to say every variation is at the same (slow) tempo as the Aria. Some of the variations with mostly 16th and 32nd notes are actually the fastest in beats-per-minute.
None of the canons are easy, unless you have three hands to play three independent parts at the same time (or you play them on the organ and use your feet....)
Aside from the technical problems, there's the challenge of figuring out "what is really going on" here. My personal opinion is that Bach was letting his hair down a bit. Var 1 sounds great played by an oompah-band-style clarinet (or accordion) and tuba - plus a bit of lederhosen-slapping half way through the second half. Var 30 is a half-inebriated choir in the pub after a gig or a rehearsal - or maybe a Welsh Rugby crowd in full song. The third from last bar of Var 30 really has 5 beats in it, not the 4 that are written ......
Comment: I don't get too hung up about "musicological." An hour's practical experience playing a harpsichord will teach you more about the Aria (than reading 20 books of musicology IMO. In Bach;s time, the foundations of Liberal Arts education were grammar, logic, and rhetoric. The second level subjects were arithmetic, geometry, music, and astronomy. Thing of musical ornaments as analogous to the rhetorical devices used when delivering a speech, arguing a point, etc.
Comment: She isn't going to end up in jail if she copies somebody else's version blindly. But from your other questions I got the idea you wanted to learn something about how to play Bach, not just copy somebody else's version. Why bother do to that if you have the CD already? The idea of a "fixed" version is wrong. Just like any other sort of oratory or rhetoric, reacting to the audience situation is a better plan. If they are bored and half asleep, just do a competent job. On the other hand, if they seem to be up for a white-knuckle ride, take them on one...
Comment: thanks for a great answer.
I'm not sure how to interpret the first part, though - does it equate the Aria being tricky for a performer to get it right from a musicological, philological and artistic standpoint enough to impress the NYT critic, but not preventing my (fictional) Aunt Martha who happens to love the theme to play it copying e.g. Gould's ornamentation when her (fictional) friends Angela and Maria come over for tea? Also, could you elaborate a bit more on the lederhosen thing? I'm sure you don't mean *literal* lederhosen :)
Comment: I mean literal lederhosen. Var 1 sounds to me like a dance that belongs in a Bier-keller. It just happens to be in perfectly constructed two-part counterpoint as well as being a dance. If you know any clarinettists, tuba players, or accordianists, get them to actually play it for you sometime and see if you agree.
Comment: still, *can* Aunt Martha copy Gould's or Hewitt's ornaments and be done with it or *cannot*?
(You DO realize that I DO know an accordionist and I WILL make his life miserable until he does that, right. You do, of course you do.)
Comment: Well, of course. What I was trying to understand here is if the difficulties are purely technical or there's something more to it than agile fingers. You are making me think of the latter. (Not that I *ever* plan to play the Goldbergs myself, much less in front of an audience).
Comment: Aunt Martha should absolutely play what she loves.  It'll make her happy, and she'll learn a lot, and she can pick and choose variations.  And while the goal may be to find her own interpretation, trying to play it the same as some recording will also be an interesting learning experience.
Answer: I have started practing Goldberg since November 2019 and now I am on Variation 11. To be honest I was not feeling Goldberg was impossible for me to learn because each variation is short and the wide variety of the variations make it so appealing to learn. It was not until lately do I find how demanding the work is. Because first of all the structure is very clearly outlined, leaving a lot of room for errors and complains (missing note, or lack of clarity in voicing and phrasing and dynamic plan). It is work that needs a lot more work from the player to present it effectively. For example, you have to spend time analizing the sturcture, the counterpoint and make personal decisions on dynamics and tempo. Not to mention the fundamental technical requirement - crossing hands and perfect touch (carbonated, or legato when and how). For me Goldberg is much more demanding then Preludes and Fugues becuase it is much more artistically challenging and leaves much bigger room for interpretation. The interesting thing is that although it is exhausting to practice it I just can not have enough. The depth and the challenge of the nature just makes me want more. I am patiently working on it, waiting to achieve the final satisfatory magical moment when the Aria comes back. It has been a journey and I know it will prove worthwhile like our life! I admire Gould's interpretation the most and am mostly inspired by it. I love his second recording much more than his first. By the way I am a classical pianist based in Calgary, Canada.
Answer: Well, the technical difficulties are basically what you'll encounter with the three-part inventions or symphonies.  In contrast to them, they are assembled into a musical whole rather than an educational one.
The typical pianist rather rarely is confronted with the wish to make a performance from all three-part inventions.  The Goldberg variations were designed to be pleasant enough and listened as a coherent whole, so they are more sought after, resulting in a larger competition.  And you can't go easy on either the difficult or easy ones without impacting your overall performance.
I think it may be mostly Gould's fault making the Goldberg Variations get the current attention from audience and players: before his recordings they were usually associated with play on the harpsichord, with a limited circle of interested audience.  Not all that different from the three-part inventions.
Partly it's a bit of a self-fulfilling prophesy: some performers think "it's from Bach, so it can't be bad", and they work until they discover a satisfactory angle for performing them.  Somewhat like photographers working with supermodels: the basics of the material are well-known, reliable and solid and recognized by an audience.
Give Buxtehude or Telemann or a number of others the Bach treatment, and they'll probably fare comparably well.  In fact, they already did in their lifetime.  But nowadays few ensembles try to improve on recognizable qualities of particular pieces.  So there is not a performing dynamic like it currently is behind the Goldberg Variations but not the inventions.
So in short: the importance of the Goldberg Variations to piano players at this point of time is just how history played out.  The Goldberg Variations lend themselves to that, but it's not like they stand out entirely in the manner that the current "scene" would suggest.
Answer: Baroque and earlier music are easy to read (sometimes not) but helluva hard to perform as the way it was intended. The majority of information needed for a good performance isn't written in original sheet music - as the pro baroque player was well versed in music, most of information and customs weren't written because it was redundant - so usually you need to figure out all by yourself (or by listening to performances or reading books and papers about it) 'cause this ain't anymore our sociocultural context.
Aside this, we're dealing here (Goldberg) with an idiomatic writing for a different keyboard instrument - harpsichord with double manuals. Piano and harpsichord are similar only in keyboard layout and having strings within - all other features are very different. The sound mechanism is completely different and demand different technical gestures when playing keys on each instrument.
Harpsichord doesn't have real dynamic changes - when a key is pressed, it will sound at the same volume. But it has 2, 3 or more different sets of strings (called registers) and changing registrations will affect dynamics and tone. Apart this, there's special fingering techniques to emulate crescendos and decrescendos (aural illusion). Even if you're not supposed to use these fingerings, the dynamic changes aren't written, so you need to know when do or do not these by rhetoric.
Ornaments and improvising are a completely new level, we cannot explain even the basics in a short post here. And you're supposed to use this in every Bach's art piece. Or Handel's. Or Telemann's... you get it.
Playing polyphonic passages requires an additional effort: make each voice sound well separately and unique when grouped together. Fugues and canons provide more difficulties because, to assure coherence, you need to play the same articulations when the same subjects appear - sometimes, there's situations when you cannot physically play what is demanding, so you need to understand the problem and provide solutions.
Another "problem" when performing Bach is harmony clarity: you usually are within an harmonic context that is cristal clear. One wrong note or even a note played non confidently and you will sound wrong - like as someone painting the sea with only vivid reds at a midsummer day marine painting. Every listener, even not trained, will catch instantaneously and intuitively every error.
To me, Goldberg Variations, The Art of Fugue and Musical Offering are the pinnacle of Bach's music, along with concertos and strings solo music. As I said, looks easy on paper, but it is hard a lot to play well.


How to read one jpg file as php htaccess

Question: so I have a directory which contains many JPG files like this:
1.jpg
2.jpg
loll.jpg
image.jpg

i know this code with read all files jpg as php
AddType application/x-httpd-php52 .jpg

but i want to focus juts on one file  image.jpg
so i want to create an ht access file to read just the file image.jpg as a php file while other images can be displayed normally as a jpg
thanks
Answer: In site root .htaccess you can use this rule to set MIMI-type for a particular image file:
RewriteEngine On

RewriteRule (?:^|/)image\.jpg$ - [T=application/x-httpd-php]

Apache documentation of flag T says that:

Sets the MIME type with which the resulting response will be sent. This has the same effect as the AddType directive.
Comment: ihave tried it sir but the result is when i want to execute the http://localhost/images/image.jpg  , the browser ask me to download the file
Comment: Does `localhost/images/image.jpg` exist as a valid file?
Comment: Try updated rule. On my Apache, it displays content of `image.jpg` (which has some PHP sample code)
Comment: i have tried but nothing changed

is ther any valid  htaccess code  to try  it !
Comment: This is a working solution tested on my Apache. You  should just copy paste this in a blank htaccess and then test.


How to prevent from text to extend the  container height?

Question: My code - Plunker
I try to create a fluid layout, my sidebar is made of a list of links. I want each
 element to be a perfect square, the problem starts when I add the text inside. It seems to be adding height to my square and what I get is a rectangle. If you examine my code the dimensions of my list objects are
32px X 43px. How can I prevent from an inside text to extend the
 elements?
And how can I make the text appear on the bottom left side of the
 element?
My CSS:
body{
   width: 100%;
   margin: 0 auto;
 }

 .content {
    width: 95%;
    display: inline;
    float: left;
  }

  .sidebar{
      width: 5%;
      display: inline;
      float: left;
   }

 .sidebar ul{
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    list-style: none;

  }

 .sidebar li{
    padding: 50%;
    background-color: oldlace;
  }

  .sidebar a{
    display: block;
    font-size: 0.5em;
  }

My HTML:

Hello Plunker!

ANALYTICS

STYLES

VOTERS

GET STARTED

UPDATE

Blahahhhahhhahahahahahahhahahah blahahahh bluah

Comment: I'm not quite sure I understand what you're trying to accomplish. By looking at the CSS, it's not specifying a height, so if you add a text inside the square, it will increase the height by whatever size text you've added in there, no? Why not "height:32px; width:32px; overflow:hidden;"?
Comment: Have you tried `word-wrap`?
Comment: I added the code, and yes I tried word-wrap it seems to make the problem worse.
Comment: Also, your sidebar is awfully narrow on small screens.
Comment: I'm trying to implement a liquid layout, so I don't specify `px` units only percentage. By using `padding: 50%` It is making the `` a prefect square the 32px is window dependent. Anyway what ruins the perfect square is the text, it adds more px to the height.
Answer: You could use position: relative on the li and position: absolute on the a.  Using absolute will cause the a element to not affect the li's dimensions.  In this way you can also position it in the corner.
http://plnkr.co/edit/kcjCl1?p=preview
.sidebar li{
      padding: 50%;
      position: relative;
}

.sidebar a{
        display: block;
        position: absolute;
        bottom: 0;
        left: 0;
}

Comment: So that the `a` elements are positioned relative to the `li` they are contained in, instead of relative to the whole document.  That is why `bottom: 0` and `left: 0` put the element in the corner of the `li` instead of the corner of the document.
Comment: Why did you use `position: relative`?


Wait-free queue implementation in C++

Question: Is it possible to implement a Concurrent Queue which is completely wait-free and can support simultaneously multiple writers and readers?I know I can use mutexes or an existing library, but I really want to implement it myself.Any ideas?
Comment: Just keep in mind, wait free data structures tend to perform better than mutex-based structures only when there are no (or few) threads that can make forward progress without accessing the structure. Otherwise, the wait free logic just increases contention. That makes them good for "core" things like memory management that no thread can avoid touching but a bad choice for things not close to the core.
Comment: @DEIMOS: You probably know this, but it may not be the best idea to use a single MPMC structure. Better to avoid sharing altogether and give each thread a SPSC container (much faster), where the single consumer is a single harvester thread that collects all the thread-local queues.
Comment: @Mehrdad Consider two cores and three threads, A1, A2, and B1. Threads A1 and A2 frequently access the same collection. Thread B1 does not. If thread A2 is waiting for a mutex, thread B1 can be scheduled, allowing threads A1 and B1 to run with no contention. A wait-free data structure will let A1 and A2 run together, frequently contending and performing poorly. The lock keeps the contending threads from running at the same time, with a performance benefit. The wait-free data structure actually maximizes contention by preventing conflicting threads from being descheduled.
Comment: Boost implements the Michael-Scott queue since 1.53 I think.
Comment: I have a design for a single consumer single producer class, will this work? (I am pretty sure arbitrary numbers of consumers,producers is not doable without mutexes)
Comment: Threading Building Block (TBB) include several thread safe container.
Comment: @JustinMeiners: It is possible, modulo memory management concerns (it's tricky to know when to release a node). Apart from Michael-Scott, there are modified proposals by Fober-Orlarey-Letz worth checking out.
Comment: @DavidSchwartz: I'm not sure I understand, how can having multiple threads wait for a mutex be any better than having them access the wait-free data structure?
Answer: You can find a wait-free queue for multiple enqueuers and dequeuers here, but as @David Schwartz said this will not be necessarily faster just for being wait-free.
This is another paper about wait-free queue.
On the references of these papers you also can find other proposed queues based on arrays, that means they have a limited capacity, but they are faster than those based on lists.
If you are looking for a practical solution Michael and Scott's Lock-Free queue is probably a good alternative.
If you want to learn more and give it a try yourself, Here you can find a good resume of the possible alternatives and there are a few code examples.

Wait-free queue implementation in C++


Representing a polynom with a base

Question: How to do I present $$P(x)= 6x^2+4x+2$$ with the base $$B=\frac{1}{\sqrt2},\qquad x\sqrt\frac32,\qquad \sqrt\frac58(1-3x^2)$$
Answer: Let $B_c=(1,X,X^2)$ be the canonical basis of $\mathbb R_2[X]$. In this basis the coordinate vector $P=(2,4,6)^t$. Now the change matrix from $B_c$ to $B$ is
$$Q=\begin{pmatrix}\dfrac{1}{\sqrt {2}}&0&\dfrac{\sqrt {5}}{\sqrt {8}}\\0&\dfrac{\sqrt {3}}{\sqrt {2}}&0\\1&0&-3\dfrac{\sqrt {5}}{\sqrt {8}}\end{pmatrix}$$ We compute the  matrix $Q^{-1}$ and
 the coordinate vector of the polynomial $P$ in the basis
$B$ is  obtained by taking the product $Q^{-1}P$ which gives the vector
$$(\dfrac{-8}{2 \sqrt5 + 3 \sqrt{10}}, \dfrac{-16}{2 \sqrt5 + 3 \sqrt{10}}, \dfrac{-24}{2 \sqrt5 + 3 \sqrt{10}})^t$$
meaning that
$$P=\dfrac{-8}{2 \sqrt5 + 3 \sqrt{10}}*\dfrac{1}{\sqrt2} + \dfrac{-16}{2 \sqrt5 + 3 \sqrt{10}}*\dfrac{\sqrt3}{\sqrt2}x+ \dfrac{-24}{2 \sqrt5 + 3 \sqrt{10}}*\dfrac{\sqrt5}{\sqrt8}(1-3x^2)$$

Representing a polynom with a base


spring data jdbc store and retrieve LocalDateTime as java.sql.Timestamp instead of java.sql.Date

Question: I use spring-data-jdbc to store and retrieve data from the underlying repository.
I have a date-time field that has to be stored with hour, minutes and seconds.
So in my entity the field is declared as LocalDateTime.
My understanding is that the framework converts my LocalDateTime to a java.sql.Date, so the precision is lost during the insertion in the database.
I use ListCrudRepository<AuditLogEntity,Long> to store and retrieve the records.
After multiple searches on the web, I didn't find any article, tutorial related to my problem.
What I tried is to replace my LocalDateTime by Timestamp.
Here is my entity:
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table("AUDIT_LOG")
public class AuditLogEntity {

    @Id
    private Long id;

    @Column("USER_ID")
    private String userId;

    @Column("ACTION_ORIGIN")
    private String actionOrigin;

    @Column("ACTION_NAME")
    private String actionName;

    @Column("ACTION_DATE")
    private Timestamp actionDate;

    @Column("REFERENCE")
    private String reference;

    @Column("ACTION_BODY")
    private String actionBody;

    public static AuditLogEntity create(AuditLogCreation auditLogCreation) {
        return new AuditLogEntity(null,
            auditLogCreation.getUserId(),
            auditLogCreation.getActionOrigin(),
            auditLogCreation.getActionName(),
            Timestamp.valueOf(auditLogCreation.getActionDate()),
            auditLogCreation.getReference(),
            auditLogCreation.getActionBody());

    }

    public static AuditLog toModel(AuditLogEntity entity) {
        return new AuditLog(entity.getUserId(),
            entity.getActionName(),
            entity.getActionOrigin(),
            entity.getActionDate().toLocalDateTime(),
            entity.getReference(),
            entity.getActionBody());
    }

Here is my repository:
@Component
public class AuditLogRepositoryImpl implements AuditLogRepository {

    private final JdbcAuditLogRepository jdbcAuditLogRepository;

    public AuditLogRepositoryImpl(JdbcAuditLogRepository jdbcAuditLogRepository) {
        this.jdbcAuditLogRepository = jdbcAuditLogRepository;
    }

    @Override
    public AuditLog create(AuditLogCreation auditLogCreation) {
        AuditLogEntity auditLogEntity = AuditLogEntity.create(auditLogCreation);
        AuditLogEntity save = this.jdbcAuditLogRepository.save(auditLogEntity);
        return AuditLogEntity.toModel(save);
    }

    @Override
    public List<AuditLog> findAll() {
        List<AuditLogEntity> all = this.jdbcAuditLogRepository.findAll();
        return all
            .stream()
            .map(AuditLogEntity::toModel)
            .toList();
    }

}

The ListCrudRepository:
@Repository
public interface JdbcAuditLogRepository extends ListCrudRepository<AuditLogEntity, Long> {
}

My test:
@SpringBootTest
@ActiveProfiles("integration")
class AuditLogRepositoryImplIntegrationTest {

    @Inject
    private AuditLogRepository auditLogRepository;

    @Test
    void test() {
        LocalDateTime expected = LocalDateTime.of(LocalDate.of(2020, 4, 30), LocalTime.of(3, 26, 50));
        AuditLogCreation auditLogCreation = AuditLogCreation.builder()
            .userId("UserId")
            .reference("Reference")
            .actionName("Action Name")
            .actionOrigin("Action origin")
            .actionDate(expected)
            .actionBody("Action Body")
            .build();
        this.auditLogRepository.create(auditLogCreation);
        List<AuditLog> all = this.auditLogRepository.findAll();
        AuditLog auditLog = all.get(0);
        assertThat(auditLog.getActionDate()).isEqualTo(expected);
    }

}

And the result:
org.opentest4j.AssertionFailedError:
expected: 2020-04-30T03:26:50 (java.time.LocalDateTime)
 but was: 2020-04-30T00:00 (java.time.LocalDateTime)
when comparing values using 'ChronoLocalDateTime.timeLineOrder()'
Expected :2020-04-30T03:26:50 (java.time.LocalDateTime)
Actual   :2020-04-30T00:00 (java.time.LocalDateTime)

If I check the following topic: Spring-data-jdbc microsecond precision lost during insert of LocalDateTime type variable It seems he succeeds in storing the date with a precision of the milliseconds whilst on my side only the date without hh:MM:ss is stored.
So I'm a bit lost. Am I missing something?
Thanks for your help.
Comment: Edit your Question to state clearly (a) exactly what database engine you use, and (b) *precisely* what is the data type of the column.
Comment: Maybe there is a misundestanding in my question. I want to store the date and time, thats's the reason why I use LocalDateTime. And my date is like 30-04-2020 03:26:50, so dd-MM-yyyy hh:mm:ss. With JPA it's simple as using the @Temporal annotation. But with spring-data-jdbc I didn't find any type of annotation to tell him to store my date as a timestamp. He keeps storing it by truncating hh:mm:ss which is the default behavior because behind they implicitely convert my LocalDateTime to a java.sql.Date.
Comment: Yep sorry it was unclear.
I use H2 for my integration tests and Oracle as my primary database.
Comment: And delete irrelevant code and prose. Your question appears to be much too long for what I'm guessing is a rather simple issue.
Comment: Well, finally the problem is between the seat and the keyboard. I use Liquibase to generate my tables and the datatype differs between H2 and Oracle for the Date. With Oracle you can use Date whilst with H2 you have to use Timestamp.
Comment: *So in my entity the field is declared as LocalDateTime.* Wrong. A `LocalDateTime` has both date and time of day so doesn't work for the time part alone. *My understanding is that the framework converts my LocalDateTime to a java.sql.Date,* That would be wrong. Apart from the fact that they should not use `java.sql.Date` at all, that class was for a date without time of day, so unsuitable for a `LocalDateTime`.
Comment: Which brand of database engine are you using under Spring JDBC?
Comment: Why map to Java type `java.sql.Timestamp` in your entity  ?   Why not simply map to `Instant` ?    In the next [upcoming JPA spec](https://jakarta.ee/specifications/persistence/3.2/) support for `Timestamp` will be deprecated.  Why map to `LocalDateTime`?  Isn't what you really want is to store a point in time when something happened? Sounds more like an `Instant` to me.
Answer: I finally understood what's going on.
In fact I use Liquibase to generate my tables.
And after a small research I found that by using the date type the conversion to the database datatype differs between H2 and Oracle.
With H2 the date type means that only the date is stored.
On the other hand with Oracle the date and time are stored.
So the solution is to use two properties in your databaseChangeLog:
For H2: <property name="dateType" value="timestamp" dbms="h2"/>
For Oracle: <property name="dateType" value="date" dbms="oracle"/>
And then use the property in your column definition:
<column name="ACTION_DATE" type="${dateType}"/>
Here is a link where all datatypes are listed: https://stackoverflow.com/a/28626825/1878414


Can all hereditarily shrinking relations define sets?

Question: Let $R$ be a relation definable in the language of set theory. We call $R$ as inherently proper class relation over domain $D$ if it and its complementary output over domain $D$ are proper classes, i.e. for each $x$ the class of all $y \in D$ such that $y R x$ is a proper class, and the class of all $y \in D$ such that $ y \not R x $ is also a proper class.
We recursively define $\in^n$ as:
$y \in^0 x \leftrightarrow y=x$
$y \in^{n+1} x \leftrightarrow \exists z (z \in^n x \land y \in z)$
Define $R^n$ recursively as:
$y R^0 x \leftrightarrow y=y$
$y R^{n+1} x \leftrightarrow y R^n x \land \forall z \in^n y (z R x)$
We say a relation is hereditarily shrinking if and only if for each $n>0$:$\ R^n$ is inherently proper class relation over its prior domain. That is, for each $x$ the class of all $y$ such that  $y R^{n-1} x \land y R^n x$ is a proper class, and the class of all $y$ such that $y R^{n-1} x \land \neg y R^n x$ is a proper class too.

Is the following provable in $ZFC$?
$R \text { is hereditarily shrinking } \to \forall x \exists s (s=\{y|\forall n \in \omega (y R^n x)\}) $
Comment: In your definition of $R^n$, should "$zRx$" be "$zR^nx$" at the end? Also, do you have an example of a hereditarily shrinking relation?
Comment: @NoahSchweber, I think the defintion I gave is OK. Examples of hereditarily shrinking relations are: "is singleton or empty","is subnumerous to", "is almost a subset of", the last is what I call as "quasi-subset" and it entails that there can maximally be one element of the quasi-subset that is not an element of the mother set, etc..
Answer: The above schema is inconsistent with ZF.
Take the $x R y$ to be $x=x \land (y \text{ is singleton} \lor y\text{ is a set of singletons})$
Clearly $R$ is hereditarily shrinking relation, yet the class of all sets $y$ hereditarily satisfying $R$ (for whatever $x$) is indeed a proper class.


Laurent series of $\frac{1}{z^2(z-1)}$ when $0<\lvert z\rvert<1$

Question: $\frac{1}{z^2(z-1)} = -\left(\frac{1}{z}+\frac{1}{z^2}+\frac{1}{1-z}\right)$.
I know that $\frac{1}{1-z}=\sum\limits_{n=0}^\infty z^n$, but what about the other two terms, should they be left as they are, since we can already think of $\frac{1}{z}$ and $\frac{1}{z^2}$ as Laurent series where $b_1 = 1$ in the first case, and the rest of $b_n=0$, and $b_2 = 1$ in the 2nd case, with all other $b_n=0$? Please let me know if there is a better way to find Laurent series.
Answer: Your approach is right, at the end you just add the three series to obtain the Laurent series of $\frac{1}{z^2(z-1)}$ :
$$-(\sum\limits_{n=0}^\infty z^n+\frac{1}{z}+\frac{1}{z^2})=-\sum\limits_{n=-2}^\infty z^n$$
Answer: Your answer
$$\frac{1}{z^2(z-1)} = -\left(\frac{1}{z}+\frac{1}{z^2}+\sum\limits_{n=0}^\infty z^n\right), \quad 0<\lvert z\rvert<1,$$
is fine. The first two terms on the right hand side are already the principal part of the sought Laurent series expansion.


When exactly do we use stored procedures with output parameters?

Question: When exactly do we use stored procedures with output parameters and when do we use stored procedures without parameters?
I base my question on an example:
Stored procedure with output parameter
CREATE PROCEDURE uspGetContactsCountByCity
    @City nvarchar(60),
    @ContactsCount int OUT
AS
BEGIN
    SELECT @ContactsCount = COUNT(ContactID)
    FROM Contacts
    WHERE City = @City
END

Stored procedure executing
DECLARE @ContactsTotal INT

EXEC uspGetContactsCountByCity @ContactsCount = @ContactsTotal OUT, @city = 'Berlin'
SELECT @ContactsTotal

Results: 2
Stored procedure without output parameter
CREATE PROCEDURE uspGetContactsCountByCity2
    @City nvarchar(60)
AS
BEGIN
    SELECT COUNT(ContactID)
    FROM Contacts
    WHERE City = @City
END

Stored procedure executing:
EXEC uspGetContactsCountByCity2 @city = 'Berlin'

Results: 2
Both procedures return the same result, in same form, so what's the difference?
Comment: Aside: Just to add to the fun, a stored procedure can return multiple result sets, e.g. `GetCustomerOrder( @OrderId )` could return a result set with an order header and a second with the line items from the order. If it makes sense to return the customer's credit rating in an output parameter, that's fine. Mix and match as appropriate.
Answer: Basically, the result you're seeing is actually the result of your SELECT at the end of the procedure, which is doing the same thing.
Please take a look at this documentation:

If you specify the OUTPUT keyword for a parameter in the procedure definition, the stored procedure can return the current value of the parameter to the calling program when the stored procedure exits. To save the value of the parameter in a variable that can be used in the calling program, the calling program must use the OUTPUT keyword when executing the stored procedure.

So basically if you would like your stored procedure to just return just a value instead of a data set, you could use the output parameter. For example, let's take the procedures you have given as an example. They both do the same thing, this is why you got the same result. But what about changing a little bit in the first procedure that has the output parameter.
Here's an example:
create table OutputParameter (
    ParaName varchar(100)
)

insert into OutputParameter values ('one'), ('two'),('three'),('one')

CREATE PROCEDURE AllDataAndCountWhereOne
    @name nvarchar(60),
    @count int OUT
    as
    Begin
    SELECT @count = COUNT(*) from OutputParameter
    Where ParaName = @name

    select Distinct(ParaName) from OutputParameter
End

Declare @TotalCount int
Exec AllDataAndCountWhereOne @count = @TotalCount OUT, @name = 'One'
Select @TotalCount

With this example, you are getting all the distinct stored data in the table, plus getting the count of a given name.
ParaName
--------------------
one
three
two

(3 row(s) affected)

-----------
2

(1 row(s) affected)

This is one way of using the output parameter. You got both the distinct data and the count you wanted without doing extra query after getting the initial data set.
At the end, to answer your question:

Both procedures gives us the same result, in same form, so what's the difference?

You didn't make a difference in your own results, this is why you didn't really notice the difference.
Other Examples:
You could use the OUT parameter in other kinds of procedures. Let's assume that your stored procedure doesn't return anything, it's more like a command to the DB, but you still want a kind of message back, or more specifically a value. Take these two examples:
CREATE PROCEDURE InsertDbAndGetLastInsertedId
    --This procedure will insert your name in the database, and return as output parameter the last inserted ID.
    @name nvarchar(60),
    @LastId int OUT
    as
    Begin
    insert into OutputParameterWithId values (@name);
    SELECT @LastId = SCOPE_IDENTITY()
End

or:
CREATE PROCEDURE InsertIntoDbUnlessSomeLogicFails
    --This procedure will only insert into the db if name does exist, but there's no more than 5 of it
    @name nvarchar(60),
    @ErrorMessage varchar(100) OUT
    as
    Begin
    set @ErrorMessage = ''

    if ((select count(*) from OutputParameterWithId) = 0)
    begin
        set @ErrorMessage = 'Name Does Not Exist'
        return
    end

    if ((select count(*) from OutputParameterWithId) = 5)
    begin
        set @ErrorMessage = 'Already have five'
        return
    end

    insert into OutputParameterWithId values (@name);
End

These are just dummy examples, but just to make the idea more clear.
Comment: okey, that starts to make sense now, but still the line between stored proceudres with and without output parameters seems to be really thin
Comment: Well, it all comes down on how do you like to use it. For example, you can also use it in some other kind of queries. Let's say you just want to Insert or Update, or actually have some logic in your SP (which I don't like), I will edit my answer to have such an example.
Comment: Ok but what exactly does Output parameter gives us? I mean ok, SP without Output params returns to us some results or value, while SP with output params gives us some variables - that we can actually use later in our code/another procedure or something or not?
Comment: Yes, it's just a value that the SP will return, you can use it to direct the flow of your program or just have information out of it, as I previously said, it will depend on how do you want to use it if needed.
Comment: First, better edit your comment, such words aren't welcome in SO. Second, always make sure to accept an answer if it suits you well and responds to your question. (It could be this or any other answer.) And welcome to Stackoverflow.
Answer: An example, based on yours would be if you introduced paging to the query.
So the result set is constrained to 10 items, and you use a total count out parameter to drive paging on a grid on screen.
Comment: What? I honestly don't understand.
I've run this two queries before and both of them gave me the same results as I write in my question
Comment: It's just different ways of doing things. You're overthinking it. In my example, I'm suggesting the stored process returns resultset, and the output var returns a total count.
Answer: Answer from ozz regarding paging does not make sense because there is no input param that implements a contraint on the number of records returned.
However, to answer the question...  the results returned by these stored procedures are not the same.  The first returns the record count of contacts in given city in the out param ContactsCount. While the count may also be recieved in the second implement through examining the reader.Rows.Count, the actual records are also made a available.  In the first, no records are returned - only the count.


unpickling a dictionary of encoded words

Question: I have created a dictionary (which as Keys has encoded words in utf-8) :
import os.path
import codecs
import pickle
from collections import Counter

wordDict = {}

def pathFilesList():
     source='StemmedDataset'
     retList = []
     for r, d, f in os.walk(source):
         for files in f:
             retList.append(os.path.join(r, files))
return retList

# Starts to parse a corpus, it counts the frequency of each word and
# the date of the data (the date is the file name.) then saves words
# as keys of dictionary and the tuple of (freq,date) as values of each
# key.
def parsing():
    fileList = pathFilesList()
    for f in fileList:
        date_stamp = f[15:-4]
        print "Processing file: " + str(f)
        fileWordList = []
        fileWordSet = set()
        # One word per line, strip space. No empty lines.
        fw = codecs.open(f, mode = 'r' , encoding='utf-8')
        fileWords = Counter(w for w in fw.read().split())
        # For each unique word, count occurance and store in dict.
        for stemWord, stemFreq in fileWords.items():
            if stemWord not in wordDict:
                wordDict[stemWord] = [(date_stamp, stemFreq)]
            else:
                wordDict[stemWord].append((date_stamp, stemFreq))
        # Close file and do next.
        fw.close()
if __name__ == "__main__":
# Parse all files and store in wordDict.
    parsing()

output = open('data.pkl', 'wb')

print "Dumping wordDict of size {0}".format(len(wordDict))
pickle.dump(wordDict, output)

output.close()

when I unpickle the pickled data , and query this dictionary I can't query alphabetical words , even words of which I'm sure they're in the dictionary,it always returns false , but for the numeric query , it works fine. here is how I unpickle the data and query :
    pkl_file=codecs.open('data.pkl' , 'rb' )
    wd=pickle.load(pkl_file)
    pprint.pprint(wd)    #to make sure the wd is correct and it has been created
    print type(wd)      #making sure of the type of data structure
    pkl_file.close()

   #tried lots of other ways to query like if wd.has_key('some_encoded_word')
   value= None
   inputList= ['اندیمشک' , '16' , 'درحوزه' ]
   for i in inputList :
       if i in wd :
           value = wd[i]
           print value
       else:
           print 'False'

here is my output
pa@pa:~/Desktop$ python unpickle.py
False
[('2000-05-07', 5), ('2000-07-05', 2)]
False

so I'm quite sure there's something wrong with the encoded words .
Answer: Your problem is that you're using codecs.open. That function is specifically for opening a text file and automatically decoding the data to Unicode. (As a side note, you usually want io.open, not codecs.open, even for that case.)
To open a binary file to be passed as bytes to something like pickle.load, just use the builtin open function, not codecs.open.
Meanwhile, it usually makes things simpler to use Unicode strings throughout your program, and only use byte strings at the edges, decoding input as soon as you get it and encoding output as late as possible.
Also, you have literal Unicode characters in non-Unicode string literals. Never, ever, ever do this. That's the surest way to create invisible mojibake strings. Always use Unicode literals (like u'abc' instead of 'abc') when you have non-ASCII characters.
Plus, if you use non-ASCII characters in the source, always use a coding declaration (and of course make sure your editor is using the same encoding you put in the coding declaration),
Also, keep in mind that == (and dict lookup) may not do what you want for Unicode. If you have a word stored in NFC, and look up the same word in NFD, the characters won't be identical even though they represent the same string. Without knowing the exact strings you're using and how they're represented it's hard to know if this is a problem in your code, but it's pretty common with, e.g., Mac programs that get strings out of filenames or Cocoa GUI apps.


How to handle bulk file uploads behind HAProxy configuration?

Question: About my setup:

I've got an HAProxy configuration for my WordPress environments.
I've got multiple server pools for the "front-end" of each WordPress website.
I force everyone to connect to one specific server for anything in
    the "back-end" of each WordPress website. For now... This just makes
    things simple for file syncing and database replication.

My problem:
My clients are uploading massive amounts of photos to their websites in one big bulk upload. Most of the time, the files are uploading as expected. However, randomly and sporadically some of the photos are failing to upload with a fairly generic error code in WordPress of "HTTP Error".
The photos which fail to upload are never the same photo file. It's completely random in each case.
I've been trouble shooting this problem for about a week or so now, and can't seem to hunt down the problem.

I've verified the DNS is correct and functioning as intended. The user is resolving to the HAProxy server, and the connection is forwarded to the appropriate server hosting the "back-end" of the WordPress website.
I've thoroughly checked Apache, PHP, and MySQL configurations on the server
hosting the "back-end" of each WordPress website.
I've checked out everything related to WordPress from head to toe.

The only thing I can think of at this point is that there's a problem with my HAProxy configuration. I feel like there's too many requests being made too quickly, and the HAProxy Server isn't keeping up with the communication to and from the server hosting the "back-end" of the WordPress website (where the bulk uploads are taking place).
I'd like to solve this problem related to HAProxy. If you feel like my configuration could be simplified or improved upon elsewhere (unrelated to this particular problem), I'm open for improvements overall with my current HAProxy configuration, but the main focus is on this "HTTP Error" problem related to bulk uploading of files.
Here's my HAProxy 1.6.9 configuration:
defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http
    retries 3
    option redispatch
    maxconn 2000
    timeout connect 5000
    timeout check 5000
    timeout client 300000
    timeout server 300000

frontend http-in
    bind *:80
    option  httplog
    option http-server-close

    acl has_domain hdr(host) -m found
    acl has_www hdr_beg(host) -i www.

    acl has_admin path_beg /wp-admin
    acl has_login path_beg /wp-login.php
    acl has_custom_login path_beg /manage

    acl has_server1 hdr_beg(host) -i server1.

    use_backend admin_servers if has_domain has_www has_admin or has_domain has_www has_login or has_domain has_www has_custom_login

    use_backend live_servers if has_domain !has_admin !has_login !has_custom_login or has_www !has_admin !has_login !has_custom_login

    use_backend default_servers if has_server1

    default_backend default_servers

backend default_servers
    mode http
    stats enable
    stats uri /haproxy?stats
    balance roundrobin
    option httpclose
    option forwardfor
    cookie SERVERID insert indirect nocache
    server server1 188.8.131.52:80 check cookie server1

backend admin_servers
    mode http
    stats enable
    stats uri /haproxy?stats
    balance roundrobin
    option httpclose
    option forwardfor
    cookie SERVERID insert indirect nocache
    server server1 220.127.116.11:80 check cookie server1

backend live_servers
    mode http
    stats enable
    stats uri /haproxy?stats
    balance roundrobin
    option httpclose
    option forwardfor
    cookie SERVERID insert indirect nocache
    server server1 220.127.116.11:80 check cookie server1 weight 200
    server server2 220.127.116.11:80 check cookie server2 weight 25 maxconn 256

Comment: probably you need to have sticky sessions in your haproxy - you are balancing round robin and this could cause clients to move server during http put, if you clients are coming from different sites then you could balance based on there source address 'balance source' - there are lots of options
Comment: @Sum1sAdmin Thanks for the tip. It does make sense to make that adjustment. However, it still didn't improve or solve the problem.
Answer: After a TON of digging... I've solved the problem. Turns out the problem here wasn't related to HAProxy.
As mentioned in the question. There were HTTP Errors (Internal Server Error - 500) while uploading files to a WordPress website. The error was always random and never consistent.
These WordPress websites were in a WordPress Multisite configuration.
The problem was an related to HTTP. So there's something which WordPress and my web server (Apache) both relied on, that wasn't working properly. The only common link that came to mind was the .htaccess file.
WordPress Multisite has two network modes:

Subdirectory Installtion
Subdomain Installation

Depending on which network mode you configure WordPress Multisite to use, it requires a different set of rewrite rules for your .htaccess file.
My WordPress Multisite was configured as a "subdirectory" installation.
I replaced the rewrite rules for a "subdirectory" installation with the appropriate rewrite rules for a "subdomain" installation. I then also updated wp-config.php to change define('SUBDOMAIN_INSTALL', false); to this define('SUBDOMAIN_INSTALL', true);
The HTTP Error on file uploads had then completely vanished and bulk uploads began to upload at a 100% success rate once again.
Comment: you should delete this question instead. If sulution is completely unrelated its not benefical to anyone other than you.
Comment: @TheFool Vote to delete it then.


Using .NET Framework 4.8 WinForm webView control to display local html

Question: I need to display a local HTML file with both images and fonts that are included via an external or internal style sheet. I want to use the new webView control introduced with .NET Framework 4.8 for WinForms.
I tried a few different ways. Hosting an HTTP Server with the font and the images do work. Sadly that's not a solution when rolling out the program as it is too much configuration for each individual pc.
Encoding the images and font to base64 strings and using them as the source does work. But I would like to use the NavigateToLocalStreamUri Method to have a solution which is easy to read and doesn't need too much overhead to make it work.
The NuGet package Microsoft.Toolkit.Forms.UI.Controls.WebView is installed in its most recent stable version 5.1.1
Below you see the code I am currently using to try and get the NavigateToLocalStreamUri running.
var uri = new Uri(someLocalPath);
webView1.NavigateToLocalStreamUri(uri, new CustomUriToStreamResolver());

private class CustomUriToStreamResolver : IUriToStreamResolver
        {
            public Stream UriToStream(Uri uri)
            {
                var stream = new FileStream(uri.AbsolutePath, FileMode.Open);
                return stream;
            }
        }

The expected behaviour is opening the HTML file that is located at someLocalPath
Instead it throws the following exception, which I do not fully understand.
Could not find any resources appropriate for the specified culture or the
neutral culture. Make sure \"Microsoft.Toolkit.Win32.UI.Controls.DesignerUI.resources\"
was correctly embedded or linked into assembly
\"Microsoft.Toolkit.Forms.UI.Controls.WebView\" at compile time, or that all
the satellite assemblies required are loadable and fully signed.

Is the problem my CustomUriToStreamResolver or is there an underlying issue I am unaware of?
If you know of any other way to open the someLocalPath HTML file with the webView control in WinForm please do let me know.
Comment: I don't have an answer, i came to say that I am also trying to implement webview 5.1.1.  I am using it to navigate an Intranet site.  However, this is not possible without enabling the IsPrivateNetworkClientServerCapabilityEnabled flag.  When this is enabled I am getting the same issue as you.  Make sure "Microsoft.Toolkit.Win32.UI.Controls.DesignerUI.resources" was correctly embedded or linked into assembly...  Any news?
Comment: This control is owned/operated by the Edge team. Your best bet is to go to the repo where you got the control and ask them. Docs are here: [https://learn.microsoft.com/en-us/dotnet/api/microsoft.toolkit.forms.ui.controls.webview?view=win-comm-toolkit-dotnet-stable](https://learn.microsoft.com/en-us/dotnet/api/microsoft.toolkit.forms.ui.controls.webview?view=win-comm-toolkit-dotnet-stable) Github repo is located here: [https://github.com/windows-toolkit/Microsoft.Toolkit.Win32](https://github.com/windows-toolkit/Microsoft.Toolkit.Win32)
Comment: Im also looking at the same issue and have opened a feature request here: https://github.com/windows-toolkit/Microsoft.Toolkit.Win32/issues/176
Answer: Instead of using the current directory or getting the assembly, just use the Application.ExecutablePath property:
//using System.IO;

string applicationDirectory = Path.GetDirectoryName(Application.ExecutablePath);

string myFile = Path.Combine(applicationDirectory, "Sample.html");

webMain.Url = new Uri("file:///" + myFile);

Answer: webView.NavigateToLocal("local file") seems to work:
this.webView.NavigateToLocal(".\\file.html");
I'm not sure why Navigate doesn't work.
EDIT: Visual Studio shows NavigateToLocal as obsolete and to use NavigateToLocalStreamUri instead.  See https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.webview.navigatetolocalstreamuri.
EDIT #2: I was not able to get NavigateToLocalStreamUri to work with a Uri that refers to the local file.  I ended up hard coding the local file name in my implementation of IUriToStreamResolver.


In how many possible combinations can you add 5 numbers?

Question: Suppose, I have 5 numbers, A,B,C,D and E.
My requirement is to add any of the numbers with any one or more of the other numbers?
For example,
I can do A+B, or A+B+C, or B+C+E, or B+C+D+E, etc.
I want to know how many such combinations are possible, and what are the steps to determine the combinations?
Since this is an addition, A+B and B+A are the same, and should not be treated as 2 distinct combinations.
I want to know the formula and the sequence / steps so that I can find answer for any n numbers.
I have arrived at the combinations for 3 numbers (A,B,C) as follows:
A+B,
A+C,
B+C,
A+B+C
Note that B+A, C+A, C+B, B+C+A, etc are not considered, as they are duplicates of existing combinations as there is no place value in addition.
Comment: ${{{{2^n-n-1}}}}$.
Comment: Can you tell me how to arrive at the combination values. I need to know not only the count, but also the distinct combinations, as I am developing a utility software. And how did you arrive at the formula for the count.
Answer: Your question basically boils down to computing subsets of the set $\{A,B,C,D,E\}$ that consist of at least 2 elements, since each such subset (for example the set $\{A,C,E\}$ corresponds to one way of forming a sum.
The number of all subsets of a set with $n$ elements is $2^n$ (for every element you have two options: include it in the subset or leave it out, which gives you $2^n$ different options to form a set). There is one subset with $0$ elements, the empty set, and there are $n$ subsets with $1$ element (the singleton sets), so that indeed gives us the answer $2^n-n-1$, or in your specific case of $n=5$, we get $32-5-1=26$.
Comment: Thanks for the beautiful explanation. I also need to know the elements of all the 2^n - n - 1 sets. Can you please help with that.
Comment: If I have to put it in an algorithm, what is the most efficient algorithm suitable for programming, to determine all such sets.
Comment: I am no programmer, so I do not know what the most efficient algorithm suitable for programming for this is. Also I'm not 100% sure if I understand correctly what your question really is. Do you want to implement an algorithm that takes a finite set and returns an array of all its subsets of cardinality at least 2?

I think this is a typical dynamic programming problem. The brute-force recursion will run very slowly, but a memoized version should be able to run much faster. If you dont know what I am talking about, https://www.youtube.com/watch?v=oBt53YbR9Kk is a cool introduction.


Calculating logs and fractional exponents by hand

Question: In view of what we can compute by hand, on a piece of paper, without having to use a computer or a calculator, how far can we go with the evaluation of $\log$-functions and fractional powers?
More concretely, are there practical methods, that work in general well enough, for computing the followings?

$\log(x)$ (natural log used here) for $x\in ]0,\infty[$ (e.g take $x=3,$ which has a natural log of $\approx 1.09$)
$x^{\alpha},$ ($x$ being any real number) for $\alpha$ not being a natural number. So e.g. $\alpha=1/2,1/3,\cdots$

It would be neat to learn about possible ways of maybe first simplifying these calculations, translating them into more feasible calculations (by hand), and then take it from there. Or if direct methods exist that work for certain values or powers. This surely begs the question, how people used to do these calculations before computers were around.
Comment: For how people used to compute values in tables, a [google books search for *logarithm+tables+explanation*, restricted to the 19th century](https://www.google.com/search?tbs=cdr%3A1%2Ccd_min%3A1800%2Ccd_max%3A1899&tbm=bks&q=logarithm+tables+explanation) gives many first-hand references for explanations.
Comment: See [Calculate logarithms by hand](http://math.stackexchange.com/questions/61279/calculate-logarithms-by-hand)
Comment: or [How to figure out the log of a number without a calculator?](http://math.stackexchange.com/questions/135368/).
Comment: for square root and cube root by hand see https://xlinux.nist.gov/dads/HTML/squareRoot.html and http://www.wikihow.com/Calculate-a-Square-Root-by-Hand and http://www.homeschoolmath.net/teaching/square-root-algorithm.php and http://www.wikihow.com/Calculate-Cube-Root-by-Hand and http://mathforum.org/library/drmath/view/52605.html also http://mathforum.org/dr.math/faq/faq.sqrt.by.hand.html and http://mathforum.org/library/drmath/sets/select/dm_sqrt_nocalc.html
Answer: The well known series
$$\log(1+x) = \sum_{k=1}^{\infty}(-1)^{k+1}\frac{x^k}{k}$$
converges for $-1< x\leq 1$, so it cannot be used to calculate $\log(3)$ with directly. However, it is possible to extend the radius of convergence using a conformal mapping. If we put $y = \frac{1+x}{1-x}$, then we have:
$$\log(y) = \log(1+x) - \log(1-x) =  2\sum_{k=0}^{\infty}\frac{x^{2k+1}}{2k+1}$$
Since $x = \frac{y-1}{y+1}$, this means that
$$\log(y) = 2\sum_{k=0}^{\infty}\frac{1}{2k+1}\left(\frac{y-1}{y+1}\right)^{2k+1}$$
and this converges for all positive y. So, you can directly insert $y = 3$ in this series and compute $\log(3)$ quite accurately using only a few terms:
$$\log(3) =1 + \frac{1}{3\times 4} + \frac{1}{5\times 16} + \frac{1}{7\times 64} + \frac{1}{9\times 256} + \frac{1}{11\times 1024} +\cdots$$
So, with 6 terms we get 5 significant figures. But for larger $y$ the series will converge more slowly, it's then more convenient to use the above series to construct a series for $\log(y+1) -\log(y) = \log\left(1+\frac{1}{y}\right)$:
$$\log(1+y)  = \log(y)+ 2\sum_{k=0}^{\infty}\frac{1}{2k+1}\left(\frac{1}{1+2y}\right)^{2k+1}$$
The series now converges faster when computing $\log(n)$ for $n$ larger than 2, but you then need to know $\log(n-1)$.  However, it is then possible to compute several logarithms simultaneously in terms of only fast converging series. E.g. to compute $\log(2)$, $\log(3)$ and $\log(5)$ simultaneously, we can use $2^4 = 16 = 15+1 = 3\times 5 +1$, $3^4 = 81 = 80+1 = 2^4\times 5 +1$, and $5^2 = 24+1 = 3\times 2^3+1$, this yields:
$$
\begin{split}
&4\log(2) - \log(3) - \log(5) &= 2\sum_{k=0}^{\infty}\frac{1}{2k+1}\left(\frac{1}{31}\right)^{2k+1}\\
&4\log(3) - 4\log(2) - \log(5) &= 2\sum_{k=0}^{\infty}\frac{1}{2k+1}\left(\frac{1}{161}\right)^{2k+1}\\
&2\log(5) - 3\log(2) - \log(3) & = 2\sum_{k=0}^{\infty}\frac{1}{2k+1}\left(\frac{1}{49}\right)^{2k+1}
\end{split}
$$
So, you can then solve for the 3 logarithms using these 3 equations involving  fast converging series.
Comment: This is just awesome stuff!! I will take my time and go through it slowly, many thanks for your answer.
Comment: You make it seem so trivial :)
Comment: Euler does exactly this to determine $\log n$ for integer $n$ from 1 to 10 in Chapter 7 of Book 1 of Introduction to Analysis of the Infinite. For $n = 7$ it is a bit more complicated; he puts $x = 1/99$ into the series for $\log \frac{1+x}{1-x}$ to obtain $\log(100/98) = \log(50/49)$. Then he subtracts this from $\log 50 = 2 \log 5 + \log 2$ to get $\log 49$ and finally halves it to get $\log 7$.
Answer: My favorite way of calculating the natural logarithm:
$$\ln(x)\approx-\gamma+\sum_{n=1}^x\frac1n$$
Where $\gamma$ is the Euler-Mascheroni constant.  Not only is this easy, but it works quite well for something like $x>10$.
If you need to calculate other bases, like $\log_b(x)$, use $\log_b(x)=\frac{\ln(x)}{\ln(b)}$.
If you are not satisfied with the result because $x$ is small, try $\ln(x)=\frac1k\ln(x^k)$ to make the approximation better.
Answer: Before computers were available log tables were used to compute logs and fractional exponents. You say "by hand" but I'm assuming that reasonably sized pre-computed tables are allowed.
The method for estimating the log of an arbitrary number is as follows:
For example to compute $y=ln(14623)$ the first step is to find $log_{10}(14623)$.
$log_{10}(14623)= log_{10}(14.623 \times 10^3)= log_{10}(14.623)+3 $
The log tables are written for base 10 and a reasonable sized one can have results for $log_{10}(a)$ for all $a$ between 1 and 100.
We want to find $log_{10}(14.623)+3$. Round it to two significant figures of accuracy and find $log_{10}(15)+3$.
Now we just look up $log_{10}(15)$ in the table which is $1.176$, therefore $log_{10}(14.623)+3 \approx 1.176+3=4.176$.
But we wanted the natural log so we use the change of base rule. $ln(x)=\frac{log_{10}(x)}{log_{10}(e)}$.
We know in advance that $log_{10}(e)=0.434$, therefore
$ln(14623)=\frac{4.176}{0.434}=9.616$
The method for computing exponents uses the above method.
To find $y=x^a$ first take the log of both sides
$log_{10}(y)=log_{10}(x^a)=alog_{10}(x)$
With the log tables we can find $log_{10}(x)$
With a table for exponents it is simple to estimate $y=10^{alog_{10}(x)}$
Comment: Make sure to put a "\" in front of the "log" so that it renders $\log$.
Comment: Thanks a lot, this is very much along the type of answer i was expecting. I don't mean to be pesky, but the how are the tabulated values obtained? :) (In this case $\log(15)$.)
Answer: Let $a$ be the value you want to compute the natural logarithm of. Take the Taylor polynomial centered at $a$, e.g. $\ln(x)=\ln(a)+\frac{1}{a}(x-a)-\frac{1}{a^2}\frac{(x-a)^2}{2}+\frac{1}{a^3}\frac{(x-a)^3}{3}-\cdots$. We know that $\ln(1)=0$, so that
$$\ln(a)\approx-\left(\frac{1}{a}(1-a)-\frac{1}{a^2}\frac{(1-a)^2}{2}+\cdots+\frac{1}{a^N}\frac{(1-a)^N}{N}\right)$$
for some $N$.
Of course, if $a$ is far away from $1$, then $N$ may need to be very large. The series converges by the ratio test when $0<1<2a$, thus $\frac{1}{2}<a$ is required. Of course, if you require and $a$ below $0.5$, use the properties of logs: $\ln (2/7)=\ln2-\ln 7$.
By hand, this can become a monstrous calculation. For $a=3$, $N=17$ suffices to get accuracy up to $3$ decimal places, but for $a=25$, $N=100$ only gives $2$ decimal place accuracy. Not at all efficient, but it's a simple idea. It only involves basic algebraic operations and careful rounding.
To evaluate a general logarithm, just use the change of base. Of course, now you have to evaluate two natural logarithms, so this method becomes even more computationally intensive.
To evaluate $b^a$, note that $b^a=e^{a\ln(b)}$, so we only need to know how to calculate exponents of $e$ and the natural logarithm (the latter is done above).
A similar Taylor series method as above gives
$$
e^a\approx \sum_{k=0}^N \frac{a^k}{k!}.
$$
The convergence properties of this approximation are pretty nice. Of course, you are still calculating integer powers of potentially unfriendly decimal expansions.
Comment: If $x$ is far form $a$, that series might not converge. Also, I fixed the last fraction saying $(1-a)^N$ instead of $(x-a)^N$.
Comment: Good point. There are definitely convergence issues, but it will at least work some of the time. I've noted that in the post. Thanks for pointing out the typo, I went in a fixed it in a few other places.
Comment: Thanks for the complementary idea to that of Hugh, indeed taylor expands are another way of going about this.
Answer: For back-of-the-envelope or mental computations, I just use $$\log_{10}(2)\approx0.3$$ (actually I remember $0.30103$). This implies $$\log_{10}(5)=0.7$$ I also recall that $\sqrt{10}\approx3.16$, so that $$\log_{10}(3.16)\approx0.5$$
From these values I grossly interpolate.
Examples:

$\pi^{10}$: $\pi$ is close to $\sqrt{10}$, then even without logarithms, $10^5$ (vs. $93648.\cdots$).
$\sqrt[5]{42}$: the log of $42$ will be a little more than $1+2\cdot0.3$, but let's stick to $1.6$. After division by $5$ we get $0.32$ corresponding to about the cube root of $10$, say $2.1$, as $2^3=8$ (vs. $2.112\cdots$).
$e^{6.3}$: $e$ is $2.71828\cdots$ and its log is closer to $\sqrt{10}$ than to $2$, let us take $0.42$. Then the product is $2.646$, with antilog about $500$ (vs. $544.\cdots$).

What matters to me is a correct order of magnitude.
Answer: Yes, it is possible.
For several hundred years, humanity has calculated log, ln, etc. by hand. It is a laborious, tedious task, and there is no easy way to verify the results either.
Even in the early 20th century, the results of these calculations were still printed and sold as books; any engineer had to have one.
Comment: *Even in the early 20th century, the results of these calculations were still printed and sold as books* Not just the early 20th century, but even in the mid 1970s. I still have my CRC handbook and some others (Schaum's Outline of tables and formulas, Barnes and Noble College Outline Series of tables and formulas, etc.) from my high school years. And pretty much every school and college algebra textbook and trigonometry textbook and calculus textbook had tables at the back of the book, even in the early 1980s (and many still had them in the late 1980s).
Comment: @DaveL.Renfro When people like the comment more than the answer.


How to calculate this double integral?

Question: Here the equation: $\iint_{A} x^2y \ cos(xy^2)dxdy \ \ | \ \ A = <0, \frac\pi 2> x <0,2> $
Now I'm aware that it means integration on a rectangle with boundaries defined by given coordinates, which means that we should be able to rewrite it like this:
$\int^{\frac \pi 2}_{0} [\  \int^{2}_{0} x^2y \ cos(xy^2)dy \ ]dx$ .
From what I know, I guess it has to be calculated using integration by parts, however, but I have troubles defining u and v' because of both the variables being located in the argument of cosine. Also substitution has come to my mind, but I'm not sure what to substitute, since the powers in the argument of cosine and the multiplier do not correspond to each other.
I'd love at least some general advice as how to calculate this. According to the results page and Wolfram Alpha, it is equal to $  \frac  \pi {-16}  $
PS. I'm sorry, it's probably trivial, but I'm quite new into this multiple integrals thing..
Thanks in advance
Answer: This integral can be solved by substitution. In fact the needed substitution does not mix $x$ and $y$, so we only need to apply single variable calculus.
The needed substitution is $t=y^2$, because then $2y\, dy=dt$ which simplifies the integral a lot.
So lets first solve the $y$-integral
$$\int_0^2 x^2 y \cos(x y^2) \, dy= \frac{1}{2}\int_0^4 x^2 \cos(xt)dt = \frac{1}{2} x \sin(4x)$$
The value of the double integral is then obtained by integrating this expression with respect to $x \in [0,\frac{\pi}{2}]$.
This integral can be calculated by integration by parts:
$$ \frac{1}{2}\int_0^{\pi/2} x \sin(4x)= \frac{1}{2} \left(\big[-\frac{x}4 \cos(4x)\big]_0^{\pi/2} +\int_0^{\pi/2}\frac{1}{4} \cos(4x)\right)$$
As the integral on the right is over a whole period of $\cos(4x)$, it vanishes.
Thus the final result is
$$-\frac{\pi}{16}.$$
Comment: Thanks for your swift reply! Just to clarify, I take it that if $t = y^2  , dt = 2ydy$ , and the $dt$ is where $ \frac 12 $ in front of the first y-integral where we substitute comes from (with boundaries coming from y=2 -> t=2*2=4 and y=0 -> t=0)?
Comment: This is correct. I somehow forgot to write the "2". It should be $2y\,dy=dt$
Comment: Great, thanks again for your explanation! :)

How to calculate this double integral?


How can I play that crazy sound in Koko Taylor's "Wang Dang Doodle"?

Question: In Koko Taylor's Wang Dang Doodle,
there's some kind of ringing arpeggio lead that almost makes you forget that the whole song has only one chord. How do you play that crazy lead?
Edit: This isn't the one I was thinking of, but the lead is similar. link
This is it: link
 the lick takes form at 0:20 and repeats a few times, punctuating the lyric.
Edit: The comments all refer to what I think is the bass, or maybe a low (baritone?) guitar riff. That's not what I'm talking about at all. I'm talking about that really high part. First few times I heard it, I thought they were plucking piano strings. If the song is pitched in D-minor, then the riff I'm talking about goes (I think) like
<code>$3 17 $2 16 $3 17   $1 15 15 $2 16 $3 17
</code>
Not the one that goes like (E minor)
<code>$6 0    5 7 $5 5   $6 7 $5 7     5    $6 3 4 0   | 0
</code>
Edit: Specifically, if it's sweep arpeggios, how do you do the reverse to the up-sweep (between the two 'A's)? Maybe I've been focusing on fingerstyle too long. I just can't seem to get this lick right.
Comment: It's more the technique I'm not clear on. Is it just sweep arpeggios, or is there a hammeron/pulloff in there?
Comment: Deleted all my comments about the main riff. You confused me by calling this very quiet background sound a 'lead'. I can't hear anything new coming in at 0:20 - but I do hear a 'steam whistle' effect which may be a barre chord strummed upwards, with some heavy eq and loose tuning.
Comment: It's there from the very beginning, but settles into the first 'theme' of the riff at 0:20. First dozen times I heard it was at Starbucks. The high bits were about all I could hear. To find out what song it is you have to go to the back room and read the screen before the next one comes on.
Comment: This is how I maintain my musical skills while working at Starbucks. :/
Answer: To my ear, the notes sound like they've got a bit of sustain in them, so it might be simpler than you're making it out to be. No hammer-ons, pulloffs, or complicated sweep picking--just finger a concert Eb minor triad (in root inversion) high on the fretboard on the top three strings and do the rest of the work with your right hand.
From the recording you linked, it sounds like the chord is just held by the left hand, and the right either slowly strums from top to bottom, or does a repeated arpeggiation with three finger picking.
It's worth noting that I also hear some Fender Rhodes piano in the mix, which has a tone not unlike this guitar sound we're trying to decipher.
Answer: Yes, after repeated listening, NReilingh is undoubtedly correct. The riff I was after is more like this:
<code>$3.17 $2.16   $3.17 $2.16 $1.15  15 $2.16 $3.17
</code>
All sweeps. Or sweep-arpeggios.


Passing an array stdClass Object from custom module to template

Question: I've created some D8 custom modules which call rest API and and it's working fine when I get simple array in my $response.
In my controller, this is working :
return [
            '#theme' => 'webservices_client',
            '#id' => $infos_clients->body->id,
            '#nom' => $infos_clients->body->nom,
 ];

But when I receive that kind of array $response->body :
Array
(
    [0] => stdClass Object
        (
            [numero] => 625
            [dateDebut] => 2018-09-27T09:21:54.5746973
        )

    [1] => stdClass Object
        (
            [numero] => 468
            [dateDebut] => 2018-05-17T16:50:33.6357383
        )

)

I don't how to send my array from the controller to the twig template and assign variable in my-module.module
Could you explain how to this ?
I've tried this kind of thing :
in controller :
return [
            '#theme' => 'webservices_informations',
            '#myvariable' => $response,
       ];

in my-module.module :
function webservices_informations_theme(array $existing, $type, $theme, $path) {
    return array(
        'webservices_informations' => array(
            'variables' => array(
                'myvariable' => NULL,
            ),
        ),
    );
}

In twig template :
{% for key, value in myvariable %}
            Key : {{ key }}

            Name : {{ value.id }}

{% endfor %

Answer: I don't know why it was not working because after I've done a simple

    {{ dump(myvariable) }}

In order to check if the array was passed to the twig template, everything is working.
So the solution is in my-template.html.twig
{% for key, value in myvariable %}
    Key : {{ key }}

    Date: {{ value.dateDebut }}

    Societe : {{ value.societe }}

{% endfor %}


Is two singing voices occasionaly being unison "allowed"?

Question: I was writing a lower harmony to an existing (rock) lead voice with a given chord progression and there is a point in time, where it seems like the two voices need to sing the very same note. The only alternatives to this are: Letting the second voice jump around alot (which does not sound right to me), making the voice generally lower (but I want the voices to stay relatively close to each other and it sounds dull to me anyway) or changing the lead voice (which I simply don't want to do, because it was already existing for quite some time).
The question is: Is it "acceptable" to let the two voices sing the same note occasionally? Are there any notable examples of works or rather popular songs where this happens? Or would people think, that it sounds strange and/or that I am just a lazy composer?
Comment: This happens a lot in rock and pop. See Indigo Girls for examples of two voice harmonization with occasional to frequent unisons.
Answer: First off, everything is allowed in music. Whether it's appropriate can be another question, but especially in rock most people basically go by "if it sounds good, it's ok".
Even by the rules of classical counterpoint, it's not forbidden for two voices to share a single note, as long as they don't move parallel in unison. In two-voice counterpoint, it's still a bit eschewed because you loose the sense of harmonicity (sometimes used deliberately for final notes!), but this doesn't really matter in an accompanied setting.
So, yes, by all means use a single uni sono note if that feels more natural than alternative options!
Answer: Yes, unison notes are possible and have precedent in well-known classical pieces.
Case in point:
The violin parts in IMSLP transcription of Johann Pachelbel's "Canon in D" are constructed by starting violin_common.ily at measure 3, 5, or 7. I plugged the first and second violin parts into an NES music converter that takes a LilyPond-derived syntax. In one listening, I heard unisons between the first and second violins at 8:3, 28:3, 32:3, and 35:2. (They recurred two measures later between the second and third violins, and I didn't listen for unisons between the first and third violins.) This doesn't count other cases where one violin starts a note and another plays the same note while the first is holding it, such as 11:3 and 42:4.

G unison in measure 8
Answer: Absolutely!  This happens in pop music all the time.  Great example would be More Than Words, by Extreme.  Notice how the two vocal lines come together on "then you".  Unity followed by divergence catches the ear in a very satisfying way.  Most importantly in harmony writing, I find, is that both lines make musical sense when heard individually.
Comment: +1 for the last sentence :)  I usually play harmony, and although it's not necessary that my part makes sense for the overall sound of the music, it generally will help it overall.  (Not to mention being easier :))
Answer: Yes, absolutely OK.   Two voices can hit a unison for one note, or can fall into unison for a passage.   Some very effective vocal arrangements are in unison apart from brief passages, maybe just the final note!
It MIGHT sound odd if the voices fall into unison for just one note.  It MIGHT sound even odder if one voice makes an awkward jump just to avoid a unison.  Your artistic choice.  You can't really write music 'by the rules'.
Answer: No two voices even when singing the same pitch will sound the same, your voice is one of the things that make you unique. So unison in regards to singing can still lead to a harmonically rich sound. Even just something as simple as a man singing with a women adds richness.
Now proper voice leading still applies, it is probably going to get borin quick if it is just two voices singing constantly in unison but still as an effect it is fine.
Comment: The Beatles were renowned for their vocal harmonies.  But when you look at the songs, there was a great deal of unison, and rarely more than two-parts.  If something simple says what you want to say, don't be afraid to leave it there.
Comment: Heck, even the Beach Boys had a lot of unison going on, and those guys where the kings of rock and roll harmony.
Answer: There is a band called Lucius with two excellent lead singers, both women. They sing almost EVERYTHING in a unison that's so perfect it's eerie, and it is strangely satisfying to the ear, once you stop trying to pry the two voices apart. They toured with Roger Waters a few years ago, here they are doing the vocals on Great Gig in the Sky. Their own stuff is totally excellent, too!


Guitar - making an "A" sound instead of an "O" sound

Question: In the solo from hey you by pink floyd, at 2:35, Gilmour does a bend when the timbre of the sound changes significantly, from an "O" kind of sound, to more of an "A". Video:

How does he do this?
Comment: Hardly a *significant* change, but anyway - what reasons do you have for asking? Curiosity, are you trying to learn the solo verbatim, part of a Pink Floyd tribute band, what?
Comment: I would say the more significant change in timbre occurs with a few notes around the 2:40 mark. Compare the note played at 2:40 with the same note at 2:35. The 2:40 has a "rounder" sound. Without listening too deeply, this sounds to me like some combination of wah pedal, as well as finger and picking technique, as described by others.
Comment: There are certain regions, within the "pickup area" where you can tap-mute the string with your thumb while picking and you get sort of harmonic-influenced twang while still having a proper note (think of it like a lot of "dry" note with some "wet mix" of a harmonic. He uses this technique a lot, and IIRC, he uses it in this solo in a few places. By moving your hand a little forward and a little back from the sweet spot, you can control the how pronounced the effect is. The flange smears it out.
Answer: The solo does have a slow and subtle wah type effect to it. According to the site below he uses an Electro Harmonix Deluxe Electric Mistress Flanger on that solo. A flanger will give you varying degrees of vowel sounds, as you described it. The site also contains information on other gear he uses and has used over the years.
https://www.pinkfloyd-guitar.com/LinksContactGear/david_gilmour_gear.html
Answer: I'm not really hearing this as a "significant" change in timbre. It seems pretty subtle to me.
I don't mean to contradict, I'm just saying so, because I don't think anything is changing in terms of electronic gear.
When you scribe the "O" sound to an "A", I think you mean generally it changes to a tone with more high end, a brighter tone. I sort of hear that, but I really don't think I would have noticed a change without you pointing out that particular moment in the solo.
It's complicated by the fact the solo starts moving up to higher pitches at that point. That's more high end sound just from playing higher pitches. But, it also makes me think there could be a string change involved. The various strings definitely have different timbres and that could be contributing. Also, picking technique can make a subtle different. Not only with the strength/release of the pluck, but where on the string the pick is placed.
So, I'm not really sure I hear the significant change in timbre that you do, but I don't think there is a change is electronic processing - there may be flange/wah like @JohnBelzaguy described, but I don't think it's changing at that point in the solo - but changing strings and pick technique can create different timbres and those may be a factor in this case.
Answer: Sounds to me as simple as he's playing on the second string, and bends up the third string at that point, which has a slightly different tone to it.
Answer: I'm hearing something, maybe, that could be as simple as moving from neck to bridge pickup, or even picking position. I've listened to this when album for 35 years and not noticed, and if I was trying to learn the solo to play out, I wouldn't peg it as important compared to everything else you'd need to nail in concert.
Answer: Off hand, my first assumption is that he went from down stroke picking to up stroke picking. That along with running the signal thru a flanger or a chorus to "widen" the sound but again as others here have mentioned, it's more subtle. Someone else here also mentioned where the pick is striking the string which can make small changes to a note as well. I believe you may want to experiment in this route more as Gilmour was greatly influenced by the Blues players before him. Blues players were known to use picking techniques that were outside of the normal to get a more original sound. Mind you, they didn't have all the technology that we enjoy today.