debian 6 preseeding keeps asking "Write the changes to disks and configure LVM?"

Question: I try to use an expert recipe configuring lvm for debian 6.0.5 netinstall. I don't want to be asked any questions, but it keeps asking me "Write the changes to disks and configure LVM?"
Here is part of my preseed.cfg:
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string lvm
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-auto/choose_recipe select boot-root
d-i partman-auto-lvm/new_vg_name string vg00
d-i partman-auto/expert_recipe string                         \
  boot-root ::                                            \
          128 50 128 ext2                                 \
                  $primary{ } $bootable{ }                \
                  method{ format } format{ }              \
                  use_filesystem{ } filesystem{ ext2 }    \
                  mountpoint{ /boot }                     \
          .                                               \
          10000 50 10000 ext4                             \
                  $defaultignore{ }                       \
                  $lvmok{ }                               \
                  lv_name{ root }                         \
                  method{ format }                        \
                  format{ }                               \
                  use_filesystem{ }                       \
                  filesystem{ ext4 }                      \
                  mountpoint{ / }                         \
         .                                                \
          2048 90 2048 linux-swap                         \
                  method{ swap } format{ }                \
          .                                               \
          10000 50 10000 ext4                             \
                  $defaultignore{ }                       \
                  $lvmok{ }                               \
                  lv_name{ var }                          \
                  method{ format }                        \
                  format{ }                               \
                  use_filesystem{ }                       \
                  filesystem{ ext4 }                      \
                  mountpoint{ /var }                      \
         .
d-i partman-lvm/confirm boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/confirm_nooverwrite boolean true
d-i partman/choose_partition select finish
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm boolean true
d-i partman/confirm_write_new_label boolean true
d-i partman/confirm_write_changes_to_disks_and_configure_lvm boolean true
d-i partman/choose_partition \
   select Finish partitioning and write changes to disk

This looks like a know problem, I am thinking of posts likes this, but the suggested solution seems not to work for me. Any hints?
Answer: At http://www.debian.org/releases/stable/i386/apbs04.html.en it says
d-i partman/choose_partition select finish

instead of
d-i partman/choose_partition \
  select Finish partitioning and write changes to disk

And also adds:
d-i partman-md/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true

Other hints:

Ubuntu Kickstart installation using LVM waits for input similar question for Ubuntu, solved with d-i partman-lvm/confirm_nooverwrite boolean true
http://ubuntuforums.org/showthread.php?p=9626883 says that "The preseed line that 'selects finish' needs to be in a certain order in your preseed, the example-preseed does not follow this."
https://bugs.launchpad.net/ubuntu/+source/partman-auto-raid/+bug/591909 relevant bug which again suggests d-i partman-md/confirm_nooverwrite boolean true plus more
Comment: More hints added.
Comment: Actually, it was a question of having the right options in the right order ...  thank you for leading me into the right direction. I'll post my working config in a seperate answer.
Answer: My 2 cents with Ubuntu 12.04 LTS variation. It seems to be necessary to also add
d-i partman/confirm_nooverwrite boolean true
d-i partman-md/confirm_nooverwrite boolean true
d-i partman-lvm/confirm_nooverwrite boolean true

Without the last two lines, the installation worked unattended on some VirtualBox VMs, while it didn't on others! The VMs were identically configured and – you guessed it! – running on the same machine. Both new and the ones with existing partitions were tried. Of course, I've tried everything else before I tried to re-run a "successfully tested" ISO.
Answer: Here is how I got my automatic partitioning working, thanks to S19N:
    ### Partitioning
    # Specify a disk to partition. The device name
    # can be given in either devfs or traditional non-devfs format.
    d-i partman-auto/disk string /dev/sda
    # In addition, you'll need to specify the method to use.
    # The presently available methods are: "regular", "lvm" and "crypto"
    d-i partman-auto/method string lvm

    # If one of the disks that are going to be automatically partitioned
    # contains an old LVM configuration, the user will normally receive a
    # warning. This can be preseeded away...
    d-i partman-auto/purge_lvm_from_device boolean true

    # http://cptyesterday.wordpress.com/2012/06/17/notes-on-using-expert_recipe-in-debianubuntu-preseed-files/
    d-i partman-auto/choose_recipe select boot-root
    d-i partman-auto-lvm/new_vg_name string vg00

    # You can put an entire recipe into the preconfiguration file in one
    # (logical) line.
    # This creates
    # a 128MB ext2 formatted partitin mounted at /boot
    # the rest will be used as a physical volume. Furthermore,
    # a 10GB ext4 formated LV mounted at /, and
    # a 10GB ext4 formated LV mounted at /var
    # will be created
    d-i partman-auto/expert_recipe string                         \
          boot-root ::                                            \
                  128 50 128 ext2                                 \
                          $primary{ } $bootable{ }                \
                          method{ format } format{ }              \
                          use_filesystem{ } filesystem{ ext2 }    \
                          mountpoint{ /boot }                     \
                  .                                               \
                  10000 50 10000 ext4                             \
                          $defaultignore{ }                       \
                          $lvmok{ }                               \
                          lv_name{ root }                         \
                          method{ format }                        \
                          format{ }                               \
                          use_filesystem{ }                       \
                          filesystem{ ext4 }                      \
                          mountpoint{ / }                         \
                 .                                                \
                  2048 90 2048 linux-swap                         \
                          method{ swap } format{ }                \
                  .                                               \
                  10000 50 10000 ext4                             \
                          $defaultignore{ }                       \
                          $lvmok{ }                               \
                          lv_name{ var }                          \
                          method{ format }                        \
                          format{ }                               \
                          use_filesystem{ }                       \
                          filesystem{ ext4 }                      \
                          mountpoint{ /var }                      \
                 .

    # Write the changes to disks and configure LVM?
    d-i partman/confirm boolean true
    d-i partman-lvm/confirm boolean true
    d-i partman-lvm/confirm_nooverwrite boolean true

    # http://ubuntuforums.org/showthread.php?p=9626883
    d-i partman-lvm/device_remove_lvm boolean true
    #d-i partman-lvm/confirm boolean true

    # This makes partman automatically partition without confirmation.
    d-i partman/choose_partition \
          select Finish partitioning and write changes to disk
    d-i partman/confirm_nooverwrite boolean true

Comment: `d-i partman-lvm/confirm_nooverwrite boolean true` is the only line that was missing from my preseed file, and adding it took care of the issue for me. Thanks.


An uncanny inequality with Gamma function

