Odd files in the /tmp directory?

Question: Wasn't able to find this here, but i have an odd issue, i found several files in the /tmp directory of my Centos web server named like.
php2qUuKs
php2v8kJc
php7XD6ku
php0652pa

And they all have content like:
ˇÿˇ‡JFIF¥¥ˇ· 'ExifII*
™∞«œ(1◊2Ú>?Fiá`XCanonCanon EOS 300D DIGITAL¥¥Adobe Photoshop CS Windows2004:10:26 19:12:519ËIË@d!ddGddd+ËKËrËöÇŒùÇ÷'àêê0221êfiêÚëëí
íí
í&í   í
í.Üí6†0100†††¢>¢F¢¢£§§§§•N2Z
2004:10:17 15:59:212004:10:17 15:59:21'§W'§'‡.|@S
¶Æ(∂$HHˇÿˇ‡JFIFHHˇÌAdobe_CMˇÓAdobedġ€Ñ

ˇ¿x†"ˇ›
ˇƒ?

3!1AQa"qÅ2ë°±B#$R¡b34rÇ—C%íS·Òcs5¢≤É&DìTdE¬£t6"U'eÚ≥Ñ√"u"ÛF'î§Ö¥ïƒ'‰Ù•µ≈'ÂıVfvÜñ¶∂∆÷ʈ7GWgwáóß∑«◊Á˜5!1AQaq"2Åë°±B#¡R—3$b·rÇíCScs4Ò%¢≤É&5¬"DìT£dEU6te'Ú≥Ñ√"u"ÛFî§Ö¥ïƒ'‰Ù•µ≈'ÂıVfvÜñ¶∂∆÷ʈ'7GWgwáóß∑«ˇ⁄?ÿ≥¨2Ê}VWIUSQJDR
_@BB  VVC]
ZKJB^[QB\WAoMXY\@ZXY
F
IG]^   LY@C[BAT]SA\KFWX_TFDUtVV]__
QRTR
DI
DBZ[Y@TZGH\
BKVW]V_pUNWKJKVPENAHKQ^_S@\D]@@CPK0^VXXED]RCURUMCBRIQ
E(
ZCKH\\XZ_QUJ]SQIQUMQ^I[_TL@
P\nCH
QG[VMTRSDC_
]JYIJN
][&

@Z^^

J

RBSX\@RWIETU
[3VUQ^\UVZDQEQY[ZKZDYVX[FD#NZ]T_LWTUFJwLQX@KMUJFRRBV@AP_KKWZ]G
JZU]\AXB@)QVA^NZNRYKU
S@IPUIR\VDQ.@TO^QOU_I
RY\GKPK    VUC
B_Q\@PAC,

BDR_B  UUQT@QRT
R

G]&CZ^^

J

]QYYXL]GRWIG[UXJNFRX]HTVX@FYRCU])XPB^NZNRYKTAWTDQ
Z\KD]!
AG@KWILPV   ULE@KTJJG<_[GoFXR\BDBYYXL@^@NZNRWKBJt^\RFZT[BC
E_QD
_]\FXAF^BAVMIQSNFWNX_C_XZGppX@A
VTKJAZ[QTQEPZ
]GPE
TDE]   /  TXGFCHY^SQ]YWDRK]T
F
IG!
ZQ\   Z[nG    BBB    QUNPBD
ZX_KJB^[QL
pR\XQCoMXY\@ZXY
F
IGF@XXW   _^IGTWBAT]SB\K[QKyV[CV_]
HIB_ULXG@BUDTW]G
]VWASP@@XJT\FYRXpHGTRAFVCKDU@JR_
N\

Z\CCp
XUB/    3
A]L  N^NRZWQPQK\KB
MUJIRR_3V
]L[T\
T  EWA]V]
GJKVSBNAA
C]VKt@P[@YT[BC
E_Q[[ZKI_ACZTFMMI^SN@[]R\Av^ZUF[S_BQ^IXYTPI\Y[
ZFJDR_ABR@RVXNUTCIo
A
VTKJAZ[Q@W^\ALXSLRE_UXN.^TO^QOU_I
_U]P]UZSC
C_QRPZBYD0AM
]_B_N
OF
CGWIQK-UUGH#VCSLC3F@Qq_@@\_][DS_BMGHS^UJFRRR(Oc[Q]XRASfZU[C]UG\3    MJNNZY]KDDR_@U
[I^QJ@XBW_\M]ZCD    PK]
]VWI
XMFG\
HIFZ\\RkOWWyTZ[OMFMOTK   I%LIR]MYWR[K S
KJJI%ENZMG@QVBJF_]JSITWP
CG;Ff[NBS[NZECSN^\ZP
;FF
@^FQVCNFUHVSNnQOPAC
ENZWPHSMG@ZP^N
SUR8
    P  C SNI
EJF@[@DWNH^G\$

OVLLTCS@ZgQ@@XS\C~GYCEIV\XP    SZIJF;JXU^[^\EQVQ^

S
ICHLBSBILWAX]KSJ^FJD
LyIT\ZLCAKF@VG@CZ_HfQUCFSOXOKP  AO@GH-[[PQJPDCXZ[YAEOJF    H;OOYCI
XPZVBV@N[^D@SS
LM
O)
BOgINLBQFV[M_]AP^UJSN[\
HLXExX_J_[XBJ       OUUP   T
VIN
JGExAS\S[XI_ZSSJA
T

JGEr\BSVZKXQ[JS
S\J@=CCI@   RVCNZB@JFUH
-VTKPPS]S@I    NGLCVDPP\[[_GS:E
NSL]HC^IAI%EBU^\D_WPIXGQ
NPW]+
WHSfFE\VC]V^^FC[UUKSO \ML    O]I;AUVV[XY@TPQ^S
JL\W9é·ÍCANF@P\FPY[MXQII3IMA:TXS\    FZ^DJBVZKBQHVSILEgPAJF[X_WOVBFTZS[S;_S
N@V[PACOS^APRXFSKw@ZPQAENT\LCAS'I
AM}R[_WVL_\S[OVIPL  OJK    I
FSQEOfPN[ZAUH[SS
R\LC&C
I
X@^FAQV@NZEXIR\PeUOMWY]
SAK3LHUGM[OPEp
LS\KFSX\V[NEW'¥∂CXQKSS
_nPSCAbQP]KTNMRFDI
OVLBHSO]DFSLtZZOfNVZ[TRFE^[  H    T
YHaEG\IFXZMXSVYL:ãÔ˜JK
C\AI
SHQM@@[\GJOV_]S O\\JP    P
OJTP]Sw_[]YL}f?#S

JA
P

VI
SHQM_N_]K}VXW@S
RWP
SJF
JWXTGBEn[ZBY\CSS
\ZHT
JMVDKSJ^FJA_L{
SNJU[P    TOIKF
S}FZCZZUDRI_ZSS
V@P  P@,SXUWE[YDCN[Y_G

IKT

(SZI
@I
SJUM^VIBG\NC\@
$N^VOHLTESV   LKHp"≥∂@\ZJAPBMS/
R\JPC
AFSH]OTBSVIVC_BS_PBH L:LSBUKCZJR_[]YLG@SJ\
T
[F    @VF\S_]\VpSD(
S+)NPJP
WIZ   CMRAR~ARPT\SZR((SWF
[WRV_WYVYYVJSI&NNX@HR"BIIFEJLAR]BWRF\BUBJS\
LU&AI
SH]OTVYLU_PQTS:EINMP\POY UV\@RQtL\I~UJE
N]yMH    T
Y=J
LBQ\R[CKRBV[D@SO@X
!KIWyRXPVEN]E^HS#)@EyLOW]F
,UWUI_U[BN]_Z
SPZ+    AOILFX\^VQBGMV[TFEW^R=P,
C]I@FCMRF]D\Y@CNIyXSMAP
P
LJDP@OVBLV[LgNSOUVYP  OGS[L@C\CObOV_Z\US
PWIPLO^NfNX_C[[[XL_ES
NTVX
P
R SG  EJQW_@X\[MCZ\@=

X      AA:SV[LG@ZY^[]VS@CkHOMWPHD;HS
[E
UGLM>
NNPBHAO^J5
]ZqPDN^XCWUM
IEmFHAJL[QK\ZDDQK{YSJS
QOPS
ME@[[BOx_U[H^CUVS
N[\]HOK] LCX]V[@XACZDNS
NNQK
A
OYCIJM^O|YTRE^OJXI
JAP

BS]SA[NM`@[\\@CR\@SU@
P
AWIN!SKQ\A_vJDM@\\\@AHP*OOSV   LJUJDAJJXA]TPL~NOPMMH  T
JPX]BQRNLs@SN[\SOCfF
MVD[YS]YRY^SX]PACZI\FFVUTOnJ[A[CLG@SMJP AK
SZIGXP@CI[QXSI@SJEdP]IJFSX]U]MSN[ZEFLyINZHSCB\ENGJPTJJtNY^GWYAS

I[   PSZ,SH[MDJB@\F[PySWRGPCA){\\CV_JG@ZP]@SNT@  T\A$JNX_CJCU]C_^
SU\P&@V@XWU[[XL_E]SW@!SWI\F    FZ^DJBE~LV["∞∂ESMFS[S[EZS\GG_WPFYI_ZEExZPSOO@VW@JXYJWED[S   pYPLCGS,S@Z\]FQQCV[TVSWK
P
S2SBQCZH^M[AAXU
'XCP   PON+FZ^RFURU\BGUFEOLK^PSOBJ>    EFXUW@PCFYQ[,T\PCKIAFE@X\BN%MUFKIR]MYW3OP
\Q^S\=/8 :ciY\[QPEX\[UGV]A_V\^LLS  SSEYOFJAKMSMH
Q[>OKVHPKSNLC_^AOVBHgXBT@SIR\P
K+AI
@I
A_\JTVXV\WYWQEzFPT\I[AKT@SrVM@BGQAEI\CH
JVbI\XCVEVVZZEUTS
NIPM(SZI
@I
SHXX_PJM_F@BRXB
EVUGHA
]SBIJPS\KOEt\JT^_ZE
I
V[G$TZS@I
DPRGZD\]\[UUKSO\HXA =CAEF_\^VI^W[BGUCS%IQAHSK$N
EVP\RHSJUASI_ZSOW]KS]L,SNYE}\@]C\]X@WXSX@H0
SgSV    LBQE\[\fBY\CSOVLL
OD[FZF\BObOG[]CS_\FEPW]PL
]SFS}YRYSVCXA_IS
IG SZ:  SBMAA@PP[QT^T

SU@LKI@F
Y\MgGSUA[C_^E
K\  AC
KI_S}€±™CZD\@@I_ZS
S
M@HLcRY]
E
Q]EJ>TK    RBOMSKR$
LT@G(
Õ¥†EIYKPQ[XULfSSW^P AWIGI
CQURVN^@GX@DV?U@ÉÛ"&HI:EC[JT@[Z[QCZILK(L
O
S@I
FZ^T@Y]UMJKl_ES
M\\PP}EN@\COfXZXV\DYAEOVL6KSV   L_Q\VVEfV_]JS
OW]LCHS]SA[NMqVSTA[^PLy[SINIUK   AG
SV[LM{@F\@@FUU

SPWR3LTZL,SXUWE[YDUVAXQAE
OWOPCOlASFZ[^N[ZBQCNMQOHA
APEy\_SN[ZYY[JE
IKWWPCgIJI
CP]_[PDGZPM:TYWSKRL
NkO[JM%ZFC

@G
T
ICRT
    R9
S6II&]Sa[MXUFUXC]@YYB^IX[TxAGQˇŸ

Any ideas on what this could be ?.
Comment: Clearly temp files created by a php program. Looks like photo uploads. You running some web server with some photo gallery software?
Comment: Then someone else is running a photo upload site on your server.  rename the files to .jpg, scan them with anti-virus or upload to virustotal, then view them as a non root user.  Use exiv2 to extract the exif data.
Comment: Also, i delete the files but they are re-generated.
Comment: No, nothing like that. That's why i find this odd.
Answer: These are PHP upload temporary files. They are left in temporary directory when not handled (moved) by an application, when moving fails due to permission problems, etc. Enable logging (check error_reporting, error_log and log_errors), preferably to a single file or syslog, to find which scripts throw errors related to ie. move_uploaded_file() function.
For security reasons, it is recommended (amongst others) to set a separate upload_tmp_dir and open_basedir for every PHP application in the system. This will prevent PHP from messing with the global temporary dir, and will also clearly indicate what app/user leaves unhandled upload files. Enabling file uploads only for the webapps that really need them will also improve security and control over your system.

Odd files in the /tmp directory?


Ubuntu Update Manager won't update when "Install Updates" is clicked

Question: I press the "Install Updates", Update Manager goes on to refreshing the updates list but does not install them.
I can install the updates through apt-get though.  What could be the problem?
Comment: Are we talking about Ubuntu, or Debian?
Answer: I assume you're talking about Ubuntu, and not Debian.  The following answer assumes this is the case, although you might want to clarify your question a bit more.
First, it's a bug.  Second, close the update manager, then in the upper-right corner, click on the icon representing the update manager, and select install updates.  The update manager will appear; click on the install checkbox, and they should install.

If the update manager is not running in the upper right-portion of the screen, yet you have updates, it could be you have some file corruption issues that can easily be fixed.  While logged into a Gnome session (regular graphical session), press Alt-F2, and type this:
gnome-terminal

Then in the terminal, type:
sudo apt-get clean ; sudo apt-get update && sudo apt-get upgrade

Close the terminal once it is completely finished.  It may take a short while to force the issue.
Answer: I cut & pasted this command into the terminal and it ran and it updated several packages, but I don't have an Update Manager icon in my top panel, at the right or anywhere else on the panel (except in System > Admin > Update Manager, of course).
Should I in fact have the UM icon in the top panel at right?  I'm running karmic on 64-bit ubuntu system75 Wild Dog desktop.
Comment: @watchpocket: this is not the place to ask a question but to answer one.


replace SCSI raid controller with SATA on SBS 2003

Question: Is it possible to add a second raid card (there is a second pci-x slot) that uses SATA and transfer the current contents of the SCSI card's HDDs to the new larger SATA HDDs
Background: I bought 2 new 1 TB SATA drives and IDE <-> SATA converters because my boss informed me that the server was IDE rather than SCSI (and I didn't check twice) but of course the cables don't fit. server is a Gateway 920 http://support.gateway.com/s/Servers/COMPO/Cases/3501437/3501437tc.shtml
so my questions are can we simply add the second raid card and new drives and boot from something (Windows rescue cd? Ubuntu Live cd?) and clone the old SCSI disks to the new larger SATA disks and set the server to boot from there? if so can someone point me in the right direction?
Comment: You poor bugger.  Are you allowed to buy a real server?  [Seriously, you can buy a much, much, MUCH better server on eBay for under $250.](http://www.ebay.com/sch/i.html?_trksid=p5197.m570.l1311&_nkw=dell+poweredge+2950&_sacat=0&_from=R40)
Comment: Well, honestly, rather than screwing around on a "server" that has lower specs than my smartphone, I'd take the plunge and buy a nice, inexpensive Dell or HP server from a couple generations back and move the data from the old server to the new one.  It'll be faster, work better, and probably end up being cheaper than trying to cram more hardware into your current "server."
Comment: Yes and that was a possible option if this cant be fixed
Answer: There comes a point where it doesn't make financial sense to invest in old hardware. Parallel-ATA, parallel-SCSI and PCI-X started to disappear from the server landscape in 2004.
When the street value of late-model production-quality servers is < $500, and new servers of that class are under < $1000, those may be better options than surgery on an older system...
Yes, the disk swap you speak of is technically possible, but it carries much higher risk of problems than simply moving to a new system. You also lose your fallback.

What if during power-down to install the PCI card, one of the old drives fails to spin up?
What if there's a system board battery issue and you lose BIOS settings?
What if the cloned OS refuses to boot because of a driver issue on the new SATA card?

You risk more downtime and complexity than just moving to a new server.


C# and Namespaces

Question: Should differentiation by namespaces be only used when there are third party libraries and be avoided to differentiate the classes we write ourselves?
In Web Api, if the controller and action names are the same but the namespaces are different, routing does not happen and 404 error is given. I found out that a custom controller selector can be used to overcome this but since the built-in selector ignores it, I wonder if this is a deliberate design decision. Is there a reason why I should avoid differentiation only by namespaces?
Comment: In one of my first jobs, I worked at a place with 3 other Amy's.  Whenever a call would come in over the PA system, all four of us would show up at the front desk.  Eventually we gave each other nicknames (I was Scooter) to differentiate us.  Don't let this happen to your code.  Try to give things distinctive names *and* logically organize them using namespaces.
Comment: Yes, things named the same tend to be confused with each other (by humans).
Comment: Can you talk us through what the **benefits** of having two things (e.g. controllers) called the same thing but being in different namespaces would be @JohnL ?
Answer: In ASP.NET MVC/WebApi the routes are determined automatically from the Controller's name. So, if there are two Controllers with the same name and do not override the route with a RouteAttribute, they share the same route.
There are two ways you can solve this problem:

Use Areas: areas are meant to separate your application into multiple MVCs, each with specific sections (commonly separated by authentication/authorization rules). This would look like:

Public

Controllers
Views
Models

Admin

Controllers
Views
Models

Override the route that the controllers use (though untested, not sure if it would work):
[Route("MyHome")]
public class HomeController : Controller
{
}

[Route("MySecondHome")]
public class HomeController : ApiController
{
}

Also notice that for the RouteAttribute to work, you need to enable it first. You can find more information here.
public static void Register(HttpConfiguration config)
{
    // Attribute routing.
    config.MapHttpAttributeRoutes();

    // Convention-based routing.
    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );
}

However, you should attempt not to use classes with the same name, regardless of the namespace structure. It makes it harder to recognize what exactly you are dealing with.
Comment: I expected that to be the case.  Same thing here.
Comment: You left out the option to use the `namespaces` parameter on the route, in which this is exactly the case that parameter is meant to solve. But I agree that if name collisions can be avoided altogether it would be best.
Comment: I think to fit with the OP's question, one of your example controllers should be an `ApiController`.  `Route` will work if attribute routing is enabled.
Comment: @Amy I had forgotten that Web Api 2 uses `ApiController` (been using ASP.NET Core for some time now). Answer updated
Comment: @NightOwl888 I really did not know of that option, I'll add it, thanks

C# and Namespaces


Drupal shows ?? instead of special characters with oracle

Question: I have a Drupal 7 installation working with Oracle 11g database with Apache/2.2.12 (Linux/SUSE) and PHP/5.3.8
The problem I face is that special characters are not displayed correctly. Instead two question marks ('??') are shown.
I've been able to correct some static pieces of content (in blocks) converting the characters to their corresponding html entity. However, new content and menus dont support this.
I would like to know how to show those characters correctly.
Answer: Check you are using UTF8 character set in Oracle database, and in apache config.
For data in Oracle db that is not UTF8 be careful if you need to convert, you need to identify what the original characterset is and the best way to convert to UTF8.

The general rule of thumb is that if you are using UTF8 all the way
  you should not see those question marks in the browser.

Take a look here for Oracle UTF8 conversion info: https://stackoverflow.com/questions/8239250/how-to-configure-utf8-character-set-in-oracle
Comment: Changes

The values for these variables in the DB already are
NLS_CHARACTERSET : AL32UTF8
NLS_NCHAR_CHARACTERSET : AL16UTF16

The following lines have been added to the httpd.conf file
AddDefaultCharset UTF-8
SetEnv NLS_LANG AMERICAN_AMERICA.AL32UTF8

And for the headers in every page, using html.tpl.php template, this was already done:

Even in the template.php file these lines are present for the html_head_alter hook
$head_elements['system_meta_content_type']['#attributes'] = array('charset' => 'utf-8');

I still get the same


Predicate Logic "John drinks any type of drink"

Question: For the following English statement,what would be the correct predicate logic translation:
John drinks any type of drink.
1.$\forall x {(Drinks(John,x))}$
2.$\forall x(Drink(x) \to Drinks(John,x)\\$
I would read the statement back into English as:

John drinks all everything.
John drinks everything that is a drink.
Comment: Yes, both readings are correct. So for your initial statement, the second one would be correct.
Answer: The problem with the first one is that John is part of the domain, and hence it implies that John drinks himself!
So, I would definitely go with the second one.
Comment: Bram28, thanks for writing up this answer (have deleted mine for being at best superfluous)!
Comment: @ryang I appreciate it! You are graceful as always .. I wish there would be more of you on this site :)
Comment: Gosh, thanks for your very kind words!


Add backticks in creating table to mysql with csv file -PHP

Question: I have a php code that will create a table to mysql database using a csv file. However, some column headers are not being read by mysql. The only time that mysql will read the query is when I add backticks(`). Can you help me on where to put backticks in my query?  :(
Here's my code:
<code>   $file = 'C:\Users\user\Desktop\Sample CSV
Files\672VER.csv';
$table = '`672ver`';

// get structure from csv and insert db
ini_set('auto_detect_line_endings',TRUE);
$handle = fopen($file,'r');
// first row, structure
 if ( ($data = fgetcsv($handle) ) === FALSE ) {
echo "Cannot read from csv $file";die();
}
$fields = array();
$field_count = 0;
for($i=0;$i<count($data); $i++) {
$f = strtolower(trim($data[$i]));
if ($f) {
// normalize the field name, strip to 20 chars if too long
$f = substr(preg_replace ('/[^0-9a-z]/', '_', $f), 0, 100);
$field_count++;
$fields[] = $f.' VARCHAR(500)';
}
}

$sqlcreate = "CREATE TABLE $table (" . implode(', ', $fields)  . ')';

echo $sqlcreate;
</code>
Answer: If you enclose the field name in backticks, this will stop it trying to interpret some column names as reserved words...
<code>$fields[] = '`'.$f.'` VARCHAR(500)';
</code>
Comment: That did it :D  Thank you! :)  and if you dont mind me asking... what do you mean column names as reserved words?  can you give me some example?
Comment: Column names such as `order`, `select`, `value` ... basically any word that is normally part of a SQL statement is treated differently.
Comment: alright. I'll try to keep those column names in mind when I use my backticks :) thanks for the tip. :)
Answer: Change the last line of the loop this way:
<code>$fields[] = '`' . $f . '` VARCHAR(500)';
</code>
I hope it works fine,
Answer: I think you could do
<code>$sqlcreate = "CREATE TABLE $table (`" . implode("`, `", $fields)  . "`)";
</code>
Comment: sorry... mysql didn't read my query because the comma(,) has not been read :c
Comment: its saying a comma or closing bracket was expected
Comment: Thiis will put the ` around the field type definition as well.
Comment: Good point - should have properly inspected the code to see what was going on before leaping to the wrong conclusion


Equivalence of category of subsets and subobjects

Question: I'm trying to show that the categories $\mathcal{P}(X)$ and $Sub(X)$ are equivalent.
According to Steve Awodey's "Category Theory" I need to find two functors

$ E: \mathcal{P}(X) \to Sub(X)$
$F: Sub(X) \to \mathcal{P}(X)$

and a pair of natural isomorphisms

$\alpha: 1_{\mathcal{P}(X)} \overset{\sim}{\to} F \circ E$
$\beta: 1_{Sub(X)}: \overset{\sim}{\to} E \circ F$

I believe I've constructed E and F correctly on the objects. On object $Y \in \mathcal{P}(X)$ I define $E(Y) = \lambda y. y$, and since $Y$ is a subset of $X$ this has the type $Y \to X$ as required.
On object $f \in Sub(X)$ I define $E(f) = \lbrace f(x) \mid x \in \mathsf{dom}(f) \rbrace \subseteq X$ as required.
I'm not sure how I define the functors on morphisms in both cases though.
Edit: I forgot to define $Sub(X)$, so here's a definition:
The objects in $Sub(X)$ are monomorphisms $m$ with $cod(m) = X$ and the given two objects $m$ and $m'$ an arrow in $Sub(X)$ is $f: m \to m'$ such that $m = m' \circ f$.
Hopefully that clears things up.
Comment: You'll have to be more specific - it is not clear how $\mathcal{Sub}(X)$ is defined differently from $\mathcal{P}(X)$.
Comment: I think you can work less. If  you prove that one of your functors is full, faithfull and essentially surjective on objects you're done.
Comment: Oh sorry. I've added a definition in an edit now
Answer: Well, what are the arrows in $P(X)$?
I assume it is the poset category, ie. the arrows are just the inclusions $Y_1\subseteq Y_2$.
Basically $E$ is the identity, also on arrows: for $Y_1\subseteq Y_2\subseteq X$, $\ E$ maps it to the identical inclusions $Y_1\hookrightarrow Y_2\hookrightarrow X$.
On the other hand, for an $f:m\to m'$, i.e. $m=m'\circ f$, first prove that $f$ is also a monomorphism, then take its image and map all these into $X$ by $m'$.


Is there a function $f$ such that $f(-x)=\sum_{k=0}^{+\infty}{\frac{f(k)}{k!} x^k}$?

Question: You can rewrite this as the requirement that $(-1)^k f^{(k)}(0)=f(k)$ but I do not feel this helps much. I also saw some similarities with Ramanujan's master theorem/interpolation formula but I also got stuck there. The closest function I found was $\cos(\pi x)$ but this function still has an additional $\pi^k$, which I feel is not easily fixable unless I am missing something. Is there a such function $f$ that is not exactly the zero-function?
Comment: @KurtG. are u sure about your example?
Comment: @AjinShajiJose . Maybe not. Apparently the series in the title is not the Taylor series. Sorry about the confusion.
Comment: zero function satisfies it trivially. but i reckon you want a non-trivial example
Comment: $f(x)=\sum\frac{f(k)}{k!}(-x)^k$ is the only function that can satisfy, if that sum converges, because trivially $f(x)=f(-(-x))=\sum\frac{f(k)}{k!}(-x)^k$.
Comment: Yes I am interested in a non-trivial example, I edited the question.
Comment: Every analytic and even function. Non-trivial example: $f(x)=\cos x\,.$
Answer: If a function $f$ solves the delay differential equation
$$ f'(x) = -f(x+1), \tag{1} $$
then $f^{(k)}(x) = (-1)^k f(x+k)$ and hence $(-1)^k f^{(k)}(0) = f(k)$ will be satisfied. Then, assuming $f(x)$ takes the form $f(x) = e^{rx}$ and plugging this to $\text{(1)}$, we find that $f$ is indeed a solution of $\text{(1)}$ if
$$ r + e^r = 0. \tag{2} $$
This equation has infinitely many complex roots with values approximately
\begin{gather}
-0.567143, \\
1.53391 \pm 4.37519 i, \\
2.40159 \pm 10.7763 i, \\
2.85358 \pm 17.1135 i, \\
3.16295 \pm 23.4277 i, \\
3.39869 \pm 29.7313 i, \\
\vdots
\end{gather}
In fact, any linear combination $f(x)=\sum_{n=1}^{N} c_n e^{r_n x}$ with each $r = r_n$ satisfying $\text{(2)}$ also solves $\text{(1)}$ by linearity.
Remark. The zeros of $\text{(2)}$ are of the form $-W_k(1)$, $k\in\mathbb{Z}$, where each $W_k$ is a branch of the Lambert W-function. In particular, $-W_0(1) \approx -0.567143$ corresponds to the negative of the Omega constant.


MS SQL Server 2 identical databases on different servers replication or mirroring to each other possible?

Question: Hi: I have one free version of SQL Server 2012 express database running on Amazon AWS with 1 CPU and only 1 GB Ram . As you can see the CPU and RAM power are barely enough for my PHP scripts running on a separate AWS desktop machine to pump data into the server but its free except that I have to pay for data coming in and going out. I have this setup because I need a reliable database that is always on. It has data constantly coming in and I want to achieve the following:

In order to keep my outbound data expenses very low and to get high  SQL server performance to I want to replicate my data from the Amazon AWS database to my database running on my personal laptop which is very powerful. This way I can run queries as much as I want without disturbing the little Amazon AWS engine database or incurring heavy data transfer charges. I usually turn off my laptop so constant replication is not possible. Is there a way I can set my replication on my laptop in such a way that as soon as my laptop is switched on and online then it will automatically replicate from when it was switched off and then I can do my stuff? It can even be manual replication and I'm perfectly fine with it.
Different scenario: So as I mentioned in the top paragraph that I have PHP scripts running on a separate Amazon AWS Windows desktop that are pumping data into the single CPU 1 GB ram MS SQL server running on a separate AWS instance. On rare occasions these scripts slip up and skip writing data and then my data goes bad. To prevent this I want to have another identical setup with Amazon BUT I want to set these two separate but identical databases to either replicate or mirror with each other so any time data on is changed one database they both synchronize with each other. Is it possible to have two databases be slave master of each other or parallel mirroring with each other? If so then how can I make this happen?

Thanks to all in advance.
Romina.
Comment: "I have one free version of SQL Server 2012 express database" -> then no. Express has zero options for replication or mirroring because it is free.
Answer: Point 2, can be addressed by using AWS RDS to back up data for you.
Otherwise, you manually need to create a snapshot of your EC2 instance but this involved a tiny bit of downtime and will cost money to store on S3.
Point 1, just restore the database
Either way, you want a high level of functionality that you don't want to pay for, so our options for helping you are limited.
Answer: Agreed -- db mirroring would be highly unlikely in this situation since it works best if it's persistent and would need manual intervention every time you turned your desktop system on. Snapshot Replication is the only realistic option in the replication world, and there's no benefit gained over using a simple database backup and restore or AWS snapshot.


How to compute weighted means of a vector within factor levels?

Question: I am able to successfully get a simple mean of a given vector within factor levels, but in attempting to take it to the next step of weighting the observations, I can't get it to work.  This works:
> tapply(exp.f,part.f.p.d,mean)
    1         2         3         4         5         6         7        8             9        10
0.8535996 1.1256058 0.6968142 1.4346451 0.8136110 1.2006801 1.6112160 1.9168835     1.5135006 3.0312460

But this doesn't:
> tapply(exp.f,part.f.p.d,weighted.mean,b.pct)
Error in weighted.mean.default(X[[1L]], ...) :
  'x' and 'w' must have the same length
>

In the code below, I am trying to find the weighted mean of exp.f, within levels of the factor part.f.p.d, weighted by the observations within b.pct that are in each level.
b.exp <- tapply(exp.f,part.f.p.d,weighted.mean,b.pct)

Error in weighted.mean.default(X[[1L]], ...) :
  'x' and 'w' must have the same length

I am thinking I must be supplying the incorrect syntax, as all 3 of these vectors are the same length:
> length(b.pct)
[1] 978
> length(exp.f)
[1] 978
> length(part.f.p.d)
[1] 978

What is the correct way to do this?  Thank you in advance.
Comment: Hi jonw-  exp.f is a numeric vector of stock expected returns,part.f.p.d is a factor with 10 levels, and b.pct are percentages for each stock in an index (the top 1000 stocks)
Comment: See answers to http://stackoverflow.com/questions/3685492/r-speeding-up-group-by-operations.
Answer: Now I do it like this (thanks to Gavin):
sapply(split(Data,Data$part.f.p.d), function(x) weighted.mean(x$exp.f,x$b.pct)))

Others likely use ddply from the plyr package:
ddply(Data, "part.f.p.d", function(x) weighted.mean(x$exp.f, x$b.pct))

Comment: @Joshua the `do.call` is a bit of extra overkill here. `sapply(split(Data, Data$part.f.p.d), function(x) weighted.mean(x$exp.f,x$b.pct))` would be sufficient to return a vector of weighted means. The simplicity of your `split` approach (+1) is hidden by the `rbind`+`do.call` wrapping.
Comment: Why the plyr love-in? ;-) I agree it is a very nice package, but such simple problems as that posed in the Q can be handled very nicely via basic R functionality without needing to learn a new package.
Comment: @Prasad: I knew the obligatory plyr solution would get some up-votes. ;-)
Comment: thank you - I can see that I need to invest some time learning what plyr is all about. cheers.
Comment: @Gavin: The `do.call(rbind, ...)` stuff is just habit that works on more general problems.  You're right that `sapply` is much nicer in this case.
Comment: @Gavin the idea behind plyr is that by being more consistent you don't need to remember the bewildering array of aggregation functions in base r, let alone their inconsistent parameters.
Comment: @hadley I guess having grown up in a world before plyr the various base R options and arguments are burned into my synapses - probably as a result of having to remember all the various functions and inconsistent arguments :-)
Answer: I've recreated the error with some dummy data. I'm assuming that part.f.p.d is some kind of factor that you're using to separate the other vectors.
b.pct <- sample(1:100, 10) / 100
exp.f <- sample(1:1000, 10)
part.f.p.d <- factor(rep(letters[1:5], 2))

tapply(exp.f, part.f.p.d, mean) # this works
tapply(exp.f, part.f.p.d, weighted.mean, w = b.pct) # this doesn't

A call to traceback() helps to uncover the problem. The reason the second doesn't work is because the INDEX argument (ie part.f.p.d) that you passed to tapply() is used to split the X argument (ie exp.f) into smaller vectors. Each of these splits is applied to weighted.mean() together with the w argument (ie b.pct), which was not split.
EDIT: This should do what you want.
sapply(levels(part.f.p.d),
       function(whichpart) weighted.mean(x = exp.f[part.f.p.d == whichpart],
                                         w = b.pct[part.f.p.d == whichpart]))

Comment: thank you - is there some tweak that would make this work to calculate a weighted.mean that you know of?
Answer: Your problem is that tapply does not "split" the extra arguments supplied (through its ... arguments) to the function, as it does for the main argument X. See the 'Note' on the help page for tapply (?tapply).

Optional arguments to FUN supplied by
  the ... argument are not divided into
  cells. It is therefore inappropriate
  for FUN to expect additional arguments
  with the same length as X.

Here is a hacky solution.
exp.f <- rnorm(10)
part.f.p.d <- factor(sample(1:5, size = 10, replace = T))
b.pct <- rnorm(10)
a <- split(exp.f, part.f.p.d)
b <- split(b.pct, part.f.p.d)
lapply(seq_along(a), function(i){
  weighted.mean(a[[i]], b[[i]])
})


Is R-squared value appropriate for comparing models?

Question: I'm trying to identify the best model to predict the prices of automobiles, using the prices and features available on automobile classified advertisement sites.
For this I used a couple of models from the scikit-learn library and neural network models from pybrain and neurolab. The approach I used so far is to run a fixed amount of data through some models(machine learning algorithms) and compare there $R^2$ values which was calculated with the scikit-learn metrics module.

Is $R^2$ a good method to compare the performance of different models?
Although I got quite acceptable results for models such as Elastic net and Random forests I got very poor $R^2$ values for Neural network models,so is $R^2$ an appropriate method for evaluating neural networks (or non-linear methods)?
Comment: The short answer is **no**. It might help you to read my answer here: [Model evaluation and comparison for selecting the best model](http://stats.stackexchange.com/questions/22902//22905#22905), which is fairly closely related to your question. A candidate solution is described [here](http://stats.stackexchange.com/questions/78973/zero-inflate-models-vs-generalized-mixture-model/78977#78977). For more general understanding, you might try reading some of the threads on the site categorized under the [tag:model-selection] tag.
Comment: @gung Thank you!may I ask what would be a an appropriate goodness of fit measure for regression using neural networks?
Comment: "Model evaluation and comparison for selecting the best model" broken link :)
Comment: Link is:  https://stats.stackexchange.com/questions/22902/model-evaluation-and-comparison-for-selecting-the-best-model
Answer: I think the crucial part to consider in answering your question is

I'm trying to identify the best model to predict the prices of automobiles

because this statement implies something about why you want to use the model. Model choice and evaluation should be based on what you want to achieve with your fitted values.
First, lets recap what $R^2$ does: It computes a scaled measure based on the quadratic loss function, which I am sure you are already aware of. To see this, define residual $e_i = y_i - \hat{y}_i$ for your i-th observation $y_i$ and the corresponding fitted value $\hat{y}_i$. Using the convenient notation $SSR := \sum_{i=1}^Ne_i^2$, $SST:=\sum_{i=1}^N(y_i - \bar{y})^2$, $R^2$ is simply defined as $R^2 = 1 - SSR/SST$.
Second, let us see what using $R^2$ for model choice/evaluation means. Suppose we choose from a set of predictions $\bar{Y}_M$ that were generated using a model $M:M \in \mathcal{M}$, where $\mathcal{M}$ is the collection of models under consideration (in your example, this collection would contain Neural networks, random forests, elastic nets, ...). Since $SST$ will remain constant amongst all the models, if minimizing $R^2$ you will choose exactly the model that minimizes $SSR$. In other words, you will choose $M \in \mathcal{M}$ that produces the minimal square error loss!
Third, let us consider why $R^2$ or equivalently, $SSR$ might be interesting for model choice. Traditionally, the square loss ($L^2$ norm) is used for three reasons: (1) It is easier computable than Least Absolute Deviations (LAD, the $L^1$ norm) because no absolute value appears in the computation, (2) it punishes fitted values that are far off from the actual value much more than LAD (in a squared rather than an absolute sense) and thereby makes sure we have less extreme outliers, (3) it is symmetric: Over- or underestimating the price of a car is considered to be equally bad.
Fourth (and last), let us see if this is what you need for your predictions. The point that might be of most interest here is (3) from the last paragraph. Suppose you want to take a neutral stance, and you are neither buyer nor seller of a car. Then, $R^2$ can make sense: You are impartial, and you wish to punish deviations to over- or underpricing exactly identically. The same applies if you just want to model the relation between the quantities without wishing to predict unobserved values. Now suppose you are working for a consumer/buyer on a tight budget: In this situation, you might want to punish overestimation of the price in a quadratic sense, but underestimation in an $L^p$ sense, where $1 \leqslant p <2$. For $p=1$, you would punish in an absolute deviation sense. This can be seen to reflect the goals and intentions of the buyer, and biasing the estimation downward might be of interest for him/her. Conversely, you could flip the thinking if you were to model the price predictions for the seller. Needless to say, any norm $L^p$ could be chosen to reflect the preferences of the modeller/the agent you model for. You can also punish outside of the $L^p$ norm entirely, and use constant, exponential, or log loss on one side and a different loss on the other.
In summary, model choice/evaluation cannot be considered independently of the model's aim.


The import com.google.android.maps.OverlayController cannot be resolved

Question: I need some help here. I am actually following the
http://www.anddev.org/google_driving_directions_-_mapview_overlayed-t826.html
tutorial for learning the Driving direction on google maps but the following libraries I cant import
<code>   com.google.android.maps.OverlayController;
   com.google.googlenav;
   com.google.googlenav;
</code>
The are giving the errors. The direction by eclipse is The import com.google.android.maps.OverlayController cannot be resolved
I have set the Google Api emulator (means not using general emulator) and also included
<code><uses-library android:name="com.google.android.maps" />
</code>
in the Menifest (Application) tab
Comment: Did you find a solution? If my question was of any help I'd suggest that you accept it. If you haven't solved the problem yet please provide more information.
Answer: Umm, that example is from 2008. It's really old and obsolete. The most recent documentation regarding Google Maps can be found here:
https://developers.google.com/maps/documentation/android/
Google Maps is part of the Google Play SDK and it's really easy to integrate Google Maps into your own app.
If you take a look at the comments to the forum post you linked to you'll see that people in more recent posts have problems getting this to work since the API has changed. I guess the correct way to implement it using the current Google Maps API is to use the Google Maps Directions API: https://developers.google.com/maps/documentation/directions/ to get the directions from point A to B and then create an overlay using with some kind of poly line.
I think you'll find a bunch of related questions on SO if you do a search.


Sqlite relacionamento entre tabelas

Question: Sobre relacionamento entre tabelas:
Tentei rodar o seguinte código e o SQLite me retorna o seguinte erro:

table "Jogos" has more than one primary key

-- -----------------------------------------------------
-- Table `times`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `times` (
  `_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  `nome` VARCHAR(45) NOT NULL,
  `sigla` VARCHAR(3) NOT NULL,
  `imagem` MEDIUMTEXT NUL);

-- -----------------------------------------------------
-- Table `Jogos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Jogos` (
  `_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  `rodada` INT NOT NULL,
  `data_hora` VARCHAR(45) NOT NULL,
  `local` VARCHAR(100) NOT NULL,
  `gols_mandante` VARCHAR(45) NULL,
  `gols_visitante` VARCHAR(45) NULL,
  `id_mandante` INT NOT NULL,
  `id_visitante` INT NOT NULL,
  PRIMARY KEY (`_id`, `id_mandante`, `id_visitante`),
  CONSTRAINT `fk_Jogos_times1`
    FOREIGN KEY (`id_mandante`)
    REFERENCES `times` (`_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Jogos_times2`
    FOREIGN KEY (`id_visitante`)
    REFERENCES `times` (`_id`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
;

CREATE INDEX `fk_Jogos_times1_idx` on `Jogos` (`id_mandante` ASC);
CREATE INDEX `fk_Jogos_times2_idx` on `Jogos` (`id_visitante` ASC);

Parece que o erro surge quando tento adicionar as chaves estrangeiras oriundas da tabela times na tabela jogos.
Answer: O problema é que estás a definir duas PRIMARY KEY na sua tabela.
E só pode ter UMA PRIMARY KEY por tabela.
-- -----------------------------------------------------
-- Table `Jogos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Jogos` (
  `_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,       -- UMA
  `rodada` INT NOT NULL,
  `data_hora` VARCHAR(45) NOT NULL,
  `local` VARCHAR(100) NOT NULL,
  `gols_mandante` VARCHAR(45) NULL,
  `gols_visitante` VARCHAR(45) NULL,
  `id_mandante` INT NOT NULL,
  `id_visitante` INT NOT NULL,
  PRIMARY KEY (`_id`, `id_mandante`, `id_visitante`),     -- DUAS

Apague a PRIMARY KEY do _id e vai funcionar:
-- -----------------------------------------------------
-- Table `Jogos`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Jogos` (
  `_id` INTEGER NOT NULL AUTOINCREMENT,
  `rodada` INT NOT NULL,
  `data_hora` VARCHAR(45) NOT NULL,
  `local` VARCHAR(100) NOT NULL,
  `gols_mandante` VARCHAR(45) NULL,
  `gols_visitante` VARCHAR(45) NULL,
  `id_mandante` INT NOT NULL,
  `id_visitante` INT NOT NULL,
  PRIMARY KEY (`_id`, `id_mandante`, `id_visitante`),

Comment: Obrigado Jorge, mas não posso apagar a pk _id pois essa é a chave primária da tabela jogos. Não seria apagar "id_mandante" e "id_visitante" ficando assim: PRIMARY KEY (`_id`)
Comment: E se esse for o caso, não perderia a integridade relacional?
Comment: Não, manténs a integridade relacional. As tabelas não precisam de ter primary key o id, pode ser outro campo ou um chave primária múltipla como tu tens

Sqlite relacionamento entre tabelas


Remove navigation bar in sidemenu based template in Ionic/Angular JS

Question: I created an application using the Ionic Framework and it works great. It is based on the sidemenu-template, so I always have a navigation bar on top of the application.
<ion-side-menus enable-menu-with-back-views="false">
  <ion-side-menu-content>
    <ion-nav-bar class="bar-calm">
      <ion-nav-back-button></ion-nav-back-button>
      <ion-nav-buttons side="left">
        <button class="button button-icon button-clear ion-navicon-round" menu-toggle="left"></button>
      </ion-nav-buttons>
    </ion-nav-bar>
    <ion-nav-view name="menuContent"></ion-nav-view>
  </ion-side-menu-content>
  <ion-side-menu side="left">
    <ion-content>

           Bla

           Sign-up

           Login

    </ion-content>
  </ion-side-menu>
</ion-side-menus>

app.js:
$stateProvider.state('app.login', {
  url: '/login',
  views: {
    'menuContent': {
      templateUrl: 'templates/login.html',
      controller: 'LoginCtrl'
    }
  }
})

$stateProvider.state('app.start', {
  url: '/start',
  views: {
    'menuContent': {
      templateUrl: 'templates/start.html',
      controller: 'StartsCtrl'
    }
  }
})

Now for the registration and login view I don't want to show the navigation bar at all. How can I remove it on specific view? I find this hard because the nav-bar is defined in menu.html which is called before the views.
Comment: you app.js is showing "ReferenceError: $stateProvider is not defined"..can you post your full codes including any js  source scripts and css scripts?
Comment: I only posted the relevant parts, because I am not going to add hundreds of lines to stackoverflow :)
Comment: can you do a jsfiddle then....?
Comment: one other way : u can remove  from menu and add it in the only views u want..!
Answer: I had to modify the routes definition in app.js:
$stateProvider.state('login', {
  url: '/login',
  templateUrl: 'templates/login.html',
  controller: 'LoginCtrl'
})

$stateProvider.state('start', {
  url: '/start',
  templateUrl: 'templates/start.html',
  controller: 'StartsCtrl'
})

Only removing the toogle button did not work, as the user was still able to swipe right on the screen to show the menu.
Answer: Simply hiding the menu-toggle button should do the trick for you.
Set a variable on the rootScope based on which you can show/hide the navigation bar toggle button:
<button ng-if="$root.isShowNav" class="button button-icon button-clear ion-navicon-round" menu-toggle="left">

Set this variable's value inside your app's .run:
.run(function($ionicPlatform, $rootScope) {
  // $rootScope.isShowNav = true/false based on some condition.
}

For example, here you could do something like this:
.run(function($ionicPlatform, $rootScope) {
  $rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState) {
    if (toState.name !== "app.login" || toState.name !== "app.start") {
      $rootScope.isShowNav = true;
    }
    else {
      $rootScope.isShowNav = false;
    }
   }
}

Comment: Only removing the toogle button did not work, as the user was still able to swipe right on the screen to show the menu.
Comment: Then you may apply this ng-if to your ion-side-menus itself


Why is the 2nd note of a chord called major third?

Question: On a piano, the root note of the C major chord is referred to as 1. The second note played is E, which is actually the fifth key when starting at C. Not 3?
Yes this makes senses to call it a 3 when referring to written music, but written music is confusing because the white and black notes are unevenly placed on 12 notes of each octave.
So from a piano, a major chord would be less confusing if though of as 1,5,8
A minor chord would be less confusing if though of as 1,4,8.
After many attempts to look into music theory and understand chord combinations this now makes sense to me. Using numbers to refer to the next note on the instrument I'm playing — guitar or piano, not some complicated stave of circles in lines that makes me feel dyslexic.
Comment: As I understand it, on account of being the third note of the Major Scale.
Answer: It's more about context than it is about written music. It's called a third because it's the third step in the scale.
Take the C major scale for example.

1  2  3  4  5  6  7
C  D  E  F  G  A  B

The C major chord is C E G: the first, third, and fifth steps (degrees) of the C major scale.
It's the same case with minor triads. Here is the C minor scale:

1  2  3  4  5  6  7
C  D  Eb F  G  Ab Bb

The C minor chord is C Eb G: the first, third, and fifth degrees of the C minor scale.
This is the simplest way to see it, but you can also see it as intervals, which are based on the distance between two notes.

semitones interval

1         minor second
2         major second
3         minor third
4         major third
5         perfect fourth
6         tritone
7         perfect fifth
8         minor sixth
9         major sixth
10        minor seventh
11        major seventh
12        octave

One semitone is the distance between two adjacent keys in the piano. Your suggested notation is slightly incorrect (typically we count the semitones from the root). A major chord, in semitone notation, would be r, 4, 7. A minor chord would be r, 3, 7. Using the table above we can translate them:
r, 4, 7 = root, major third, perfect fifth
r, 3, 7 = root, minor third, perfect fifth
From this you can also notice that the second note of a chord is not always a major third. It can be a minor third, or anything else. The C minor chord has a minor third, for example.
As you can see it's not a complicated stave of circles in lines, it's much simpler.
So, why use interval notation instead of your suggested notation? Because it takes into consideration the context, the scale, the key, which actually simplifies things a lot (even if you can't see it now). Your suggestion only uses the root as the reference, but nothing more.
Look at the C major and C minor scales again. In both cases the third note of the scale is the second note of the chord. Both are thirds (a major third in the major chords, and a minor third in the minor chord). This link is not present in your suggested notation, in which a major third would be a "5", and a minor third would be a "4".
That link is very important, because in tonal music everything gravitates around something (the key), everything functions in relation to something else. The interval notation implies these relationships, making things more clear and simpler. Once you start seeing things in terms of tonality, once you dive into music theory, this will become evident.
Comment: It's also about written music (1st para.). Assuming a normal stave, the root goes on, say, a line. The 3rd goes on the next line up, and the 5th on the next line after that. Count the line with the 1st dot as one, space as 2, etc., and it's 1-3-5. Sharps and flats go in automatically, as do letter names. I use this as a sight reading aid for guitarists, who can then play in any key from the word go, assuming they know a two octave pattern of maj. and min. scales. Works the same for spaces, too. +1 for an erudite answer.
Comment: @NeilMeyer - it rather depend on which set of notes one uses. C minor can also use Bb if one considers the melodic minor. Its relative major is Eb, having a  Bb note.
Comment: @Tim: You're of course right about the Bb, but it's not *melodic* minor (which indeed has a B natural), but *natural* minor which has the Bb.
Comment: @MattL. - the Bb does occur in melodic minor, generally in a descending manner, as in the classical way. Look at the scale and, yes, there's a B on the way up, but a Bb on the way down. Also A up and Ab down.  You're right about natural minor.
Comment: @Tim: Yes, but my point was that the melodic minor example could be a bit misleading, because *natural* minor already has a Bb. The "descending melodic minor" (which only exists in books) is nothing but the natural minor scale. And, at least ascending, C melodic minor has an A and a B, as you know. Anyway, it's of course not about right or wrong, but only about making it as little confusing as possible.
Comment: c minor has a b natural just BTW.
Comment: 1. Don't forget, due to the importance of the fifth, the tritone and minor sixth are frequently referred to as diminished and augmented fifths respectively (the correct name depends on context.) 2. The minor second has always seemed odd to me, because the second note of the minor scale is 2 semitones from the root, not one - but the reasoning behind that would be a whole other question,
Answer: It's intriguing that you mention this, because your suggestion that we call a major triad 1,5,8 is very close to how musical set theory works. In set theory, one of the primary goals is to classify harmonies as objectively as possible without privileging any scale (or indeed the entire idea of key and enharmonic pitches). The only primary difference is that the first number set theorists use is 0 instead of 1. Faced with a major triad, a set theorist would say that the "normal form" of the simultaneity is [047]. (NB there is variance about when to use square brackets or other kinds of brackets). They would go further, and say that the "prime form" is (037), but the explanation of that is complicated and belongs in a different question.
Answer: Much of our western music is based on several common scales which all have only 7 distinct notes and not all 12.  Many chords are then formed relative to notes found in any given scale.  So the relationships between notes is not from one note to the next one of the 12 notes, but to the next or another note within a certain scale.
Intervals, upon which chords are constructed, are named for their relative distance from one letter to another letter.  The distance from the letter A to the letter C never changes.  If A is the 1st letter, C is always the 3rd letter.  It does not matter if the letters are flat, sharp, or natural the distance from A to C is always the same.  The interval numbers 3rd, 4th, etc. become independent of any scale or key.  The terms major, minor, perfect, diminished, and augmented come to play in relationship to a given scale.
Answer: This question seems not so much to be about the reasoning behind the nomenclature of standard Western music theory (the OP already seems to have an adequate answer in mind, despite some some confusion about the staff system), but instead about representation of music in general and what feels "natural." I venture that the most significant factor behind the question is level of comfort with traditional Western notation. The reasons behind this notation (and just why the 2nd note of a chord is called the major third) are more a historical matter than a philosophical/logical one, i.e. it ain't science, it's art!
If you first come to music by picking up a guitar or playing piano by ear, you are more likely to develop you own conceptual apparatus for working through the peculiarities of note layout on those respective instruments. There are some advantages to this, but it may make traditional music theory at times seem convoluted (see https://en.wikipedia.org/wiki/Enharmonic for a classic case in point).
@PatMuchmore makes a good point, and the OP might follow up on this and find the classification system used in musical set theory more intuitive and appealing for his purposes.
Answer: Thankyou all very much for your answers. This is all very much appreciated. I think the reason i have struggled to understand music theory and written music for so long is because of its dominance within music teaching emphasizing so much information that could have easily been explained in terms of what is on the instrument, 12 notes, not 7. There are many scales from western to eastern, and many different types of instruments but most are tuned to these key 12 notes. The guitar doesnt have black notes so a c# has no distinguishing visible difference where as the piano which distinguishes very clearly non flats and non sharps on the white keys. If i want to learn an eastern scale it is easier for me to think in terms of a sequence of number combinations than trying to read a stave of a letter plus a sharp or flat variation. There is simply one logic, not two.
Comment: The theory using counted semitones works well on a graphically laid out keyboard, and to some extent, a guitar. The black and white bits need to be used in different sequences to play a particular tune in different keys - not necessarily so on guitar - the exact same fingering, etc. can be used, but starting on a different fret, for a new key. Most other instruments don't lend themselves to this thinking: woodwind and brass don't follow an easy to see pattern when moving in semitones. Most diatonic tunes won't need more than the 7 notes, anyway. Or have I missed the point?
Answer: I think this is a question one could actually write a book about. In my opinion, coming from the piano, you are already approaching that from the wrong end (historically). The 12 well-defined semitones are a compromise, dealing equal distribution for perfect harmonics, while having the error as small as possible.
Where we're actually coming from is a world of whole-number ratios like 1:2 for an octave, 2:3 for a quint, and so on. This gives pure-sounding harmonics, the 12th-root-of-2 steps implemented on a piano do not.
What historically evolved was the diatonic scale of 7 steps (or 8, if you want to count in the octave), based entirely on whole-number ratios. Depending on which step you start, you get a major scale, a minor scale, or even 5 different possibilities (like doric ... should probably not be discussed here) that lost their relevance nowadays. In this system, you have 2 possibilities for a third step -- a smaller or a bigger one (being the major or the minor third). Also note the third was perceived dis-harmonic for a long time, while nowadays, even seconds or sevenths might sound harmonic to our ears.
The actual problem with a pure diatonic scale is that it results in slightly different notes, depending on at which step you start. That's why you have these 12th-root-of-2 semitone steps on instruments with discrete tones. they are the best approximation distributing the error equally.
So my bet for an answer: In a world of 12-tone-music, your suggestion would match. But then, in this world, something like major or minor lost its meaning anyways. Talking about major or minor chords, just think in terms of the diatonic scale and keep in mind instruments like a piano only approximate it.


Examples of songs or phrases played in different temperaments

Question: I've read about the fact that 12 tone equal temperament is a relatively recent phenomenon, and that historically, each key would have a different character due to the unequal temperament. I'm curious about how equal temperament changes the character of songs, and what sort of variety we've lost by moving to equal temperament.
I've heard a few examples of individual intervals and chords, but never an entire song or phrase in another temperament. Are there any sources of recordings of the same song, or phrase, that I can listen to side-by-side (alternating between them, or simply played one after the other) which demonstrate the difference between equal temperament and other temperaments?
Comment: I wonder the extent to which string quartets or a cappella choirs are non-ET. They are often cited as examples of the tendency towards just intonation when not using fixed-frequency instruments but I'd be interested to know if that's demonstrably true in certain recordings, etc.  http://music.stackexchange.com/q/3014/28
Comment: @DRL I think you're mistaken about what we're talking about here: a different temperament would have the same 12 notes; it's just that the distances between them would not be equal. This means that a major triad is going to sound different when played on an F vs. a C. No quarter tones required. _Temperament_ itself refers to the _adjustment_ of tuning systems so that a keyboard can play in any key, it's just that in the old days they weren't exactly equal.
Comment: The variety lost, is in those songs which use quarter tones and other sub-divisions of notes - unless a piece uses some of these tones (ad loses something via transpositions into equal temperament) then its difficult to compare.  Sadly i have no examples.   If your transposing something from one temperament into another which has least all the tones of the source temperament, then nothing is lost (learning to play it on your instrument is another matter).
Comment: http://soundcloud.com/tracks/search?q[fulltext]=just+intonation http://soundcloud.com/tracks/search?q[fulltext]=xenharmonic http://soundcloud.com/tracks/search?q[fulltext]=microtonal  or the same searches on freesound.org for smaller snippets
Answer: Here are links to YouTube videos, all three of which were posted by the same person, using the same synthesizer, all three playing Bach's Air on the G String.  But each link uses a different tuning system:

Equal Temperament: http://www.youtube.com/watch?v=c6XkgNT20Eg
Just Intonation: http://www.youtube.com/watch?v=gdL8aPQUOk0
Pythagorean Tuning: http://www.youtube.com/watch?v=hq-SrgV7_Ow
Comment: @Alex : the basic idea is very good but the trouble is that the three versions are really _awful_ to hear no matter which tuning is used. The original music is not respected, the tempo is wrong, the sound wave is botched and badly digitized, there are many artefacts, etc.
Comment: @ogerard: FWIW, I didn't make them, and I don't know the person who did. Nor would I cite them as examples of fine musical performance. That said, from the perspective of a scientific experiment trying to isolate the effect of tuning systems, I like the idea of a computer-generated sound file that allows one to control for traits such as tempo, dynamics, etc. that would otherwise distract from the point of the experiment.
Comment: @ogerard: That'd be great.  Go for it.
Comment: Interesting! Yeah, you can definitely hear the difference in the tuning there, though it all sounds kind of odd due to the use of pure sine waves. It would be nice to hear the difference on real instruments, too.
Comment: @Brian: I agree, although for an experiment like this I'd prefer synth instruments for purposes of control.  Either way, my guess is that real instruments (or their synth equivalents) would make the differences between the tunings even more dramatic, due to the interplay of the overtones.
Comment: @Alex : I know you did not. I only hope we can find better examples.
Answer: I like this site for comparisons between different tunings.
Wendy Carlos has also made synthesizer versions of Bach's works in different temperaments. So this can be interesting to look up.
Answer: Provided your MIDI player allows pitch bends - there is the "Warped Canon" page.
Pachebel's Canon in many different tunings:
http://www.io.com/~hmiller/music/warped-canon.html
Answer: In case you were waiting for it (and I know you weren't), there's another piece synthesized with pythogoras. It's Beethoven's Romanza Op 50.
Pythagorean: http://www.youtube.com/watch?v=APfI69-d7zw
Just Intonation: http://www.youtube.com/watch?v=gTmWPU1ENd0
Tempered: http://www.youtube.com/watch?v=U4kk09r6YIc
I'll start working on adding timbres as a next step for the project (perhaps releasing version 1.0 once I get there).
Answer: For your further exploration:
Wendy Carlos has an album called "Beauty in the Beast" with some pretty exotic temperaments realized with interesting synth timbers.  She has a site at wendycarlos.com.
http://www.wendycarlos.com/resources/pitch.html
http://www.pandora.com/wendy-carlos/beauty-in-beast (tracks 2 and 4 are good)
Harry Partch composed for some unusual divisions of the octave and created his own instruments -- most are acoustic and the percussion tend to have overtones which can make it hard to sense the intervals fully, but it does have an unearthly feel.

Some from YouTube:


How to find the best fixed effect in a mixed model?

Question: I am trying to see the difference between two variables in mixed models.
Background: The models are for an experiment with a randomized complete block design, but there is a bit of missing data. Yield is being estimated by the fixed effect of 31 different treatments with 1 to 3 replicates in 4 blocks. The additional fixed effects that I am trying to sort through measure several parameters of each treatment (height, diameter, width, height_2--a different method of measuring height--, etc). My basic model starts with the following formula yield ~ Treatment + (Treatment:Block) using the lme4 function lmer in R. I removed the block effect and am only including the interaction because when the models got more complicated I was warned of singular fits, and one of the suggestions I read about on how to deal with that was to simplify the model. I should probably have deleted the interaction and kept only the block effect, but this is beside the point for my question here.
Problem
My problem comes from when I am comparing two models like the following,

a <- lmer(yield ~ Treatment + (1|Treatment:Block) + height, data=df)
b <- lmer(yield ~ Treatment + (1|Treatment:Block) + height_2, data=df)

I want to know if one effect (height or height_2) explain yield better when controlling for treatment and block effects. When I run anova(a,b) the models are refit to ML instead of REML (which is typical), and the table shows Chi Df of 0 and a Pr(>Chisq) of 1. I don't think I am doing this appropriately.

I read somewhere that to see if fixed effects are different make a model including both and another similar model but include an interaction of the two effects like below. From the anova(c,d) I should know whether the variables (height and height_2) have different effects on yield...(I think)

. c <- lmer(yield ~ Treatment + (1|Treatment:Block) + height + height_2,
data=df)
. d <- lmer(yield ~ Treatment + (1|Treatment:Block) + height + height_2 + (height:height_2), data=df)

Is the purpose of the previous comparison correct as I wrote it?
I still need to know: How to test whether one variable is a better predictor compared to the other if my first method is incorrect?
Bonus question: Are my variables (all or some) crossed or nested? Am I coding them correctly in lmer()... I read the answer to this question and I am still a bit fuzzy on how it applies to my situation.
Comment: Why do you have treatment as a random effect? I would think you should only have Block as fixed effect.
Comment: I have not intended to have treatment as a random effect. Does it become random as a result of the interaction term? The situation is that the treatments acted differently in different Blocks and I need to control for that treatment effect before I can look at the other parameters. When more than 2 of the fixed parameters were added I ran into the singular fit issues and block by itself didn't improve the model, but the interaction did. Why do you say to have only block as a fixed effect?
Comment: Oh, if the treatment effects differ between the blocks, that is not so good. In that case I don't know how to analyze the data best.
Comment: Oops, I meant that I thought that the treatment should only be fixed! Apoligies
Answer: The first method of comparing the two heights is wrong because the two models are not nested as anova requires. Instead you can just compare the likelihood values of the two models and choose the height variable that produces the highest likelihood (which is equivalent to AIC here because the two models have the same number of free parameters). In your dataset, model A has a higher likelihood (-727.1 compared to -752.7), meaning that height predicts the yield better than heigjt_2.
The second method you suggest compares the height variables by defining a model with both of them and testing if either height variables can be removed from the model (hope I understood that correctly). That is okay, but it can be inconclusive if both of them can be removed from model.
Comment: Are you suggesting I do `ab_compare<-anova(a,b)` then only look at `ab_compare$logLik` for comparing? If not then how do I get the likelihood value? If yes then how come the likelihood of `ab_compare` is correct without having the two models nested correctly?
Comment: Yes that you can do. Anova tries to calculate the chisquare likelihood ratio tests between the two models, and that it can't do because the models are not nested. Anova also reports the likelihood values and yes, those you can use to compare the models even though the models are not nested. (I wrote that the anova was wrong because the chisquare test was impossible)
Comment: How could I compare whether the differences in log likelihood are "significant" through some sort of p<0.05 approach?
Comment: It is not really possible to get a P value for the comparison here


Consider the two point space $X = \{a, b\}$ equipped with the topology $T = \{\emptyset, X, \{a\}\}$. Prove that $X$ is path connected.

Question: I am trying to solve this problem and I am unsure of where to start. Would it be enough to just show that every pair of points, i.e. $a,b$, can be joined by a path in $X$?
Answer: Let $f: [0,1] \to X$ given by $f(x)=a$ if $0\le x < 1$ and $f(1)=b$.
Then $f^{-1}[\{a\}]= [0,1)$, which is open in $[0,1]$, and so are $f^{-1}[\emptyset]=\emptyset$ and $f^{-1}[X]=[0,1]$. So the inverse images of all open subsets of $X$ is open, so $f$ is continuous and thus a path from $a$ to $b$, showing that $X$ is path-connected.
Answer: Prove that there exists a continuous map $f:[0,1] \longrightarrow X$ with $f(0)=a$ and $f(1)=b$.
Comment: @DataD96 You need to show that $X$ is path connected with that topology. You can't begin the proof assuming what you must to show. Besides, to conclude that $X$ is connected, note that the clopen sets in that topology are only $\emptyset$ and $X$.
Comment: @DataD96, you just need to prove existence, so construct a continuous function $f$ that satisfies the conditions, and you're done. You may see Godel's answer for an idea.
Comment: Assume X is a path connected space with a nonempty open and closed subset a such
that $a\neq X$  Let γ : [0, 1] → X be a path on X such that γ(0) = x and γ(1) = y where
x ∈ X \ a and y ∈ a. Because of the continuity of γ, $γ^{-1}$(a) is an open and closed subset of [0, 1]. But because [0, 1] is a connected space, the only open and closed sets are either the empty set or [0, 1], so $γ^{-1}$(a) must be all of [0, 1]. Therefore a = X, i.e., X is a connected space.
Comment: Would the above solution be correct then?
Answer: Consider the function $f:[0,1]\rightarrow\{a,b\}$ such that $f(x)=a$ iff $x\in[0,\epsilon)$ for some $0<\epsilon<1$.
Comment: @DataD96 $\frac{x-a}{b-a}$ is not a well-defined point of $\{a,b\}=X$.....
Comment: okay, how about this solution then. Given x, y ∈ X and a, b ∈ R, a < b. Now X is a pathwise connected space implies there exists a continuous function say $f_{1}$ : [0, 1] → X such that $f_{1}$(0) = x and $f_{1}$(1) = y. Now let $f_{2}$(x) = x−a/b−a, x ∈ [a, b]. Now $f_{2}$ is a continuous function such that $f_{2}$(a) = 0 and f2(b) = 1. Hence g : $f_{1}$ ◦ $f_{2}$ : [a, b] → X is a continuous function such that g(a) = $f_{1}$($f_{2}$(a)) = $f_{1}$(0) = x and g(b) = $f_{1}$($f_{2}$(b)) = $f_{1}$(1) = y.


Probability of $k \in \{1, 2, \dots, n\}$ people sharing the same birthday in a room of $n$ people

Question: In a room of $n$ people, what is the probability that at least $k \in \{1, 2, \dots, n\}$ people all share a common birthday?
For example, what is the probability that at least 5 people all share the same birthday in a room of a 1000 people.
I have found a formula on Wikipedia for solving this problem when $k = 2$ but I would like to be able to solve for $n > 365$ and $k > 2$.
I know that $p(k \text{ people share the same birthday}) = 1$ for $k = \lceil\frac{n}{365}\rceil$ but I don't know how to solve beyond this point. I assume there are $365^n$ different ways the birthdays of $n$ people can be distributed within a year hence I am struggling to reach an answer using a combinatorial approach.
I have researched this problem online but most answers stop at the probability of one or more shared birthday in a group of 60 people max.
Answer: Unfortunately the reason no one wants to do this calculation is that it's messy. This is $1$ minus the probability that every birthday is shared by at most $k-1$ people. To compute this, let $f_{n, k}$ be the number of ways $n$ people can have birthdays such that every birthday is shared by at most $k-1$ people, so that we want to compute $1 - \frac{f_{n, k}}{365^n}$. General results imply that $f$ has an exponential generating function
$$\boxed{ \sum_n f_{n, k} \frac{t^n}{n!} = \left( \sum_{i=0}^{k-1} \frac{t^i}{i!} \right)^{365} }.$$
For example, to find the probability for $k = 5, n = 1000$ as you ask for we need the coefficient of $t^{1000}$ in $\left( 1 + t + \frac{t^2}{2} + \frac{t^3}{6} + \frac{t^4}{24} \right)^{365}$. As far as I know, this is about as good as it gets for the exact count. You should be able to expand this out in a good computer algebra system but it's a little too big for WolframAlpha.
So instead of asking for the exact count let's ask for an approximation. There is a Poisson approximation available here, generalizing the one discussed on Wikipedia: the number of people having a given birthday is approximately Poisson with mean $\frac{n}{365}$, and moreover for different birthdays these Poisson random variables are approximately independent. This means that the probability that every birthday is shared by at most $k-1$ people is approximately
$$\frac{f_{n,k}}{365^n} \approx \left( \sum_{i=0}^{k-1} \frac{ \left( \frac{n}{365} \right)^i}{i!} e^{- \frac{n}{365}} \right)^{365} = \boxed{ e^{-n} \left( \sum_{i=0}^{k-1} \frac{ n^i}{365^i i!} \right)^{365} }.$$
This is actually much better; in particular for $k = 5, n = 1000$ this is now a computation we can easily ask WolframAlpha to do. It gives
$$\frac{f_{1000, 5}}{365^{1000}} \approx e^{-1000} \left( 1 + \frac{1000}{365} + \frac{1000^2}{365^2 2!} + \frac{1000^3}{365^3 3!} + \frac{1000^4}{365^4 4!} \right)^{365} \approx \boxed{ 3 \times 10^{-25} }$$
so the probability that in a group of $1000$ people at least $5$ share the same birthday is very close to $1$.
To get a better sense of how these numbers behave we could ask: for a given $n$, such as $n = 1000$, about what value of $k$ do we need for this probability to no longer be very small like this? In other words, what can we say about the distribution of the largest cluster of people sharing the same birthday? In the Poisson approximation this is equivalent to asking: what is the distribution of the maximum of $365$ iid Poisson random variables with mean $\frac{n}{365}$? It's known that this distribution clusters closely around
$$\frac{\log 365}{W \left( \frac{\log 365}{e \frac{n}{365} } \right)}$$
where $W$ is the Lambert W function, which is complicated-looking but for large $n$ grows roughly like $\frac{en}{365}$ and in any case for $n = 1000$ evaluates to about $\boxed{12}$. This could be tested experimentally by generating some random birthday distributions, as well as by substituting $k = 10, 11, 12, 13, 14$ into the Poisson approximation above.
Edit: An alternative argument which produces a rigorous upper bound starting from the generating function is the following. Write $p(t) = \sum_{i=0}^{k-1} \frac{t^i}{i!}$. Applying the saddle point bound to the generating function gives
$$\frac{f_{n, k}}{n!} \le \frac{p(r)^{365}}{r^n}$$
for any $r > 0$. The optimal value of $r$ is obtained by setting the logarithmic derivative of the RHS to zero; this gives $365 \frac{p'(r)}{p(r)} - \frac{n}{r} = 0$, which is complicated, but if we're willing to approximate $\frac{p'(r)}{p(r)} \approx 1$ then this gives $r \approx \frac{n}{365}$ which is much easier to work with. We get a bound
$$\frac{f_{n, k}}{n!} \le \frac{\left( \sum_{i=0}^{k-1} \frac{ \left( \frac{n}{365} \right)^i}{i!} \right)^{365}}{ \left( \frac{n}{365} \right)^n }$$
and rearranging this, then using the crude Stirling inequality $n! \le en \left( \frac{n}{e} \right)^n$, we get a rigorous upper bound
$$\boxed{ \frac{f_{n, k}}{365^n} \le \frac{n}{e^{n-1}} \left( \sum_{i=0}^{k-1} \frac{n^i}{365^i i!} \right)^{365} }$$
which is very similar to the above bound, and we could improve it a bit by using a more accurate form of Stirling's approximation and
a bit more by estimating $r$ more accurately, and a bit more by using a more precise version of the saddle point bound. In any case this bound gives, similar to the above,
$$\frac{f_{1000, 5}}{365^{1000}} \le \frac{1000}{e^{999}} \left( 1 + \frac{1000}{365} + \frac{1000^2}{365^2 2!} + \frac{1000^3}{365^3 3!} + \frac{1000^4}{365^4 4!} \right)^{365} \approx \boxed{ 9 \times 10^{-22} }.$$
Answer: if $n>365$ then by pigeonhole principle at least 2 share the same birthday.
pigeonholes = 365, pigeons = $n$.
in fact if $n=365k+1$ then at least $k+1$ people share the same birthday.
for $n\leq 365$ use the probability that no one was born on the same day.
so we have:
$q=1/365*1/364*...*1/(365-n+1)$
then $p=1-q$ is the probability for at least 2 people sharing same birthday.
Comment: This is not an answer to the OP's question.


Mysqldump causes "Too many connections"

Question: A scheduled backup using mysqldump on one of our databases is causing Too many connections. The database is of both InnoDB and MyISAM tables with size of around 500Mb.
The Too many connections appears for about 2-3 minutes
We understand that mysqldump locks the tables and causes all other queries and connections to pile up and jam the mysql server.
We need frequent backups and we cannot afford server downtime or putting websites in maintenance mode while doing it. Our websites are global and traffic is high all the time so its hard to find a moment for backups.
How can we avoid downtime during backups?Is there maybe a way to use mysqldump in way that it will not lock all tables at the same time?Is there an alternative to backing up with mysqldump?
Comment: 2-3 minutes for 500MB sounds like you are dumping directly over the network.  You might get a shorter lock time if you dump to your local disk(s) and then transfer over the network after the tables are unlocked.  You might also get *worse* lock times if you are using slow disks or the contention causes lots of little delays.  @faker's suggestion of XtraBackup will only lock for the MyISAM tables which will also help.
Comment: And XtraBackup will only get a write lock on MyISAM tables instead of a read lock like mysqldump uses (IIRC)
Answer: 1) Setup a second server, replicate your DB to it, backup from there
This might not be a good solution if you have lots of changes on your master server, since replication on the slave is single threaded.
2) Use http://www.percona.com/doc/percona-xtrabackup/
Or as always, consult the official documentation which outlines other alternatives:
http://dev.mysql.com/doc/refman/5.1/en/backup-methods.html
Comment: Thank you, faker! We will research and test xtrabackup as you suggested. A second server would not give us the best results since the data is very dynamic and changes often.
Answer: At first, try to backup table by table or DB by DB - do not lock everything.
Increase max_connections, try to use connection limit otherwise:
http://dev.mysql.com/doc/refman/5.5/en/user-resources.html
I'm not sure it will take too much of memory for increased max_connections.
If you are using MyISAM - there is no other way for backup.
With InnoDB or XTraDB - no problems.
http://www.innodb.com/doc/hot_backup/manual.html
Comment: Xtrabackup, mysqlhotcopy, MySQL Enterprise Backup and file system snapshots are all possible while using MyISAM
Comment: Thank you, GioMac, we did some experiments with max_connections and it seems its a good solution although maybe just a temporary one. DB by Db and Xtrabackup are our next candidates
Comment: `SET GLOBAL max_connections = 2500;` seems to have helped in my case.
Answer:
Is there an alternative to backing up with mysqldump?

How do you plan on using them? If you want quick and cheap incremental backups, I'd just use rsync (or rsnapshot which uses rsync to keep multiple concurrent copies without occupying too much extra disk space) to backup the /var/lib/mysql (or wherever the datafiles may be).
I am assuming you won't really use them to replicate/parse or otherwise interpret, but just in case your server(s) fail you want to do (essentially) a full-disk restore. This also makes such a restore incredibly fast (but rigid, you restore everything or nothing really) since its a standard copy operation. At best, you would use this as often as you want, with another backup mechanism (say a mysqldump at a off-peak time) to ensure you're never without an updated parsable dump.
Comment: If MySQL is running while you rsync the files, you might end up with a corrupted backup
Comment: A snapshot-aware filesystem is a much better way to manage this sort of backup.  You can lock all tables, create the snapshot and unlock in a few seconds.
Answer: Your mix of myisam and innodb-tables complicates matters somewhat. If you can convert the myisam-tables to innodb-tables you could run mysqldump inside a transaction. This way you would get a consistent backup without the need for a table/database lock.
Problems may be:

Performance: Innodb could be slower than myisam for you application
Features: If you use features only present with myisam

Mysqldump causes "Too many connections"


$\lim_{(x,y)\to(0,0)}\frac{y^2}{x}=0$ in $D:\{\forall(x,y)\in\Bbb R^2 : |y|\le x \le1\}$?

Question: I need to prove that the following function
$$f(x,y) = \frac{y^2}{x}$$
$$f(x,y) =
\left\{
 \begin{array}{ll}
   \frac{y^2}{x}  & \mbox{if } x \ne 0 \\
  0 & \mbox{if } x = 0
 \end{array}
\right.$$
Is continuous in $D:\{\forall(x,y)\in\Bbb R^2 : |y|\le x \le1\}$.
I see that for $x\ne0$ the fraction is well defined, so I study the behavior of the function when I approach the origin in $D$.
$$\lim_{(x,y)\to(0,0)}\frac{y^2}{x}=0$$
I see from $D$ that $0\le x \le 1$, so by the Squeeze Theorem I can write
$$0\le|\frac{y^2}{x}|\le \frac{|y^2|}{x}\le\dots$$
Here I noticed that
$$|y|\le x \le1$$
$$|y|^2\le x^2 \le1$$
So I can continue the inequalities
$$\dots\frac{x^2}{x}\leq x$$
To conclude that
$$\lim_{(x,y)\to(0,0)}\frac{y^2}{x}=0\le\lim_{x \to 0}x=0$$
Hence $f(x,y)$ is continuous in $D$.
I'm not sure about the inequality part, can someone help me understand if this is the correct approach?
Comment: What you have done is correct but the last line can be written more transparently  as $ 0\leq f(x,y) \leq x$ on $D$ so the conclusion follows by Sqeeze Theorem.
Answer: Similar to your previous question, I would split the analysis into cases.
Case 1: If $x=0$, then $f(x,y)=0$ by definition.
Case 2: If $x\neq0$ and $y= 0$, then
$$f(x,y)=\lim_{(x,y) \to (0,0)} \frac{y^2}{x}$$
where $f(x,y)\to 0$ as $y= 0$.
Case 3: If $x\neq 0$ and $y\neq 0$, then
$$f(x,y)=\lim_{(x,y) \to (0,0)} \frac{y^2}{x}$$
given that
$$0 \leq|y|\le x \leq 1$$
you can conclude that
$$0 \leq \frac{y^2}{x} \leq \frac{x^2}{x}=x$$
so that
$$f(x,y)=\lim_{(x,y) \to (0,0)} \frac{y^2}{x} \leq \lim_{(x,y) \to (0,0)} x$$
then, by the Squeeze theorem, we have that
$$\lim_{(x,y) \to (0,0)} 0 \leq \lim_{(x,y) \to (0,0)} \frac{y^2}{x} \leq \lim_{(x,y) \to (0,0)} x$$
and therefore
$$\lim_{(x,y) \to (0,0)} \frac{y^2}{x}=0$$
So, the function $f(x,y)$ is continuous in $D$.


Não apareço como colaboradora em um projeto que faço parte no Git

Question: Estou realizando um trabalho para uma disciplina com meus colegas. Consigo fazer pull e commits, entretanto,eu não apareço como contribuidora do projeto, não mostrando meu gráfico.Meus colegas só conseguem ver que eu fiz commits. Eu apareço como uma pessoa do repositório, mas não apareço como contribuidora. Consigo visualizar tudo que meus colegas fazem. Quando o projeto iniciou eu aceitei o convite para fazer parte do projeto. O que pode ta rolando?
Comment: Vocês já tentaram ir nas configurações do projeto, em contribuidores/colaboradores e adicionar um novo contribuidor/colaborador?
Comment: Já tentei, mas também continua dando errado.
Answer: Realmente você faz parte dos commits. Pede para realizarem o processo de inserção de colaborador novamente com o seu nome do GitHub. Realize a confirmação e pelo e-mail, e verifique novamente se foi adicionada como colaboradora. Basicamente é um processo simples e não vejo como isso daria errado.

Verifica também se sua conta do GitHub está confirmada.
Comment: Bruno, fiz o que me recomendastes, mas continuou com o mesmo problema.
Answer: O GitHub identifica pelo e-mail do autor do commit. Rode no seu terminal:
git config --list

Veja se no output desse comando tem o seu e-mail, e qual está configurado. Esse precisa ser o mesmo e-mail que está no seu cadastro do GitHub. Se não for, você pode adicionar um e-mail à sua conta do GitHub.
Se infelizmente você não encontrou seu e-mail no output do comando, você fez os commits sem um e-mail específico. Para corrigir isso você precisará fazer um rebase --interactive alterando todos os commits, adicionando seu e-mail ao autor do commit, e depois fazer um push --force-with-lease. Não recomendo que faça isso, pois tem grandes chances de dar errado, ainda mais por fazer um push forçado.
Comment: O `--force-with-lease` só faz o `push` se no remote não houver nenhum commit depois do histórico do repo local. Entendeu +/-?
Comment: O que é esse `--force-with-lease`? Eu só conhecia o `-f`/`--force` ; se achar digno, posso abrir uma questão específica sobre isso
Comment: entendi perfeitamente. Muito grato


run full php-script in ajax/jquery

Question: Sorry for my bad english. I'm trying to run a PHP function through an ajax script. The PHP script should run as a FULL NORMAL php script. My idea is to run a recaptcha by a Submit button WITHOUT refreshing the page. That is working, but I found no way to run a normal php script after that. Here is the part of my script.
php:
if( isset( $_REQUEST['startattack'] )){
    $secret="********************";
    $response=$_POST["g-recaptcha-response"];
    $verify=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");

    $captcha_success=json_decode($verify);

    if ($captcha_success->success==false) {
        echo "";
    } else if ($captcha_success->success==true) {
        echo "";
    }
}

html:
<form method='post' id="myform">

    <button type="submit" id="startattack" name="startattack" onclick="mycall()" class="btn btn-attack">Start Attack</button>
</form>

ajax:

I want to check the recaptcha here. If correct, it should echo correct in PHP and I want to add feature later. The same with the false captcha.
Answer: I think you can simplify things a bit. You don't return the response in the Ajax is your main problem.
PHP:
Just echo the returned json from the recaptcha (although I have no idea where you get the g-recaptcha-response key/value, you are not sending it anywhere).
if(isset( $_POST['startattack'] )){
    $secret   = "********************";
    // I have added a key/value in the ajax called "sitekey",
    // this might be what you are trying to retrieve?
    $response = $_POST["g-recaptcha-response"];
    echo file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
    exit;
}

AJAX:
I think since the return from the recaptcha is json anyway, just echo it and pick it up on this side:
$(function () {
    $('button').bind('click', function (event) {
        var statusBlock =   $('#status');
        statusBlock.text('button was submitted');
        $.ajax({
            type: 'POST',
            url: 'post.php',
            data: {
                // Not sure if you are trying to pass this key or not...
                "sitekey":$('.g-recaptcha').data('sitekey'),
                "startattack":true
            },
            success: function (response) {
                var decode    = JSON.parse(response);
                var alertMsg  = (decode.success)? 'Success' : 'Failed';
                statusBlock.text('');
                alert(alertMsg);
            }
        });
        // using this page stop being refreshing
        event.preventDefault();
    });
});

Form:
Leave a spot to post the submit status so it doesn't interfere with the return alert dialog window.
<form method='post' id="myform">

    <button type="submit" id="startattack" name="startattack" onclick="mycall()" class="btn btn-attack">Start Attack</button>
</form>

run full php-script in ajax/jquery


Setar valor com voz em um editText

Question: Quando aperto o botao falo o nome por exemplo potencia ele coloca o autofocus no editText, porem quando ele esta com o focus no edittext deveria apertar o botao e dizer o valor a ser escrito naquele campo, alguém me ajuda por favor.
essa é a mainActivity.java
private final int REQ_CODE_SPECH_INPUT = 100;
EditText potencia;
EditText tensao;
EditText corrente;
Button calcular;
View v;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
private void promptSpeechInput(){
    Intent it = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    it.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    it.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    it.putExtra(RecognizerIntent.EXTRA_PROMPT, "Diga Algo");
    try{
        startActivityForResult(it,REQ_CODE_SPECH_INPUT);
    }catch (ActivityNotFoundException a){
    }
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode,resultCode,data);
    switch (requestCode) {
        case REQ_CODE_SPECH_INPUT: {
        if(resultCode == RESULT_OK && data != null){
                ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                String mensagem = result.get(0);
                potencia = findViewById(R.id.potencia);
                tensao = findViewById(R.id.tensao);
                corrente = findViewById(R.id.corrente);
                calcular = findViewById(R.id.calcular);
                v = findViewById(R.id.view);
                if(mensagem.equals("potência")){
                    potencia.requestFocus();
                }else
                if(mensagem.equals("tensão")){
                    tensao.requestFocus();
                }else
                if(mensagem.equals("corrente")){
                    corrente.requestFocus();
                }else
                if(mensagem.equals("calcular")){
                }
            }
        }
    }
}
public void Falar(View view) {
    promptSpeechInput();
}

}
essa é a activit.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="79dp"
        android:layout_height="wrap_content"

        android:text="Potência" />

    <EditText
        android:id="@+id/potencia"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="79dp"
        android:layout_height="wrap_content"

        android:text="Tensão" />

    <EditText
        android:id="@+id/tensao"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="79dp"
        android:layout_height="wrap_content"

        android:text="Corrente" />

    <EditText
        android:id="@+id/corrente"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="79dp"
        android:layout_height="wrap_content"

        android:text="Resistência" />

    <EditText
        android:id="@+id/resistencia"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</LinearLayout>

<Button
    android:id="@+id/calcular"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Microfone"
    android:onClick="Falar"
    />

Comment: Não ficou muito claro pra mim, mas você deseja que quando o `EditText` ganhe o foco o `Speech Recognition` seja ativado?
Answer:
Esse trecho chama o onActivityResult()
  startActivityForResult(it,REQ_CODE_SPECH_INPUT);

Eu comentei as linhas que foram adicionadas e expliquei a logica delas dentro do codigo.
private final int REQ_CODE_SPECH_INPUT = 100;
private String textViewFocus = ""; //Adicionei essa linha pra voce saber quem esta com Focus quando chamar novamente o onActivityResult()
EditText potencia;
EditText tensao;
EditText corrente;
Button calcular;
View v;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}
private void promptSpeechInput(){
    Intent it = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    it.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    it.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    it.putExtra(RecognizerIntent.EXTRA_PROMPT, "Diga Algo");
    try{
        startActivityForResult(it,REQ_CODE_SPECH_INPUT);
    }catch (ActivityNotFoundException a){
    }
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode,resultCode,data);
    switch (requestCode) {
        case REQ_CODE_SPECH_INPUT: {
        if(resultCode == RESULT_OK && data != null)  {
                ArrayList<String> result =
                data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                String mensagem = result.get(0);
                potencia = findViewById(R.id.potencia);
                tensao = findViewById(R.id.tensao);
                corrente = findViewById(R.id.corrente);
                calcular = findViewById(R.id.calcular);
                v = findViewById(R.id.view);
                if(mensagem.equals("potência")){
                    potencia.requestFocus();
                    if(potencia.hasFocus()) {
                        promptSpeechInput()
                        textViewFocus = "potencia";
                    } //Caso esteja com Focus, chama o metodo de Voz novamente.
                }
                else if(mensagem.equals("tensão")){
                    tensao.requestFocus();
                    if(mensagem.hasFocus()) {
                        promptSpeechInput()
                        textViewFocus = "tensão";
                    }
                }
                else if(mensagem.equals("corrente")){
                    corrente.requestFocus();
                    if(corrente.hasFocus()) {
                        promptSpeechInput()
                        textViewFocus = "corrente";
                    }
                }
                else if(mensagem.equals("calcular")){
                    if(calcular.hasFocus()) {
                        promptSpeechInput()
                        textViewFocus = "calcular";
                    }
                }else {
                    //Essa ultima condicao vai verificar se algo diferente dos textos acima foi dito e entao inserir no textView q tem Focus True
                    switch (textViewFocus) {
                        case "potencia" :
                        potencia.setText(mensagem); // Fiz so o exemplo de potencia pra voce testar, caso de certo e so replicar
                        break;
                    }
                }

                }

            }
        }
    }
}
public void Falar(View view) {
    promptSpeechInput();
}

Setar valor com voz em um editText


I have a question and a solution for a Pigeonhole Principle question. Can you explain to me why?

Question: I was quite sure that I have understood the pigeonhole principle, but this question does not make sense. Or does it?
The question:
A drawer contains $5$ blue socks, $7$ red socks and $6$ black socks. Socks are
randomly removed one by one and placed on a table.
(a) What is the least number of socks that need to be removed to ensure that there are two socks of the same colour on the table?
(b) What is the least number of socks that need to be removed to ensure that there are three socks of the same colour on the table?
The solution:
This is the Pigeonhole Principle with the socks as pigeons and the colours as pigeonholes. There are $3$ colours. (a) $4$. (b) $7$.
Since the socks are chosen randomly and there are plenty of socks so that you have a chance of choosing $2$ socks of the same colour so shouldn't it be $2$ for (a) and $3$ for (b)?
Please tell me where I have gone wrong.
Comment: This isn't a question about probability.  It asks you to *guarantee* that you have a matching pair.  $4$ will clearly work for $(a)$ since you can't draw $4$ distinct colors.  $3$ won't work since you could get one blue, one red, and one black.
Comment: umm if you draw 6 socks, it won't work because you could get 2blue, 2 red and 2 black so when you draw 2+2+2+1=7 it works?
Comment: Sorry I see what you mean now
Comment: So, how does it work for 3 socks of the same colour?
Comment: Well, try to solve that yourself.
Comment: That's all it takes.  Note that the actual number of socks of each color really doesn't matter much here.  It matters that there are at least two of each, but that's it.
Comment: so if n socks, it would be always 3n + 1?
Answer: For point (a):If you are lucky you can get 2 socks of the same color by picking just 2 socks.But thats not the question. The question asks the minimum number of tries when you are not lucky in order to ensure that you will get 2 socks of the same color .In that case you will need to pick 4 socks in case you are not lucky and pick 3 different colors in the first 3 tries.Then you are sure that by picking the fourth sock it will be of one of the 3 different colors you have picked before so the answer is 4
For point (b) following the same reasoning if we are unlucky to pick 3 pairs of socks each pair having a different color then the seventh pick will belong to one of the 3 colors you picked before so it is sure that you will get 3 socks of the same color therefore the answer is 7


Problem with Panel Data

Question: I am having a problem with estimation of a model using panel data in Stata. The dataset consists of 12 cross sectional units, each of these units has around 950 time periods (the panel is unbalanced). The issue is that usage of certain set of explanatory variables causes the value of "sigma_u" to be 0. Specifically, this problem arises if I add either three seasonal dummy variables or 4 weekday dummy variables to 9 other "normal" (non-dummy) variables. However, if I only use 8 of the normal variables, then the value of "sigma_u" is NOT 0 even if I add the seasonal dummy variables or the weekday ones (but not both of these groups). My question is: is "sigma_u = 0" a problem in the first place? If I undestand it corectly, RE estimation "only" degenerates to Pooled OLS - but if this happens, then there is probably something fundamentally wrong with the model's specification - maybe collinearity?
Comment: What are "normal" variables? Can you give an example?
Comment: Continuous variables like GDP or stock return.
Comment: What are the "cross sectional" units? It's not something to do with 12 months?
Comment: By "cross-sectional units" I meant number of panels, i.e. what Stata calls "Number of groups" when I run -xtreg-.
Answer: You must be exhausting the between-panel space with your explanatory variables. I don't really know if there's any good collinearity-type diagnostics to detect that; you could try generating white noise and running a regression with that as the dependent variable to see if the issue with the regressors or with any weird patterns of variability in your dependent variable. Keep in mind that the traditional econometric asymptotics for panel data is $N \to \infty, T$ is small or fixed, and you have a flip of that.
Comment: So, generally, if the structure of the dataset is opposite to the "traditional econometric asymptotics", i.e. $N$ is relatively small compared to $T$, is it more justified to use e.g. fixed effects?
Comment: In the usual economic setting; when that is the case, you have no idea what is going on... The statistics have (usually) no known distribution, and things gets very complicated.

Problem with Panel Data