Is there a name for the points on the body of electric guitars?

Question: I was trying to describe a part of the guitar to a friend a I could not come up with the proper name for it. I was try to refer to the two points on the body of an electric guitar where typically part of the strap typically goes on one side. I've included a picture and circled the parts on the guitar that I'm referring to.

Is there a proper name for those parts of the guitar?
Comment: I don't think there is a specific name; I've heard people call them 'horns', especially when referring to Gibson SGs
Comment: See also [What is a "horn" on a bass guitar?](https://music.stackexchange.com/questions/50235)
Answer: They are indeed called horns. In the 60s/70s, Burns made some electric guitars called Black Bison, I seem to remember,and the horns did resemble those of a bison.The cutaway is necessary to reach higher frets, but if the horns were removed as well, the balance of the instrument would be compromised even more. Besides which,as you say, most manufacturers need the top horn to fit the strap button to.
Comment: I've seen a guitar or three without horns and they look *ugly* (I don't mean flying V or voyager style designs, I mean ones that would have horns but the horn is cut off) - somehow we've been programmed over the last 100+ years to need some of that classic guitar shape to be retained even with a double cutaway. Even ESP LTD guitars with just very small horns don't look right.
Comment: @Basstickler - that's fair. On six of my basses, the top horn is level with about fret 14, and they all balance really well. It also puts the strap button in a good place - with a shorter horn, it would tip.
Comment: Doubtful, as the majority of lefties would expect the whole thing to be mirror image. Excepting Jimi, of course, who really didn't mind which way the guitar was. Good job he had a preference for Strats - or was that why?
Comment: Les Claypool had Carl Thompson build him a custom 6-string and actually had to have them rework it to include a longer horn to balance the instrument.  I think the balance consideration is a little more important on basses since they have a longer scale (more leverage) and are heavier in general, not to say that it's not important on guitars.
Comment: Agreed, @Basstickler. The "balance" of the guitar on your leg is much more apparent to me with a bass than with a guitar.
Comment: @ToddWilcox - true, and there's really no need for a top horn, although aesthetics dictate there could be. I guess Mr. Fender started it all back in the 50s. Where that idea came from, who knows?
Comment: I wonder if the double horn came about because of lefties playing right handed guitars upside down.
Comment: @Tim: Hendrix did later in his career play some flying V's (more symmetric) and actual lefthand models, but he always seemed to prefer the old righty Strats overall; so this is apparently not just due to the Strat's swapping-suitability.
Answer: They're called horns:

The indentations next to them (beside the neck) are referred to as cutouts or cutaways, and are usually more often what is referenced in relation to the general shape of a guitar body. In the image I've provided, the guitar is a single cutaway, and the image you have shown is a double cutaway.
Comment: @Dedwards You may not have made this image, but it does not make it correct. The only parts that are correct are the joint, shoulder, waist and horn. Everything else is entirely fictional, made up by whoever made the image.
Comment: I did not make this image, and I have not heard "tricep" anymore than I've heard "Jackhole". :P
Comment: Yes, jackhole did sound a little out of order - it's always been a jack socket to me. Although after explaining to a student that the plug was called a jack, he asked if the corresponding part on the guitar was Jill...
Comment: I always understood the socket to be the jack, and the type of plug that mates with a jack can be referred to as a jack plug. OED agrees: http://www.oxforddictionaries.com/definition/english/jack
Comment: Did you make up 'tricep'? Never heard of that one!


issue while creating a dynamic dropdown box using multiselect jquery plugin

Question: I am trying to make a dynamic select dropdown, I tried writing the code in javascript and jquery both but can't append the options in the dropdown. When I tried seeing what is stored then the Html select code along with all the options is shown. What should I add or change in it so the options are stored in the correct position?

lines=["B","C","D","E","F","G"];
$(document).ready(function(){
  $("#select1").multiselect({
    placeholder: 'Features'
  });
});

   // var selectFir = document.getElementById("select1");

   // for (var i = 0; i < firstLine.length; i++) {
         // var x = document.createElement("OPTION"),
           //     txt = document.createTextNode(firstLine[i]);
          // x.appendChild(txt);
          //  x.setAttribute("value", firstLine[i]);
          //  selectFir.appendChild(x);
          //  selectFir.insertBefore(x, selectFir.lastChild);
   //  }console.log(selectFir);

firstLine = lines[0];
// Calls function to generate drop downs using options above
       for(var i=0; i< firstLine.length;i++)
       {
        //creates option tag
         jQuery('<option/>', {
               value: firstLine[i],
               html: firstLine[i]
               }).appendTo('#select1');
       }
       jQuery('#select1').multiselect('refresh');

<select multiple id="select1">
 <option value="A">A</option>
</select>
Comment: Looks like you are looking forward to put code after this "// Calls function to generate drop downs using options above" in function on some click event, correct?
Comment: Yeah, the problem is I can see the whole select tag of html code when I display selectFir, it is not pushing the options in the options tag. Is there a jquery plugin that can populate dynamic dropdown?
Comment: Isn't solution code i provided answer your question?
Comment: Oh yeah, that helped, sorry I didn't reply, and thank you!
Answer:

lines=["B","C","D","E","F","G"];
$(document).ready(function(){
  $("#select1").multiselect({
    placeholder: 'Features'
  });
});

   // var selectFir = document.getElementById("select1");

   // for (var i = 0; i < firstLine.length; i++) {
         // var x = document.createElement("OPTION"),
           //     txt = document.createTextNode(firstLine[i]);
          // x.appendChild(txt);
          //  x.setAttribute("value", firstLine[i]);
          //  selectFir.appendChild(x);
          //  selectFir.insertBefore(x, selectFir.lastChild);
   //  }console.log(selectFir);

firstLine = lines;
// Calls function to generate drop downs using options above
       for(var i=0; i< firstLine .length;i++)
       {
        //creates option tag
         jQuery('<option/>', {
               value: firstLine[i],
               html: firstLine[i]
               }).appendTo('#select1');
       }
       jQuery('#select1').multiselect('refresh');

<select multiple id="select1">
 <option value="A">A</option>
</select>


Java TCP Socket Connection Issue -- handshake failure while connecting to legacy equipment

Question: I am attempting to write a Java program that will replace an old DOS-based program that my company currently uses. When I attempt to simply open a socket to communicate with the piece of equipment the program is being written for, the TCP handshake never completes. I have a fairly decent idea of what the problem may be, but I am truly a novice network programmer and I'm not totally sure (nor am I sure how to resolve the issue). I'll try to make this explanation both brief and useful.
The equipment that I'm attempting to connect with is OLD -- like 20+ years old. The device is typically controlled by either a GPIB connection or over a network. Historically, all the programs that have connected to this device over a network have been run on Solaris system. The GPIB port has been the only option available for PC-based connections.
Now, one downside is that I don't have access to any of the source code from either the "client" accessing the machine nor the "server" on the machine. All the information I have has been gleaned by intercepting the IP traffic between a Solaris box and the equipment. I do believe that the equipment is utilizing a UNIX-like embedded system. And if you want proof of how old these things are, check out the MAC address below that starts with "00:80:12:00".
The bottom line of my problem is this -- it seems that there is enough difference between the packets that my system and JVM (Win7 with Java 7) send and the packets that the equipment produce to cause a TCP connection to not function. I have a feeling that Java doesn't have any built-in methods or classes to functionally modify a TCP packet. I ran into a similar limitation when I was writing a RARP server and found out that I couldn't easily send a ping from a Java program.
I'm including some basic packet information that I've intercepted off the network. The first set of six packets are the first packets exchanged between the Solaris system and the equipment. The second set of six packets are the only six packets sent between my Windows 7-based Java program and the equipment. Key items that I've noticed already about the difference between these two sets of packets:
1) The port being used by this equipment is 2112 (AKA idonix-metanet). The extremely limited information I've found about this port/protocol just shows how utterly old this equipment and protocol are.
2) The working packets from the Solaris system do not contain any entry involving "WS=XXX". I'd imagine this is because that particular aspect of TCP didn't exist way-back-when.
3) It seems to me that my PC/program is the entity deciding to close the attempted TCP connection. When I open the socket in Java, it sends a SYN packet, receives a SYN, ACK packet, sends an ACK packet, then instantly sends a FIN, ACK packet which then starts the process of terminating the connection. To me and my limited experience, this tells me that something in the single SYN,ACK packet that was sent from the equipment made my program(or OS) decide that this connection was not working properly.
4) I also noticed that the value for "Win" was drastically different between the two. In the functional Solaris packets, Win starts off with a value of 24820. This value changes in later packets. I did manually modify my program to have a fixed Win value of 24820, but this had no effect.
5) The length of the first packet is four greater (66) in my Java-based communications than it is in the Solaris-based communications. This is probably due to the additional WS field.
I am not including any Java code since all I am doing at this point is opening a Socket to the equipment's IP and port.
First -- the working Solaris packets:
No.     Time        Source                Destination           Protocol Length Info
      1 0.000000    192.168.1.135         192.168.1.23          TCP      62     33384 > idonix-metanet [SYN] Seq=0 Win=24820 Len=0 SACK_PERM=1 MSS=1460

    0000  00 80 12 00 03 33 00 03 ba 13 6b ec 08 00 45 00    .....3....k...E.
    0010  00 30 48 37 40 00 40 06 6e a2 c0 a8 01 87 c0 a8   .0H7@.@.n.......
    0020  01 17 82 68 08 40 cf f8 45 a0 00 00 00 00 70 02   ...h.@..E.....p.
    0030  60 f4 fd fa 00 00 01 01 04 02 02 04 05 b4         `.............

No.     Time        Source                Destination           Protocol Length Info
      2 0.000970    192.168.1.23          192.168.1.135         TCP      60     idonix-metanet > 33384 [SYN, ACK] Seq=0 Ack=1 Win=4096 Len=0 MSS=1024

    0000  00 03 ba 13 6b ec 00 80 12 00 03 33 08 00 45 00   ....k......3..E.
    0010  00 2c 00 05 00 00 64 06 d2 d8 c0 a8 01 17 c0 a8   .,....d.........
    0020  01 87 08 40 82 68 00 39 c0 00 cf f8 45 a1 60 12   ...@.h.9....E.`.
    0030  10 00 a5 5f 00 00 02 04 04 00 00 00               ..._........