Question: Prove for $x>0$ that
$$ \frac{\Gamma^{\prime}(x+1)}{\Gamma(x+1)}>\log x$$
How to prove this inequality? thanks. This is a problem from Miklos Schweitzer Competition.
Answer: Let $~g(x)=\dfrac{\Gamma'(x+1)}{\Gamma(x+1)}-\log x$. Now we have
$$\eqalign{g'(x)&=-\frac{1}{x}+\sum_{k=1}^\infty\frac{1}{(x+k)^2}\cr
&<-\frac{1}{x}+\sum_{k=1}^\infty\int_{k-1}^k\frac{dt}{(x+t)^2}\cr
&=-\frac{1}{x}+\int_0^\infty\frac{dt}{(x+t)^2}=0
}$$
So $g$ is decreasing on $(0,+\infty)$. Moreover
$$g(n)=\sum_{k=1}^n\frac{1}{k}-\gamma-\log n$$
So $\lim_{n\to\infty}g(n)=0$ and consequently $\lim_{x\to\infty}g(x)=0$,and because $g$ is decreasing on $(0,+\infty)$ we conclude that $g >0$ on this interval and we are done.
Comment: This is a nice answer!
Answer: Since $\log(\Gamma(x))$ is convex, we have
$$
\frac{\log(\Gamma(x+1))-\log(\Gamma(x))}{(x+1)-x}\le\frac{\mathrm{d}}{\mathrm{d}x}\log(\Gamma(x+1))\le\frac{\log(\Gamma(x+2))-\log(\Gamma(x+1))}{(x+2)-(x+1)}
$$
which can be rewritten, using $\Gamma(x+1)=x\Gamma(x)$, as
$$
\log(x)\le\frac{\Gamma'(x+1)}{\Gamma(x+1)}\le\log(x+1)
$$
Answer: If you use Stirling approximation for $n!$, you then have $$\Gamma(1+x)\simeq \sqrt{2 \pi } e^{-x} x^{x+\frac{1}{2}}$$ Computing the derivative $$\Gamma'(1+x)\simeq \sqrt{\frac{\pi }{2}} e^{-x} x^{x-\frac{1}{2}} (2 x \log (x)+1)$$ so, after simplification, $$\frac{\Gamma^{\prime}(x+1)}{\Gamma(x+1)}=\frac{1}{2 x}+\log (x)$$ If, instead, you use Gosper  approximation $$\Gamma(1+x)\simeq \sqrt{\pi } e^{-x} x^x \sqrt{2 x+\frac{1}{3}}$$ you should arrive to $$\frac{\Gamma^{\prime}(x+1)}{\Gamma(x+1)}=\frac{3}{6 x+1}+\log (x)$$ If you use Burnside approximation $$\Gamma(1+x)\simeq \sqrt{2 \pi } e^{-x-\frac{1}{2}} \left(x+\frac{1}{2}\right)^{x+\frac{1}{2}}$$ you should arrive to $$\frac{\Gamma^{\prime}(x+1)}{\Gamma(x+1)}=\log \left(x+\frac{1}{2}\right)$$ If you use Ramanujan approximation $$\Gamma(1+x)\simeq \sqrt{\pi } e^{-x} x^x \sqrt[6]{8 x^3+4 x^2+x+\frac{1}{30}}$$ you should arrive to $$\frac{\Gamma^{\prime}(x+1)}{\Gamma(x+1)}=\frac{5 (8 x (3 x+1)+1)}{30 x \left(8 x^2+4 x+1\right)+1}+\log (x)$$
Comment: Nice simplification.
Comment: Note that all these are asymptotic formulas and non of them proves the inequality for $x>0$.
Comment: @OmranKouba. I agree partly with you since they are very good approximations. I thought that it was simpler than to prove that $\psi ^{(0)}(x+1) >\log (x)$


A drive is failing on Windows Server 2003. How should I back it up? How should I restore it?

Question: My drive is failing and I have a new one ready to go.
Can I just create a BKF file on a separate drive with the Backup utility, then shut down, swap in new drive for failing one, insert Windows Server 2003 disk, and restore the drive from the BKF file?
I'm just really concerned with the mention of needing to "connect a floppy drive".  I'm not interested in jumping through hoops involving floppy drives and hunting down ASR-related files in system directories.  This kind of thing should be simple.
Comment: Wow, take a deep breath. I'm glad to hear the data is RAIDed. I'm perfectly capable of answering this question, but don't have the time to do it properly at the moment. Short version - don't bother with the windows backup client. Take the server offline and use a disk cloning utility to clone the OS drive to the new one.
Comment: This sort of thing *is* simple if you set things up correctly (using RAID) in the first place. Sounds like you didn't do that, though.
Comment: Does this drive also have the system partition?
Comment: @gravyface.  Yes, it's the OS drive.  I ran "backup" and selected drive C and "System State", and it wrote a BKF file to my data drive (E).  I wasn't prompted for a floppy or anything, so I don't have one.  If I shut this down and replace the old drive, is the Windows Server 2003 CD/DVD going to b*tch about needing a floppy, or will it be able to restore the new drive from the BKF file?
Answer: Easiest option? Use a cloning utility such as Acronis or ShadowProtect to image directly onto the new drive.
For free, ShadowProtect Server will give you 30 days, install, clone, done.
*I'm not affiliated with either product, just someone who has used SP with enormous success in the past.
Comment: @EvanAnderson, If its a DC, it should be one of a pair or more, so a reinstall would be fine. However, if its an SMB, I would argue that it holds a lot of roles and an image may be whats best.
Comment: Disk imaging DCs is a bad idea. The OP doesn't give us enough information. If it's a DC he should back off the DC role first, then disk image it, and re-promote it. If it's the only DC then he should bring up another DC first, transfer off the FSMO roles, then proceed with backing off the DC role and disk imaging the server.
Comment: If it's a domain controller disk imaging isn't the best way to move forward.
Answer: If none of those other image solutions work, for whatever reason, you can try Clonezilla.  It's pretty stupid easy to use for the most part and I use it all the time for workstations at my current place of employment.
Answer: If you can take your server down for a few hours, I've had really good luck on workstations using Seagate's MaxBlast disk image http://www.seagate.com/ww/v/index.jsp?locale=en-US&name=MaxBlast_5&vgnextoid=7add8b9c4a8ff010VgnVCM100000dd04090aRCRD
Comment: I'm not paying for backup software.  The OS should provide a usable solution out of the box, after all, it's THE OPERATING SYSTEM, and it should be able to do something simple like save a drive image and restore it later.  Personally, I use Acronis True Image for drive imaging.
Comment: @Triynko - stop being rude, or we'll suspend you and then nobody will be trying to help you, gratefully accepted or not.
Comment: @Triynko. That's actually a free version of it. It does a sector by sector copy. You boot from an ISO.
Answer: Have you installed the new HDD, installed the same exact version of windows (same service packs and hotfixes) and ran the Backup and Restore Program?
Comment: @Triynko - unfortunately Windows doesn't work like that. @DanBig's answer is your best bet. Just use the software he suggested or some other cloning software to clone to a new drive.
Comment: You mean, put my Windows Server 2003 disc in... then instead of RESTORING MY BACKUP, I'm going to waste an hour pointlessly REINSTALLING THE OS from the disc, then immediately OVERWRITE it with the backup, from within the OS.  No.  I refuse to to do something so pointless.  I'd like to insert the OS install disc, and RESTORE MY BACKUP, in one simple step.
Comment: I find the "I'd like to insert the OS install disc, and RESTORE MY BACKUP, in one simple step." statement amusing. There are lot of things in life I'd like, too. >smile<


Wireshark can monitor mac, but can't see iphone on same network

Question: I have three devices on a wireless network.  One is a linux desktop, which is running wireshark, and I am trying to use the desktop to monitor the wireless traffic on my network.  The other two devices on the network are an iphone and a macbook pro.
I am able to use the desktop to monitor traffic going between the router and the macbook pro.  This leads be to believe that I successfully put the wireless interface on the desktop into promiscuous mode.  I am also able to see the traffic between the iphone if I make the iphone check what networks are available, but normal traffic doesn't appear at all.
I thought of a number of explanations, but none of them make sense.
a) The iphone 4s only has the ability to communicate on 802.11N wireless on 2.4 GHz, so perhaps this is why I can't see any of its traffic.  This, however, doesn't make sense, because if I was only looking for 5 GHz traffic, I wouldn't expect to be able to see any traffic originating from the iphone.
b) The iphone is using the cellular network.  This doesn't make sense either, since I have the iphone in airplane mode connected to the wireless network only.
c) The iphone is only using channels that I am not monitoring.  This doesn't make sense either, because if channel hopping really was the problem, why would the macbook pro's traffic be visible, but none the iphone's traffic not visible?  This would imply that the macbook pro channel hops, while the iphone doesn't, but that the iphone goes back to the channel I happen to be monitoring when it wants to check what networks there are.
Does anyone have any ideas as to why only certain traffic from the iphone is visible?
Comment: This question is off-topic as it isn't about programming.
Comment: Does the "check what networks are available" traffic from the iPhone consist only of 802.11 beacon frames?  Is this a "protected" network (using WEP or WPA/WPA2)?  If so, have you entered the network's password into Wireshark, and what happens if you turn the phone off, turn it back on again while Wireshark is running, and have it send and receive network traffic?
Comment: If I go to the iphone's list of wireless networks it generates a bunch of traffic that the desktop can see, but otherwise it doesn't ever generate any traffic that the desktop can see.
Comment: As I mentioned in b), the iphone isn't connected to the cellular network at all, so any data that is going to the phone has to be going through the wireless network, unless the iphone has the ability to bypass the airplane mode setting.
Comment: "If I go to the iphone's list of wireless networks it generates a bunch of traffic that the desktop can see"  What precise sort of traffic is that?
Comment: It is difficult to tell precisely what kind of traffic it is because I didn't decrypt it but if I were to hazard a guess I believe it has something to do with asking what the different available wireless networks are.
Comment: "It is difficult to tell precisely what kind of traffic it is because I didn't decrypt it" Wireshark should be doing that for you if you've specified the password for the network and, if it's a WPA/WPA2 network, you've captured the EAPOL handshake.  Which of those didn't happen?
Comment: I never told wireshark the password to the network.  I am not sure if wireshark saw the EAP handshake between the iphone and the router, because I can't tell if the traffic it picked up was the EAP handshake, or if that traffic it picked up was some other random thing.
Comment: "I never told wireshark the password to the network."  Then I suggest you do so (and turn the phone off and on again, to provoke it to re-associate with the network and send the EAPOL handshake), in order to tell what kind of traffic you're getting from the iPhone, so that we have more information and are more able to determine what the underlying problem is.
Answer: Well, if We take care about that when You monitorize with wireshark a network, It doesn't care about the channels It's working in, You should capture all traffic on the network.
If You didn't, I think in two possibilities:
a) Did You put a capture filter? This is the only way to select the traffic You sniff, and maybe It's the cause why You don't take all iPhone's traffic.
b) Maybe your iPhone is using the Cell Network just for some apps or services that doesn't work with WiFi, despite of his connection to a WiFi network too.
Comment: "Well, if We take care about that when You monitorize with wireshark a network, It doesn't care about the channels It's working in, You should capture all traffic on the network."  Actually, no - in monitor mode, an 802.11 adapter will only capture packets on the channel its radio is tuned to receive from (unless it has a special extremely-broadband radio that can listen on multiple channels, but I don't know of any that do).
Comment: But a network (usually) is working in just one channel, except if you have mutiple stations as Tx working in different channels to avoid colisions, doesn't it? So if you try to sniff a network traffic, you should only need to monitorize a channel. (Summarizing, I mean that usual networks will be working in just one channel, so you should capture all its traffic monitorizing that channel).
Comment: Any given 802.11 network will run on one channel; if you want to capture the traffic from that network, then your adapter will have to be set to that channel, so in that sense it *does* care about the channel.


How to search a particular character in a string in KornShell scripting?

Question: My KornShell (ksh) script receives command line arguments as input.
My task is to check if those arguments contains abc in it and print only those arguments which contain abc in it.
For Example:-
./tree.sh rabc try qwerty

Output should be ::
rabc

This is what I have tried:
var=$*
z=grep "abc" var
echo $z

Any insight regarding this?
Comment: It would help if you also show what you've tried so far. Others can then help you understand what went wrong. Simply providing a requirement and expecting others to give you the full solution is generally frowned upon on [so].
Comment: What went wrong with what you tried? How have you tried to fix it?
Answer: Firstly, you need to be able to loop over the arguments. If we take a look at man ksh, we find the below:

for vname [ in word ... ] ;do list ;done

Each time a for command is executed, vname is set to the next word taken from the in word list. If in word  ... is  omitted, then  the for command executes the do list once for each positional parameter that is set starting from 1 (see Parameter Expansion below).  Execution ends when there are no more words in the list.

So to get the loop, we'll need something like this:
for arg
do
    <stuff>
done

At the point we're running <stuff>, $arg will be one of the parameters passed in. Note you need the $ part at the front; ksh requires this to know to use the value stored in the variable, not just the variable name as-is.
Next, we need to work out whether $arg contains abc. We'll use grep, but remember grep looks through files you give it, or through whatever's passed in on it's standard input ("stdin"). The grep "abc" var you've given would have grep trying to look for abc in a file called var.
We need to get $arg into grep's stdin. We'll use echo, which puts things onto standard output ("stdout"), and a "pipe", which joins one command's stdin to another's stdout:
echo "$arg" | grep abc

The above will put whatever's in $arg onto stdin, then grep will print it only if it contains abc.
Thus the complete script is as below:
#!/bin/ksh
for arg
do
    echo "$arg" | grep abc
done

This won't properly handle the case where arguments contain newlines; I'll leave that as a future problem for you to resolve yourself.
Comment: can i store the value returned by echo "$arg" | grep abc in a variable ?? Because when i do var=echo "$arg" | grep abc, Nothing is displayed in $var.. please help
Comment: @user1466466: You need to use "command substitution": `var=$(echo "$arg" | grep abc)`. Without that, ksh can't tell between you wanting to store the string "echo …" and you wanting to store the output of running that string as a command.


How to retrieve a HTML tag from a column

Question: I have an SQL table which has a column that includes some HTML/XML tag. Here is an example:
<root><Physicians><name>John Helsinki, MD</name>
<picture></picture>
<gender>M</gender>
<specialty>OPT</specialty>
<specialty2></specialty2>
<specialty3></specialty3>
<additional_specialty></additional_specialty>
</Physicians>
</root>

How can I extract the  tag that is in between <picture></picture>?
I know I can use the LIKE keyword in SQL but I am not sure how to proceed...
Comment: If you want to do this with SQL, which database product are you using?
Answer: You can use XPath taking advantage of the columns type - XML
declare @thing XML
set @thing = '<root><Physicians><name>John Helsinki, MD</name>
<picture></picture>
<gender>M</gender>
<specialty>OPT</specialty>
<specialty2></specialty2>
<specialty3></specialty3>
<additional_specialty></additional_specialty>
</Physicians>
</root>'

SELECT @thing.query('/root/Physicians/picture/img')

An alternative way of doing it via a table:
DECLARE @XmlTable TABLE (ID INT NOT NULL, XmlData XML)
INSERT INTO @XmlTable
        (ID, XmlData)
VALUES
        (1, '<root><Physicians><name>John Helsinki, MD</name>
<picture></picture>
<gender>M</gender>
<specialty>OPT</specialty>
<specialty2></specialty2>
<specialty3></specialty3>
<additional_specialty></additional_specialty>
</Physicians>
</root>')

select XmlData.query('/root/Physicians/picture/img') from @XmlTable

This takes advantage of the query method available on any XML variable type thus in this context:
select [column].query('/root/Physicians/picture/img') from [table]

Comment: @SiKni8 Create a new table and set the column as NVARCHAR(MAX) and then import the xml data into the new table. Then you do a cast - SELECT CAST(newNvarcharColumn AS XML) which means you can update a newly created XML column or you can say CAST(newNvarcharColumn AS XML).query('etc...
Comment: The `@thing` is dynamic and never for the same person.
Comment: That works great. Can I insert a SELECT statement to get the @thing instead of hard coding the string value?
Comment: The column will constantly change so hard coding it, even in a table is not an option for me unfortunately. I was trying something like this: `set @thing = (SELECT [column] FROM [database].[dbo].[table])` but it was giving me an error.
Comment: I have it like this: `declare @thing XML
set @thing = SELECT [content_html].query('/root/Physicians/picture/img') from [Database].[dbo].[table]
SELECT @thing.query('/root/Physicians/picture/img')` but I get an error: `Incorrect syntax near the keyword 'SELECT'.`
Comment: @SiKni8 You don't need the intermediate variable to get the result you can just run: SELECT [content_html].query('/root/Physicians/picture/img')
from [Database].[dbo].[table]
Comment: I figured so I went ahead and ran it and I get this error: `Cannot find either column "content_html" or the user-defined function or aggregate "content_html.query", or the name is ambiguous.`
Comment: @SiKni8 What is the data type of your column - content-html? The type must be set to XML in the table designer
Comment: It is `ntext` data type. I have like 200 rows in my table and want to display all 200 rows with just the `` tag stripped from the column `content_html`
Comment: It is a sensitive table. I am wondering If I can copy the column to a temporary table and assign it as XML and then use it?
Comment: If there is a way to copy the column to an new table with the XML data type and then query that using a Stored Procedure?
Comment: Took your idea and used the existing query to get it to work :)... Here is my final query: `SELECT CAST([content_html] AS XML).query('/root/Physicians/picture/img') FROM [dbase].[dbo].[content] WHERE [folder_id] = '188'`
Comment: I will but have to wait 11 minutes. One concern (I can ask a new question if need be) is what if there are more than one image tag and I want to insert each tag in it's own row?


OpenGL loading multiple textures - not working

Question: I have successfully loaded a single texture using the gltLoadTGA function that I have. Now that I am trying to load multiple textures it's not working. This is the texturing part of my setup function:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glGenTextures(numTextures, textures);

// Load the first texture
glBindTexture(GL_TEXTURE_2D, textures[SHAPE_TEX]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytes = gltLoadTGA("TexasFlag.tga", &iWidth, &iHeight, &iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);

// Load the "A"
glBindTexture(GL_TEXTURE_2D, textures[A_TEX]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytesA = gltLoadTGA("letter a.tga", &iWidth, &iHeight, &iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytesA);
free(pBytesA);

// Load the "B"
glBindTexture(GL_TEXTURE_2D, textures[B_TEX]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytesB = gltLoadTGA("letter b.tga", &iWidth, &iHeight, &iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytesB);
free(pBytesB);

// Load the "C"
glBindTexture(GL_TEXTURE_2D, textures[C_TEX]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytesC = gltLoadTGA("letter c.tga", &iWidth, &iHeight, &iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytesC);
free(pBytesC);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_2D);

And my draw function is basically:
    glBindTexture(GL_TEXTURE_2D, SHAPE_TEX);
    // draw a lot...
But no texture is showing up at all. Whats wrong?
**By the way this has to be in C only, not C++
Answer: When you call glTexParameteri (man page), it only applies to the current texture.  You will have to call it separately for each texture whose parameters you want to change, after you bind the texture.  Failing to set the minification / magnification filter can make it look like texture loading failed.
You may also wish to call glGetError after attempting to load a texture, to see if it failed.
Comment: Ironically the `glPixelStorei` settings the OS sets for each texture upload are *not* bound to the texture object.
Comment: @datenwolf: When you start to think of OpenGL with a client-server model, those distinctions actually make a lot of sense.  For example, arrays (the OpenGL 1.x variety) are all client-side so they are managed with `glEnableClientState` and the like.  Basically anything that directly touches program memory is going to pass through the client, and this includes texture packing and unpacking.  The client packs or unpacks the pixels to/from a myriad of formats that can be supplied by the user, and the server only has to work with packed data.  So the `glPixelStore` behavior should be unsurprising.
Comment: Thanks, I'm well familiar with OpenGL's client server model, and use it regularily for OpenGL over GLX over TCP.
Comment: @datenwolf: That's a different concept.  I'm talking about the client/server model inside OpenGL itself, even when you are not using the network.  Parts of the OpenGL API manipulate client state, such as `glPixelStore`, which notes in the documentation that "pixel storage modes are client state".  No TCP, no GLX necessary.  The client/server model explains why there are separate functions `glPushAttrib` and `glPushClientAttrib`.
Comment: Where do you think the OpenGL client/server model stems from? Hint: SGI, Irix (= a Unix), X11 (a server and clients). Also the concept of Display Lists is a direct influence of X11 on OpenGL.


Comparison of waiting times to geometric distribution

Question: I am analysing data taken from observing about one million people over 24 months.  For each person, each month is classified as a "success" or a "failure".  I am specifically interested in the distribution of waiting times (= the lengths of runs of failures) between successes and in comparing this distribution to the distribution that would arise if success was a Bernoulli process - the Geometric distribution.
My approach has been to firstly to identify three subsets of people in my original group - those with the 3 total successes in 24 months, those with 8 and those with 12.  The rationale is that only groups with a single success probability throughout can be compared to a geometric distribution, which is itself parameterised by a single success probability.  The three specific values 3, 8 and 12 total successes out of 24 I just selected pretty arbitrarily to reflect the range of interest.
Let me use the group of people with 3 out of 24 successes as an example.  Just using total counts, we can estimate the success probability for this group as
$$ \hat{p} = \frac{3}{24} = 0.125 $$
I then proceed to graph the actual waiting times histogram for the 3 out of 24 group against the Geometric distribution with parameter $p=0.125$ and find that e.g. the observed frequency of waiting time = 0 months is substantially higher than frequency of 0 months given by the Geometric distribution and I interpret this as meaning that, for the 3 out of 24 group, two successes in a row occur more often than they would if success was a Bernoulli process.
However, I can also compare to a different Geometric distribution where I estimate its parameter $p$ using the method of moments, or by equating the mean waiting time observed in the sample of 3 out of 24, $\mu$, to the expected waiting time for the Geometric distribution as follows
$$ \frac{1-\hat{p}}{\hat{p}} = \mu$$
This gives me an estimate of $\hat{p} \approx 0.169$ which is very different to $\hat{p}=0.125$.  Visually, this distribution fits the 3 out of 24 waiting time data a lot better but the observed data still deviate clearly for being Geometrically distributed, the deviations just show up in different places now.  I could do a statistical test of the fit, but because of my very large sample size I have no doubt it will tell me that the data differ from the Geometric distribution at any significance level I like.
I have favoured the first method of finding $\hat{p}$ because

I don't want to fit a Geometric distribution to my data.  I know the data is not quite geometrically distributed and I am specifically interested in the systematic differences (as opposed to measurement error) between it and the appropriate Geometric distribution.
Since the data isn't Geometrically distributed, this makes me think that the method of moments will be "thrown off" and will not give me the parameter of the Geometric distribution that I should use as a baseline for comparison, but rather of another Geometric distribution that happens to fit the data better.

Is what I'm doing legitimate and how should I determine $\hat{p}$?
(I can provide an R example if I haven't been precise enough in expressing the problem as a theory problem.)
Comment: Why not compare to a poisson distrubtion for waiting times?
Answer: I believe I have answered my own question by figuring out (thanks to a colleague) that what I was doing was not legitimate after all.  The distribution of waiting times in a set that is determined in advance to consist of 24 Bernoulli trials, 3 of which are successful, is not given by the Geometric distribution.  Instead it is given by a similar but different distribution that is supported only on the finite set 0...21.  I haven't been able to solve the combinatorics to write down this distribution, but I was able to determine it for 24 trials using computational brute force (I generated every combination of 3 successes out of 24 and then just counted waiting time frequencies).  I think the Geometric distribution, which is supported on all of $\mathbb N$, is obtained in the limit as the number of trials goes to infinity.


jquery not working in asp.net mvc after publishing to server

Question: I've built an mvc application which contains some jquery code.  When I run the app from my ide, everything works perfectly.  When I publish to the server and open the page, the jquery does not work.  I get object expected errors.
Could this be due to my file mappings?  here is a sample of my mapping in the app -

I published the app to iis7 successfully, but the jquery is broken.  I did publish to an application within an existing web site.
Any thoughts?
Answer: You may be experiencing problems with your relative path.
You can try this, which is a path from the application root:

Or this C# solution:

Comment: Thanks.  Is either one of these solutions preferred over the other, or just use whatever one works?
Comment: Won't the second option also disable jQuery Intellisense for any JavaScript code on the page?
Comment: Well... yes, but his problem is a deployment not developement.


How to store a zip file in document directory?

Question: I am working on a webservice based app, in which after calling a web service method the response is zip file and I have to store this zip file into a document directory folder. Please explain me how to do it. Thank you in advance.
Answer: You can store zip in document directory using bellow code:-
<code> NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                           NSString *documentDirectory = [path objectAtIndex:0];
                           NSString *setPath = [documentDirectory stringByAppendingPathComponent:filname.zip];
                           NSData *data = .... // your Zip data
                           [data writeToFile:setPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
</code>


SELECT statement for getting counts in table

Question: I have a table "downloads" with the following information:
objKey     CustNum    UserId    DownloadDate
51048879   123        7654       2014-09-01
51048879   234        32434      2014-09-02
51048879   123        7654       2014-09-01
51047379   2132       3456       2014-08-20
51048879   2132       9786       2014-09-01
51047379   123        7654       2014-09-02

I want to get counts by downloadDate of how many products, customers, and users downloaded. So I would want:
DownloadDate      Products       Customers    Users
2014-09-01         1              2            2
2014-09-02         2              2            2
2014-08-20         1              1            1

Can someone help me with the SELECT statement? Each time I have tried I get incorrect numbers. I would think this should be easier than what I tried.
Comment: They key here is you can use distinct within a count to get unique values.
Answer: select downloaddate,
       count(distinct objkey) as products,
       count(distinct custnum) as customers,
       count(distinct userid) as users
from downloads
group by downloaddate

Answer: You want count(distinct).  I think this does what you want:
select DownloadDate, count(distinct objKey) as Products,
       count(distinct CustNum) as Customers,
       count(distinct UserId) as Users
from table t
group by DownloadDate
order by DownloadDate;

Answer: Something like this might do it:
select DownloadDate, count(disinct objKey) as products, count(distinct CustNum) as customers, count(distinct UserId) as users
from downloads
group by DownloadDate
order by DownloadDate

Comment: I have another Select that is a little similar. The file has custNumb, projNum, and a status in each record. There can be multiple records per customer.  I would like to get custNum, count of status = 'Live', count of status = 'Identification', count of total projects. Some counts can be zero. I tried a SELECT similar to the ones provided above with the distinct but they didn't produce the right results. Any suggestions?
Comment: You need to study a little SQL.  You can't get this done by asking here.


Mapping boundaries in SAGE

Question: I'm trying to find the fundamental domain of congruence subgroups in SAGE by mapping the boundaries of the fundamental domain of $\mathrm{SL}_2(\mathbb{Z})$ by certain matrices. How can I transform the boundary, say $x=-\frac{1}{2}$, $y \ge \frac{\sqrt{3}}{2}$?
Answer: I'd make use of the fact that every Moebius transformation from $\operatorname{SL}(2,\mathbb{R})$ maps the set of vertical line segments and circular arcs around centers that lie on the real axis into itself. This essentially translates the problem to mapping the vertices of the standard fundamental domain, including $\mathrm{i}\infty$, and finding the arc or vertical line segment through each given pair of (mapped) vertices.
With less than 70 lines of asymptote code, I have thus implemented a drawing procedure map_fundamental_region(a,b,c,d) taking the transformation parameters. Some calls to that routine (plus a bit of decoration) then resulted in images like this:

Mapping boundaries in SAGE


Proving that three numbers are in A.P.

Question: A number $a$ is the Arithmetic Mean(A.M.) between $b$ and $c$, $b$ is the Geometric Mean(G.M.) between $a$ and $c$. Prove that $$\frac{1}{a}, \frac{1}{c} and \frac{1}{b}$$ are in Arithmetic Progressions(A.P.).
I haven't been able to do much, but this is it :
As, $a$ is the A.M. between $b$ and $c$,
$$a = \frac{b+c}{2}$$ or, $$2a = b+c$$
And, $b$ is the G.M. between $a$ and $c$, so, $$b^2 = ac$$ or, $$b = \sqrt{ac}$$How do i proceed next?
Comment: Having you tried proving instead from $\frac{1}{c} - \frac{1}{a} = \frac{1}{b} - \frac{1}{c}$?
Answer: Write $b = 2a - c$ so that $b^2 = (2a - c)^2$.  Then with the additional condition $b^2 = ac$, eliminate $b$ and obtain an equation in $a, c$.  Factor this equation and consider two cases, one of which is $a = c$.
Comment: This only works if you think that $-2$ is the geometric mean of $1$ and $4$, or that $2$ is the geometric mean of $-1$ and $-4$.  I would not accept this, and the reciprocals are then not in arithmetic progression
Comment: wait, there is another case except $a=b=c$? I overlooked something then maybe.
Comment: I only hinted at considering the nontrivial case; I intended the OP to figure out the issues that arise from considering this case.
Comment: I deleted my comment solving the equation.
Comment: No, it's fine.  You haven't given away everything.  One just has to be careful about the notion of geometric mean.
Answer: As $a$ is the Arithmetic mean, it lies between $b$ and $c$. But, as $b$ is the geometric mean it will lie between $a$ and $c$. This can only mean that $a=b$. And because $a=\frac{b+c}{2}$,  $a=b=c$. Clearly,$\frac{1}{a}= \frac{1}{c} = \frac{1}{b}$ and therefore, trivially, in AP.
Comment: I think that the non-trivial case is a spurious solution resulting from squaring
Comment: @Henry oh right. I didn't notice. I am doing a rollback.
Comment: $a=\frac c 4$ yields $b<0$
Comment: @alex yeah, it was a spurious solution. I undid my edit.
Comment: @Sabyasachi Sorry, I was too quick...
Comment: @alex not a big deal, it can be hard to keep track of edits.

Proving that three numbers are in A.P.


plot value labels along with bars

Question:
Possible Duplicate:
Showing data values on stacked bar chart in ggplot2

I have the following ggplot

dt <- structure(list(Age.group = structure(1:5, .Label = c("0-29 yrs", "30-49 yrs", "50-64 yrs", "65-79 yrs", "80+ years"), class = "factor"),     Rx.Brufen = c(4.91767279891635, 24.849329416471, 39.384529665324,     42.0512030516413, 45.0282816501013), Brufen.C.I = c(9.49857407873833,     10.4942035949849, 11.0935906177108, 16.7322917304551, 18.5232702433842   ), Brufen.declined = c(1.25219908256281, 1.1156980249761,     1.18510539437499, 0.73845826559561, 1.00121613129538)), .Names = c("Age.group", "Rx.Brufen", "Brufen.C.I", "Brufen.declined"), row.names = c(NA, -5L), class = "data.frame")

dt.m <- melt(dt, 1)

colnames(dt.m)[2] <- "Rx"
colnames(dt.m)[3] <- "Proportion"
ggplot(dt.m, aes(x=Age.group,y=Proportion, fill=Rx)) +
    geom_bar() +
    labs(x="Age Group", y="Proportion %",fill = "") +
    theme(legend.position=c(.5, .9), legend.direction = "horizontal" ) +
    ylim(c(0,100))

I would like to plot the actual values, as percentages (inside the bars for the green and red bars,  and just above for the blue ones, since they won't fit inside). Can someone advise how to achieve this ?
Comment: Are you sure about function theme()?
Comment: @AliSharifi , sorry, I didn't understand your question. Sure about what ? theme() is positioning the legend I think........?
Answer: p <-  ggplot(dt.m, aes(x=Age.group,y=Proportion, fill=Rx)) +
geom_bar() +
labs(x="Age Group", y="Proportion %",fill = "") +
theme(legend.position=c(.5, .9), legend.direction = "horizontal" ) +
ylim(c(0,100))

library(plyr)
dt.m.text <- ddply(dt.m, .variables="Age.group", transform, text.y=cumsum(Proportion))
p+geom_text(data=dt.m.text, aes(x = Age.group, y = text.y, label = round(Proportion)))
#close

dt.m.text <- ddply(dt.m, .variables="Age.group", transform, text.y = cumsum(Proportion)-1/2*Proportion)
p+geom_text(data=dt.m.text, aes(x=Age.group,y=text.y, label=round(Proportion)))

#manually increase Brufen.declined
up <-  dt.m.text[dt.m.text$Rx=="Brufen.declined","text.y"]
dt.m.text[dt.m.text$Rx=="Brufen.declined","text.y"] <- up + 1
p+geom_text(data=dt.m.text, aes(x=Age.group,y=text.y, label=round(Proportion)))

Answer: Add this one after you have defined your data dt to find the label positions - as you need:
p=dt
p[,4]=p[,4]+p[,3]+p[,2]
p[,3]=p[,3]/2+p[,2]
p[,2]=p[,2]/2
p.m = melt(p)
colnames(p.m)[2:3]=c("Rx","Proportion")

And add this part to your ggplot command:
+ geom_text(aes(Age.group, `Proportion`, label = sprintf("%2.1f", `Proportion`)), data=p.m)

plot value labels along with bars


Rails :text_area with tool box

Question: I want to design a text_area with toolbox in rails. Is there any way or gem to do that?
Comment: @pojaAgarwal You are not having a problem - you are asking for someone to do the job for you, because you are not capable to do it yourself. Provide what you have tried and someone might help you with a specific problem.
Comment: down voters please comment the reason here.
Answer: I achieved that through tinymce-rails gem.

Rails :text_area with tool box


Cannot drop index from MySQL INNODB table with foreign keys/references

Question: I'm about to drop an index from a mySQL INNODB table. There are references defined already. When I try to alter it, it says:
#1025 - Error on rename of 'X/#sql-2a5f_219828' to 'X' (errno: 150)

Which at first seems logical, since there are relations, it can't be renamed. But even if I disable foreign key checking:
SET foreign_key_checks = 0;
ALTER TABLE flyers DROP INDEX Index_5, ROW_FORMAT = DYNAMIC;
I get the same! I don't want to drop ALL foreign key definitions, drop that index, and define them again! Another solution?
Comment: http://stackoverflow.com/questions/160233/what-does-mysql-error-1025-hy000-error-on-rename-of-foo-errorno-150-mea
Answer: Create a new index before dropping the old one.
Comment: what has a new index has to do with the old one?
Comment: My answer may be incorrect if it does not help for you. I recently faced a situation where I had a foreign key referring to a column in another table and wanted to change/re-create the index for that column. I was not able to get rid of the old index, but after I first created a new index (basically a duplicate of the original index) I was able to drop the old one. Maybe the error message was different though and this is not related... Sorry about the noise.
Answer: the problem was there was already an index on the foreign key field :) and I didnt know that foreign key is also an index. Anyway I ripped all my hair out in the end, I had to drop all indexes to get rid of it. I will never use innoDB again


Como fazer um formulário HTML ficar responsivo

Question: Eu tenho um formulário HTML e CSS que está perfeito no meu site, porem quando tento abri-lo em um dispositivo móvel (celular ou tablet) fica totalmente distorcido. Estou utilizando o Bootstrap como framework CSS.
Meu código:

.tudo-border-box {
      box-sizing: border-box;
  }

  .header-urna {
   border: solid;
      background-color: #565656;
      padding: 30px;
      text-align: center;
      font-size: 35px;
      color: white;
  }

  .nav-urna {
      float: right;
      width: 30%;
      border: solid;
      height: 400px; /* only for demonstration, should be removed */
      background: #565656;
      color: white;
      padding: 20px;
  }

  .nav-urna ul {
      list-style-type: none;
      padding: 0;
  }

  .article-urna {
      float: left;
      padding: 20px;
      /* border: solid; */
      width: 70%;
      background-color: #f1f1f1;
      height: 400px; /* only for demonstration, should be removed */
  }

  .section-urna:after {
      content: "";
      display: table;
      clear: both;
  }

  .footer-urna {
   border: solid;
      background-color: #565656;
      padding: 10px;
      text-align: center;
      color: white;
  }

  @media (max-width: 600px) {
      .nav-urna, .article-urna {
          width: 100%;
          height: auto;
      }
  }

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

Urna Digital

Digite o numero do seu candidato

       <button type="button" id="btn1" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">1</button>

       <button type="button"  id="btn2" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">2</button>

       <button type="button" id="btn3"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">3</button>

       <button type="button"  id="btn4" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">4</button>

       <button type="button"  id="btn5" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">5</button>

       <button type="button" id="btn6"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">6</button>

       <button type="button" id="btn7"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">7</button>

       <button type="button" id="btn8"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">8</button>

       <button type="button"  id="btn9" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">9</button>

       <button type="button"  id="btn0" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">0</button>

       <button type="button" class="btn btn-default "  id="btnBranco" >BRANCO</button>

       <button type="button" class="btn btn-warning "  id="btnCorrige"  style="background-color: #fb3f14; border-color: #fb3f14;">CORRIGE</button>

       <button type="button" class="btn btn-success "  id="btnConfirma" >CONFIRMA</button>

       Esse simulador funciona da mesma forma que uma urna eletronica,
        você digita o numero de seu candidato a presidencia e pressionar Confirma.
        Caso digitou o numero errado clique em Corrige.
        Caso desejar votar em branco, clique em Branco.

Comment: Cara, tu pode fazer o seguinte... Usar bootstrap, feito responderam, mas também tu pode usar ao invés de pixels com medida tu pode usar medidas relativas, feito: % vw, vh... Da uma olhada
http://desenvolvimentoparaweb.com/css/unidades-css-rem-vh-vw-vmin-vmax-ex-ch/
Answer: Amigo, a tag col-sm é para dispositivos moveis ate ai tudo bem, mas você cria seu html totalmente encima dela, você deveria usar as tags de responsividade para cada tamanho de tela, por exemplo, quando o dispositivo é desktop ele ira abrir a tela toda, quando ele estiver em um telefone, usar a área de input embaixo ou encima da tela, no caso seu código somente usa um tamanho único pra todas as telas.
Recomendo ler este artigo.
Comment: valeu pelas dicas mano!!
Comment: Que isso cara, estamos todos aqui pra isso :D
Answer: Cara basicamente vc tem que trocar a col- dos btns de col-md-4 para col-xs-4 pois usando XS vc garante que as colunas vão continuar divididas da forma correta até em telas pequenas, sem colocar um btn em cada linha como está acontecendo no seu código.
Veja o exemplo abaixo para visualizar como fica.

 .tudo-border-box {
      box-sizing: border-box;
  }

  .header-urna {
   border: solid;
      background-color: #565656;
      padding: 30px;
      text-align: center;
      font-size: 35px;
      color: white;
  }

  .nav-urna {
      float: right;
      width: 30%;
      border: solid;
      height: 400px; /* only for demonstration, should be removed */
      background: #565656;
      color: white;
      padding: 20px;
  }

  .nav-urna ul {
      list-style-type: none;
      padding: 0;
  }

  .article-urna {
      float: left;
      padding: 20px;
      /* border: solid; */
      width: 70%;
      background-color: #f1f1f1;
      height: 400px; /* only for demonstration, should be removed */
  }

  .section-urna:after {
      content: "";
      display: table;
      clear: both;
  }

  .footer-urna {
   border: solid;
      background-color: #565656;
      padding: 10px;
      text-align: center;
      color: white;
  }

  @media (max-width: 600px) {
      .nav-urna, .article-urna {
          width: 100%;
          height: auto;
      }
  }
<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />

Urna Digital

Digite o numero do seu candidato

          <button type="button" id="btn1" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">1</button>

          <button type="button"  id="btn2" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">2</button>

          <button type="button" id="btn3"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">3</button>

          <button type="button"  id="btn4" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">4</button>

          <button type="button"  id="btn5" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">5</button>

          <button type="button" id="btn6"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">6</button>

          <button type="button" id="btn7"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">7</button>

          <button type="button" id="btn8"  class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">8</button>

          <button type="button"  id="btn9" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">9</button>

          <button type="button"  id="btn0" class="btn btn-primary btn-lg" style=" background-color: black; border-color: black;">0</button>

          <button type="button" class="btn btn-default "  id="btnBranco" >BRANCO</button>

          <button type="button" class="btn btn-warning "  id="btnCorrige"  style="background-color: #fb3f14; border-color: #fb3f14;">CORRIGE</button>

          <button type="button" class="btn btn-success "  id="btnConfirma" >CONFIRMA</button>

        Esse simulador funciona da mesma forma que uma urna eletronica,
         você digita o numero de seu candidato a presidencia e pressionar Confirma.
         Caso digitou o numero errado clique em Corrige.
         Caso desejar votar em branco, clique em Branco.

OBS: Independente disso vc ainda precisa fazer uns ajustes de CSS tipo no btn-group
Comment: @sergioBertolazzo tranquilo jovem tmj! Sucesso com o projeto ai
Comment: Valeu ai pela ajuda mano, era exatamente oque precisava deixar os botões lado a lado e funcionou perfeitamente!


Deriving a lower bound of $2^k$ for the size of the sample space $\Omega$

Question: I am trying to derive a lower bound of $2^k$ for the size of the sample space $\Omega$ given that in the probability space there exists $k$ non-trivial independent events. I am not looking for a solution per se, but rather a hint.
I suppose I don't fully understand the connection between the size of an event and the surrounding sample space. Namely I do understand that the fact that the events $E_1, \dots, E_k$ are non trivial mean that $\mathrm{Pr}(E_i) \in (0, 1)$ or equivalently that each event contains at least one element, but no event contain all elements of the space. But how do you go about deriving the lower bound from this? To me $2^k$ speaks that some element has a binary choice to be or not to be included in all of the $k$ events in the probability space. $2^k$ could also mean the number of possible subsets for $k$ elements. However I don't see how either of these reasoning strategies yields anything useful, as they don't take into account the relationships between the events $E_1, \dots, E_k$.
Comment: If there are $k$ mutually disjoint events covering the space, each with positive probability, then clearly you can take the power set of these as a subset of the sigma-algebra, though one element of the power set (the empty event) will have probability $0$ and one (the universal event) will have probability $1$, so that would suggest to me $2^n-2$ for your lower bound
Comment: @Henry I just noticed a deadly typo in my text: The events $E_1,\dots,E_k$ should be independent. So the exact form in my material is that given that there are $k$ non-trivial independent events, show that the sample space has a size of at least $2^k$.
Answer: For $\alpha\in \{0,1\}^k$, consider the event $C_{\alpha}\equiv \bigcap_{i=1}^kA_i$, where $A_i=E_i$ if $\alpha_i=0$ and $A_i=E_i^c$ if $\alpha_i=1$. Now, $\mathcal{C}\equiv\{C_{\alpha}:\alpha\in\{0,1\}^k\}$ is a collection of disjoint (non-empty) events, and $|\mathcal{C}|=2^k$.
Comment: The trick is to consider all possible intersections of these events and their complements.
Comment: No because for $\alpha_1\ne \alpha_2$, $C_{\alpha_1}\cap C_{\alpha_2}\subset E_i\cap E_i^c=\emptyset$ for some $1\le i\le k$.
Comment: So the trick was to model the events in the sample space as binary strings of length $k$?
Comment: If you refer by an event to $C_\alpha$, then why are the elements of $\mathcal{C}$ disjoint? Isn't $C_{\alpha_1} \cap C_{\alpha_2} \neq \varnothing$ if some $A_i = 1$ in both $C_{\alpha_1}$ and $C_{\alpha_2}$?


Javascript and jQuery: iterate through an array but wait for animations to finish

Question: I have a simple example with several boxes to move across the screen. Each box shouldn't move until the previous one completes. I have a working solution using .shift() but I should be able to iterate through this using a for-loop and $.each. Anyone know how to get the for and $.each to work?
fiddle here the shift button works the way I would like it to.
Thanks.
JS:
boxes = [
  ['.box0', 'animate', [ {left: '200px' }, 1000 ] ],
  ['.box1', 'animate', [ {left: '200px' }, 1000 ] ],
  ['.box2', 'animate', [ {left: '200px' }, 1000 ] ],
  ['.box3', 'animate', [ {left: '200px' }, 1000 ] ],
  ['.box4', 'animate', [ {left: '200px' }, 1000 ] ],
  ['div', 'animate', [ {left: '0px' }, 1000 ] ]
];
$('.eachMethod').click(animEach);
$('.ifMethod').click(animFor);
$('.shiftMethod').click(animShift);
function animEach(){
  $.each(boxes, function(){
    $.fn[this[1]].apply($(this[0]), this[2]).promise().done();
  });
};
function animFor(){
  for (i=0; i < boxes.length; i++) {
    b=boxes[i];
    $.fn[b[1]].apply($(b[0]), b[2]).promise().done();
  }
};
function animShift(){
  b = boxes.shift();
  if (b) {
    $.fn[b[1]].apply($(b[0]), b[2]).promise().done(animShift);
  }
};

HTML:

<button class='eachMethod'>$.each</button>

<button class='ifMethod'>if</button>

<button class='shiftMethod'>shift</button>

CSS:
div{
 clear: both;
 background-color: green;
 width: 40px;
 height: 40px;
 Position: relative;
}
ul li {
  float: left;
}

Answer: animate() is asynchronous, so the loops will complete in a few milliseconds invoking the animation on each element virtually simultaneously. Your .promise().done() is not doing anything when you use the loops.
The version using animShift() is only applying the animation to one element at a time, and since the next call is within done() it won't fire until the first animation is complete
Comment: Thanks for the help; without the .promise() the next animation doesn't seem to fire.


Append special character to Excel Cell with Macro

Question: i have created a macro in excel in which i open a csv file and make some changes that works fine. But i am stuck in what i want to do next.
I want to add the " character at the beginning and the end of the column K with keeping the content.
Any idea how can i do this ?
Thanks in advance.
here is the code that i have tried :
<code> Columns("K").Select
    Selection.NumberFormat = "@"
Dim k As Range
    For Each k In Range("K2", Range("K" & Rows.Count).End(xlUp))
    k.Value = WorksheetFunction.Text(k.Text, "0000000000")
    k.Value = Chr(34) & k.Value & Chr(34)
  Next k
</code>
but i get the value of the k column like this : """0000062447"""
Comment: You mean the basic `val = """" & val & """"` (in a loop on range or array, array being the better choice) or `val = chr(34) & val & chr(34)`
Comment: Can you post your code?
Comment: tried this :
Columns("K").Select
    Selection.NumberFormat = "@"
Dim k As Range
    For Each k In Range("K2", Range("K" & Rows.Count).End(xlUp))
    k.Value = WorksheetFunction.Text(k.Text, "0000000000")
    k.Value = Chr(34) & k.Value & Chr(34)
  Next k

but i get the numbers like this : """0000062447"""
Comment: Sadly, this is behaving as per Microsoft's design for writing CSV files. It's not really possible to get it to perform differently. You may want to consider writing your own export program.
Answer: This will apply the double quotes just the once, and if run again will ignore any cells already double quoted:
<code>Columns("K").NumberFormat = "@"
Dim k As Range
For Each k In Range("K2", Range("K" & Rows.Count).End(xlUp))
    If Not (Left(k.Value, 1) = Chr(34) And Right(k.Value, 1) = Chr(34)) Then
        k.Value = WorksheetFunction.Text(k.Text, "0000000000")
        k.Value = Chr(34) & k.Value & Chr(34)
    End If
Next k
</code>
Input:

Output
Comment: Ah, okay. This is an issue with the built in CSV export function in Excel, nothing wrong with the cell contents.
Comment: tried and still the same outcome
Comment: There must be something else at play here, the code you've provided - and that I've altered slightly - does exactly what you've asked for.
Comment: maybe because i use a csv file to read the data ?
Comment: actually the excel i created has a button which when pressed it asks the user to select a csv file to open and create a new csv file which makes the changes i said


please help solve v02 formula

Question: How can I simplify the formula:
$[\{x/15 \times 1.33\} \times 0.17] + 33.3$, where $x$ is traveled distance
I don't know what the "$[$" and the "$\{$" are for.
Can anyone please explain?
Note: this is Staminanya stability formula for running.
Comment: These are simple brackets. It's the same as using "(".
Comment: And you can remove them confidently
Comment: now i get it, thanks to both of you, and @goodvibration too
Answer: The square "[" and curly "{" brackets in this case are both uses as parentheses. Evaluate $[\{x/15 \times 1.33\} \times 0.17] + 33.3$ the same as you would $((x/15 \times 1.33) \times 0.17) + 33.3$.
After simplifying, you can get, $0.0150733\times x + 33.3$.
Does this help?

please help solve v02 formula


Which of the following value(s) of $t^3$ are not possible?

Question: Let $t$ be a real number such that $t^2 = at + b$ for some positive integers $a$ and $b$. Then for any choice of positive integers $a$ and $b$, $t^3$ is not equal to -
1) $4t+3$
2) $8t+5$
3) $10t+3$
4) $6t+5$
This question is from a prestigious Indian Scholarship exam, and I'm solving it for fun. But I can't get at the bottom of the problem. I'm also a bit shaky on which concept to use in this problem.
My try on this question
$t^2 =at +b$
$t = \sqrt(at+b)$
For $t \in R$
$at+b \ge 0$
Since $a$ and $b$ are positive integers
$at \ge -b$  and
$t \ge \frac{-b}{a}$
I also tried differentiating the function    $t^2 = at + b$ to get
$\frac{d}{dt}(t^2) = a\frac{d}{dt}(t) + 0$
$2t = a$
Alas it leads nowhere. But
$\frac{a}{2} \ge \frac{-b}{a}$
Since $a$ and $2$ are positive integers
$a^2 \ge -2b$
What has to done next? Please help
Comment: Your very last step is trivial as we're given $\;a,b>0\;$ ...
Comment: Please suggest a right step @DonAntonio
Comment: @Y Thinking now...
Answer: Hint:$$t^3 = t^2\cdot t \\= (at+b)\cdot t \\= at^2 + bt \\= a(at+b) + bt \\= (a^2 + b)t + ab$$
Comment: @YourAverageEuler In finished proofs you never see all the failed attempts, so one might be tempted to think that in order to do well in mathematics you have to always be able to see the solution immediately. That is not the case at all. The best mathematicians in the world try and fail all the time, but it's the working solutions they share with the rest of the world. Of course, even their failed attempts are much better than what I could ever come up with, which is why I'm not a world-class mathematician. At least not yet :P
Comment: @YourAverageEuler That's the solution, yes. Note that we can prove that the 2nd option is impossible (not just "difficult" or "we couldn't find a solution", but actually impossible) becase we must have $ab = 5$, which forces $a = 1, b = 5$ or vice versa, and neither gives $a^2 + b = 8$.
Comment: @YourAverageEuler There isn't so much a method to problem solving as just being able to see what approaches are easy and fast, and _might_ give a solution, so you just check those before you go on to the heavier stuff.
Comment: What should be the next step?
Comment: I am quite certain that you know that already, @labbhattacharjee. I am not inclined to give more until the OP has read this and had a go at cracking it themself. That's why I put "Hint" at the top.
Comment: By plugging from the list of options  we can reach to the correct answer..
Comment: @YourAverageEuler This does lend itself to a brute force method, yes. Mostly because you don't have too many possibilities to check. If the options were more along the lines of $1934t + 782$, you would have to be a bit more clever. It also helps that all the constant terms in all the options are primes.
Comment: In the most general setting, I think it'd be enough to consider stuff modulo $\;8\;$ to solve .
Comment: @Arthur since $a,b$ are positive integers... from your solution we can assume $a=1$ and $b=3$ and vice versa. That gives us the 1st and 3rd option. For $a=5$ and $b=1$ and we get  $26t + 5$ and by switching $a$ and $b$ we get the 4th option. This means 2nd option is not possible.
Comment: Thanks @Arthur Is there a better way to do it, like a general case
Comment: @YourAverageEuler Nice, and as Arthur said: checking all the possibilities the second one is ruled out as for the other three we can get example. The interesting thing would be if you had more options to choose from...
Comment: @DonAntonio yes you are right. But even this was tough for me and I was on the wrong track to solve this one. God knows when I'll be able to think such methodically
Comment: @Arthur nice point. Thanks!
Answer: Assume that $t^3$ does equal $ut+v$ (where $u=4$, $v=3$ for the first part, etc.).
Then $t$ is a root of the cubic polynomial
$$f(X)=X^3-uX-v \in\Bbb Z[X]$$
as well as of the quadratic polynomial
$$g(X)=X^2-aX-b \in\Bbb Z[X].$$
But then $t$ is also a root of
$$f(X)-Xg(X) =aX^2+(b-u)X-v$$
and also of
$$h(X)=(f(X)-Xg(X))-ag(X)=(a^2+b-u)X+ab-v. $$
There are two possibilities:

If $a^2+b=u$ then we conclude $ab=v$. Two of the problem parts allow you to find $a,b$ with these properties. As the corresponding $g(X)$ has two real roots (the discriminant $a^2+4b$ is certainly positive), in these cases it is possible that $t^3=ut+v$.
If $a^2+b\ne u$, $h(X)$ has a unique root $t$ and it is rational. By the rational root theorem, $t$ must in fact be an integer and among the signed divisors of $v$. Conveniently, $v$ is prime in all problem parts, you you need only check for $t\in\{v,1,-1,-v\}$ whether or not $t^3=ut+v$. That is, check if $v^2=u+1$ or $u=0$ or $v=u-1$ or $v^2=u-1$.
Comment: Nice one @HagenvonEitzen This might be a general solution (like if the options were not given) is it?


Observations made if dataset performs better on Linear Kernel than Polynomial Kernel in SVM and vice versa?

Question: When I run a dataset using Support Vector Machines(SVM) and I am use both Polynomial and Linear Kernels. The performance I obtain is different, so I was wondering if there is any information I can obtain about the data from how it performs on each kernel.
Or phrased in a different way, what kind of data tends to perform better with a Polynomial Kernel vs a Linear Kernel and vice versa.
Answer:
what kind of data tends to perform better with a Polynomial Kernel vs a Linear Kernel

Polynomial kernel is more suitable nonlinear inseparable data, linear kernel is more suitable linear separable data.
Before choosing the kernel, you can visualize  the training data, make sure the linear kernel is enough.


Drupal 6 CCK date field is saving current time when the time field is left blank

Question: I have a node type='event' that has a "text field with date popup calendar".  The date format is "05/13/2015 - 7:02pm".  On the edit page, the form renders as two fields: a calendar popup text field and a separate field for the time.  This field is mandatory; but, it has been requested that the time value not be mandatory.
The problem occurs when the node is saved.  It saves the date correctly; but, it inserts the current time if no time has been entered.   Is there a way to have it not enter a time or just default to midnight if no time has been entered?
Answer: Set your Default value for your event date field to Blank. This will make the date/time field empty upon default. A user has to enter date if it's a required field, but can leave the time field blank. If it's left blank it will default to 00:00.


Programa em C para concatenar strings não executa corretamente

Question: include
int main(){

    void concatenarStrings(char string1[], int t1,
                           char string2[], int t2,
                           char string3[]);

    char palavra1[]={'p','a','o','c','o','m'};
    char palavra2[]={'m','o','r','t','a','d','e','l','a'};
    char novaPalavra[16];

    concatenarStrings(palavra1,6,palavra2,9,novaPalavra);

    int i;
    for(int i = 0;i < 1;++i){
        printf("%c",novaPalavra[i]);
    }

    return 0;
}

void concatenarStrings(char string1[], int t1,
                       char string2[], int t2,
                       char string3[]){
    int i,j;

    for(i = 0; i < t1; ++i){
        string3[i] = string1[i];
}
    for(j = 0; j < t2; ++j){
        string3[t1 + j] = string2[j];

    }
}

Meu código acima compila corretamente no DEV C++,não apresenta nenhum erro. É um código para concatenar as strings palavra1 e palavra2,porém sempre quando executo ele,ao invés de formar a palavra pao com mortadela,ele exibe somente a palavra p.
Não consigo ver onde está o erro.
Answer: Marco, o problema é o for no seu main. Declare-o assim:
//Você já declarou a variável i, então pode usá-la sem declará-la novamente
for(i = 0; i < 16; i++)

Quando for chamar um for, prefira usar variável++, assim ela só será incrementada depois da primeira iteração.
Comment: Muito obrigado.


How do you graphically understand this definition of Taylor's theorem?

Question: Today, we learned about Taylor's theorem, and how a real valued function $f: (a,b) \mapsto \mathbb{R}$, and with some further criterions, can be approximated with a polynomial.
I've seen the Taylor approximation before, often in this form:
$f(x) =\sum_{k=0}^{\infty}\frac{f^{(k)}(x_0)}{k!}(x-x_0)^n$
Personally, I think this definition is quite intuitive. I've seen many youtube videos that describe how this formula arises. However, our lecturer showed us another definition instead, that we'll be using. Instead of memorizing it, I want to try and understand every single part of it.
From here on, I'll present the definition, and pinpoint every part of it that I struggle to understand. So here it is:

$f: (a,b) \mapsto \mathbb{R}$, where $f$ is $(n+1)$ times continously differentiable on $(a,b)$. Let $x_0 \in(a,b), \forall y \in \mathbb{R} : x_0 + y \in (a,b), \exists \theta = \theta (x) \in (0,1) : f(x_0 + y) = \sum_{k=0}^{n}\frac{f^{(k)}(x_0)}{k!}y^k + \frac{f^{(n+1)}(x_0+\theta y)}{n+1!}y^{n+1}$

Wow, that took a while :) First and foremost, I want to establish that I do understand that the first term is equal to our Taylor polynomial, whereas the last term is Lagrange's residue term.
So here are all my thoughts on this definition:

What role does $\theta$ play in this definition? How can we graphically interpret how this $\theta$ in some way or another, has an effect on the error term? I hope I expressed myself clearly enough regarding this question.

Why do we have an $f(x_0 +y)$ and not an $f(x)$ as presented in the first definition above.

At the moment, that's all the questions I want to ask you. If you have any more ideas that you could share, that could help me further understand this definition, I'd be glad if you could share them. Whatever they might be.
Thanks!
Comment: Starting from the second question, the $x_0+y$ and $x$ are the same. The $\theta$ is just saying that the residual is evaluated somewhere between $x$ and $x_0$
Answer: Taylor's theorem is a special case of Hermite polynomial interpolation. In Taylor's theorem, you have $x_0 \in (a, b)$ and you want a polynomial $p$ such that $p^{(k)}(x_0) = f^{(k)}(x_0)$ for all $k \in \{0, 1, \dots, n\}$. By writing $p(x) = a_0 + a_1(x - x_0) + \dots + a_n(x - x_0)^n$ and differentiating, it is easy to see that $p(x) = \sum_{k = 0}^{n}\frac{f^{(k)}(x_0)}{k!}(x - x_0)^k$ is the unique polynomial of degree at most $n$ that solves the problem.
It remains to estimate the error. There are many proofs giving rise to various error formulas. To get the one you wrote we can argue via Rolle's theorem. Suppose we want to find the error $f(y) - p(y)$ at $y \in (a, b)$. If $y = x_0$, the problem is trivial, so assume $y \neq x_0$; actually assume $y > x_0$, the proof for the case $y < x_0$ will be similar. Let $K = \frac{f(y) - p(y)}{(y - x_0)^{n + 1}}$ so that
$$f(y) = p(y) + K(y - x_0)^{n + 1}.$$
You can think of this as extending $p$ to interpolate $y$. Consider $F : (a, b) \to \mathbb{R}$ defined by
$$F(x) = f(x) - p(x) - K(x - x_0)^{n + 1}.$$
Note that $F$ has the two zeroes $x_0, y$. By Rolle's theorem, $F'$ has a zero $y_1 \in (x_0, y)$. Note that $F'$ has the two zeroes $x_0, y_1$. Thus by Rolle's theorem, $F''$ has a zero $y_2 \in (x_0, y_1)$. Continuing in this way (by induction), we find that $F^{(n)}$ has a zero $y_n \in (x_0, y_{n - 1})$, and finally that $F^{(n + 1)}$ has a zero $y_{n + 1} \in (x_0, y_n)$. Plugging this in gives
$$0 = f^{(n + 1)}(y_{n + 1}) - 0 - (n + 1)!K,$$
so that
$$K = \frac{f^{(n + 1)}(y_{n + 1})}{(n + 1)!}.$$
Graphically, we can say that $y_{n + 1} \in (x_0, y)$ is a zero of $F^{(n + 1)}$.


Question regarding the integral of random variables with same distribution.

Question: Suppose $X,Y$ are independent random variables with the same distribution then is it the case that for all measurable sets $A$, $E[X1_A]=E[Y1_A]$. I think it is true but I can't prove why. Any hints or suggestions? Also if the statement isn't true, what conditions can be imposed on the sets $A$ such that the equality holds.
Comment: @hgmath What can you say about the distributions of the random variables $X1_A$ and $Y1_A$? Are they the same?
Comment: So, $A$ is a subset of the probability space $\Omega$, right?
Comment: Yes A is a measurable subset of the probability space.
Comment: The distributions are definitely not the same, in general. For example, if $a < 0$ and $A = \{X\le b\}$, then you have$$P(X1_A\le a) = P(X\le\min\{a,b\})\quad\text{and}\quad P(Y1_A\le a) = P(X\le a)\cdot P(X\le b).$$
Comment: @amsmath Thanks. But if you have the time please look at the following link:https://math.stackexchange.com/questions/3691659/given-a-sequence-of-i-i-d-random-variables-prove-a-result-involving-conditiona?rq=1. In the answer provided, the poster says that $E[X_11_E]=E[Y_11_E]$. Could you explain why that is the case?
Comment: @JhonDoe sorry for my confusion in the first comment. I found this explanation that might help: https://math.stackexchange.com/questions/308816/conditional-expectation-of-iid-random-variables
Answer: This is not correct. Just flip a coin twice. Then $\Omega = \{0,1\}\times\{0,1\}$, $P(s,t)=1/4$ for all $(s,t)\in\Omega$, $X(s,t) = s$, $Y(s,t) = t$. These are definitely i.i.d. Now, choose $A = \{(0,1)\}\subset\Omega$. We have
$$
E(X1_A) = P(X1_A=1) = P(X=1,s=0,t=1) = 0,
$$
but
$$
E(Y1_A) = P(Y1_A=1) = P(Y=1,s=0,t=1) = P(s=0,t=1) = \frac 14.
$$


Determine whether the given set is bounded and find its supremum and its infimum.

Question: Let $A = \{x \mid \Bbb R \mid x^2 \lt 2\}$. Is the set $A$ bounded?
If yes, find its supremum and its infimum.
Attempt:
Notice that
\begin{align*}
A &= \{x \in \Bbb R \mid x^2 \lt 2 \} \\
&= \{x \in \Bbb R \mid x^2 - 2 \lt 0 \} \\
&= \{x \in \Bbb R \mid (x - \sqrt{2})(x + \sqrt{2}) \lt 0 \} \\
&= \{x \in \Bbb R \mid -\sqrt{2} \lt x \lt \sqrt{2} \} \\
&= (-\sqrt{2},\sqrt{2}).
\end{align*}
Hence, by definition, $A$ is bounded. Now, I claim $\sup A = \sqrt{2}$ and $\inf A = -\sqrt{2}$ which is true, indeed. For the supremum, let $M$ be the another upper bound of $A$ and suppose $M \lt \sqrt{2}$.
Then, since $A$ is bounded, there exist an element of $A$, say $r$, such that
$M \lt r$. A contradiction with the definition of an upper bound, that's $M$. Hence, we must have
$\sqrt{2} \le M$ i.e. $\sup A = \sqrt{2}$.
Now, for the infimum, let $m$ be the another lower bound of $A$ and suppose
$-\sqrt{2} \lt m$.
Then, since $A$ is bounded, there exist an element of $A$, say $s$, such that
$s \lt m$. A contradiction with the definition of a lower bound, that's $m$. Hence, we must have
$m \le -\sqrt{2}$ i.e. $\inf A = -\sqrt{2}$.
Am I true ?
Answer: This is mostly right, but I think you should be a little more explicit about where you get the contradiction from. In particular, how do you know that there is an element $r \in A$ such that $M<r$? This doesn't come from the fact that $A$ is bounded, it's because $M < \sqrt{2}$.
Comment: You could find an example of such an $r$ explicitly. For example, suppose $M< \sqrt{2}$ and let $r=\frac{M+\sqrt{2}}{2}$. Then $r^2 < 2$ so $r \in A$, but $M<r$ which contradicts the assumption that $M$ is an upper bound of $A$.
Comment: And so, where does it come from sir ?
Comment: Well, nice. Thanks sir for the correction


Different types of merging in dataframes

Question: I have two dataframes with shapes:
df1.shape = (30649, 18)
df2.shape = (5730, 4)

I have two ways of merging:
new_df = df1.merge(df2, left_on=["A", "B", "I],
          right_on=["A", "B", "P"])

new_df_v1 = pd.merge(df1, df2, how='right', left_on=["A", "B", "I"],
                     right_on=["A", "B", "P"])

The column names are the same, except for the 'I' and 'P', however the values in each column  are the same type.
When I inspect the output of the shapes, I get:
print(f"{df1.shape}, {df2.shape}, {new_df.shape}, {new_df_v1.shape}")
(30649, 18), (5730, 4), (5468, 20), (5732, 20)

I was expecting the new_df and new_df_v1 shapes to be the same, but they differ. What am I overlooking here?
Comment: `df1.merge(df2, left_on=["A", "B", "I], right_on=["A", "B", "P"])` here `how` is `inner`, in latter `how` is `right`, so different output.
Comment: in the first case you missed `how='right'`?
Comment: @Ch3steR (and political scientist): thanks, I though it was something overlooked.
Answer: In the new_df_v1, the how='right' argument is telling the merging function to use only keys from right frame, similar to a SQL right outer join; preserve key order. Whereas when you do df.merge, the default behavior is to join by the union of the keys: * inner: use intersection of keys from both frames, similar to a SQL inner join; preserve the order of the left keys.
Comment: @ Landmaster: I changed it, yes you're right and now the shapes are the same. Not originally asked, but is one method of merging (df1.merge or pd.merge) favoured over the other?
Comment: Merge, join, and concat are a helluva topic - you can read about it in the pandas [documentation](https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html). I really don't think there's a 'better way,' but I havent really taken the time to profile their run times.
Comment: Yes I anticipate too there is a difference between these 3 constructors...I was just trying to figure why one can merge using two different ways (using just the 'merge' constructor).


Symbols "M", "C", "D", and "P" in Guitar Tablature

Question: I was reading a songbook by Richie Kotzen, and in the song "Shine" (which he played with Mr. Big), there's a rythm guitar part that goes like this:

What do the symbols M, C, D and P mean? I'm pretty sure "M" is for "palm-mute" and "P" is for "pull-off". But I'm not certain as to what C and D mean. Maybe "D" is for "don't play", since there's a bow line from the same note, but what about C?
By the way, it's probably not a slide or a hammer-on, since those are noted in other ways. Check out an excerpt of the solo part of the same song:

Notice the presence of "C" and "D" again, but now alongside "H", "P" and "S", indicating that they are something else.
So, what do these symbols mean?
Answer: I don't know for sure, but I'm fairly certain "C" means a string bend and "D" means a release.  Here's why I think so:
Notice the tab in the rhythm part.  Where the "C" occurs, you play the D-string, 4th fret---that's an F#.  And sure enough, the standard notation shows an F#.  But then the standard notation shows that note becoming a G, while the tab continues to show D-string, 4th fret.  The only way to play a G at that string/fret is to bend the string a half-step.
And then the standard notation shows the note going back to an F# at the same place where the "D" occurs, which makes me think the "D" indicates releasing the bend.
If you look at the solo, you'll see the same thing occur.  At the beginning of the solo, the tab shows B-string, 12th fret -- that's a B.  Then it's marked with that "C" marking.  The standard notation shows a B grace note going up to a C, which again could only be achieved on the 12th fret of the B-string by bending it a half-step.  And then the pitch of the note goes from that high C back down to the B, while the tab stays on the 12th fret, but this time marks it with "D".
Basically, wherever C is notated, the pitch of the note goes up, but the fret stays the same, and when D is notated, the pitch goes back down again.  Notice, too, that "C" and "D" seem to come in pairs.
So again, I don't know for certain, but this is my educated guess: "C" means "bend the string" and "D" means "release the bend".
Comment: I know that 'C' stands for Choke: a quick bend, I've also seen it spelled as CH on some tabs
not sure what D stands for though
Comment: Good explanation. Note how the bend (="C" action) is used to produce an appogiatura (the little grace note before the main one, first bar of second extract). You should play on position not-bended the first B and bend quickly do C before releasing in the next bar. I am surprised to find these "C" and "D" letters though. In contradiction to the other letters, I do not find an easy mnemonics. I have seen a "Z" for bend sometimes.
Answer: I would agree with what Alex said above about M, C, and D -- the other symbols are most likely:
H => Hammer-on
P => Pull-off
S => Slide
Answer: Consult this Wikipedia article on tablature symbols. It contains an extensive chart of commonly-used symbols and their meaning.
http://en.wikipedia.org/wiki/Tablature#Guitar_tablature
But the bottom line is that there are no universally-agreed-upon conventions for notation. You must consult the individual book that this example comes from.
Comment: It was the first thing I tried... although a good reference overall, this Wikipedia article unfortunately doesn't cover this particular "corner case".
Answer: C - Crescendo - Move Pitch, or volume, UP
D - Descend - Move Pitch, or volume, DOWN
H - Hammer-On - Hit note to produce a sound
P - Pull-Off - Remove Finger to allow note, of lower pitch, to sound
S - Slide - Raise/Lower Pitch, while maintaining sounding note, & changing Finger Position
Answer: P = Pulgar (thumb in Spanish) To be played by the thumb.
Comment: This seems inconsistent with both the original question and the other answers, which say P is for "pull off". Do you have a source for your answer? That would help better establish it.
Comment: _For this particular piece_, I find it unlikely that "P" is "thumb", as the piece is played entirely with a pick and the part where the "P" appears is certainly a legato-based trill.


Error while create view uncaught exception thrown by method called through reflection

Question: I am using Visual Studio 2013 Professional, and I was trying to create a view, but I got he error below suddenly,
There was an error running the selected code generator:

uncaught exception thrown by method called through reflection
  (Exception from HRESULT:0x0131604).

I have searched Google, but it is no luck.
Comment: Try Re-installing the VS2013
Comment: Thanks your reply during the Christmas holiday! Merry Christmas!
Answer: Finally, I found the issue. It is wrong tag in web.confg, after I changed it to the correct one, it is working again!
Comment: Correct, I also had an issue in the web.config and I was facing this same issue, thanks for the answer, it saved my time.
Comment: I had this issue, and it turned out that I had two instances of appSettings - in general, it seems that having an invalid web.config will cause this error.


Improper Integral of $(y-1)^{-3/2}$ from $0$ to $2$

Question: improper integral $$\int_{0}^{2}  \frac{1}{(y-1)^{3/2}}\, dy$$
I know it doesn't work when $y = 1$, so I split the integral, right. But then i realized, it doesn't work with $0$ either, as that would leave a $-1$ under the square root.
So how does this work?
Comment: @Dr.SonnhardGraubner could you elaborate? Which complex value? Do you take into account that $\int_1^2$ diverges? What methods do you use to arrive at your conclusion? What do you mean?
Comment: the integral gives a complex value
Answer: $$\int_0^2\frac1{(y-1)^{\frac 3 2}}dy$$
$$=\int_{-1}^1 \frac1{u^{\frac 3 2}}du$$
$$=\int_{-1}^1 u^{-\frac 3 2}du$$
$$= -2u^{-\frac 1 2}|_{-1}^1$$
It looks normal so far, except if you substitute $u=1$ into the expression, you will get imaginary numbers. The reason of that is because the original function is not defined for $y\leq 1$ if your range is the real numbers, as you cannot take square root of negative numbers. (As depicted here http://m.wolframalpha.com/input/?i=%28x-1%29%5E%28-3%2F2%29%3Dy&x=0&y=0 )
So if you insist, you need to break it into two parts:
$$\frac{-2}{\sqrt u} |_{-1}^0 + \frac{-2}{\sqrt u} |_0^1$$
The first part correspond to the imaginary part of the original integral while the second part is the real area. However it does not converge as you see you get $\frac2 0$
Answer: One guess at what some people might mean by this integral is
$$\int_{0}^{2}  \frac{1}{(y-1)^{3/2}}\, dy=\lim_{a\to0}\left(\int_0^{1-a} {1\over (y-1)^{3/2}}\,dy+\int_{1+a}^2 {1\over (y-1)^{3/2}}\,dy\right)$$
One often writes things this way in the expectation of a helpful cancellation that leads to a finite limit.
However, the first of these two integrals is purely imaginary and thus tends to $\pm i\infty$, whereas the second is real and tends to $+\infty$.  Thus, there is no helpful cancellation and it does not seem possible to give the integral a useful meaning by this route.