No.     Time        Source                Destination           Protocol Length Info
      3 0.000975    192.168.1.135         192.168.1.23          TCP      60     33384 > idonix-metanet [ACK] Seq=1 Ack=1 Win=25600 Len=0

    0000  00 80 12 00 03 33 00 03 ba 13 6b ec 08 00 45 00   .....3....k...E.
    0010  00 28 48 38 40 00 40 06 6e a9 c0 a8 01 87 c0 a8   .(H8@.@.n.......
    0020  01 17 82 68 08 40 cf f8 45 a1 00 39 c0 01 50 10   ...h.@..E..9..P.
    0030  64 00 67 68 00 00 55 55 55 55 55 55               d.gh..UUUUUU

No.     Time        Source                Destination           Protocol Length Info
      4 0.001235    192.168.1.135         192.168.1.23          TCP      62     33384 > idonix-metanet [PSH, ACK] Seq=1 Ack=1 Win=25600 Len=8

    0000  00 80 12 00 03 33 00 03 ba 13 6b ec 08 00 45 00   .....3....k...E.
    0010  00 30 48 39 40 00 40 06 6e a0 c0 a8 01 87 c0 a8   .0H9@.@.n.......
    0020  01 17 82 68 08 40 cf f8 45 a1 00 39 c0 01 50 18   ...h.@..E..9..P.
    0030  64 00 26 55 00 00 41 03 00 00 00 00 00 00         d.&U..A.......

No.     Time        Source                Destination           Protocol Length Info
      5 0.002694    192.168.1.23          192.168.1.135         TCP      60     idonix-metanet > 33384 [ACK] Seq=1 Ack=9 Win=4088 Len=0

    0000  00 03 ba 13 6b ec 00 80 12 00 03 33 08 00 45 00   ....k......3..E.
    0010  00 28 00 06 00 00 64 06 d2 db c0 a8 01 17 c0 a8   .(....d.........
    0020  01 87 08 40 82 68 00 39 c0 01 cf f8 45 a9 50 10   ...@.h.9....E.P.
    0030  0f f8 bb 68 00 00 00 00 00 00 00 00               ...h........

No.     Time        Source                Destination           Protocol Length Info
      6 0.019280    192.168.1.23          192.168.1.135         TCP      62     idonix-metanet > 33384 [PSH, ACK] Seq=1 Ack=9 Win=4096 Len=8

    0000  00 03 ba 13 6b ec 00 80 12 00 03 33 08 00 45 00   ....k......3..E.
    0010  00 30 00 07 00 00 64 06 d2 d2 c0 a8 01 17 c0 a8   .0....d.........
    0020  01 87 08 40 82 68 00 39 c0 01 cf f8 45 a9 50 18   ...@.h.9....E.P.
    0030  10 00 79 fb 00 00 41 03 00 00 00 00 00 52         ..y...A......R

Now, the non-functional Java-based packets (packets 1 and 2 were removed since they were just broadcasts looking for the equipment's MAC address):
No.     Time        Source                Destination           Protocol Length Info
      3 0.001154    192.168.1.79          192.168.1.23          TCP      66     49931 > idonix-metanet [SYN] Seq=0 Win=8192 Len=0 MSS=1460 WS=256 SACK_PERM=1

    0000  00 80 12 00 03 33 14 da e9 1a c9 c4 08 00 45 00   .....3........E.
    0010  00 34 01 9a 40 00 80 06 75 73 c0 a8 01 4f c0 a8   .4..@...us...O..
    0020  01 17 c3 0b 08 40 22 6f b1 8d 00 00 00 00 80 02   .....@"o........
    0030  20 00 2c 11 00 00 02 04 05 b4 01 03 03 08 01 01    .,.............
    0040  04 02                                             ..

No.     Time        Source                Destination           Protocol Length Info
      4 0.002375    192.168.1.23          192.168.1.79          TCP      60     idonix-metanet > 49931 [SYN, ACK] Seq=0 Ack=1 Win=4096 Len=0 MSS=1024

    0000  14 da e9 1a c9 c4 00 80 12 00 03 33 08 00 45 00   ...........3..E.
    0010  00 2c 00 05 00 00 64 06 d3 10 c0 a8 01 17 c0 a8   .,....d.........
    0020  01 4f 08 40 c3 0b 00 3a 70 00 22 6f b1 8e 60 12   .O.@...:p."o..`.
    0030  10 00 f6 8f 00 00 02 04 04 00 00 00               ............

No.     Time        Source                Destination           Protocol Length Info
      5 0.002379    192.168.1.79          192.168.1.23          TCP      60     49931 > idonix-metanet [ACK] Seq=1 Ack=1 Win=64512 Len=0

    0000  00 80 12 00 03 33 14 da e9 1a c9 c4 08 00 45 00   .....3........E.
    0010  00 28 01 9b 40 00 80 06 75 7e c0 a8 01 4f c0 a8   .(..@...u~...O..
    0020  01 17 c3 0b 08 40 22 6f b1 8e 00 3a 70 01 50 10   .....@"o...:p.P.
    0030  fc 00 20 98 00 00 00 00 00 00 00 00               .. .........

No.     Time        Source                Destination           Protocol Length Info
      6 0.003002    192.168.1.79          192.168.1.23          TCP      60     49931 > idonix-metanet [FIN, ACK] Seq=1 Ack=1 Win=64512 Len=0

    0000  00 80 12 00 03 33 14 da e9 1a c9 c4 08 00 45 00   .....3........E.
    0010  00 28 01 9c 40 00 80 06 75 7d c0 a8 01 4f c0 a8   .(..@...u}...O..
    0020  01 17 c3 0b 08 40 22 6f b1 8e 00 3a 70 01 50 11   .....@"o...:p.P.
    0030  fc 00 20 97 00 00 00 00 00 00 00 00               .. .........

No.     Time        Source                Destination           Protocol Length Info
      7 0.004242    192.168.1.23          192.168.1.79          TCP      60     idonix-metanet > 49931 [FIN, ACK] Seq=1 Ack=2 Win=4096 Len=0

    0000  14 da e9 1a c9 c4 00 80 12 00 03 33 08 00 45 00   ...........3..E.
    0010  00 28 00 06 00 00 64 06 d3 13 c0 a8 01 17 c0 a8   .(....d.........
    0020  01 4f 08 40 c3 0b 00 3a 70 01 22 6f b1 8f 50 11   .O.@...:p."o..P.
    0030  10 00 0c 97 00 00 02 04 04 00 00 00               ............

No.     Time        Source                Destination           Protocol Length Info
      8 0.004246    192.168.1.79          192.168.1.23          TCP      60     49931 > idonix-metanet [ACK] Seq=2 Ack=2 Win=64512 Len=0

    0000  00 80 12 00 03 33 14 da e9 1a c9 c4 08 00 45 00   .....3........E.
    0010  00 28 01 9d 40 00 80 06 75 7c c0 a8 01 4f c0 a8   .(..@...u|...O..
    0020  01 17 c3 0b 08 40 22 6f b1 8f 00 3a 70 02 50 10   .....@"o...:p.P.
    0030  fc 00 20 96 00 00 00 00 00 00 00 00               .. .........

So, now to my main question -- how in the world do I make this connection function properly in Java? My GUESS is that I'll need some C/C++ code to act as an intermediary between my program and my OS/hardware, but I really hope there is another way. I don't have the slightest clue how to do that.
Also, I do have all the Solaris-based header and compiled class files (C/C++) that are needed to access this equipment, but I don't know how useful compiled classes would be.
Many many thanks in advance for any help. Please let me know if there is any additional information that would help.
Jonathan
Comment: you said 'enough difference between the packets that my system and JVM (Win7 with Java 7) send and ...', have you tried establishing the connection from a C/C++/PERL etc program instead of Java, if C/C++ worked you could use JNI - http://en.wikipedia.org/wiki/Java_Native_Interface
Comment: However C++ *won't* work any differently from Java. Java doesn't send SYN or ACK or FIN packets, the underlying TCP stack does that.
Answer:
I am not including any Java code since all I am doing at this point is
  opening a Socket to the equipment's IP and port.

Are you sure about that? Sure you're not closing the socket, or letting it be GC'd, or closing its input stream or output stream, or calling shutdownOutput()? Because those are the only things that will cause your host to send a FIN.
Comment: @Jonathan Java doesn't create TCP packets at all. It just calls socket(), bind(), connect(), send(), recv(), etc. The kernel provides the TCP implementation. You are definitely barking up the wrong tree.
Comment: Wow -- you're totally right. I've been barking up the wrong tree. The TCP handshake is just fine. It just closes the connection immediately afterwards. Now on to the problem that made me think that I had a TCP issue... my program just sits waiting forever when I do a (Scanner object).hasNext(). Shouldn't it just return false if there is no input stream data?
Comment: @EJP Ha, wow. Good catch I was assuming something was incorrect in the handshake also.
Comment: @Jonathan Scanner can block on next/hasNext. The Scanner is for doing lexing of tokens. Until you get to EOF it won't stop. And it won't be EOF on your stream until you close the connection.
Comment: btw, +1 for finding such an obvious answer to the original problem. Sometimes we engineers look for problems where there are not any.
Comment: Well, the original problem still kind of exists, and I still do suspect that there is a pretty large difference in the way that Java on Windows 7 creates TCP packets and how my old Sparc Solaris Ultra 10 box does. I'm able to mimic two packet exchanges with Java in Windows 7 that I observed occurring between the Solaris box and the equipment, but then it all just breaks down. The third command I issue doesn't elicit a response like the first two.
Comment: What about Jpcap? From what I've seen, it permits me to make some fairly fundamental changes to a packets form.
Comment: @Jonathon Jpcap lets you make up your own packets and send them via raw sockets. It doesn't let you alter packets already in flight.


Fender Strat - parity between neck and middle pickups

Question: I'm currently in the process of upgrading the pickups in my MIM Stratocaster. Since I've already purchased a neck pup and a humbucker for the bridge, I'd like to buy the middle one in isolation.
I've noticed that very few vendors sell the middle pickup separately. Interestingly, I've read on a few websites that in a lot of pickup sets, the neck and middle pickups are identical. Is there any truth behind this claim?
Comment: On the original Strats, from '50s/'60s, I thought all three pups were the same - the different sound is from their positions on the body.
Answer: Yes, in the old days all three strat pickups would have been the same, wound on a simple machine.  As tastes progressed it became fairly common to buy an add on bridge pickup with more windings, for a higher level and "heavier" tone, or even a humbucker - but the neck and middle tend not to be different in construction.
However there's one thing in your case; the middle pickup these days can often be got in reverse wind/reverse polarity configuration.  If you can get one of these for your strat it will sound the same as a regular middle pickup, but it will also cancel hum when the pickup selector is at the "in-between" position between neck & middle.  (It won't cancel hum when used at bridge & middle in your case, as your bridge position pickup is already a humbucker.)
So, you might like to see if you can get a RW/RP pickup from the same maker as your current neck pickup, so the turns match for hum cancelling.  But otherwise, any single coil will do fine.


Setting up a VDSL router on OpenBSD & NIC with TCO support

Question: this is my first question and I hope I do everything correct. Thanks for setting up serverfault - such a site was missing in the internet for a long time now.
In the next few weeks I will get my VDSL 25 connection (at best it's 25 Mbit Download and 5 Mbit Upload). So now I was thinking about setting up my own router for VDSL because i dont want to use the Speedport router I'm getting with VDSL 25.
I'm really into OpenBSD and I found a nice guide about Using OpenBSD with VDSL. In a german article about setting up the FreeBSD based pfSense for VDSL i read that the computer should have at least 1 GHz with 1024 MB RAM.
My machine will be a 800 MHz Pentium 3 with 512 MB RAM but I consider to buy a 30$ Intel Gigbit NIC with TCO (TCP Checksum Offloading). A co-worker suggested this to me because he ment that would heavily decrease the CPU load and my 800 MHz P3 could be more than enough then.
So do you have some experience about the "hardware requirements" for VDSL and if a NIC with TCO could help there?
Thanks in advance for all your answers!
Answer: The recommended specs for pfSense are way, way, way overkill. Your machine should handle that load quite handily. For a point of reference, I used a Soekris Net5501 in production for a little while and it fell over at about 45Mbps. It was spec'd out with a 500MHz Geode, 256MB RAM, and some of the worst NICs ever created (Via Rhinestone - vr driver).
In my experience, the most common big performance obstacle on a router like this is the context switching required by rapid-firing interrupts. Shitty NICs like the Rhinestones fire an interrupt for every single packet they receive. This becomes a major problem because each packet has to be processed, but oops! In the middle of processing it, another one comes in. So you pull that out, get interrupted, etc etc. Context switching is an expensive operation and quickly overwhelms a slow CPU.
Good NICs (Intel and Broadcom are both solid) have interrupt mitigation capabilities, which means they only bug the CPU when they have a certain number of packets accumulated, or when a timer hits 0. Operating in chunks like this is far, far more efficient than constant context switching.
Some operating systems attempt to mimic interrupt mitigation with polling - the kernel ignores the NIC's interrupts and just checks its buffers every so often. This can lead to much higher throughput and lower CPU utilization, but at the expense of latency, possibly losing packets if the NIC's buffers fill up, etc. OpenBSD has not implemented polling. In my experience interrupt mitigation is superior to polling, and the price of decent NICs is low enough that there's not much excuse.
Memory really should not be an issue. OpenBSD and PF are very efficient. On a pretty slow day (today), one of my production routers has about 17.5k states in memory. It's also running spamd, logging all blocked packets, and doing a tcpdump on its most active interface. Using 191MB of RAM.
So all that to say your specs are more than enough, TCO or no.
Comment: thank you for your answer and experiences!
I thought it would probably require a "good" cpu because of the VLAN tagging which VDSL requires.

OpenBSD and PF are really pretty efficient - so thanks to get me an inside view on how much ressources it takes in real life production use.
Comment: VLAN tagging requires minimal resources - it already has to build/parse the layer 2 packet, this is just another field that has to be filled in or looked at. OpenBSD makes VLAN handling super-simple from a configuration standpoint too, so it shouldn't be a problem to get going.
Answer: OpenBSD doesn't support TCO so you won't get any benefit from such card.
Comment: Actually it does on several different drivers. Example is em(4) - the main Intel driver: http://www.openbsd.org/cgi-bin/man.cgi?query=em&apropos=0&sektion=0&manpath=OpenBSD+4.5&arch=i386&format=html
Comment: Hmm, strange http://www.onlamp.com/pub/a/bsd/2007/11/01/whats-new-in-bsd-42.html in this interview they say it won't be supported.
Comment: Those comments refer to engines that take a large part of the TCP stack into the hardware realm as opposed to the TCP Checksum Offloading. The latter is just error-checking math that can be safely offloaded to hardware without bypassing any of OpenBSD's specialized network stack. Full TCP offload or segmentation engines try to handle a large part of TCP processing in hardware. Nominally good for performance, but trusting hardware black-magic is not something the OpenBSD crowd is very in favor of.


What is the difference between a duet and a duo?

Question: I wrote a peice for piano and flute but I don't know if it should be called duet or duo. I see that duet is when the players have equal importance but that is not necessarily the case fo my composition. Would duo work? There is no Wikipedia article for it. Also, I'm not referring to pop terms like "duo"=a pair for singers
Did classical composers write pieces named "duo per/pour x and y"?
Comment: Listening to some renditions, I feel that **duel** is more appropriate...
Comment: @Tim: [Echo Sonata for Two Unfriendly Groups of Instruments](https://www.youtube.com/watch?v=8VaM7OtiQ4w)
Comment: @Tim - Your comment reminds me of certain Japanese electronic music pieces with authorship displayed as "X **vs.** Y".
Answer: A duo is two people performing or singing.
A duet is the piece they are performing or singing.
So, it's a duet for piano & flute.
Comment: Note that a "duo" could also refer to two people in any field, not just musicians, e.g. Batman and Robin, a.k.a. The Dynamic Duo.  Whereas "duet" refers pretty much exclusively to music.
Comment: @wabisabied if they're streaming from an AI that passed the Turing test. Actually, make them... AI-Pods.
Comment: @user1258361 that would depend: have the AirPods been granted personhood?
Comment: In that case, does a pair of AirPods count as a duo?
Comment: It's a duo playing a duet for piano and flute ;)
Answer: Think most people would consider a duo as two players, just as a trio is three.
And consider a duet as a piece for two players. However, the words appear to be synonymous, so you could use either for the piece, although duet would make more sense to more people.
If you make it for three, trio gets even more confusing...
Comment: There have been, and no doubt will be, many famous *sextets* - but I guess the more politically correct word is *hexad* - more commonly heard on stage in 'Who the hexad my pint!'
Comment: Yeah… I was avoiding trio, quartet et al for similar reasons. Can you play a triet with a trio, or a quartet with a quarto…? If that followed logically, I think I'd avoid being in a 6-piece band, for sure ;-)
Comment: If you make 8-bit music with 6 channels, does that make it... hexad-ecimal?
Answer: I would have argued like Tim and Tetsujin, but my research has shown that e.g. Beethoven calls a piece: Duo in Eb. Thus it seems that the term duo is also used like trio to name the piece and not only the performers, while duett is mostly used for the note arrangement but it can also be related to the formation and performers:
Duo or Duett

A Duo or Duett of this description, is a piece for two concerting instruments, without accompaniment. It must  not only contain as complete an harmony throughout, as has been required for Solos without accompaniments, (§ 7 :) but the two parts should also  be constantly imitating each other, or at least the one have as good a share  in the harmony and the passages as the other. It may be set, either for two performers on one Keyed Instrument, such as the Organ or the Piano Forte; or for two familiar instruments, such as two Violins or two Violoncellos ; or for two inftruments of å different nature, such as a Violin and Hautboy ; or a Violin and Violoncello. And in all three cases it may consist  either of two regular parts or melodics only ; or of passages which contain a harmony of three and four parts. See my Essay on Harmony, Chap. XIII, § 14, 15. I shall endeavour to speak of the pieces in question in the following order: 1, Duetts for two Performers on one Keyed Instrument may be set for three or four hands. Of the former sort is Haesssler's grand Sonata for three hands, published by Wornum; and my Fugue at Plate XVIII, which also may be considered as a trio on one instrument ; and of the latter fort Dussek's grand overture for two performers; and similar fine works by Kozeluch, Clementi, and other composers. These duetts for four hands may also be set as Quatuors on one instrument, when each hand has an obligato part different from the others; of which sort, I have not yet feen a good example. The particular rule for pieces of all these descriptions is, that the parts must be distributed according to what I have said in my Essay on Harmony, Chap. III, § 2 ; and so, that neither the bass be too noisy for the upper parts, nor the parts of the first  and second performer be in each other's way. 2, Duetts for two keyed instruments  are the most  refpectable fort of the fecond clafs; or of thofe for similar instruments: but as it is seldom that two such instruments can be found in the same room, as well as the same pitch of tune, there have been but few attempts made to write them. But two excellent Fugues of this description are in Seb. Bach's Art of the Fugue, which might be played on the two Sets of keys of one Organ. This great Author has also  written Concertos for two, three, and even four Keyed Instruments. Duetts for two Violins or two Flutes, or two Hautboys, &c. are more frequent. But in regard to these Duetts, I must mention a fault which is very frequently committed, viz : that of repeating a passage with the mere change of primo for secondo, or vice versa. This change in similar instruments  such as the above-mentioned, has no other effect than a mere repetition without a change of the parts; and consequently is no proper variety for the duetts in question. But for those of the following class it produces a variety in the effect. The third class of Duetts are those, for two different instruments. In regard to these, one of the principal considerations is : to choose such instruments as may have a good effect together. Another consideration is : that if a Duett is set for a Bass and a Treble Instrument, and intended to be alfo executed by two Basses or two Trebles, the harmony must be calculated accordingly. If thereforeDuett for a Violin and Violoncello shall  ..also calculated lated for two Violins or two Violoncellos, care must  be taken, that it produces no irregular intermixture, or no disallowed inversion of the parts when contracted on two similar instruments. $ 16.
Answer: There is some ambiguity, particularly when we stray outside the English language.
But I think I can safely say that it will never be WRONG to call the piece a Duet, the players a Duo.
Answer: IME: A song for two singers (with or without instruments) is a duet.
A piece for two players at a single piano is a piano duet.
A piece for two instruments, or for a larger ensemble with two soloists, may be called a duo. Weber's sonata for clarinet and piano op.48, and Alkan's sonata for violin and piano op.21, are each called Grand Duo Concertant.
Comment: "Grand Duo Concertant" is a French title, not English, and I believe the use of "duo" to refer to a piece of music is only a French usage, not an English one.


97% range around the mean

Question: I am doing some industry work in public transport and we are reviewing the time tables. To do this we are extracting data from a real time information system we have for the last 12 months.
We are looking at the difference between the time the bus arrives at timing points and the scheduled time and taking the mean of these differences. However, we want more information about the range of the data before we make any decisions on how much to change the timetable by.
We have thought about looking at the range but then thought it would be better to look at the range that say 95% of the data falls within.
Would you suggest that the data follows a normal distribution and we can look at the standard deviation to get the range that 95% of the data falls within (2 standard deviations above and below the mean).
If you have any other statistics that would be good to look at please let me know.
Thanks
Answer: It is very unlikely that your data follows a normal distribution, particularly out on the tails where you are interested.  You can imagine that the dispersion in most bus arrival times are because of variation in time waiting for red lights, passengers to load, etc.  There will be a most common arrival time and the distribution near that may be rather symmetric, but very few if any buses will arrive very much before it while some will be quite late.  You can compute the standard deviation, but it will probably be more influenced by the few very late buses than by normal activity.
Just making up some data, suppose you have $100$ arrival times. $10$ of them are $2$ minutes before the most common, $20$ are $1$ minute before, $35$ are at the most common, $20$ are $1$ minute after, $10$ are $2$ minutes after, and you have one each of $5,8,10,15,30$ minutes after.  The mean is only $0.69$ minutes after the most common, so you represent the most common reasonably well.  The standard deviation is $3.75$, so no bus is even $1\sigma $ early and $95\%$ fall within $\pm 1 \sigma$ instead of $68\%$ with the normal distribution. If the long delays are even longer, the mean will stop representing "normal behavior".
I would suggest that a more useful statistic would be the fraction of time that you are more than $x$ minutes late (say $3$ to $5$, but that is dependent on how late makes your passengers upset) then what fraction you are more than $2x, 3x$, etc.  I would suggest that reducing the fraction of the time you are $2$ minutes late will do less to make your public happy than eliminating the $30$ minute delay.  Of course, eliminating the one big event is hard to do, and focusing on that makes year to year comparisons very noisy.
Answer: I'll guess from your question that you hope to change the published timetable so it agrees more closely with reality (as opposed to making changes to the system itself).
This isn't my professional area, but my first thought would be that identifying and improving some summary statistic of the past discrepancies, like range, mean, or width of a percentile-based interval isn't what you need.
I'd ask "What do I hope to improve?" and then compare that under the current timetable (using the historical data) to the same thing under various alternate timetables. The number of data points isn't in the billions, so computationally, it's feasible to evaluate even weird measures against many alternatives using all the data.
Perhaps you want to minimize the number of people per week (if you have passenger-count data; or number of minutes in the day if not, either of which might be weighted by when on-timeness is likely most critical to passengers, if not) who have to wait - I don't know - either more than five minutes or more than half the time to the next listed arrival time.
The armchair psychologist in me thinks (for buses and subways, not commuter trains) people don't care about the timetable until they've been waiting several minutes or some length of time approaching the frequency of arrivals on the line.
With that in mind, I think I would brainstorm a variety of measurables like the percent or raw number of printed arrival times where a transport (the scheduled one or a previous late one) arrived on the line within the next N minutes, where N is max(4,half the interval between arrivals on the line at that time of the day/week) - maybe separately measured on weekdays and weekends (maybe extra-weighted on Friday afternoons...), and see how they would change under different schedules. It's probably a little, but not a lot, harder to do this than to work with plain averages and intervals.
Although "our timetables are nearly correct" might be a good goal for PR (and possibly for industry benchmarking), you may also want to aim for "our timetables don't frustrate customers," even if the latter is trickier to nail down.
My $2.75 worth, or whatever a ticket costs.

97% range around the mean


Matrix P to the power of 4, i.e $P^4$, is this the same as $P^2 \cdot P^2$?

Question: Basically, what it says in the title.
I have a $5 \times 5$ matrix and I need to work out $P^4$, is it possible to just do $P^2$ and multiply this with itself?
Comment: Yes.${}{}{}{}{}$
Comment: This is the simplest case of binary "fast" exponentiation.  For larger exponents than 4 there may be "chains" of multiplication (addition of exponents) that improve on the naive binary expansion.  For more discussion see [Algorithm for calculating $A^n$ with as few multiplications as possible](http://math.stackexchange.com/q/721/3111).
Answer:
I have a $5 \times 5$ matrix and I need to work out $P^4$, is it possible to just do $P^2$ and multiply this with itself?

Yes, Why?: Because A square matrix always commutes with itself, under matrix multiplication. $\quad\;\;$WHY? Because matrix multiplication (when well-defined) is associative. $$P\cdot (P \cdot (P\cdot P)) = P\cdot ((P \cdot P)\cdot P) = (P\cdot (P\cdot P)) \cdot P $$ $$ =  ((P\cdot P) \cdot P) \cdot P = (P\cdot P) \cdot (P \cdot P) = P^2\cdot P^2 = P^4.$$

But be careful. Generally speaking, for square matrices $A, B$ such that $P = AB$, $$P^4 = (AB)^4 = (AB)^2\cdot (AB)^2 \ne A^2 \cdot A^2\cdot B^2 \cdot B^2 = A^4\cdot B^4  $$ since here, we cannot assume that $A$ and $B$ commute.
Answer: $P^4=P^2\times P^2$ for a matrix $P$. Multiplication of matrices is associative, so you can do that.
Comment: @Belgi Why? Note that if the multiplication was not associative, $A^4$ would be an abuse of notation. It could mean $((AA)A)A$ and also $(A(AA))A$ and $(AA)(AA)$ and $A(A(AA))$ and $A((AA)A)$.... Usually $A^n$ is defined as $A^{n-1}A$ so $A^4$ usually means $((AA)A)A$. Why is that the same as $(AA)(AA)$?
Comment: @Belgi: Although associativity makes up for the lack of commutativity generally (in implying powers are well-defined & commute $P^a\cdot P^b=P^b\cdot P^a$), here's an example to show we need something like associativity.  Consider a binary operation on $\{p,q\}$ where $p\cdot p=q\cdot p = q$ and $p\cdot q=q\cdot q = p$.  Then $(p\cdot p)\cdot (p\cdot p) = q\cdot q = p$ but $((p\cdot p)\cdot p)\cdot p= q$.
Comment: So I can do $P^2 \cdot P^2$? As $P^2$ is the same, it doesn't matter which way round it goes does it.
Comment: Even if matrix multiplication was not associative the result still holds
Comment: @N.S. thanks for the note about the notation!
Answer: What does $P^4$ mean to you? It might mean $$P\cdot P\cdot P\cdot P$$ but this is not exactly defined until you agree that matrix multiplication is asociative. Otherwise $P^4$ should mean something like $$((P\cdot P)\cdot P)\cdot P$$ Now if you believe that the multiplication is associative, then this is the same as $$(P\cdot P)\cdot (P\cdot P)$$ which is almost certainly what you would mean by $P^2\cdot P^2$.


Getting WPF Dispatcher from library

Question: Is there a way to get the GUI Dispatcher from a library without passing reference from the GUI?
I'm working with a library (MVVM) that can invalidate datasources which will cause a GUI update. The Invalidate call needs to come from the GUI thread. I can just pass the reference, but it would be nice not to have to do that.
Answer: The GUI dispatcher for the library will be the same dispatcher for your application. Anything that needs to run on the UI thread can just be called with Application.Current.Dispatcher.
Answer: Application.Current.Dispatcher

Getting WPF Dispatcher from library


Inverse of a particular operator

Question: I need help finding the inverse of the following operator. I am not sure about how to start. Any help would be hugely appreciated.
Operator: $( I + \frac{\partial^2}{\partial x^2})$
Edit:
I actually need the inverse of this whole thing:
$\begin{bmatrix}  I + \beta\frac{\partial^2}{\partial x^2} & 0 \\ 0 & I \end{bmatrix}$.
I am assuming L2 space.
Comment: What space are you acting the operator on?  It is also likely to be unbounded.  If you are looking at $C^\infty$ functions on $[0,1]$ for example, the sequence of functions $\sin(nx)$ should give a sequence whose uniform norm is unbounded when applying the operator.
Comment: Hi, Thanks. I have edited the question.
Answer: You haven't specified the domain and range of this function. If you mean the operator over the $C^\infty$ functions, note that it will not be invertible.  Taking for example $f(x) = \sin(x)$, we have
$$
\left(I + \frac{\partial^2}{\partial x^2}\right) f(x) = 0
$$
so your function is certainly not injective.

Suppose we are considering the operator over the space of functions with period $2$.  We define the inner product
$$
\langle f,g\rangle = \int_0^1 f(x) \overline{g(x)}\,dx
$$
Then the family of functions
$$
a(x) = 1\\
b_n(x) = \sin(n \pi x)\\
c_n(x) = \cos(n \pi x)
$$
forms an orthonormal (Schauder) basis of this set.  Relative to the basis $\{a,b_1,c_1,b_2,c_2,\dots\}$, we can represent the operator $(I + \beta\frac{\partial^2}{\partial x^2})$ as
$$
\pmatrix{1\\
&1-\pi^2\beta\\
&&1-\pi^2\beta\\
&&&1 - 2^2 \pi^2 \beta\\
&&&&1 - 2^2 \pi^2 \beta\\
&&&&&1 - 3^2 \pi^2 \beta\\
&&&&&& \ddots}
$$
We can find the inverse of this operator as we would find the inverse of any other diagonal operator.
Comment: Hi, Thanks. I have edited the question.
Comment: We have the same problem.  The operator
$$
\pmatrix{A\\&B}
$$
is only invertible if both $A$ and $B$ are invertible.
Comment: Why isn't $I + \beta\frac{\partial^2}{\partial x^2}$ invertible?
Comment: @T119 for the same reason.  Take $f(x) = \sin(\sqrt\beta x)$.
Comment: So? The operation gives $sin(\sqrt\beta x) - \beta sin(\sqrt\beta x)$.
Comment: @T119 No it doesn't; use the chain rule.  Anyway, I mean
$$
f(x) = \sin\left(\frac{x}{\sqrt \beta}\right)
$$
none of this should be particularly surprising to you
Comment: But in finite dimensions the determinant of this operator is not zero. Can a sequence of non singular operators converge to something singular?
Comment: @T119 yes; the set of invertible operators is not closed (it is open, though).
Comment: Perhaps you'd like an inverse of this function over the space of polynomials
Comment: I am working with C0 functions. But I still do not understand why you are saying it doesn't have an inverse. :(
Comment: The inverse of an operator $T$ is an operator $S$ satisfying
$$
TS = ST = I
$$
In this case, there can be no operator $S$ satisfying $ST = I$.
Comment: But what if take functions like $sin(n \pi x)$?
Comment: @T119 do you mean that the domain of your operator is the set of such functions?
Comment: Yes that's what I meant.
Comment: Then depending on your choice of $\beta$, you might be okay.  Are you considering something like the set of periodic functions?  That might also be okay (again, depending on $\beta$).
Comment: Having these in order, can you suggest me a way to go about finding the inverse?
Comment: See my edit.   ${}$

Inverse of a particular operator


Elasticsearch processor for shingles similar to split?

Question: Is there a processor that will do shingles or can I make a custom one somehow?
In the pipeline processor below, I split on the space character, but I'd also like to combine words like a shingle analyzer would:
PUT _ingest/pipeline/split
{
  "processors": [
    {
      "split": {
        "field": "title",
        "target_field": "title_suggest.input",
        "separator": "\\s+"
      }
    }
  ]
}

Example:
"Senior Business Developer" needs a suggestion field with these terms.

Senior Business Developer
Business Developer
Developer

Here are the links to the article and answer that inspired this question:

https://blog.mimacom.com/autocomplete-elasticsearch-part3/
How to combine completion, suggestion and match phrase across multiple text fields?
Answer: Here is one solution I came up with using a custom script:
PUT _ingest/pipeline/shingle
{
  "description" : "Create basic shingles from title field and input in another field title_suggest",
  "processors" : [
    {
      "script": {
        "lang": "painless",
        "source": """
              String[] split(String s, char d) {
                int count = 0;

                for (char c : s.toCharArray()) {
                    if (c == d) {
                        ++count;
                    }
                }

                if (count == 0) {
                    return new String[] {s};
                }

                String[] r = new String[count + 1];
                int i0 = 0, i1 = 0;
                count = 0;

                for (char c : s.toCharArray()) {
                    if (c == d) {
                        r[count++] = s.substring(i0, i1);
                        i0 = i1 + 1;
                    }

                    ++i1;
                }

                r[count] = s.substring(i0, i1);

                return r;
              }

              if (!ctx.containsKey('title')) { return; }
              def title_words = split(ctx['title'], (char)' ');
              def title_suggest = [];
              for (def i = 0; i < title_words.length; i++) {
                def shingle = title_words[i];
                title_suggest.add(shingle);
                for (def j = i + 1; j < title_words.length; j++) {
                  shingle = shingle + ' ' + title_words[j];
                  title_suggest.add(shingle);
                }
              }
              ctx['title_suggest'] = title_suggest;

            """
      }
    }
  ]
}


Django Test request.method == 'POST' not working

Question: I am working on an example in TDD with python and am trying to accept a post request.
Django's Request and response objects page for HttpRequest.method suggests using the following snippet to responde to GET and POST differently
if request.method == 'GET':
    do_something()
elif request.method == 'POST':
    do_something_else()

With this in mind, my view is setup like so:
from django.shortcuts import render
from django.http import HttpResponse
from items.models import Item

def index_page(request):

    name = ''
    if request.method == 'POST':
        name = request.POST['item']
        Item.objects.create(name=name)

    return render(request, 'items/index.html', {'item': name})

My test file contains the following
from django.test import TestCase
from django.http import HttpRequest
from items.views import index_page
from items.models import Item

class IndexPageTest(TestCase):

    def test_index_page_can_save_a_post_request(self):
        request = HttpRequest()
        request.POST['item'] = 'MyItem'
        response = index_page(request)

        self.assertEqual(Item.objects.count(), 1)
        self.assertEqual(Item.objects.first().name, 'MyItem')

Which yields the following error
======================================================================
FAIL: test_index_page_can_save_a_post_request (items.tests.IndexPageTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/items/tests.py", line 43, in test_index_page_can_save_a_post_request
    self.assertEqual(Item.objects.count(), 1)
AssertionError: 0 != 1

However when I alter the view to the following, the test passes.
from django.shortcuts import render
from django.http import HttpResponse
from items.models import Item

def index_page(request):

    name = request.POST.get('item', '')
    if name:
        Item.objects.create(name=name)

    return render(request, 'items/index.html', {'item': name})

Clearly, my page is repsonding to POST requests and the test is sending POST data, but I'm not sure why the if request.method == 'POST': line does not appear to work.
$ python --version
Python 3.5.2 :: Continuum Analytics, Inc.
$ django-admin --version
1.10.3

Comment: Also set the `request.method = 'POST'` as your first example is making check based on rquest method and you are not setting that up
Answer: Your test isn't sending a post. You should use the RequestFactory rather than instantiating HttpRequest directly. Or even better, use the built in test client.
Comment: I'm looking into the client, but how would `name = request.POST.get('item', '')` be returning the correct value if the `HttpRequest` wasn't sending POST data?
Comment: Probably the test passes because you created request object yourself and added only `item` key to it. So when you pass that request to second view, it finds a value for `item`, as you specified it, and creates the Item object. But
Comment: Well, you added an item to request.POST, so of course that works. But that doesn't change the request method.


Find all ideals of $K \times K$ where K is a field

Question: I know that there is no nontrivial ideals of any field $K$. Again  $K \times 0$ and $0 \times K$ are nontrivial ideals of $K \times K$. But how can we give a complete classification for all ideals of $K \times K$? Thanks!
Answer: Hint: If an ideal contains the element $(a,b)$ where $a \ne 0$ and $b\ne 0$, what else must it contain?
Answer: If $A_1$ and $A_2$ are rings, every ideal $I$ in $A_1 \times A_2$ can be written as $I_1 \times I_2$; now a field $\mathbb{K}$ has only two ideals, $(0)$ and $\mathbb{K}$. Endstory.
Comment: Reducing to a harder problem?
Comment: @Myself it's not really harder, if you look at my answer you'll see this is quite easy to prove since we have the first isomorphism theorem.
Comment: @Adam Hughes: If it's a "research problem" I agree with you, but this is more likely from a chapter one in ring theory. So no Endstory (yet).
Answer: The image of an ideal under the canonical projection homomorphisms onto each factor would also be an ideal by definition of a homomorphism and by the first isomorphism theorem, all ideals arise in this way, so looking at
$$\pi_1:\begin{cases}K\times K\to K \\ (a,b)\mapsto a\end{cases}$$
$$\pi_2:\begin{cases}K\times K\to K \\ (a,b)\mapsto b\end{cases}$$
and noting that the only ideals of $K$ are $\{0\}$ and $K$, you get the ideals to be
$$\{\pi_1^{-1}(I)\times\pi_2^{-1}(J)\}=\{\{0\}\times\{0\}, \{0\}\times K, K\times\{0\}, K\times K\}$$
where here, $I,J\in\{\{0\},K\}$.
Comment: Could you please expand the section where you explain how these are the only ideals?
Comment: @Myself that the only ideals of a field, $K$, are $\{0\}$ and $K$ is a more basic problem the op says he already understands in his original post. If you're interested in why this is, it's considered appropriate to post a question of your own and link this one to indicate why you're interested.
Comment: sorry that was not really what I meant. I mean the point where you apply the first isomorphism theorem to conclude that every ideal arises from on of the two morphisms that you give. I mean, *a priori* there may be other morphisms that you haven't considered so this point is a bit unclear.
Comment: So to be completely clear, the first isomorphism theorem states that every ideal *containing the kernel of the morphism* can be retraced in the image of the morphism, in other words you have found every morphism containing the kernel of either of both your morphisms, that leaves open the question if a morphism must necessarily contain one of those kernels.
Comment: @Myself Any surjective homomorphism will do, all maps out of $K\times K$ arise as a product of two maps, this is the **definition** of a direct product. It would take another line, but using this one can show that any other just reduces to this case. I opted for being succinct rather than pedantic for clarity.
Comment: Sorry, still confused. Why does your proof not apply to show that the only subgroups of $\mathbf C_p \times \mathbf C_p$ are $1$, $1\times\mathbf C_p$, $\mathbf C_p\times 1$ and $\mathbf C_p \times\mathbf C_p$.
Comment: These are ring maps, not group maps.
Comment: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/16904/discussion-between-myself-and-adam-hughes).


Need help redirecting through PHP

Question: I'm currently building a survey. I've made quite a bit of progress so far. If a participant completes and submits the survey it successfully enters my database and returns the participant to the main page of my site but if one question is skipped by the participant, when they try to submit the survey it returns a blank display and no data is fed into my database.
I want to create a survey that gives participants the ability to skip questions, and returns them to the homepage after submitting the survey.
I understand it may be easy for some but I'm fairly new to PHP so I'm still learning, please see the code below.
<?php
$radioVal1 = $_POST["q1"];
$radioVal2 = $_POST["q2"];
$radioVal3 = $_POST["q3"];
$radioVal4 = $_POST["q4"];
$radioVal5 = $_POST["q5"];
$checkboxVal6 = $_POST["q6"];
$textAreaVal = $_POST["comment"];
session_start();
require_once('DBConnection.php');
if(isset($_POST["submit_questionnaire"])){
    if(isset($_POST["q1"]) && isset($_POST["q2"]) && isset($_POST["q3"]) && isset($_POST["q4"]) && isset($_POST["q5"]) && isset($_POST["q6"]) && $textAreaVal!=null){
        echo "blyat";
        $username = $_SESSION['username'];
        $db = new DBConnection();
        $conn= $db::getInstance()->dbConnect();
        $query_code = "SELECT id_code FROM users WHERE name = '$username'";
        $id_codeRow = $db::getInstance()->selectDB($query_code)->fetch_row();
        $id_code = (string)array_values($id_codeRow)[0];
        $query = "INSERT INTO questionnaire VALUES (default, '$id_code', '$radioVal1', '$radioVal2', '$radioVal3','$radioVal4', '$radioVal5', '$checkboxVal6', '$textAreaVal')";
        $insert_value = $db::getInstance()->selectDB($query);
        session_destroy();
        header("Location: index.php");
        exit();
    }

}

Comment: its because the ```insert``` into db and the redirection doesn't happen if the very long if statement isn't true so you need to do for example redirect to ```index.php``` anyways if the if statement is true or not
Comment: **Warning:** You are wide open to [SQL Injections](http://php.net/manual/en/security.database.sql-injection.php) and should really use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](http://php.net/manual/en/pdo.prepared-statements.php) or by [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Never trust any kind of input, especially that which comes from the client side. Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/).
Answer: // You can remplace "&&" by "OR" so any questions can be skipped by the user but the user have to complete atleast 1 question.
<?php
$radioVal1 = $_POST["q1"];
$radioVal2 = $_POST["q2"];
$radioVal3 = $_POST["q3"];
$radioVal4 = $_POST["q4"];
$radioVal5 = $_POST["q5"];
$checkboxVal6 = $_POST["q6"];
$textAreaVal = $_POST["comment"];
session_start();
require_once('DBConnection.php');
if(isset($_POST["submit_questionnaire"])){
    if(isset($_POST["q1"]) OR isset($_POST["q2"]) OR isset($_POST["q3"]) OR isset($_POST["q4"]) OR isset($_POST["q5"]) OR isset($_POST["q6"])){
        echo "blyat";
        $username = $_SESSION['username'];
        $db = new DBConnection();
        $conn= $db::getInstance()->dbConnect();
        $query_code = "SELECT id_code FROM users WHERE name = '$username'";
        $id_codeRow = $db::getInstance()->selectDB($query_code)->fetch_row();
        $id_code = (string)array_values($id_codeRow)[0];
        $query = "INSERT INTO questionnaire VALUES (default, '$id_code', '$radioVal1', '$radioVal2', '$radioVal3','$radioVal4', '$radioVal5', '$checkboxVal6', '$textAreaVal')";
        $insert_value = $db::getInstance()->selectDB($query);
        session_destroy();
        header("Location: index.php");
        exit();
    }

}

Need help redirecting through PHP


Measuring User Login Time of a User in an Active Directory Environment from an End User Perspective

Question: I want to measure the time taken by the users to login to the Active Directory Server, note that this time should also include the time taken for the logon scripts to run fully.
After lots of Googling I was repeatedly told to add performance counters but that wouldn't be much of a end user perspective.
So I really wanted to know if there are any ways (through VBscript/Powershell for example) I could simulate a login.
Note: Initially I thought of authenticating using a program (C#), but that wouldn't include the loading of the logon Script.
Answer: If you're running Windows 2000, Windows XP, or Windows Server 2003 you can enable user environment debug logging:
http://support.microsoft.com/kb/221833
If you're running Windows Vista, Windows 7, or Windows Server 2008 you can look in the Group Policy event log:
http://blogs.technet.com/b/askperf/archive/2008/03/11/group-policy-logging-on-windows-vista.aspx


What is the definition of "death rate" in survival analysis?

Question: I am reading a text on survival analysis (Smith's 2002 Analysis of Failure and Survival Data). All concepts like hazard function, survival function, density of survival variable $Y$ are rigorously defined. However, in an exercise (p.14) it says "Suppose that the death rate of a person that smokes is at each age twice that of a non-smoker. If $h_s(y)$ denotes the hazard rate of a smoker at age $y$ and $h_n(y)$ that of a non-smoker at age $y$, write an equation relating $h_s(y)$ and $h_n(y)$".
This left me puzzled on what the author means by death rate (it has not been defined as far as I can see). Perhaps he means the derivative of the survival function or something alike.
This idea may be backed up by a google search in which I found the definition
$$\lambda = \frac{D}{T}$$
where $D$ number of deaths in time interval $T$. In probability terms I would thus conclude a useful definition may be
$$\lambda = \frac{F(Y+t) - F(Y) }{t}$$
where $F(Y)$ the cummulative distribution function. Furthermore if I let
$$\lim_{t \rightarrow 0} \frac{F(Y+t) - F(Y) }{t} = f(y)=-S'(Y)$$
where $f$ the density and $S$ the survival function.
Is this logic formalized or convention somewhere?
Answer: A rate has a specific definition of $\frac{\# \mbox{events}}{\# \mbox{person-years}}$. A risk on the other hand refers to a particular individual's risk of experiencing an outcome of interest, and it is risk which is intrinsically related to the hazard (instantaneous risk). The language the question uses is consistent with this understanding. If I had to change it, I would say, "The death rate for smokers is twice that of *non-smokers". They also failed to mention whether these were age adjusted rates or not.
To understand this a little more deeply, relative rates and relative risks are estimated with fundamentally different models.
If you wanted to formalize a rate, you can think of this as estimating:
$$E \left( \frac{\# \mbox{events}}{\# \mbox{person-years}} \right) =\frac{\sum_i Pr(Y_i < t_i)} {\sum_i t_i} $$
($Y_i$ is the death time and $t_i$ is the observation time for the $i$-th individual, note the times are considered fixed and not random!)
You'll recognize the numerator is a bunch of CDFs, or 1-survival functions, and the relationship with survival functions and hazards is well known.
So if you took a ratio of rates:
$$ 2 = E \left( \frac{ \# \mbox{smoker deaths} \times \# \mbox{non-smoker person-years}}{\# {non-smoker deaths} \times \# \mbox{smoker person years}} \right) = \frac{\sum_i t_i}{\sum_j t_j} \frac{\sum_j Pr(Y_j < t_j)}{\sum_i Pr(Y_i < t_i)}$$
$$ = \frac{\sum_i t_i}{\sum_j t_j} \frac{ n_j-\sum_jS(t_j)}{n_i-\sum_iS(t_i)}$$
Since it's self study, you should probably do the algebra and solve the remainder of the equation!
Answer: By "death rate", they essentially mean hazard rate. Death rates are often reported as deaths per 100,000 subjects per year, making the death rate proportional to the hazard rate, so they are not necessarily exactly alike.
In regards to the book, part "i" of the problem is quite easy as you said. Using what they ask you to prove in part "ii" of the problem, we can actually show that proportional hazards imply proportional death rates in case you don't want to just blindly take my word. Which you shouldn't.
Part "ii" says "using the relation between the hazard rates, show that the survival probability of smokers is the square of the survival probability for non-smokers" (paraphrasing).
This tells us that
$S_s(t) = S_{ns}(t)^2$
Since hazard rates are related to survival curves by
$S(t) = e^{-\int h(t)}$
This implies that
$e^{-\int h_s(t)}$ = $(e^{-\int h_{ns}(t)})^2$
Further implying that
$e^{-\int h_s(t)}$ = $(e^{-2\int h_{ns}(t)})$
Which finally leaves us with $h_s(t) = 2 h_{ns}(t)$ (provided some assumptions about the smoothness of the hazard function).
Since $h_s(t) = 2 h_{ns}(t)$, note that this has the exact same relation as described with the "death rate". Technically, this doesn't prove that "death rate" is the same as hazard rate but it implies that if death rates are proportional (whatever they are), then hazard rates are proportional.
Comment: Okay, but I somehow sense that then the exercise would be a bit trivial. The level of difficulty of the other exercises is generally higher.
Comment: Please see edit above; I found some definition for death rate that is not the hazard rate. What do you think?
Comment: @ThomasKlausch: Looking at the book (thanks google books!), part "i" of the question *is* very easy. However, part "ii" is slightly harder. Furthermore, you can take the results that you are supposed to prove in part "ii" to prove that hazard rate = death rate.
Comment: @ThomasKlausch: also, in regards to your definition, it is still the hazard rate (kind of). What's important is that when you evaluate the death rate in interval $I$, it is dependent on the size of the population in interval $I$ **and thus is proportional to current living population, not total population** (although in practice it's a little odder because the population gets replenished). It still works out to be basically getting the hazard rate. I had the same confusion when I first came across the terminology myself.
Comment: @ThomasKlausch: ah, actually death rates are not *exactly* like hazard rates. I'm edited my answer (a lot) to more thoroughly answer the question.
Comment: That makes it pretty clear. Thanks! I believe my 'definition' does not fit into this logic though.
Comment: @CliffAB We do not call them "hazard rates", a "hazard" is simply a hazard. There is, however, the concept of a hazard ratio.
Comment: @AdamO: Huh? While it can be called "hazard", "hazard rate" is, to my knowledge, a valid term. Take a look at the [first line defining the hazard ratio in wikipedia](https://en.wikipedia.org/wiki/Hazard_ratio)
Comment: @CliffAB it's not the first time statistical language is abused in Wikipedia. In the Hosmer Lemeshow May survival analysis text, 2nd ed. there are separate index entries for the hazard *function* (or hazard) and hazard *rate*. Hazard *rates* are constant hazards, e.g. exponentially distributed survival times.
Comment: @AdamO: [here's](http://www.jstor.org/stable/2242051?seq=1#page_scan_tab_contents) an Annals of Statistics publication that refers to hazard rates in the title (to be fair, cumulative hazard rates. But the abstract refers to "unspecified hazard rates"). Furthermore, it doesn't take much reading to see they are not referring specifically to the exponential distribution.


What do you call it when volume is decreased at bass beats?

Question: I've noticed that it seems popular in some electronic music genres to quickly lower the volume of the music (except the bass) right around each bass beat.
Not sure why you'd wanna do this, perhaps to make the bass more pronounced? Personally I find it very tiring and annoying to listen to, almost to the point of making me physically uncomfortable even at very low volume.
Does this "effect" have a name?
Comment: Sometimes videos of people talking, which usually have some background music, uses this method (aka sidechaining) so that the music doesn't interrupt the talking but also fills the gap when the speaker(s) pauses (so the audio doesn't feel too dry)
Answer: It's called ducking, sidechain ducking, sidechain compression or sometimes even "sidechaining".
A compressor is a device which lowers the volume of a signal when it gets louder than a set threshold level. Compressors are used in many ways to alter the dynamics of individual instruments and mixes. In a sidechaining compressor, the "key" signal that's used to control the attenuator, is taken from a different place than the signal that's attenuated. For example, a string pad might be the processed signal, and a kick drum (bass drum) is used as the key signal. Every time the kick drum hits, the string pad's volume drops and rises back after a release time has passed.
A similar technique is used for example in radio shows, to automatically duck the background music when someone speaks to the microphone.
Sidechain ducking is used to glue sounds together and to let drums or other things be loud and pronounced all the time, while allowing everything else to be loud all the time too! :) Everything is loud all the time - win/win situation?
Another effect achieved with sidechain ducking that's used a lot in electronic dance music is rhythmic pumping. If the release time is set so that the ducked instrument comes back after a musical meaningful time value like 1/8 note after the kick drum, then the background pad pumps in sync with the kick drum beat almost as if it was a guitar or accordion playing a back beat. So, the compressor is used partly as an automatic mixer, or almost like an arrangement helper.
Here's a demonstration. The musical effect is the same, but kids these days don't want to hear accordions anymore, they want boom boom kicks and ducking pads. Same thing really. ;)
Comment: Perhaps [pumping](https://en.wikipedia.org/wiki/Pumping_(audio)) is the general name for the effect, while sidechaining / sidechain compression is one way of achieving it..?
Comment: Obviously OP isn't impressed by the effect, so what is the purpose of using it?
Comment: @topoReinstateMonica Isn't that what I said? :) Pumping is an effect achieved with sidechain ducking
Comment: I saw that you mentioned pumping, but personally thought the word 'pumping' perhaps deserved to be in the first line of the answer (as in - i thought that the answer to *What do you call it when volume is decreased at bass beats?* is "pumping", first and foremost; it can be achieved with side chaining, but can also be achieved without it). I may be wrong and I've nothing to add to your excellent answer otherwise - +1.
Comment: Sometimes the effect isn't desired, in which case it's called "suckout."  You'll frequently hear this on the radio when they play "Crazy Train" by Ozzy.  The intro has a guitar lick then two bass/drum hits and a volume drop.


Create IDs dynamically to change class with jQuery

Question: I create a table dynamically with PHP giving each column an ID. What I want to do is change the class on ever ID after an ajax call triggered by a button click. The ajax part works fine, but on success, I am struggling on how to change the class on the selected row columns. After a button click fires off the ajax call, I want to change the class on the following  elements from class='active' to class='inactive'. Of course, there could be dozens of rows.
The HTML for the table looks like this:

    S-2016-000700
    48.0137.000
    SCHOELL PETER W
    S-2016-000700 DLQ DRINKING WATER FEE
    1
     $ 2.29
    <input type='text' id='fld4' class='postData' name='S-2016-000700|48.0137.000' value='300.00' />
    <input type='button' id='del4' value='X' />

And the jQuery script (Not optimized AT ALL) I'm trying to get working is:

My thought process is to get the ID of the button click (var pID) which gives me the 'index' the row...ie, The ID of the button clicked is 'del4' so i strip off the 'del' part to get (pID = 4). I now know the column IDs to change are: col14, col24, col34, etc.
I'm trying to create these as a variable (ie: var c1 = 'col1' + pID) for the column IDs to use in the qJuery .removeClass and .addClass functions.  Not sure if I can create a 'dynamic' variable id this way or not.
Can someone please give me some ideas on how I can accomplish this?  I'm probably doing it all wrong, or at least the hard way, but its the only way I can think of to accomplish it.
Answer: Could you pass the number to JS like this:
function strike(idNum){
        //Setting the classList to "inactive" removes the active class 'active'
        document.getElementById("col"+idNum).classList = "inactive";
    }


confused about equation Solve $x^2 – 50 = 0$

Question: I found the solution to above involved the following steps
$$\begin{align}
x^2-50=0&\implies x^2=50\\
&\implies\sqrt{x^2}=\sqrt{50}\\
&\implies x=\pm\sqrt{50}\\
&\implies x=\pm\sqrt{2\cdot 25}\\
&\implies x=\pm 5\sqrt{2}.
\end{align}$$
why is ±sqrt(2.25) in the steps, it obviously not the square root of 50 or I am missing something my math is still baby.
Comment: It's probably meant as $2\cdot 25=50$ and not $2.25=\frac{225}{100}$
Comment: In some countries, they use $.$ to indicate multiplication.
Comment: @Arthur I see now.
Answer: The dot here is used for multiplication and not as a decimal mark.Depending on context this could be because some sites which can't display math can't type $\cdot$ so they type . instead or because some countries simply use  . as multiplication


URL specific form for anonymous user

Question: I'd like to investigate if the following scenario is plausible somehow in Drupal 7:
The creation of a public form (node form/webform or whatever) with many instances so that each instance can be accessed only by a specific URL and can be filled by an anonymous user. The anonymous user should be able to fill in some of the fields, save his progress and come back later to fill some more using the same URL.
This scenario would allow the admin to create new instances, pre-fill some fields and send the form url by email to the final anonymous user.
The reason for all this is basically to avoid user registration and hold each user's submission to his unique URL form.
Comment: 2 main ideas: set 404 in .htaccess for all internal url,  generate a new route for those instances with encoded url.
Comment: @LePhleg `can be accessed only by a specific URL and can be filled by an anonymous user` Are these anonymous users anonymous outside of Drupal? as in you don't know them at all? or you know these people and will be sending them an e-mail with the specific url?
Comment: @NoSssweat The end users, I supposed, would be specific individuals with no Drupal account and yes, the site admin would send them their specific form URL after he has pre-filled some fields first.
Comment: Then it's possible, you just have to use the last url `/` part as an ID. Ex: example.com/filloutform/asdfjkl and `asdfjkl` will be the ID of the anonymous user for the DB.
Answer: Any instance of a Webform is a node so each anonymous user get his own submissionreference. So e.g the name of the form is harrypotter the user is getting harrypotter/1
Where 1 is the submission nr.
In rules you are able to get the submission id, get the content and redirect to the form again.
However you have to protect it again other users. Therefore you can use another Web form in front of it which ask for a pincode. You can redirect the user with the help of the pincode and rules to the correct submissionid

URL specific form for anonymous user


How do I get "insert or update" behaviour without using CONFLICT_REPLACE?

Question: My Android app is using an SQLite FTS3 table to provide full text search. I'm using insertWithOnConflict with CONFLICT_REPLACE to update my database, inserting a new row if need be or updating an existing row if it's present.
I was very surprised to find that my table ended up containing duplicate rows — but it looks like this is a documented "feature" of SQLite's FTS modules:
From the SQLite FTS3 and FTS4 Extensions page:

Datatypes and column constraints are specified along with each column.
  These are completely ignored by FTS and SQLite.

It's pretty easy to replicate the duplication from the command line:
sqlite> CREATE VIRTUAL TABLE test_duplicates USING FTS3
   ...> (id INTEGER PRIMARY KEY, name TEXT);
sqlite> INSERT INTO test_duplicates (id, name) VALUES (1, "George");
sqlite> INSERT INTO test_duplicates (id, name) VALUES (1, "George");
sqlite> INSERT OR REPLACE INTO test_duplicates (id, name) VALUES (1, "George");
sqlite> SELECT * FROM test_duplicates;
1|George
1|George
1|George
sqlite>

My question is: what's the best (simplest, most robust) way to replicate the behaviour of CONFLICT_REPLACE?
My ideas at the moment are either to (A) do a SELECT, then an UPDATE or INSERT based on the result or (B) blindly try DELETE the existing row (which may or may not be present) and then INSERT.
Answer: refering to the fts document, i found this paragraph:

... each FTS table has a "rowid" column. The rowid of an FTS table behaves in the same way as the rowid column of an ordinary SQLite table, except that the values stored in the rowid column of an FTS table remain unchanged if the database is rebuilt using the VACUUM command. For FTS tables, "docid" is allowed as an alias along with the usual "rowid", "oid" and "oid" identifiers. Attempting to insert or update a row with a docid value that already exists in the table is an error, just as it would be with an ordinary SQLite table.

which means you could use the built-in docid column as your primary key and let the fts table apply it's constraint on it.
Answer: I have the same problem. I found out that when we CREATE VIRTUAL TABLE test_duplicates USING FTS3 it will create a column named rowid and it's primary key of this table so that we just need using rowid instead id that will work correctly.
If you change:
INSERT INTO test_duplicates (id, name) VALUES (1, "George");
to:
INSERT INTO test_duplicates (rowid, id, name) VALUES (1, 1, "George");
INSERT INTO test_duplicates (rowid, id, name) VALUES (2, 2, "George");

Answer: i won't take credit for this. but i can't find the original link i got this from.
you do a query, then:
if (cursor.moveToFirst()) {
        // record exists
    } else {
        // record not found

Answer: I use the following query for INSERT OR REPLACE
INSERT OR REPLACE INTO test_duplicates (`rowid`, `name`) VALUES
((SELECT `rowid` FROM test_duplicates WHERE `name` = "George" LIMIT 1), "George")

And it works. But in this case, you can't supply the rowid. rowid will be handled by Database itself.