text:
Q: Inconsistent plot_ly colorscale I've made two heatmaps in R using plot_ly but can't get the color scales to map consistently, even by setting the same zmin and zmax for both. This seems like it should be relatively simple and yet there's no way to pass a zcenter or zmid or the likes, and no way to specify breaks to make them consistent. Am I missing something or can it not be done in R?
My plot_ly code is below, with the resultant plots, as you can see, even though zmin = -10000 and zmax = 10000 for both plots, 0 corresponds to white for the first picture but to pink for the second and I can't for the life of me figure out why it's not consistent.
first picture:
plot_ly(z = data.matrix(tines.pre1[,-1]), type = "heatmap", transpose = TRUE, zauto = FALSE, zmin = -10000, zmax = 10000, colors = c("blue", "white", "red"))

second picture:
plot_ly(z = data.matrix(tines.pre2[,-1]), type = "heatmap", transpose = TRUE, zauto = FALSE, zmin = -10000, zmax = 10000, colors = c("blue", "white", "red"))

Here's the data that produced the second picture:
`pre2 = matrix(c(1,1147,-118,124,937,591,168,19,63,-47,626,680,1309,529,1386,53,60,77,-358,103,651,4054,679,620,484,0,311,1985,-244,-16,416,159,1562,145,181,666,1225,936,2968,324,676,196,597,412,609,1159,-187,439,-193,657,995,2178,637,-534,14,100,279,438,-39,390,348,916,100,-171,91,-35,19,270,1220,2205,933,170,181,91,258,-201,1258,250,1730,472,389,346,
                2,675,-29,29,404,119,-3,63,4,-593,-201,175,40,438,844,92,-19,187,75,481,4,1617,246,1248,203,-163,344,1720,-319,79,234,-702,491,-43,-135,491,394,627,2062,748,375,-194,1060,-387,695,-244,201,-42,-64,231,655,1438,128,-533,93,-88,114,253,204,80,317,-211,181,-82,-140,-107,8,39,477,950,752,340,-412,-684,578,218,675,-86,390,152,-74,73,
                3,755,37,-332,83,50,-165,67,46,-252,3,-185,464,251,577,-181,-211,-198,-261,-129,51,1056,586,169,-19,-61,429,1219,-415,67,46,-171,245,112,-91,860,-356,164,1829,286,286,-513,-73,220,34,-475,-143,-483,-334,-3,-251,2195,-279,-120,6,130,143,84,-118,148,32,-292,-250,-294,-87,-282,-131,-416,138,282,363,-20,-1060,-173,53,305,566,-157,-302,-6,-375,283,
                4,404,-71,-119,-124,166,-111,164,-20,-556,-471,84,-144,11,-23,-162,-304,74,-27,835,-333,58,292,472,-111,163,192,624,-221,22,237,-513,-44,-10,-204,856,235,65,625,61,-68,7,415,138,-868,152,-65,63,115,36,-275,1,280,-531,330,-68,-75,217,-88,-77,-234,-143,96,-354,-80,-48,37,-355,577,-273,-320,48,-410,15,-65,-433,-1094,89,241,-129,63,898,
                5,22,494,53,337,111,313,213,-185,68,108,58,-134,16,66,-75,74,131,-67,-753,-125,66,202,-175,-344,-9,-142,260,-169,-145,-227,-431,97,-302,-120,-152,638,-24,-209,151,96,-71,148,257,-368,61,-53,463,106,-19,63,-840,-554,-537,-95,-113,26,-17,84,-24,-192,363,-130,22,75,101,-131,217,126,-39,-127,-223,56,212,95,373,-1195,-124,11,-151,221,-24,
                6,-476,-45,146,206,-162,-227,-143,290,234,399,-503,1088,116,-110,-104,-105,-81,-61,-200,145,-15,-474,171,-9,-276,1,-434,96,61,-125,368,30,86,25,-772,-60,-56,-381,-226,6,-55,137,129,715,-70,347,-187,-519,-5,231,-932,-31,-137,-599,108,-23,0,61,154,-9,-439,-501,382,42,-65,10,507,-460,-122,279,-42,-466,299,-145,172,564,-216,152,74,-57,24,
                7,-499,-64,123,-346,34,186,-40,45,-104,-499,15,-342,127,-89,140,284,-77,107,-278,-5,-28,8,12,3,74,308,-422,-160,-84,-301,790,-514,81,107,-94,-632,-245,-25,1,101,134,-328,-399,563,169,-83,-394,157,105,95,442,16,571,379,56,3,-196,35,57,337,-11,506,11,-173,15,54,-130,-248,9,2,-104,382,-178,-245,-81,553,125,-119,217,-249,-645,
                8,549,-315,-202,-73,-149,-161,-194,-129,358,463,346,-469,-271,155,200,50,-47,48,396,319,-81,-28,-481,461,48,-359,-28,454,146,416,-213,431,145,192,162,-181,260,-10,13,-134,-15,-373,-124,-41,-312,-146,55,142,-117,-114,1329,289,633,-16,17,70,-4,-91,-110,98,231,29,-60,135,-2,30,-240,5,425,166,321,439,-348,360,-30,1172,126,-285,-11,21,-253,
                9,611,292,45,230,-25,100,-127,56,-159,310,754,312,250,-471,96,-131,72,176,288,-231,639,269,-544,343,368,139,-166,456,-162,201,-409,126,234,260,766,-499,-422,151,-85,128,263,-5,-168,-613,-1108,-262,-3,-143,92,-26,520,-184,54,296,210,-103,-9,-90,-20,-256,241,563,50,141,290,69,-502,155,1264,272,259,-138,-371,672,-247,1007,-159,112,154,76,-163,
                10,348,76,-430,280,212,90,-163,-77,-171,552,626,431,-65,233,-159,-163,180,-171,40,-256,999,460,-597,-145,395,113,94,-28,218,-75,-763,-182,80,-74,-151,-54,-264,205,-666,302,379,-347,-258,-879,-958,-167,-420,-459,285,130,1053,-149,91,173,264,4,-89,-230,161,-106,-48,175,-444,-95,-74,-25,-485,532,1861,-313,-229,-371,39,649,-279,-4,-345,97,-67,182,165,
                11,179,366,-14,-524,-105,-97,-92,-253,-494,-219,2111,-591,-136,442,-290,-120,342,-104,-61,-200,438,3444,3183,4069,-279,-3,-507,-857,24,-18,-403,101,1202,1057,1499,-477,246,-213,-1216,554,40,-539,-94,-1891,-428,-622,208,-405,-701,1204,1040,-186,-8,8,137,19,-53,-53,-50,-225,-417,-241,-538,-1,-509,-89,-575,374,2212,2121,3563,140,2590,2329,-15,-124,420,-184,-162,-145,314,
                12,1936,554,229,761,610,385,-105,-388,-740,-1035,2246,-2387,-590,878,178,166,628,75,880,-80,4286,2960,2797,4244,260,-207,-222,-701,207,265,371,126,2343,1477,3083,1253,353,1025,-2578,35,-501,-1762,-938,-3281,-3286,389,-34,-954,-311,866,-1411,-981,-674,-209,25,-62,-163,-84,-121,466,-1638,-1446,-816,87,-132,-63,535,-397,1847,1154,3508,-2404,1547,2961,2245,-781,3338,119,-1200,166,1029,
                13,660,308,-135,67,181,129,-244,-432,-1101,-2582,1695,-4415,-441,105,-584,200,892,-199,-293,-603,4282,1630,1662,2808,160,-173,-818,-620,2,-340,9,-628,1560,1296,3646,1124,269,462,-2778,-132,-638,-3190,-1672,-4430,-6093,215,-287,-1563,-816,1289,-1208,-1055,-825,-266,107,-156,-480,16,-122,-198,-2583,-1281,-1284,23,9,86,237,-1227,1050,642,2920,-3288,372,3702,2900,-572,3574,-255,-2288,485,1133,
                14,-227,345,-809,-795,-29,-93,-654,-408,-1151,-2619,518,-2625,-1027,299,-403,394,1295,416,612,-823,1951,82,2367,1430,-277,-600,-1150,-564,-80,-242,332,-3011,1155,249,2914,-938,-352,-2181,-2821,-45,-189,-3795,-1274,-4192,-5830,3,-577,-1817,-1148,1096,-2127,-1683,-444,88,-6,-258,-800,-291,-110,-516,-2953,-1624,-1237,-98,-676,-158,-63,-2060,-859,-13,863,-3650,-258,2361,2272,829,4159,-1616,-2631,540,402,
                15,-1917,46,-27,-740,-436,28,-356,-733,-1042,-2476,577,-4315,-884,-35,-730,296,1056,-62,387,-1499,1275,-36,2520,168,-387,-24,-700,163,137,-338,817,-2314,600,595,2024,-442,-311,-1911,-2899,-95,-297,-3679,-1776,-4095,-5756,-358,-641,-2599,-1783,120,-1573,-1647,68,313,-59,-235,-376,2,-29,-95,-2170,-1327,-1187,-114,-203,-96,-6,-1902,-1371,-215,-150,-4831,-296,1706,2555,310,4994,-1379,-2581,190,-199,
                16,-2953,-180,-504,-1380,-440,-111,-980,-644,-1079,-2445,518,-3652,-949,-405,-645,17,420,-273,26,-1022,430,-331,2185,171,-481,-208,-1013,-387,-59,100,372,-2644,401,250,1776,-1096,-373,-1789,-1651,-158,-451,-3265,-1457,-3886,-5053,-760,-676,-2179,-1512,1522,-2024,-1462,-558,520,222,-161,-690,-203,45,-746,-1354,-1138,-1334,-151,-527,-167,-12,-1970,-1296,281,88,-3943,-233,1651,1343,545,3569,-2148,-1949,-682,-577,
                17,-2226,149,0,-2010,-380,91,-950,-163,-999,-2978,-449,-3630,-1050,-205,-741,-131,712,-138,-102,-1505,-513,-620,3642,399,-342,-7,-953,485,-32,-386,445,-2635,205,511,972,-1116,-540,-3017,-3614,-235,-325,-3273,-1758,-4311,-5930,-379,-485,-2472,-1419,986,-2593,-1583,-1047,194,-37,-165,-772,-213,398,-498,-2002,-876,-985,-156,-691,-197,616,-2550,-1637,-360,-572,-4339,-1174,1059,1625,3473,5172,-1634,-2004,-685,-286,
                18,-3373,16,-113,-638,-389,-73,-450,-265,-799,-2237,319,-3083,-840,-98,-731,-325,469,-615,-324,-1323,-965,-747,3102,-252,-478,8,-982,-404,-233,-512,-181,-2683,22,333,1656,-1340,651,-2538,-3222,873,-569,-3039,-1221,-4301,-4715,-162,-938,-1931,-1542,1651,-1637,-1235,142,602,-56,-315,-457,-236,91,-507,-857,-625,-1247,-329,-767,-121,1538,-2130,-205,132,-255,-4083,-1338,1677,422,4085,2748,-2523,-1949,-948,-706,
                19,-1826,377,-152,-873,-79,118,-653,-283,-946,-1780,-83,-3504,-637,-113,-568,-61,381,-106,-850,-1298,333,-173,3623,-109,-776,-398,-1199,-587,148,-365,-760,-2660,260,316,1294,-1209,1379,-2138,-2566,1207,-442,-4097,-1596,-4826,-4702,-192,-295,-2410,-1193,1495,-1561,-1173,-403,653,22,-192,-451,-174,-116,-460,-585,-899,-1169,-59,-28,-115,1347,-325,794,48,225,-3962,-915,1681,-56,8588,1604,-1517,-1954,-938,-254,
                20,-1394,-90,311,-673,-406,73,-265,263,-573,-1246,169,-1609,-597,-132,-323,-360,521,-215,-725,-836,518,-93,1969,17,-586,-656,-1123,-184,48,-293,-241,-1772,122,180,1386,-1112,244,-2057,-2364,377,-96,-3112,-1013,-3781,-4494,-546,-632,-2067,-1266,763,-1527,-752,-605,217,61,-126,-345,-423,53,-526,-1173,-700,-1020,7,-426,-36,768,-1535,438,-150,-449,-3168,-1260,149,-626,9486,1809,-651,-1486,-394,-182,
                21,-1357,-262,-313,-929,-92,-427,-659,27,-435,-1487,-62,-1073,-440,-425,-415,-301,-111,-251,-476,-1046,-638,-791,3023,135,-293,108,-1239,-598,-46,-542,-180,-1635,142,-86,1141,-1429,456,-2925,-2284,298,-612,-2566,-643,-2982,-3858,-720,-505,-2357,-859,531,-2229,-1346,-571,671,60,-169,-592,-339,-89,-706,-1698,-308,-787,-81,-364,-82,281,-1269,-422,54,-448,-2937,-1124,565,-557,6805,941,-1114,-1106,-256,-362,
                22,-1502,71,65,-665,-59,-106,-195,88,-378,-390,589,-1532,-466,-114,-382,-296,237,-76,-696,-1075,326,-16,1958,224,-645,-180,-849,-878,463,-276,7,-1391,-366,-77,463,-995,-398,-2494,-2242,166,-281,-2633,-704,-3056,-2990,-559,-795,-1813,-694,1022,-1275,-179,-852,672,282,-73,-527,-96,-117,-645,-1240,-373,-918,25,-309,40,208,-408,1206,-205,252,-1636,-1088,-167,-300,6556,862,-1204,-652,49,1,
                23,-577,53,-35,419,510,337,-222,13,-307,1008,1069,-888,-207,40,-315,-252,9,-147,-244,475,2813,592,1997,-220,4,-2,-663,-505,167,205,244,1654,14,25,1153,101,-1240,-48,-928,-789,-670,-1847,-541,-2432,-2836,-572,-241,-1246,-258,632,-1500,-583,-826,168,-28,128,25,155,54,18,-1524,-318,-783,21,-214,28,-425,-8,1330,-243,50,-871,-941,-157,-65,5100,612,-804,-1277,-22,494,
                24,-331,-142,288,594,614,172,-73,193,-68,834,1973,962,-265,118,-414,110,313,-315,-263,353,3681,1137,1954,536,210,701,-260,-446,181,888,-52,2210,-92,157,1187,1343,-276,1014,-1392,-385,-932,-1129,-1179,-2754,-5413,-466,-681,-760,-578,539,-1566,-286,-624,351,93,98,238,413,313,-57,-1463,-117,-901,151,-99,73,-678,746,2414,-460,582,-696,-973,502,585,4413,497,-313,-1113,68,227,
                25,671,84,-163,-138,402,-258,11,31,162,-157,1058,-1094,-551,281,-321,-412,284,-135,-757,160,3704,558,1834,233,-397,-287,210,-157,396,528,355,639,-47,421,1447,202,288,-358,-1752,720,-156,-2196,-208,-2977,-3354,-59,31,-669,-326,549,-1519,-119,-339,382,199,138,-397,120,-283,-236,-964,-737,-736,227,-344,46,84,763,2602,-175,737,-2308,-1337,535,161,2811,577,-578,-1537,189,1461,
                26,-104,193,224,-482,-82,-153,-107,-189,774,489,1344,-700,-397,-137,-201,-145,362,-234,-245,-605,1920,263,1589,35,-209,-269,-295,-482,425,-209,-142,-1408,280,158,1245,-833,423,-2082,-1192,81,-1023,-732,93,-3472,-3669,-620,-212,-969,-1019,1877,-2094,-209,-622,179,24,152,-401,151,12,-673,-1148,-630,-710,189,-251,8,-708,-144,1557,65,1396,-889,-678,928,-163,2800,-126,-617,-1649,455,1086,
                27,-425,-61,305,-651,181,76,-510,500,-247,-204,339,-2765,113,464,-331,18,397,-83,-584,-749,1781,84,1044,36,-383,84,-290,-483,-216,-185,-267,-893,42,-197,678,-691,-92,-1894,-2548,-165,-382,-1438,-538,-2698,-2273,-370,-72,-1014,-971,986,-2537,-641,-672,163,43,145,-423,-41,-265,-649,-1091,-628,-436,99,-505,69,-456,225,658,-358,729,-965,-796,229,151,1102,371,-286,-1445,-96,386,
                28,-673,33,379,126,382,-157,-536,256,345,88,1133,-3531,-505,-25,89,-55,264,-210,209,-88,2127,388,1761,52,-87,682,376,-675,122,212,-108,884,-244,-94,489,-80,-264,-644,-947,-601,-256,-355,27,-2128,-2968,-818,-134,-419,-886,1660,-2462,-998,-801,501,277,75,-190,172,70,-71,-1539,71,-696,225,56,-54,-1027,-782,657,191,526,-1593,-1664,-467,170,2301,576,-1016,-1256,203,107,
                29,-465,-211,546,-112,151,-300,-205,65,51,-134,1162,-4626,-148,-385,159,-117,348,-80,-304,-484,1840,62,2013,397,-382,336,252,-781,146,176,190,246,-68,-267,510,-496,18,-1016,-2068,-85,218,-617,141,-1217,-4180,-678,-802,-310,-864,623,-995,-545,-261,576,97,111,-479,230,231,-188,-722,-335,-589,91,84,27,-509,-474,405,328,1605,-2054,-524,912,45,973,357,-903,-612,-450,-76,
                30,-561,-60,280,-491,3,89,38,62,309,-768,97,-4672,-467,-268,-376,-236,52,-540,-265,-439,-116,-430,1215,-526,-433,293,-466,-869,-235,-219,817,-1201,252,0,368,-911,-858,-2266,-1136,20,57,-1037,492,-571,-3634,-718,-317,-847,-1189,623,-1605,-1003,-149,583,139,73,-887,-43,-176,-498,-962,-154,-622,69,-364,2,19,-949,-307,-57,755,-1727,-1361,51,-570,311,57,-1025,-859,-454,-196,
                31,-1549,-481,-53,-1093,-99,-558,-605,45,206,-1407,-788,-3913,-336,-598,-231,-319,160,-207,-768,-1334,-786,-393,1069,-62,-443,-40,-167,-131,147,-779,139,-2066,-358,-293,16,-1245,-396,-2894,-1736,217,-479,-1275,-470,-1198,-3343,-725,-30,-555,-384,209,-2546,-794,-432,101,81,-227,-748,-156,-110,-550,-271,-497,-771,100,-417,-31,-486,-1307,82,-497,-128,-2734,-1067,-50,-349,-900,256,-1039,-699,-31,-228,
                32,-1752,-55,202,-433,-261,197,-391,123,-77,-511,610,-3780,-693,-187,-330,-56,2,-274,-434,-932,-1406,-431,738,-93,-153,-196,-161,-390,128,-722,-70,-1480,217,-256,436,-1611,-583,-2934,-1723,-163,-515,-1496,-69,-1176,-3596,-835,-623,-567,-659,487,-1172,-747,-282,81,308,1,-1007,-86,7,-935,-694,-358,-807,-56,-232,71,-1139,-585,-620,-30,-126,-1956,-900,538,-418,-223,-238,-1163,-1558,-211,-125,
                33,-608,-257,-15,-545,145,-210,-433,28,-531,-1038,302,-2823,-239,-817,-648,-239,52,-97,-442,-1171,-608,-525,518,-442,-135,-30,-94,-446,-107,-515,-238,-2492,297,-190,304,-1665,-238,-3438,-1834,-387,-685,-1742,225,-1542,-3106,-682,-6,-338,-873,521,-1935,-847,-465,325,350,-124,-948,-156,97,-776,13,-1029,-772,26,-612,-46,-1193,37,169,-574,-181,-2080,-738,3,-382,-623,171,-156,-1128,63,282,
                34,-1122,-143,330,-917,8,-224,-367,-82,-97,-1166,115,-2922,-290,79,-511,-334,312,-261,-365,-742,-152,-350,851,-119,-508,24,-117,-644,-229,-291,-482,-1400,-179,-73,550,-1804,93,-2935,-1918,-409,-271,-1741,-691,-2003,-2679,-783,-652,-457,-402,-254,-1168,-457,-275,581,94,49,-805,-318,-17,-173,-422,-969,-846,-52,-192,13,-1079,526,294,-305,108,-1951,-978,515,-543,-47,-617,-440,-1568,614,-219,
                35,-302,-72,-50,-650,-175,-334,-420,201,276,-1420,-216,-1944,-180,-26,-375,-232,269,-278,-450,-649,-127,-325,-73,-522,-35,-280,70,-337,99,-307,177,-1853,-227,-202,100,-1162,-316,-2876,-2067,-226,-329,-1054,-556,-1873,-2374,-933,-650,-106,-618,335,-1867,-994,-646,40,151,-60,-969,-164,-311,-732,-727,-1101,-962,87,-278,29,-1515,219,1108,-406,-48,-1619,-1136,-33,-119,-140,422,-467,-1508,-167,-232,
                36,-1336,216,380,-332,-88,280,-141,201,-119,-1002,227,-2501,-398,119,-401,-271,93,-330,59,-832,321,-501,55,-131,-575,-356,-430,-479,-135,-368,189,-1667,-99,-203,-237,-1037,69,-2814,-2726,-65,-742,-1712,-292,-1577,-2132,-453,-787,-499,-1224,-63,-2595,-827,-352,412,233,-56,-794,-69,86,-67,-315,-453,-790,-17,185,-56,-523,541,2077,75,194,-1193,-949,-171,-437,-773,-39,-378,-1353,-113,-423,
                37,-659,-320,480,-113,113,220,-111,82,-85,-1778,24,-2801,-843,-5,-475,-239,349,-339,-136,-826,-212,-513,234,-383,-572,-282,-510,-638,-342,-992,429,-1586,-106,-381,152,-1628,-396,-2731,-1741,-454,-358,-1863,-144,-2296,-2470,-1156,-713,-367,-952,122,-2133,-677,-419,136,365,-61,-668,-188,-181,-348,-402,-558,-886,-142,-136,-101,-752,417,443,-546,87,-2084,-763,-241,-526,-773,-99,-544,-1357,91,-840,
                38,-1148,265,369,-603,-42,-322,-237,-95,-130,-1132,362,-3040,-419,131,-284,-35,-25,-319,-580,-477,496,33,214,-310,-854,210,-602,-1323,404,-362,548,-515,-301,9,563,-1226,-503,-2420,-1748,-240,237,-2316,-479,-1431,-2945,-925,-137,-587,-1297,-18,-1200,-524,-373,209,150,-5,-571,-112,-87,-522,113,-321,-658,71,-139,-52,-816,708,1611,-174,592,-1630,-468,82,-168,-870,-500,40,-1597,-455,-568,
                39,-894,-30,184,365,76,-350,-223,57,-171,-1467,74,-2895,-495,547,27,-113,313,-61,-210,-275,1181,-168,-99,-320,-860,-76,-833,-682,137,153,591,-1050,-158,-198,-146,-1282,-316,-2041,-1778,-558,115,-1621,-528,-2550,-3261,-849,-151,-782,-538,-335,-2105,-389,-645,331,199,-85,-699,22,-164,-405,-904,-852,-846,102,-44,-74,-712,166,1429,-138,-38,-1172,-445,128,-123,-900,-332,-990,-831,-625,-171,
                40,-335,96,607,-266,129,-156,-252,51,117,-686,322,-2119,-744,48,-286,-112,318,-316,-213,-488,865,-234,55,-652,-285,-201,-619,-851,-251,-714,139,-316,-128,208,114,-1130,-168,-2519,-1899,-496,91,-2345,121,-3221,-3852,-887,-62,-501,-1145,322,-1928,87,-687,439,98,-30,-933,16,-276,-864,-661,-1182,-868,-28,-360,63,-764,-172,578,-621,-32,-1627,-210,-32,-472,-614,-251,-845,-1660,-36,-492,
                41,-831,-286,-117,-959,29,-121,-348,33,-62,-1493,-623,-3302,-645,-543,-537,-361,99,-508,-692,-551,-419,-359,205,-742,-578,-245,-1013,-377,-154,-268,-127,-1776,-83,-384,-488,-1748,-402,-3403,-1272,-147,-549,-2054,290,-1854,-4360,-661,-496,-825,-426,-330,-2148,-256,-264,171,235,-148,-912,-104,-290,-772,-534,-1133,-1005,-51,-419,-57,-768,258,426,-696,-314,-1253,-1365,82,-496,-567,-366,-1467,-2006,-187,-217,
                42,-973,-247,514,-1759,37,96,-342,-67,-108,-305,52,-2409,37,-265,-161,-197,359,-478,309,-936,-1103,-576,-50,-427,-124,112,-561,-937,-246,-484,434,-2110,21,-354,-319,-1819,-919,-4065,-1824,-338,-323,-1820,-170,-2161,-3255,-699,-633,-1399,-555,487,-1836,-320,-210,254,314,-158,-751,-188,-73,-893,-568,-1156,-778,-275,-371,88,-1065,-657,297,-713,-149,-1235,-707,381,-347,1373,-199,-756,-1913,-364,-366,
                43,-1287,88,252,-1293,-67,-58,-467,-45,-204,-1513,-147,-1983,-657,307,-514,-213,124,-449,-75,-475,-576,-247,373,-244,-531,50,-1236,-784,-533,-590,33,-1516,-235,-99,-1246,-1760,-630,-4413,-1671,-738,423,-2520,-657,-1147,-2512,-349,5,-1053,-396,435,-2007,-537,-457,-29,110,-243,-1185,-177,-110,-742,-418,-984,-751,34,-60,-77,-473,-126,177,-494,165,-2500,-1038,-240,-671,-2,-347,152,-1068,-861,-786,
                44,-771,-19,282,-95,413,33,-229,-72,-156,-1913,568,-4400,-324,-295,-1,-281,-16,-439,-258,481,1000,795,524,739,147,-26,-831,-668,88,681,731,588,-124,-50,-276,-320,-1352,-2067,-1313,-720,667,-2432,-202,-751,-4170,-667,-521,-497,-899,105,-1447,348,-399,523,93,-31,-604,32,-32,-91,-2084,-566,-572,76,-71,86,-596,-33,305,-275,892,-1436,-670,-266,-7,35,-347,-1270,-930,-260,-72,
                45,420,-67,349,-208,457,-219,-462,-217,-244,-1606,604,-4546,-173,158,-422,-286,69,-507,-55,-548,1320,121,-112,-117,-205,-209,-642,-442,-178,248,468,-1156,-42,-74,445,-1266,-470,-2517,-1889,-719,406,-2263,-499,-2107,-4183,-911,-155,-761,-635,-710,-338,467,-267,545,524,-139,-951,-6,-257,-649,-1420,-785,-826,157,-266,93,-32,-566,1417,-225,757,-1475,30,628,114,2923,-269,-1384,-1106,-100,-5,
                46,767,180,154,-230,-79,-104,-452,177,-113,-1687,226,-3346,-744,65,-358,-351,285,-235,-352,-724,148,-91,502,886,65,-46,-640,-1135,-190,-259,-48,-1146,-371,178,918,-921,-956,-2915,-1740,-605,350,-2206,-894,-1669,-3593,-927,-454,-1491,-975,-873,-636,-315,-143,-309,694,-108,-761,55,-313,-575,-1663,-956,-772,-68,-152,-6,271,-258,735,-502,630,-2084,-786,351,-403,2302,-532,-698,-1374,-253,-46,
                47,677,-110,398,-67,184,-226,-352,568,152,-1523,793,-1189,-253,-382,-257,-188,49,-304,-485,-481,-35,-114,289,283,-611,245,-658,-884,-270,-499,-235,-1573,-386,-474,-321,-1134,-496,-3565,-2112,-139,180,-2657,-320,-1773,-4464,-862,-615,-1241,-745,-386,-1297,-942,-170,570,484,-50,-1031,-16,-77,-913,-1620,-1347,-788,13,-73,131,-324,-123,747,-257,233,-1811,390,-237,-408,1029,-207,-1195,-1526,162,501,
                48,102,-276,87,-1100,111,-180,-377,-34,-433,-1783,240,-593,-530,-101,-148,-389,140,-286,-283,-769,-773,-43,192,92,-681,-118,-1109,-1058,-289,-144,238,-1913,-342,-349,72,-1700,-637,-4081,-1794,-321,-560,-2649,-1348,-2463,-4972,-788,143,-1682,-1046,-611,-1630,-388,-738,-163,293,-104,-850,89,-265,-1041,-2024,-1047,-755,-29,-371,-20,-357,-494,411,-106,-346,-1444,740,-10,-398,925,-819,-799,-1656,-537,892,
                49,-228,-308,278,-74,531,170,-347,92,-192,-1777,189,-1761,-374,-220,72,-162,57,-123,220,-1006,-647,280,322,-427,89,262,-1240,-889,-359,-461,909,-941,204,105,77,-1127,-1486,-3107,-1720,-517,-942,-2967,-262,-2675,-4985,-867,-720,-1396,-761,349,-2106,-189,-743,-106,366,-57,-896,-16,-197,-841,-1210,-1612,-1040,-39,-16,-2,-600,-716,1148,183,47,-1558,125,109,-117,-341,-522,-1147,-1281,-404,485,
                50,-12,-106,375,225,267,1,-144,125,-334,-2355,235,-2114,132,-150,-338,77,321,-277,-704,-694,332,-353,-279,-169,-338,139,-691,-913,133,-543,680,-1845,-265,-258,188,-480,-528,-3396,-1818,-708,-460,-2849,149,-3162,-4316,-450,-146,-933,-987,126,-2213,-267,-591,68,192,-202,-915,67,-48,-432,-1664,-917,-1033,94,-72,-85,-355,5,788,-753,-11,-1692,-517,18,-353,-810,-176,-828,-1997,161,1207,
                51,566,20,2,-275,-13,-116,-340,-59,-544,-1552,338,-974,-521,95,-202,-487,180,-352,-272,-485,-565,233,-497,-115,-307,-106,-1152,-1206,-371,-651,191,-1542,-119,-330,-79,-1041,-941,-3955,-1143,-884,-155,-2473,-477,-2941,-5215,-786,-327,-1491,-878,944,-2407,-663,-422,-102,169,-205,-937,-184,-94,-576,-1068,-1147,-878,1,92,35,-220,-471,-475,-395,-109,-2152,-790,310,-32,-20,-411,-1385,-1964,272,922,
                52,67,-191,52,-1361,-161,-167,-560,286,-179,-2082,-101,-500,-367,148,-319,-194,-17,-478,-135,-689,-416,-87,-749,-262,-721,178,-1362,-993,-108,-635,-149,-1491,-121,-359,-563,-1092,-1100,-4242,-1596,-614,-264,-2575,-110,-4178,-4748,-732,-383,-1543,-1383,200,-2253,-443,-671,333,80,96,-868,-32,68,-597,-1466,-1723,-816,61,122,30,-773,-497,198,-753,326,-1632,-448,-313,-511,-314,-126,-1363,-2322,698,941), ncol = 82)`

and the plot_ly
plot_ly(z = as.matrix(pre2[,-1]), type = "heatmap", transpose = TRUE, zauto = FALSE, zmin = -10000, zmax = 10000, colors = c("blue", "white", "red")

A: This behaviour is related to the distribution of your data.
When I exchange the last two values of your dataset with -10000 and 10000, the colors are displayed correctly.
It seems to be an issue with the color interpolation, here is an example using "spline" and "linear" interpolation:
Edit: added alternative solutions using library(d3heatmap) (not actively maintained anymore) and library(heatmaply)
2nd Edit: Finally found a working solution based on standard plotly (type heatmap) using a custom colorscale (see plot pCustom and the last Example here). Concerning the effort to get there I'd give heatmaply a shot.
library(plotly)

pre2 = matrix(c(1,1147,-118,124,937,591,168,19,63,-47,626,680,1309,529,1386,53,60,77,-358,103,651,4054,679,620,484,0,311,1985,-244,-16,416,159,1562,145,181,666,1225,936,2968,324,676,196,597,412,609,1159,-187,439,-193,657,995,2178,637,-534,14,100,279,438,-39,390,348,916,100,-171,91,-35,19,270,1220,2205,933,170,181,91,258,-201,1258,250,1730,472,389,346,
                2,675,-29,29,404,119,-3,63,4,-593,-201,175,40,438,844,92,-19,187,75,481,4,1617,246,1248,203,-163,344,1720,-319,79,234,-702,491,-43,-135,491,394,627,2062,748,375,-194,1060,-387,695,-244,201,-42,-64,231,655,1438,128,-533,93,-88,114,253,204,80,317,-211,181,-82,-140,-107,8,39,477,950,752,340,-412,-684,578,218,675,-86,390,152,-74,73,
                3,755,37,-332,83,50,-165,67,46,-252,3,-185,464,251,577,-181,-211,-198,-261,-129,51,1056,586,169,-19,-61,429,1219,-415,67,46,-171,245,112,-91,860,-356,164,1829,286,286,-513,-73,220,34,-475,-143,-483,-334,-3,-251,2195,-279,-120,6,130,143,84,-118,148,32,-292,-250,-294,-87,-282,-131,-416,138,282,363,-20,-1060,-173,53,305,566,-157,-302,-6,-375,283,
                4,404,-71,-119,-124,166,-111,164,-20,-556,-471,84,-144,11,-23,-162,-304,74,-27,835,-333,58,292,472,-111,163,192,624,-221,22,237,-513,-44,-10,-204,856,235,65,625,61,-68,7,415,138,-868,152,-65,63,115,36,-275,1,280,-531,330,-68,-75,217,-88,-77,-234,-143,96,-354,-80,-48,37,-355,577,-273,-320,48,-410,15,-65,-433,-1094,89,241,-129,63,898,
                5,22,494,53,337,111,313,213,-185,68,108,58,-134,16,66,-75,74,131,-67,-753,-125,66,202,-175,-344,-9,-142,260,-169,-145,-227,-431,97,-302,-120,-152,638,-24,-209,151,96,-71,148,257,-368,61,-53,463,106,-19,63,-840,-554,-537,-95,-113,26,-17,84,-24,-192,363,-130,22,75,101,-131,217,126,-39,-127,-223,56,212,95,373,-1195,-124,11,-151,221,-24,
                6,-476,-45,146,206,-162,-227,-143,290,234,399,-503,1088,116,-110,-104,-105,-81,-61,-200,145,-15,-474,171,-9,-276,1,-434,96,61,-125,368,30,86,25,-772,-60,-56,-381,-226,6,-55,137,129,715,-70,347,-187,-519,-5,231,-932,-31,-137,-599,108,-23,0,61,154,-9,-439,-501,382,42,-65,10,507,-460,-122,279,-42,-466,299,-145,172,564,-216,152,74,-57,24,
                7,-499,-64,123,-346,34,186,-40,45,-104,-499,15,-342,127,-89,140,284,-77,107,-278,-5,-28,8,12,3,74,308,-422,-160,-84,-301,790,-514,81,107,-94,-632,-245,-25,1,101,134,-328,-399,563,169,-83,-394,157,105,95,442,16,571,379,56,3,-196,35,57,337,-11,506,11,-173,15,54,-130,-248,9,2,-104,382,-178,-245,-81,553,125,-119,217,-249,-645,
                8,549,-315,-202,-73,-149,-161,-194,-129,358,463,346,-469,-271,155,200,50,-47,48,396,319,-81,-28,-481,461,48,-359,-28,454,146,416,-213,431,145,192,162,-181,260,-10,13,-134,-15,-373,-124,-41,-312,-146,55,142,-117,-114,1329,289,633,-16,17,70,-4,-91,-110,98,231,29,-60,135,-2,30,-240,5,425,166,321,439,-348,360,-30,1172,126,-285,-11,21,-253,
                9,611,292,45,230,-25,100,-127,56,-159,310,754,312,250,-471,96,-131,72,176,288,-231,639,269,-544,343,368,139,-166,456,-162,201,-409,126,234,260,766,-499,-422,151,-85,128,263,-5,-168,-613,-1108,-262,-3,-143,92,-26,520,-184,54,296,210,-103,-9,-90,-20,-256,241,563,50,141,290,69,-502,155,1264,272,259,-138,-371,672,-247,1007,-159,112,154,76,-163,
                10,348,76,-430,280,212,90,-163,-77,-171,552,626,431,-65,233,-159,-163,180,-171,40,-256,999,460,-597,-145,395,113,94,-28,218,-75,-763,-182,80,-74,-151,-54,-264,205,-666,302,379,-347,-258,-879,-958,-167,-420,-459,285,130,1053,-149,91,173,264,4,-89,-230,161,-106,-48,175,-444,-95,-74,-25,-485,532,1861,-313,-229,-371,39,649,-279,-4,-345,97,-67,182,165,
                11,179,366,-14,-524,-105,-97,-92,-253,-494,-219,2111,-591,-136,442,-290,-120,342,-104,-61,-200,438,3444,3183,4069,-279,-3,-507,-857,24,-18,-403,101,1202,1057,1499,-477,246,-213,-1216,554,40,-539,-94,-1891,-428,-622,208,-405,-701,1204,1040,-186,-8,8,137,19,-53,-53,-50,-225,-417,-241,-538,-1,-509,-89,-575,374,2212,2121,3563,140,2590,2329,-15,-124,420,-184,-162,-145,314,
                12,1936,554,229,761,610,385,-105,-388,-740,-1035,2246,-2387,-590,878,178,166,628,75,880,-80,4286,2960,2797,4244,260,-207,-222,-701,207,265,371,126,2343,1477,3083,1253,353,1025,-2578,35,-501,-1762,-938,-3281,-3286,389,-34,-954,-311,866,-1411,-981,-674,-209,25,-62,-163,-84,-121,466,-1638,-1446,-816,87,-132,-63,535,-397,1847,1154,3508,-2404,1547,2961,2245,-781,3338,119,-1200,166,1029,
                13,660,308,-135,67,181,129,-244,-432,-1101,-2582,1695,-4415,-441,105,-584,200,892,-199,-293,-603,4282,1630,1662,2808,160,-173,-818,-620,2,-340,9,-628,1560,1296,3646,1124,269,462,-2778,-132,-638,-3190,-1672,-4430,-6093,215,-287,-1563,-816,1289,-1208,-1055,-825,-266,107,-156,-480,16,-122,-198,-2583,-1281,-1284,23,9,86,237,-1227,1050,642,2920,-3288,372,3702,2900,-572,3574,-255,-2288,485,1133,
                14,-227,345,-809,-795,-29,-93,-654,-408,-1151,-2619,518,-2625,-1027,299,-403,394,1295,416,612,-823,1951,82,2367,1430,-277,-600,-1150,-564,-80,-242,332,-3011,1155,249,2914,-938,-352,-2181,-2821,-45,-189,-3795,-1274,-4192,-5830,3,-577,-1817,-1148,1096,-2127,-1683,-444,88,-6,-258,-800,-291,-110,-516,-2953,-1624,-1237,-98,-676,-158,-63,-2060,-859,-13,863,-3650,-258,2361,2272,829,4159,-1616,-2631,540,402,
                15,-1917,46,-27,-740,-436,28,-356,-733,-1042,-2476,577,-4315,-884,-35,-730,296,1056,-62,387,-1499,1275,-36,2520,168,-387,-24,-700,163,137,-338,817,-2314,600,595,2024,-442,-311,-1911,-2899,-95,-297,-3679,-1776,-4095,-5756,-358,-641,-2599,-1783,120,-1573,-1647,68,313,-59,-235,-376,2,-29,-95,-2170,-1327,-1187,-114,-203,-96,-6,-1902,-1371,-215,-150,-4831,-296,1706,2555,310,4994,-1379,-2581,190,-199,
                16,-2953,-180,-504,-1380,-440,-111,-980,-644,-1079,-2445,518,-3652,-949,-405,-645,17,420,-273,26,-1022,430,-331,2185,171,-481,-208,-1013,-387,-59,100,372,-2644,401,250,1776,-1096,-373,-1789,-1651,-158,-451,-3265,-1457,-3886,-5053,-760,-676,-2179,-1512,1522,-2024,-1462,-558,520,222,-161,-690,-203,45,-746,-1354,-1138,-1334,-151,-527,-167,-12,-1970,-1296,281,88,-3943,-233,1651,1343,545,3569,-2148,-1949,-682,-577,
                17,-2226,149,0,-2010,-380,91,-950,-163,-999,-2978,-449,-3630,-1050,-205,-741,-131,712,-138,-102,-1505,-513,-620,3642,399,-342,-7,-953,485,-32,-386,445,-2635,205,511,972,-1116,-540,-3017,-3614,-235,-325,-3273,-1758,-4311,-5930,-379,-485,-2472,-1419,986,-2593,-1583,-1047,194,-37,-165,-772,-213,398,-498,-2002,-876,-985,-156,-691,-197,616,-2550,-1637,-360,-572,-4339,-1174,1059,1625,3473,5172,-1634,-2004,-685,-286,
                18,-3373,16,-113,-638,-389,-73,-450,-265,-799,-2237,319,-3083,-840,-98,-731,-325,469,-615,-324,-1323,-965,-747,3102,-252,-478,8,-982,-404,-233,-512,-181,-2683,22,333,1656,-1340,651,-2538,-3222,873,-569,-3039,-1221,-4301,-4715,-162,-938,-1931,-1542,1651,-1637,-1235,142,602,-56,-315,-457,-236,91,-507,-857,-625,-1247,-329,-767,-121,1538,-2130,-205,132,-255,-4083,-1338,1677,422,4085,2748,-2523,-1949,-948,-706,
                19,-1826,377,-152,-873,-79,118,-653,-283,-946,-1780,-83,-3504,-637,-113,-568,-61,381,-106,-850,-1298,333,-173,3623,-109,-776,-398,-1199,-587,148,-365,-760,-2660,260,316,1294,-1209,1379,-2138,-2566,1207,-442,-4097,-1596,-4826,-4702,-192,-295,-2410,-1193,1495,-1561,-1173,-403,653,22,-192,-451,-174,-116,-460,-585,-899,-1169,-59,-28,-115,1347,-325,794,48,225,-3962,-915,1681,-56,8588,1604,-1517,-1954,-938,-254,
                20,-1394,-90,311,-673,-406,73,-265,263,-573,-1246,169,-1609,-597,-132,-323,-360,521,-215,-725,-836,518,-93,1969,17,-586,-656,-1123,-184,48,-293,-241,-1772,122,180,1386,-1112,244,-2057,-2364,377,-96,-3112,-1013,-3781,-4494,-546,-632,-2067,-1266,763,-1527,-752,-605,217,61,-126,-345,-423,53,-526,-1173,-700,-1020,7,-426,-36,768,-1535,438,-150,-449,-3168,-1260,149,-626,9486,1809,-651,-1486,-394,-182,
                21,-1357,-262,-313,-929,-92,-427,-659,27,-435,-1487,-62,-1073,-440,-425,-415,-301,-111,-251,-476,-1046,-638,-791,3023,135,-293,108,-1239,-598,-46,-542,-180,-1635,142,-86,1141,-1429,456,-2925,-2284,298,-612,-2566,-643,-2982,-3858,-720,-505,-2357,-859,531,-2229,-1346,-571,671,60,-169,-592,-339,-89,-706,-1698,-308,-787,-81,-364,-82,281,-1269,-422,54,-448,-2937,-1124,565,-557,6805,941,-1114,-1106,-256,-362,
                22,-1502,71,65,-665,-59,-106,-195,88,-378,-390,589,-1532,-466,-114,-382,-296,237,-76,-696,-1075,326,-16,1958,224,-645,-180,-849,-878,463,-276,7,-1391,-366,-77,463,-995,-398,-2494,-2242,166,-281,-2633,-704,-3056,-2990,-559,-795,-1813,-694,1022,-1275,-179,-852,672,282,-73,-527,-96,-117,-645,-1240,-373,-918,25,-309,40,208,-408,1206,-205,252,-1636,-1088,-167,-300,6556,862,-1204,-652,49,1,
                23,-577,53,-35,419,510,337,-222,13,-307,1008,1069,-888,-207,40,-315,-252,9,-147,-244,475,2813,592,1997,-220,4,-2,-663,-505,167,205,244,1654,14,25,1153,101,-1240,-48,-928,-789,-670,-1847,-541,-2432,-2836,-572,-241,-1246,-258,632,-1500,-583,-826,168,-28,128,25,155,54,18,-1524,-318,-783,21,-214,28,-425,-8,1330,-243,50,-871,-941,-157,-65,5100,612,-804,-1277,-22,494,
                24,-331,-142,288,594,614,172,-73,193,-68,834,1973,962,-265,118,-414,110,313,-315,-263,353,3681,1137,1954,536,210,701,-260,-446,181,888,-52,2210,-92,157,1187,1343,-276,1014,-1392,-385,-932,-1129,-1179,-2754,-5413,-466,-681,-760,-578,539,-1566,-286,-624,351,93,98,238,413,313,-57,-1463,-117,-901,151,-99,73,-678,746,2414,-460,582,-696,-973,502,585,4413,497,-313,-1113,68,227,
                25,671,84,-163,-138,402,-258,11,31,162,-157,1058,-1094,-551,281,-321,-412,284,-135,-757,160,3704,558,1834,233,-397,-287,210,-157,396,528,355,639,-47,421,1447,202,288,-358,-1752,720,-156,-2196,-208,-2977,-3354,-59,31,-669,-326,549,-1519,-119,-339,382,199,138,-397,120,-283,-236,-964,-737,-736,227,-344,46,84,763,2602,-175,737,-2308,-1337,535,161,2811,577,-578,-1537,189,1461,
                26,-104,193,224,-482,-82,-153,-107,-189,774,489,1344,-700,-397,-137,-201,-145,362,-234,-245,-605,1920,263,1589,35,-209,-269,-295,-482,425,-209,-142,-1408,280,158,1245,-833,423,-2082,-1192,81,-1023,-732,93,-3472,-3669,-620,-212,-969,-1019,1877,-2094,-209,-622,179,24,152,-401,151,12,-673,-1148,-630,-710,189,-251,8,-708,-144,1557,65,1396,-889,-678,928,-163,2800,-126,-617,-1649,455,1086,
                27,-425,-61,305,-651,181,76,-510,500,-247,-204,339,-2765,113,464,-331,18,397,-83,-584,-749,1781,84,1044,36,-383,84,-290,-483,-216,-185,-267,-893,42,-197,678,-691,-92,-1894,-2548,-165,-382,-1438,-538,-2698,-2273,-370,-72,-1014,-971,986,-2537,-641,-672,163,43,145,-423,-41,-265,-649,-1091,-628,-436,99,-505,69,-456,225,658,-358,729,-965,-796,229,151,1102,371,-286,-1445,-96,386,
                28,-673,33,379,126,382,-157,-536,256,345,88,1133,-3531,-505,-25,89,-55,264,-210,209,-88,2127,388,1761,52,-87,682,376,-675,122,212,-108,884,-244,-94,489,-80,-264,-644,-947,-601,-256,-355,27,-2128,-2968,-818,-134,-419,-886,1660,-2462,-998,-801,501,277,75,-190,172,70,-71,-1539,71,-696,225,56,-54,-1027,-782,657,191,526,-1593,-1664,-467,170,2301,576,-1016,-1256,203,107,
                29,-465,-211,546,-112,151,-300,-205,65,51,-134,1162,-4626,-148,-385,159,-117,348,-80,-304,-484,1840,62,2013,397,-382,336,252,-781,146,176,190,246,-68,-267,510,-496,18,-1016,-2068,-85,218,-617,141,-1217,-4180,-678,-802,-310,-864,623,-995,-545,-261,576,97,111,-479,230,231,-188,-722,-335,-589,91,84,27,-509,-474,405,328,1605,-2054,-524,912,45,973,357,-903,-612,-450,-76,
                30,-561,-60,280,-491,3,89,38,62,309,-768,97,-4672,-467,-268,-376,-236,52,-540,-265,-439,-116,-430,1215,-526,-433,293,-466,-869,-235,-219,817,-1201,252,0,368,-911,-858,-2266,-1136,20,57,-1037,492,-571,-3634,-718,-317,-847,-1189,623,-1605,-1003,-149,583,139,73,-887,-43,-176,-498,-962,-154,-622,69,-364,2,19,-949,-307,-57,755,-1727,-1361,51,-570,311,57,-1025,-859,-454,-196,
                31,-1549,-481,-53,-1093,-99,-558,-605,45,206,-1407,-788,-3913,-336,-598,-231,-319,160,-207,-768,-1334,-786,-393,1069,-62,-443,-40,-167,-131,147,-779,139,-2066,-358,-293,16,-1245,-396,-2894,-1736,217,-479,-1275,-470,-1198,-3343,-725,-30,-555,-384,209,-2546,-794,-432,101,81,-227,-748,-156,-110,-550,-271,-497,-771,100,-417,-31,-486,-1307,82,-497,-128,-2734,-1067,-50,-349,-900,256,-1039,-699,-31,-228,
                32,-1752,-55,202,-433,-261,197,-391,123,-77,-511,610,-3780,-693,-187,-330,-56,2,-274,-434,-932,-1406,-431,738,-93,-153,-196,-161,-390,128,-722,-70,-1480,217,-256,436,-1611,-583,-2934,-1723,-163,-515,-1496,-69,-1176,-3596,-835,-623,-567,-659,487,-1172,-747,-282,81,308,1,-1007,-86,7,-935,-694,-358,-807,-56,-232,71,-1139,-585,-620,-30,-126,-1956,-900,538,-418,-223,-238,-1163,-1558,-211,-125,
                33,-608,-257,-15,-545,145,-210,-433,28,-531,-1038,302,-2823,-239,-817,-648,-239,52,-97,-442,-1171,-608,-525,518,-442,-135,-30,-94,-446,-107,-515,-238,-2492,297,-190,304,-1665,-238,-3438,-1834,-387,-685,-1742,225,-1542,-3106,-682,-6,-338,-873,521,-1935,-847,-465,325,350,-124,-948,-156,97,-776,13,-1029,-772,26,-612,-46,-1193,37,169,-574,-181,-2080,-738,3,-382,-623,171,-156,-1128,63,282,
                34,-1122,-143,330,-917,8,-224,-367,-82,-97,-1166,115,-2922,-290,79,-511,-334,312,-261,-365,-742,-152,-350,851,-119,-508,24,-117,-644,-229,-291,-482,-1400,-179,-73,550,-1804,93,-2935,-1918,-409,-271,-1741,-691,-2003,-2679,-783,-652,-457,-402,-254,-1168,-457,-275,581,94,49,-805,-318,-17,-173,-422,-969,-846,-52,-192,13,-1079,526,294,-305,108,-1951,-978,515,-543,-47,-617,-440,-1568,614,-219,
                35,-302,-72,-50,-650,-175,-334,-420,201,276,-1420,-216,-1944,-180,-26,-375,-232,269,-278,-450,-649,-127,-325,-73,-522,-35,-280,70,-337,99,-307,177,-1853,-227,-202,100,-1162,-316,-2876,-2067,-226,-329,-1054,-556,-1873,-2374,-933,-650,-106,-618,335,-1867,-994,-646,40,151,-60,-969,-164,-311,-732,-727,-1101,-962,87,-278,29,-1515,219,1108,-406,-48,-1619,-1136,-33,-119,-140,422,-467,-1508,-167,-232,
                36,-1336,216,380,-332,-88,280,-141,201,-119,-1002,227,-2501,-398,119,-401,-271,93,-330,59,-832,321,-501,55,-131,-575,-356,-430,-479,-135,-368,189,-1667,-99,-203,-237,-1037,69,-2814,-2726,-65,-742,-1712,-292,-1577,-2132,-453,-787,-499,-1224,-63,-2595,-827,-352,412,233,-56,-794,-69,86,-67,-315,-453,-790,-17,185,-56,-523,541,2077,75,194,-1193,-949,-171,-437,-773,-39,-378,-1353,-113,-423,
                37,-659,-320,480,-113,113,220,-111,82,-85,-1778,24,-2801,-843,-5,-475,-239,349,-339,-136,-826,-212,-513,234,-383,-572,-282,-510,-638,-342,-992,429,-1586,-106,-381,152,-1628,-396,-2731,-1741,-454,-358,-1863,-144,-2296,-2470,-1156,-713,-367,-952,122,-2133,-677,-419,136,365,-61,-668,-188,-181,-348,-402,-558,-886,-142,-136,-101,-752,417,443,-546,87,-2084,-763,-241,-526,-773,-99,-544,-1357,91,-840,
                38,-1148,265,369,-603,-42,-322,-237,-95,-130,-1132,362,-3040,-419,131,-284,-35,-25,-319,-580,-477,496,33,214,-310,-854,210,-602,-1323,404,-362,548,-515,-301,9,563,-1226,-503,-2420,-1748,-240,237,-2316,-479,-1431,-2945,-925,-137,-587,-1297,-18,-1200,-524,-373,209,150,-5,-571,-112,-87,-522,113,-321,-658,71,-139,-52,-816,708,1611,-174,592,-1630,-468,82,-168,-870,-500,40,-1597,-455,-568,
                39,-894,-30,184,365,76,-350,-223,57,-171,-1467,74,-2895,-495,547,27,-113,313,-61,-210,-275,1181,-168,-99,-320,-860,-76,-833,-682,137,153,591,-1050,-158,-198,-146,-1282,-316,-2041,-1778,-558,115,-1621,-528,-2550,-3261,-849,-151,-782,-538,-335,-2105,-389,-645,331,199,-85,-699,22,-164,-405,-904,-852,-846,102,-44,-74,-712,166,1429,-138,-38,-1172,-445,128,-123,-900,-332,-990,-831,-625,-171,
                40,-335,96,607,-266,129,-156,-252,51,117,-686,322,-2119,-744,48,-286,-112,318,-316,-213,-488,865,-234,55,-652,-285,-201,-619,-851,-251,-714,139,-316,-128,208,114,-1130,-168,-2519,-1899,-496,91,-2345,121,-3221,-3852,-887,-62,-501,-1145,322,-1928,87,-687,439,98,-30,-933,16,-276,-864,-661,-1182,-868,-28,-360,63,-764,-172,578,-621,-32,-1627,-210,-32,-472,-614,-251,-845,-1660,-36,-492,
                41,-831,-286,-117,-959,29,-121,-348,33,-62,-1493,-623,-3302,-645,-543,-537,-361,99,-508,-692,-551,-419,-359,205,-742,-578,-245,-1013,-377,-154,-268,-127,-1776,-83,-384,-488,-1748,-402,-3403,-1272,-147,-549,-2054,290,-1854,-4360,-661,-496,-825,-426,-330,-2148,-256,-264,171,235,-148,-912,-104,-290,-772,-534,-1133,-1005,-51,-419,-57,-768,258,426,-696,-314,-1253,-1365,82,-496,-567,-366,-1467,-2006,-187,-217,
                42,-973,-247,514,-1759,37,96,-342,-67,-108,-305,52,-2409,37,-265,-161,-197,359,-478,309,-936,-1103,-576,-50,-427,-124,112,-561,-937,-246,-484,434,-2110,21,-354,-319,-1819,-919,-4065,-1824,-338,-323,-1820,-170,-2161,-3255,-699,-633,-1399,-555,487,-1836,-320,-210,254,314,-158,-751,-188,-73,-893,-568,-1156,-778,-275,-371,88,-1065,-657,297,-713,-149,-1235,-707,381,-347,1373,-199,-756,-1913,-364,-366,
                43,-1287,88,252,-1293,-67,-58,-467,-45,-204,-1513,-147,-1983,-657,307,-514,-213,124,-449,-75,-475,-576,-247,373,-244,-531,50,-1236,-784,-533,-590,33,-1516,-235,-99,-1246,-1760,-630,-4413,-1671,-738,423,-2520,-657,-1147,-2512,-349,5,-1053,-396,435,-2007,-537,-457,-29,110,-243,-1185,-177,-110,-742,-418,-984,-751,34,-60,-77,-473,-126,177,-494,165,-2500,-1038,-240,-671,-2,-347,152,-1068,-861,-786,
                44,-771,-19,282,-95,413,33,-229,-72,-156,-1913,568,-4400,-324,-295,-1,-281,-16,-439,-258,481,1000,795,524,739,147,-26,-831,-668,88,681,731,588,-124,-50,-276,-320,-1352,-2067,-1313,-720,667,-2432,-202,-751,-4170,-667,-521,-497,-899,105,-1447,348,-399,523,93,-31,-604,32,-32,-91,-2084,-566,-572,76,-71,86,-596,-33,305,-275,892,-1436,-670,-266,-7,35,-347,-1270,-930,-260,-72,
                45,420,-67,349,-208,457,-219,-462,-217,-244,-1606,604,-4546,-173,158,-422,-286,69,-507,-55,-548,1320,121,-112,-117,-205,-209,-642,-442,-178,248,468,-1156,-42,-74,445,-1266,-470,-2517,-1889,-719,406,-2263,-499,-2107,-4183,-911,-155,-761,-635,-710,-338,467,-267,545,524,-139,-951,-6,-257,-649,-1420,-785,-826,157,-266,93,-32,-566,1417,-225,757,-1475,30,628,114,2923,-269,-1384,-1106,-100,-5,
                46,767,180,154,-230,-79,-104,-452,177,-113,-1687,226,-3346,-744,65,-358,-351,285,-235,-352,-724,148,-91,502,886,65,-46,-640,-1135,-190,-259,-48,-1146,-371,178,918,-921,-956,-2915,-1740,-605,350,-2206,-894,-1669,-3593,-927,-454,-1491,-975,-873,-636,-315,-143,-309,694,-108,-761,55,-313,-575,-1663,-956,-772,-68,-152,-6,271,-258,735,-502,630,-2084,-786,351,-403,2302,-532,-698,-1374,-253,-46,
                47,677,-110,398,-67,184,-226,-352,568,152,-1523,793,-1189,-253,-382,-257,-188,49,-304,-485,-481,-35,-114,289,283,-611,245,-658,-884,-270,-499,-235,-1573,-386,-474,-321,-1134,-496,-3565,-2112,-139,180,-2657,-320,-1773,-4464,-862,-615,-1241,-745,-386,-1297,-942,-170,570,484,-50,-1031,-16,-77,-913,-1620,-1347,-788,13,-73,131,-324,-123,747,-257,233,-1811,390,-237,-408,1029,-207,-1195,-1526,162,501,
                48,102,-276,87,-1100,111,-180,-377,-34,-433,-1783,240,-593,-530,-101,-148,-389,140,-286,-283,-769,-773,-43,192,92,-681,-118,-1109,-1058,-289,-144,238,-1913,-342,-349,72,-1700,-637,-4081,-1794,-321,-560,-2649,-1348,-2463,-4972,-788,143,-1682,-1046,-611,-1630,-388,-738,-163,293,-104,-850,89,-265,-1041,-2024,-1047,-755,-29,-371,-20,-357,-494,411,-106,-346,-1444,740,-10,-398,925,-819,-799,-1656,-537,892,
                49,-228,-308,278,-74,531,170,-347,92,-192,-1777,189,-1761,-374,-220,72,-162,57,-123,220,-1006,-647,280,322,-427,89,262,-1240,-889,-359,-461,909,-941,204,105,77,-1127,-1486,-3107,-1720,-517,-942,-2967,-262,-2675,-4985,-867,-720,-1396,-761,349,-2106,-189,-743,-106,366,-57,-896,-16,-197,-841,-1210,-1612,-1040,-39,-16,-2,-600,-716,1148,183,47,-1558,125,109,-117,-341,-522,-1147,-1281,-404,485,
                50,-12,-106,375,225,267,1,-144,125,-334,-2355,235,-2114,132,-150,-338,77,321,-277,-704,-694,332,-353,-279,-169,-338,139,-691,-913,133,-543,680,-1845,-265,-258,188,-480,-528,-3396,-1818,-708,-460,-2849,149,-3162,-4316,-450,-146,-933,-987,126,-2213,-267,-591,68,192,-202,-915,67,-48,-432,-1664,-917,-1033,94,-72,-85,-355,5,788,-753,-11,-1692,-517,18,-353,-810,-176,-828,-1997,161,1207,
                51,566,20,2,-275,-13,-116,-340,-59,-544,-1552,338,-974,-521,95,-202,-487,180,-352,-272,-485,-565,233,-497,-115,-307,-106,-1152,-1206,-371,-651,191,-1542,-119,-330,-79,-1041,-941,-3955,-1143,-884,-155,-2473,-477,-2941,-5215,-786,-327,-1491,-878,944,-2407,-663,-422,-102,169,-205,-937,-184,-94,-576,-1068,-1147,-878,1,92,35,-220,-471,-475,-395,-109,-2152,-790,310,-32,-20,-411,-1385,-1964,272,922,
                52,67,-191,52,-1361,-161,-167,-560,286,-179,-2082,-101,-500,-367,148,-319,-194,-17,-478,-135,-689,-416,-87,-749,-262,-721,178,-1362,-993,-108,-635,-149,-1491,-121,-359,-563,-1092,-1100,-4242,-1596,-614,-264,-2575,-110,-4178,-4748,-732,-383,-1543,-1383,200,-2253,-443,-671,333,80,96,-868,-32,68,-597,-1466,-1723,-816,61,122,30,-773,-497,198,-753,326,-1632,-448,-313,-511,-314,-126,-1363,-2322,698,941), ncol = 82)

pLinear <- plot_ly(z = pre2[,-1], type = "heatmap", transpose = TRUE, zauto = FALSE, zmin = -10000, zmax = 10000, colors = colorRamp(colors = c("blue", "white", "red"), interpolate = "linear"))
pLinear

pSpline <- plot_ly(z = pre2[,-1], type = "heatmap", transpose = TRUE, zauto = FALSE, zmin = -10000, zmax = 10000, colors = colorRamp(colors = c("blue", "white", "red"), interpolate = "spline"))
pSpline

library(d3heatmap)
pD3heatmap <- d3heatmap(pre2[,-1], scale = "column", dendrogram = "none", color = c("blue", "white", "red"))
pD3heatmap

library(heatmaply)
pHeatmaply <- heatmaply(pre2[,-1], colors = c("blue", "white", "red"), limits=c(-10000, 10000), dendrogram = "none")
pHeatmaply

library(scales)
colRamp <- colorRampPalette(colors = c("blue", "white", "red"))
vals <- unique(scales::rescale(c(pre2[,-1])))
o <- order(vals, decreasing = FALSE)
cols <- scales::col_numeric(colRamp(length(vals)), domain = NULL)(vals)
colz <- setNames(data.frame(vals[o], cols[o]), NULL)
pCustom <- plot_ly(z = pre2[,-1], colorscale = colz, type = "heatmap", transpose = TRUE, zauto = FALSE, zmin = -10000, zmax = 10000)
pCustom


text:
Q: A href tag is not working Strange thing happens, I have this code, on my wordpress site:
    <img src="<?php echo get_template_directory_uri(); ?>/images/facebook.png"/>

The image is loaded, but is not clickable, I mean nothing happens when I click on it, what's wrong?
The link to my page is: http://toibz.com/ibz.  Click on the "facebook" logo in the lower right corner.

A: add http:// to your link like:
 <a href="http://www.google.com"..

A: Set position:fixed on the a tag instead of floating it.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Android webview for payment gateway redirection is not working I am loading an url in webview which would redirect to payment gateway screen. My url is:
 https://**hostname**/pgway/gateway/payment/paymentDebitwithPin.jsp?PaymentID=8501798561070830&trandata=b0cb7bcf4cb2f52b355fa4eb3f66905721323d2dfbbb00682dafe34bfca9948a&id=10100125

when loading this url it is redirected to below url
https://**hostname**/pgway/gateway/payment/TransactionError.jsp

The code which I am usingto load this url is
    pgWebview = (WebView)findViewById(R.id.pgWebview);
    pgWebview.getSettings().setUseWideViewPort(true);
    pgWebview.getSettings().setLoadWithOverviewMode(true);
    pgWebview.setWebViewClient(
            new SSLTolerentWebViewClient()
    );
    pgWebview.loadUrl(webURL);

The redirected screen displays the message as
Unauthorized Transaction. Your request cannot be process as the transaction is already initiated.

I have also tried shouldOverrideUrlLoading method but whatever I am getting the same error. Can anyone help me out to fix this issue?

A: You need to enable javascript for it. Add these lines before loading url:-
pgWebview.getSettings().setJavaScriptEnabled(true);
pgWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

A: Check by this way you will come to know happening while loading the url, does the url redirection happening in mobile browser?
webView.loadUrl(actualURL);

public class AppWebViewClients extends WebViewClient {

    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        Log.d(TAG, "shouldOverrideUrlLoading");
        Log.d(TAG, "actualURL: " + actualURL);
        Log.d(TAG, "NewURL: " + url);

        if (changedUrl && !url.equals(actualURL)) {
            // page has been clicked
            //TODO- load the page after redirection happens
              view.loadUrl(url);

            return true;
        } else {
            // Designate Urls that you want to load in WebView still.
            view.loadUrl(url);

            return true;
        }
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
        //SHOW LOADING IF IT ISNT ALREADY VISIBLE
        Log.d(TAG, "onPageStarted");
    }

    public void onPageFinished(WebView view, String url) {

    }

    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {

        Log.d(TAG, "Error Description: " + description);
        Log.d(TAG, "failingUrl: " + failingUrl);
    }

    @Override
    public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
        try{
            final AlertDialog.Builder builder = new AlertDialog.Builder(WebViewActivity.this);
            builder.setMessage(R.string.notification_error_ssl_cert_invalid);
            builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handler.proceed();
                }
            });
            builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handler.cancel();
                }
            });
            final AlertDialog dialog = builder.create();
            dialog.show();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

A: A better approach might be to check the redirect URL in onPageFinished()
Code
@Override
        public void onPageFinished(WebView view, String url) {
            Log.d("Final URL", url);
        }

A: This solution work for me  when you setting webclient in webview by extending calss  : WebViewClient()
 override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
    Log.d(TAG, "shouldOverrideUrlLoading")
    Log.d(TAG, "actualURL: $url")
    Log.d(TAG, "NewURL: $url")
    val parsedUrl = URL(url)

    val hitTestResult = view.hitTestResult
    //hitTestResult==null solve the redirect problem
    if (!TextUtils.isEmpty(url) && hitTestResult == null) {
        view.loadUrl(url)
        return true
    }
    //your handling logic here
}


text:
Q: Mqtt Android PahoClient Connection Issue Hi I am using Android paho library for getting connect with an mqtt server.
My app level Gradle side Code :
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

Project Level
allprojects {
    repositories {
        jcenter()
        maven {
            url "https://repo.eclipse.org/content/repositories/paho-snapshots/"
        }
        maven { url "https://jitpack.io" }
        maven {
            url "https://maven.google.com"
        }
    }
}

In Manifest File
<service android:name="org.eclipse.paho.android.service.MqttService" />

permisiions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

My issue is I am able to connect, publish data and subscribe to a topic when my server url is tcp://:1883
When I changed my url to mqtts://:8883 its failed to get connect
So what is the difference in the schemes tcp:// and mqtts:// or mqtt://
Why I am not able to connect if scheme starts with mqtt?
Please help!!!

A: tcp://hostname:1883 and mqtt://hostname:1883 are exactly the same.
mqtts://hostname:8883 is MQTT over TLS and will require that the broker has been correctly configured to support a TLS connection on port 8883.
Without details of the error when it fails to connect we can say nothing more.

A: FYI - in order use Paho Android Client over TLS/SSL I found it invaluable to follow this example:
https://www.emqx.com/en/blog/android-mqtt-ssl-tls-authentication
Unfortunately, a tiny but crucial missing bit of information is to mention about how to properly change the MQTT broker URL - for this I spent an enormous amount of time searching and finally found that golden nugget here:
https://www.thethingsnetwork.org/forum/t/cannot-connect-to-mqtt-broker-over-tls-port/48316
So using the above-mentioned "mqtts://hostname:8883" failed to make a simple test connect to test.mosquitto.org using their CA certificate provided at their website.
It only finally connected by using "ssl://test.mosquitto.org:8883"
The most hideous (and thereby time-consuming) aspect of this was that the failure was silent - nothing showed up on the Android Studio LogCat, no Exception thrown, nada.
I am sure that to all the programmers with even minimal internet/stack experience it is soooooo obvious that you have to change 'tcp' to 'ssl' whenever you change 1883 to 8883, but not to a noob - it's a painful lesson to be well remembered.


text:
Q: StackExchange Exceptional How to setup for ASP.NET Web Form As title, does anyone know how to setup StackExchange.Exceptional for asp.net web form

A: I got answer from StackExchangeException github page:
https://github.com/NickCraver/StackExchange.Exceptional/issues/82#issuecomment-280708220
Here is content:
ASP.NET Web Forms are certainly supported. Just configure your web.config file similar to this:
<configuration>
  <configSections>
    <section name="Exceptional" type="StackExchange.Exceptional.Settings, StackExchange.Exceptional"/>
  </configSections>
  <Exceptional applicationName="MyWebFormsApp">
    <!-- Error log store to use -->
    <ErrorStore type="SQL" connectionString="Data Source=.;Initial Catalog=Exceptions;Uid=Exceptions;Pwd=iloveerrors" />
  </Exceptional>
  <system.webServer>
    <modules>
      <add name="ErrorStore" type="StackExchange.Exceptional.ExceptionalModule, StackExchange.Exceptional" />
    </modules>
    <handlers>
      <add name="Exceptional" path="exceptions.axd" verb="POST,GET,HEAD" type="StackExchange.Exceptional.HandlerFactory, StackExchange.Exceptional" preCondition="integratedMode" />
    </handlers>
  </system.webServer>
</configuration>

Here's an explanation of the relevant parts and what needs to be configured.
1: The added entry in defines how to understand the section below. It pretty much should look exactly like that.
2: The section is what directly configures Exceptional.
3: The applicationName can be any name you want. It's there so that you could have multiple applications/websites storing errors in the same spot.
4: The ErrorStore is where you tell Exceptional where to save the errors. Assuming you want to store them in SQL Server, you just specify "SQL" for the type and give it the connectionString to connect to your database. (Don't forget to run the SQL script for adding the table to your database.)
5: The  section adds the ExceptionalModule, which creates a hook for grabbing any unhandled exceptions and logging them.
6: The  section adds an entry that maps the path "exceptions.axd" to the HandlerFactory, which will allow you to view the logged exceptions when you go to that path.
This is just a quick and easy basic setup. There's other ways of configuring everything and there's other things that can be added (like emailing errors). But this should at least get you started. Be sure to also check the Wiki pages.


text:
Q: Top to bottom
* element arrangement I'm trying to find out how I can force elements to start from the top going to the bottom.
I have searched through Stack Overflow and I can't seem to get the answer that i need. Below I explain:
Actual:
A--B--C--D

E--F--G--H

What I need:
A--C--E--G

B--D--F--H

A: This might not work in older browsers but you can use CSS property column-count like this:
ul {
  -moz-column-count: 4;
  -webkit-column-count: 4;
  column-count: 4;
}

Example: jsfiddle.


text:
Q: Closure function with Lottie Animation in Swift Is there a way to know when an Lottie animation is finished? I need to delete  a tableViewCell  but only AFTER the animation  is finished. This is the animation:
Setup:
    //MARK: setup Loading-Animation
func setupLoadingAnimation(){

    successAnimation.translatesAutoresizingMaskIntoConstraints = false
    self.contentView.addSubview(successAnimation)

    successAnimation.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: -30).isActive = true
    successAnimation.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
    successAnimation.widthAnchor.constraint(equalToConstant: 160).isActive = true
    successAnimation.heightAnchor.constraint(equalToConstant: 160).isActive = true

    successAnimation.isHidden = true
    successAnimation.loopMode = .playOnce
}

Action:
@objc func checkButtonTapped(){
    self.deleteWishCallback?()
    self.successAnimation.isHidden = false
    self.successAnimation.play()
}

What I would like to achieve is to be able to call self.deleteWishCallback?()  in the closure  of self.successAnimation.play(). Is there a way to get this done ? Couldnt find anything on this!

A: Lottie Animation Basic Playing
AnimationView.play(completion: LottieCompletionBlock?)

Plays the animation from its current state to the end of its timeline. Calls the completion block when the animation is stopped.
Parameters: : completion: A completion block that is called when the animation completes. The block will be passed true if the animation completes and false if the animation was interrupted. Optional.
Example:
starAnimationView.play { (finished) in
      // Animation finished
      //here if finised is true you can perform the action of deleting the tableviewCell
    }

You can find more HERE


text:
Q: Plot a 2D graph from a .csv file with string format I am reviewing the following discussion
Plot a 2D graph from a csv file using matplotlib in Python in ubuntu
However, it does not fit quite well for my case. The data format in my .csv file is string. I used the following code to show this.
rm = np.genfromtxt('test.csv', delimiter=',',dtype='str', skip_header=26)
print(rm)
np.shape(rm)

If I want to plot the data with x-axis the left position in " ; ", and the y-axis the right position in " ; ". So I want the shape to be (1001,2). How to do this?
Thanks!

A: There are many ways to do this, but I would choose this way if I were you.
with open('matrix.txt') as file:
    lines = file.read()
# lines: '1;2;3;,4;5;6;,7;8;9;,'

lines = [line.split(';') for line in lines.split(',')]
# lines: [['1', '2', '3', ''], ['4', '5', '6', ''], ['7', '8', '9', ''], ['']]

lines = [[float(value) for value in line if value] for line in lines]
lines = [line for line in lines if line]
# lines: [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]

matrix = np.array(lines)
# matrix: array([[1., 2., 3.],
#                [4., 5., 6.],
#                [7., 8., 9.]])

Or, this way also could be your choice.
with open('matrix.txt') as file:
    lines = file.read()

lines = lines.replace(';', ' ').replace(',', ';')
# lines: '1 2 3 ;4 5 6 ;7 8 9 ;'

if lines[-1] == ';':
    lines = lines[:-1]

np.matrix(lines)

When saving your code, I think this would work too.
rm = np.genfromtxt('test.csv', delimiter=',', dtype='str', skip_header=26)
rm = np.array([[float(value) for value in line.split(';') if value] for line in rm])

They are not elegant, but they work.


text:
Q: MySQL - Top 5 rank best seller plans or courses I sell subscriptions of my online course, as well as the courses in retail.
I would bring the "top 5" of best selling plans / courses. For this, I have a table called "subscriptionPlan", which stores the purchased plan ID, or in the case of a course, the course ID, and the amount spent on this transaction. Example:
table subscriptionPlan
sbpId | subId | plaId | couId | sbpAmount
1     | 1     | 1     | 1     | 499.99
2     | 2     | 1     | 2     | 499.99
3     | 3     | 2     | 0     | 899.99
4     | 4     | 1     | 1     | 499.99

Just for educational purposes, plaId = 1 is a plan called "Single Sale" that I created, to maintain the integrity of the DB. When the couId isn't empty, you also have bought a separate course, not a plan where you can attend any course.
My need is: List the top 5 sales. If it is a plan, display the plan name (plan table, column plaTitle). If it is a course, display its name (table course, colna couTitle). This logic that I can't code. I was able to rank a top 5 of PLANS, but it groups the courses, since the GROUP BY is by the ID of the plan. I believe the prank is here, maybe creating an IF / ELSE in this GROUPBY, but I don't know how to do this.
The query that i code, to rank my top 5 plans is:
SELECT sp.plaId, sp.couId, p.plaTitle, p.plaPermanent, c.couTitle, SUM(sbpAmount) AS sbpTotalAmount
FROM subscriptionPlan sp
LEFT JOIN plan p ON sp.plaId = p.plaId
LEFT JOIN course c ON sp.couId = c.couId
GROUP BY sp.plaId
ORDER BY sbpTotalAmount DESC
LIMIT 5

The result that i expected was:
plaId | couId | plaTitle        | couTitle   | plaPermanent | sbpTotalAmount
1     | 1     | Venda avulsa    | Curso 01   | true         | 999.98
2     | 0     | Acesso total    | null       | false        | 899.99
3     | 2     | Venda avulsa    | Curso 02   | true         | 499.99

How could I get into this query formula?

A: When grouping you can use:

*

*Simple columns, or

*Any [complex] expression.

In your case, it seems you need to group by an expression, such as:
GROUP BY CASE WHEN sp.plaId = 1 THEN -1 ELSE sp.couId END

In this case I chose -1 as the grouping for the "Single Plan". You can replace the value for any other that doesn't match any couId.


text:
Q: How to add and remove no records found to html search table I am trying search filter for html table. i want to show no records found when there no search field matches. It is not working as expected. no records tr should appear only when no match found.
please guide me. Thanks in advance.
even if record founds then also no records found is adding at the bottom
Here is the code

<!DOCTYPE html>

<meta name="viewport" content="width=device-width, initial-scale=1">

My Customers

<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name">

    Name
    Country

    Alfreds Futterkiste
    Germany

    Berglunds snabbkop
    Sweden

    Island Trading
    UK

    Koniglich Essen
    Germany

    Laughing Bacchus Winecellars
    Canada

    Magazzini Alimentari Riuniti
    Italy

    North/South
    UK

    Paris specialites
    France

No records found

A:

function myFunction() {
      var input, filter, table, tr, td, i, txtValue;
      input = document.getElementById("myInput");
      filter = input.value.toUpperCase();
      table = document.getElementById("listitems");
      tableNorecords = document.getElementById("NoRecords");
      tr = table.getElementsByTagName("tr");
      var count=0;
      for (i = 0; i
 -1) {
            tr[i].style.display = "";
            count++;
          } else {
            tr[i].style.display = "none";
          }
        }
      }
      if(count==0)
      {
        tableNorecords.style.display = "";
      }
      else
      {
        tableNorecords.style.display = "none";
      }

    }
 * {
      box-sizing: border-box;
    }

    #myInput {
      background-image: url('/css/searchicon.png');
      background-position: 10px 10px;
      background-repeat: no-repeat;
      width: 100%;
      font-size: 16px;
      padding: 12px 20px 12px 40px;
      border: 1px solid #ddd;
      margin-bottom: 12px;
    }

    #myTable {
      border-collapse: collapse;
      width: 100%;
      border: 1px solid #ddd;
      font-size: 18px;
    }

    #myTable th, #myTable td {
      text-align: left;
      padding: 12px;
    }

    #myTable tr {
      border-bottom: 1px solid #ddd;
    }

    #myTable tr.header, #myTable tr:hover {
      background-color: #f1f1f1;
    }
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name">

        Name
        Country

        Alfreds Futterkiste
        Germany

        Berglunds snabbkop
        Sweden

        Island Trading
        UK

        Koniglich Essen
        Germany

        Laughing Bacchus Winecellars
        Canada

        Magazzini Alimentari Riuniti
        Italy

        North/South
        UK

        Paris specialites
        France

No records found

A: Problem is that you need to check how many rows are "visible" after your loop.
Add this after your loop:
const visibleRowCount = Array.from(table.querySelectorAll('tr:not(#NoRecords)')).reduce((count, row) => {
  return count + (row.offsetHeight > 0 ? 1 : 0);
  }, 0);
tableNorecords.style.display = visibleRowCount > 0 ? "none" : "";

Demo

<!DOCTYPE html>

  <meta name="viewport" content="width=device-width, initial-scale=1">

My Customers

  <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name">

        Name
        Country

        Alfreds Futterkiste
        Germany

        Berglunds snabbkop
        Sweden

        Island Trading
        UK

        Koniglich Essen
        Germany

        Laughing Bacchus Winecellars
        Canada

        Magazzini Alimentari Riuniti
        Italy

        North/South
        UK

        Paris specialites
        France

        No records found


text:
Q: Check internet connection throughout my application I'm working on Internet based app,so i need to monitor Internet Connection. link
I used this code in on create of mainActivity to check my internet connection it works fine.
public boolean isOnline()
{
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);  return
cm.getActiveNetworkInfo().isConnectedOrConnecting();
}

But i need this monitoring should be done through out application.
Where should i use this ? Any AsyncTask needed?

A: create a BroadcastReceiver to detect change in connection status. see Eric's answer here

A: Use a BroadCast Receiver, like so :
private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
            String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);
                        boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);

            NetworkInfo currentNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
            NetworkInfo otherNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);

            // do application-specific task(s) based on the current network state, such
            // as enabling queuing of HTTP requests when currentNetworkInfo is connected etc.
        }
    };

 private void registerReceivers() {
       registerReceiver(mConnReceiver,
           new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
   }


text:
Q: process url's into application's output and strip them to create files with name of urls Created a script which makes use of an existing tool which process url's to get additional information.
now, this tool has an output format with the switch "-o" but due to the impossibility to create a filename with "output-$url-tool.txt", where the $url is a list which gets read line by line, thus: "http://www.something.com, (new line) https://www.something.com" etc.
Is it possible to strip the url while processing it to create a file with the stripped name "output-something.com-tool.txt" per url?
this might be a bit fuzzy to read but i kinda got lost and don't know any other way to ask this. im sorry.
see the example below for what i tried but obviously doesnt work due to the markup of the file.
for url in $(cat /urls.txt); do tool -u $url -o output-$url-tool.html; done

A: The construct you're using isn't particularly safe. Since cat urls.txt is split by whitespace, any whitespace accidentally in the file will break your processing. If you're sure you want to handle things line-by-line, use read.
You'll also want to quote your variables, and remove or modify characters which are not permitted within filenames.
while read -r url; do
  tool -u "$url" -o "output-${url//\//_}-tool.html"
done < urls.txt

And if you want to strip the method, you can do that with additional parameter expansion:
shopt -s extglob
while read -r url; do
  url="${url#http?(s)://}"
  url="${url%%/*}"
  tool -u "$url" -o "output-${url}-tool.html"
done < urls.txt

This uses extglob to make the s in https optional, and includes only the domain name in the filename buy stripping everything earlier in the URL, along with the entire path.
Note that extglob requires bash version 4 or above.


text:
Q: How exactly is the Wronskian tied with Cramer's rule in a system of ODEs? If we have a nonhomogeneous system of linear differential equations:
$$\frac{d\vec{y}}{dx}=A\vec{y}+\vec{b}$$
where:
$$\frac{d\vec{y}}{dx}=\begin{bmatrix}y_1'\\y_2'\\y_3'\end{bmatrix},\vec{y}=\begin{bmatrix}y_1\\y_2\\y_3\end{bmatrix},A=\begin{bmatrix}a_{11}&a_{12}&a_{13}\\a_{21}&a_{22}&a_{23}\\a_{31}&a_{32}&a_{33}\end{bmatrix}, \vec{b}=\begin{bmatrix}b_1(x)\\b_2(x)\\b_3(x)\end{bmatrix}$$
the particular solution involving these three functions could be written:
$$y_{particular}=c_1(x)e^{\lambda_1x}\vec{u_1}+c_2(x)e^{\lambda_2x}\vec{u_2}+c_3(x)e^{\lambda_3x}\vec{u_3}$$
where $\lambda_i, \vec{u_i}$ are the eigenvalues and eigenvectors of the constant matrix $A$ (I chose it constant to make things simpler.)
When trying to evaluate these $c_i(x)$ functions, I was told to evaluate them by:
$$c_i(x)=\int\frac{W_i}{W}dx$$
Where $W$ is the Wronskian determinant whose columns are the elements of the vectors $c_i(x)e^{\lambda_3i}\vec{u_i}$, and $W_i$ is the Wronskian determinant whose $i$th column was replaced by the contents of the $\vec{b}$ vector.
My questions are: How does the integral show up? Why does the process look like Cramer's rule? How did we lead up to that result? Where did this 'Wronskian' determinant come from?
If I have missed something, please point it out and I'll add it to the post.
Thanks in advance.

A: Write the general solution of the homogeneous linear ODE
$$
\tag{1}
\frac{\mathrm{d}\vec{y}}{\mathrm{d}x} = A(x) \vec{y}
$$
in the matrix form as
$$
\Phi(x; x_0) \vec{c},
$$
where $\vec{c} = \mathrm{col}(c_1, \dots, c_n)$ is a constant matrix (that is, independent of $x$), and $\Phi$ is the state-transition matrix such that $\Phi(x_0, x_0) = I$ (the identity matrix).
Now we are looking for a general solution of the nonhomogeneous linear ODE
$$
\tag{2}
\frac{\mathrm{d}\vec{y}}{\mathrm{d}x} = A(x) \vec{y} + \vec{b}(x)
$$
in the form
$$
\Phi(x, x_0) \vec{c}(x).
$$
Incidentally, here is the source of the term "variation of constants".  We look for conditions for the above function of $x$ to be a solution of $(2)$, that is, to have
$$
\frac{\mathrm{d}}{\mathrm{d}x}(\Phi(x, x_0) \vec{c}(x)) = A(x) (\Phi(x, x_0) \vec{c}(x)) + \vec{b}(x).
$$
But
$$
\frac{\mathrm{d}}{\mathrm{d}x}(\Phi(x, x_0) \vec{c}(x)) = \frac{\mathrm{d}}{\mathrm{d}x} \Phi(x, x_0) \cdot \vec{c}(x) + \Phi(x, x_0) \cdot \vec{c}'(x)
$$
and
$$
\frac{\mathrm{d}}{\mathrm{d}x} \Phi(x, x_0) = A(x) \Phi(x, x_0),
$$
so after cancellation we obtain
$$
\Phi(x, x_0) \cdot \vec{c}'(x) = \vec{b}(x),
$$
which is, for each fixed $x$, a Cramer (because $\det{\Phi(x, x_0)} = W(x, x_0) \ne 0$) system of $n$ linear equations with $n$ unknowns, $c'_1(x), \dots, c'_n(x)$.  The unknowns are given by the Cramer rule.  We have thus obtained the derivative of the matrix function $\vec{c}(x)$, so we have to integrate that derivative.  And that is the source of the integral.
The "Wrońskian" determinant was named after a nineteenth-century Polish philosopher and mathematician, Józef Maria Hoene-Wroński.
EDIT: I changed slightly the terminology and provided a reference to a Wikipedia entry.


text:
Q: The $\lambda$-integrability of the derivative of a function of bounded variation Let $f:[a, b] \to \mathbb{R}$ and $\operatorname{Var}_{[a, b]} f$ its total variation. Let $\lambda$ be the Lebesgue measure on $[a, b]$. I would like to prove below properties for functions of bounded variation, i.e.,

Theorem If $f$ is of bounded variation, then

*

*$f$ is differentiable $\lambda$-a.e.,

*The function
$$
g(x) :=
\begin{cases}
f^{\prime}(x) & \text{if } f \text { differentiable at } x \in (a, b),\\
0 & \text {otherwise}.
\end{cases}
$$
is $\lambda$-integrable such that $\int_a^b |g| \mathrm d \lambda \leq \operatorname{Var}_{[a, b]} f$.

Could you confirm if my below attempt is fine?

Proof

*

*By this lemma, there exist increasing functions $f_1, f_2:[a, b] \rightarrow \mathbb{R}$ such that $f=f_1-$ $f_2$ and
$$
\operatorname{Var}_{[a, b]} f = f_1(b)-f_1(a)+f_2(b)-f_2(a).
$$
By this lemma, $f_1, f_2$ are differentiable $\lambda$-a.e. Claim (1.) then follows.

*

*Let
$$
g_1(x) :=
\begin{cases}
f_1^{\prime}(x) & \text{if } f_1 \text { differentiable at } x \in (a, b),\\
0 & \text {otherwise}.
\end{cases}
$$
and
$$
g_2(x) :=
\begin{cases}
f_2^{\prime}(x) & \text{if } f_2 \text { differentiable at } x \in (a, b),\\
0 & \text {otherwise}.
\end{cases}
$$
I proved that $g, g_1, g_2$ are Borel measurable. So $g, g_1, g_2$ are $\lambda$-measurable. I proved that $g_1, g_2 \ge 0$ and
$$
\int_a^b g_1 \mathrm d \lambda \le f_1(b)-f_1(a)
\quad \text{and} \quad
\int_a^b g_2 \mathrm d \lambda \le f_2(b)-f_2(a).
$$
Notice that $g=g_1-g_2$ $\lambda$-a.e., so
$$
\int_a^b |g| \mathrm d \lambda \le \int_a^b |g_1| \mathrm d \lambda + \int_a^b |g_2| \mathrm d \lambda = (f_1(b)-f_1(a))+(f_2(b)-f_2(a)) = \operatorname{Var}_{[a, b]} f < \infty.
$$
This completes the proof.


text:
Q: How to get out of local optimum using simulated annealing? I have a conceptual question. I am working on an optimization project in which I used a simulated annealing metaheuristic to get better solutions. for creating neighbors in SA I have used both SWAP and 2-OPT methods to create neighbors by creating a new sequence. results even for small problem sizes show that 7 out of 10 times when I run the program (with more than 500 iterations) the best objective value achieved is the initial objective value which has been achieved heuristically.
question is what could cause such behavior?

*

*is it because the initial feasible solution has high quality?

*how much changing the cooling factor and starting temperature will help? (it did not help so far in small instances)

*am I not creating efficient neighbors?

is there something else that I am missing?

A: You need to keep track of the percentage, accepted solutions.
For instance, every 100 proposals, print the number of accepted solutions.

*

*Start with a random solution, not close to optimal one.

*In early phase, >80% should be accepted. If this is not the case, increase the temperature until so.

*In last phase, <10% should be accepted, if this is not the case, lower the stop temperature.

*Cooling scheme has only small influence on solution quality, just lower by cooling factor is good enough, between 0.99 and 0.8. (You can repeat N times on each temperature to increase the proposals)

*You can experiment with different proposals.

*If you apply on traveling salesman, you can 2-opt your output of simulated annealing (SA). Most likely, your SA with a 2-opt to 'clean' the solution, is better than 2-opt without SA.
Hope this helps.


text:
Q: How to include all points into error-less triangulation mesh with scipy.spatial.Delaunay? I am testing scipy.spatial.Delaunay and not able to solve two issues:

*

*the mesh has errors

*the mesh doesn't include all points

Code and image of plot:
import numpy as np
from scipy.spatial import Delaunay,delaunay_plot_2d
import matplotlib.pyplot as plt
#input_xyz.txt contains 1000 pts in "X Y Z" (float numbers) format
points = np.loadtxt("input_xyz.txt", delimiter=" ", usecols=(0, 1))
tri = Delaunay(points)
delaunay_plot_2d(tri)
plt.plot(points[:,0], points[:,1], 'o')
plt.show()

As mentioned under scipy.spatial.Delaunay:
"Unless you pass in the Qhull option "QJ", Qhull does not guarantee that each input point appears as a vertex in the Delaunay triangulation."
But if I use QJ:
tri = Delaunay(points, qhull_options = "QJ")

I get Qhull error and if I use QJn (n=some high number):
tri = Delaunay(points, qhull_options = "QJ200")

to overcome that error the generated mesh looks terrible - triangles all over the place crossing each other.
How to include all points into error-less triangulation mesh with scipy.spatial.Delaunay?

A: The problem is that your data set is not centered. Qhull (used to do the Delaunay triangulation) does not center the data set for you under the default options, so it runs to rounding errors far away from origin.
You can center it yourself before triangulation
points -= points.mean(axis=0)
tri = Delaunay(points)


text:
Q: How to properly use the "choices" field option in Django I'm reading the tutorial here: https://docs.djangoproject.com/en/1.5/ref/models/fields/#choices
and i'm trying to create a box where the user can select the month he was born in. What I tried was
 MONTH_CHOICES = (
    (JANUARY, "January"),
    (FEBRUARY, "February"),
    (MARCH, "March"),
    ....
    (DECEMBER, "December"),
)

month = CharField(max_length=9,
                  choices=MONTHS_CHOICES,
                  default=JANUARY)

Is this correct? I see that in the tutorial I was reading, they for some reason created variables first, like so
FRESHMAN = 'FR'
SOPHOMORE = 'SO'
JUNIOR = 'JR'
SENIOR = 'SR'

Why did they create those variables? Also, the MONTHS_CHOICES is in a model called People, so would the code I provided create a "Months Choices) column in the database called called "People" and would it say what month the user was born in after he clicks on of the months and submits the form?

A: I would suggest to use django-model-utils instead of Django built-in solution.
The main advantage of this solution is the lack of string declaration duplication. All choice items are declared exactly once. Also this is the easiest way for declaring choices using 3 values and storing database value different than usage in source code.
from django.utils.translation import ugettext_lazy as _
from model_utils import Choices

class MyModel(models.Model):
   MONTH = Choices(
       ('JAN', _('January')),
       ('FEB', _('February')),
       ('MAR', _('March')),
   )
   # [..]
   month = models.CharField(
       max_length=3,
       choices=MONTH,
       default=MONTH.JAN,
   )

And with usage IntegerField instead:
from django.utils.translation import ugettext_lazy as _
from model_utils import Choices

class MyModel(models.Model):
   MONTH = Choices(
       (1, 'JAN', _('January')),
       (2, 'FEB', _('February')),
       (3, 'MAR', _('March')),
   )
   # [..]
   month = models.PositiveSmallIntegerField(
       choices=MONTH,
       default=MONTH.JAN,
   )

*

*This method has one small disadvantage: in any IDE (eg. PyCharm) there will be no code completion for available choices (it's because those values aren't standard members of Choices class).

A: According to the documentation:

Field.choices
An iterable (e.g., a list or tuple) consisting itself of
  iterables of exactly two items (e.g. [(A, B), (A, B) ...]) to use as
  choices for this field. If this is given, the default form widget will
  be a select box with these choices instead of the standard text field.
The first element in each tuple is the actual value to be stored, and
  the second element is the human-readable name.

So, your code is correct, except that you should either define variables JANUARY, FEBRUARY etc. or use calendar module to define MONTH_CHOICES:
import calendar
...

class MyModel(models.Model):
    ...

    MONTH_CHOICES = [(str(i), calendar.month_name[i]) for i in range(1,13)]

    month = models.CharField(max_length=9, choices=MONTH_CHOICES, default='1')

A: Jan, 2023 Update:
The new way is using models.TextChoices as shown below which is built-in so you don't need to install any packages. *The 1st value is the actual value and the 2nd value is displayed on Django Admin:
# "models.py"

from django.db import models

class MyModel(models.Model):

    class Months(models.TextChoices):
     # Actual value ↓      # ↓ Displayed on Django Admin
        JANUARY = 'JAN', 'January'
        FEBRUARY = 'FEB', 'February'
        MARCH = 'MAR', 'March'
        APRIL = 'APR', 'April'
        MAY = 'MAY', 'May'

    month = models.CharField(
        max_length=3,
        choices=Months.choices,
        default=Months.APRIL
    )

    class YearInSchool(models.TextChoices):
     # Actual value ↓      # ↓ Displayed on Django Admin
        FRESHMAN = 'FR', 'Freshman'
        SOPHOMORE = 'SO', 'Sophomore'
        JUNIOR = 'JR', 'Junior'
        SENIOR = 'SR', 'Senior'
        GRADUATE = 'GR', 'Graduate'

    year_in_school = models.CharField(
        max_length=2,
        choices=YearInSchool.choices,
        default=YearInSchool.SOPHOMORE,
    )

I also rewrote the code above in the old way which is also built-in.
# "models.py"

from django.db import models

class MyModel(models.Model):
              # ↓ Actual value
    JANUARY = 'JAN'
    FEBRUARY = 'FEB'
    MARCH = 'MAR'
    APRIL = 'APR'
    MAY = 'MAY'

    MONTHS = [      # ↓ Displayed on Django Admin
        (JANUARY, 'January'),
        (FEBRUARY, 'February'),
        (MARCH, 'March'),
        (APRIL, 'April'),
        (MAY, 'May'),
    ]

    month = models.CharField(
        max_length=3,
        choices=MONTHS,
        default=APRIL # Or "default=MONTHS[3]"
    )
              # ↓ Actual value
    FRESHMAN = 'FR'
    SOPHOMORE = 'SO'
    JUNIOR = 'JR'
    SENIOR = 'SR'
    GRADUATE = 'GR'

    YEAR_IN_SCHOOL_CHOICES = [
                     # ↓ Displayed on Django Admin
        (FRESHMAN, 'Freshman'),
        (SOPHOMORE, 'Sophomore'),
        (JUNIOR, 'Junior'),
        (SENIOR, 'Senior'),
        (GRADUATE, 'Graduate'),
    ]

    year_in_school = models.CharField(
        max_length=2,
        choices=YEAR_IN_SCHOOL_CHOICES,
        default=SOPHOMORE # Or "default=YEAR_IN_SCHOOL_CHOICES[1]"
    )

A: You can't have bare words in the code, that's the reason why they created variables (your code will fail with NameError).
The code you provided would create a database table named month (plus whatever prefix django adds to that), because that's the name of the CharField.
But there are better ways to create the particular choices you want. See a previous Stack Overflow question.
import calendar
tuple((m, m) for m in calendar.month_name[1:])

A: I think no one actually has answered to the first question:

Why did they create those variables?

Those variables aren't strictly necessary. It's true. You can perfectly do something like this:
MONTH_CHOICES = (
    ("JANUARY", "January"),
    ("FEBRUARY", "February"),
    ("MARCH", "March"),
    # ....
    ("DECEMBER", "December"),
)

month = models.CharField(max_length=9,
                  choices=MONTH_CHOICES,
                  default="JANUARY")

Why using variables is better? Error prevention and logic separation.
JAN = "JANUARY"
FEB = "FEBRUARY"
MAR = "MAR"
# (...)

MONTH_CHOICES = (
    (JAN, "January"),
    (FEB, "February"),
    (MAR, "March"),
    # ....
    (DEC, "December"),
)

Now, imagine you have a view where you create a new Model instance. Instead of doing this:
new_instance = MyModel(month='JANUARY')

You'll do this:
new_instance = MyModel(month=MyModel.JAN)

In the first option you are hardcoding the value. If there is a set of values you can input, you should limit those options when coding.
Also, if you eventually need to change the code at the Model layer, now you don't need to make any change in the Views layer.

A: The cleanest solution is to use the django-model-utils library:
from model_utils import Choices

class Article(models.Model):
    STATUS = Choices('draft', 'published')
    status = models.CharField(choices=STATUS, default=STATUS.draft, max_length=20)

https://django-model-utils.readthedocs.io/en/latest/utilities.html#choices

A: For Django3.0+, use models.TextChoices (see docs-v3.0 for enumeration types)
from django.db import models

class MyModel(models.Model):
    class Month(models.TextChoices):
        JAN = "1", "JANUARY"
        FEB = "2", "FEBRUARY"
        MAR = "3", "MAR"
        # (...)

    month = models.CharField(
        max_length=2,
        choices=Month.choices,
        default=Month.JAN
    )

Usage::
>>> obj = MyModel.objects.create(month='1')
>>> assert obj.month == obj.Month.JAN == '1'
>>> assert MyModel.Month(obj.month) is obj.Month.JAN
>>> assert MyModel.Month(obj.month).value is '1'
>>> assert MyModel.Month(obj.month).label == 'JANUARY'
>>> assert MyModel.Month(obj.month).name == 'JAN'
>>> assert MyModel.objects.filter(month=MyModel.Month.JAN).count() >= 1

>>> obj2 = MyModel(month=MyModel.Month.FEB)
>>> assert obj2.get_month_display() == obj2.Month(obj2.month).label

Let's say we known the label is 'JANUARY', how to get the name 'JAN' and the value '1'?
label = "JANUARY"
name = {i.label: i.name for i in MyModel.Month}[label]
print(repr(name))  # 'JAN'
value = {i.label: i.value for i in MyModel.Month}[label]
print(repr(value))  # '1'

Personally, I would rather use models.IntegerChoices
class MyModel(models.Model):
    class Month(models.IntegerChoices):
        JAN = 1, "JANUARY"
        FEB = 2, "FEBRUARY"
        MAR = 3, "MAR"
        # (...)

    month = models.PositiveSmallIntegerField(
        choices=Month.choices,
        default=Month.JAN
    )

A: $ pip install django-better-choices
For those who are interested, I have created django-better-choices library, that provides a nice interface to work with Django choices for Python 3.7+. It supports custom parameters, lots of useful features and is very IDE friendly.
You can define your choices as a class:
from django_better_choices import Choices

class PAGE_STATUS(Choices):
    CREATED = 'Created'
    PENDING = Choices.Value('Pending', help_text='This set status to pending')
    ON_HOLD = Choices.Value('On Hold', value='custom_on_hold')

    VALID = Choices.Subset('CREATED', 'ON_HOLD')

    class INTERNAL_STATUS(Choices):
        REVIEW = 'On Review'

    @classmethod
    def get_help_text(cls):
        return tuple(
            value.help_text
            for value in cls.values()
            if hasattr(value, 'help_text')
        )

Then do the following operations and much much more:
print( PAGE_STATUS.CREATED )                # 'created'
print( PAGE_STATUS.ON_HOLD )                # 'custom_on_hold'
print( PAGE_STATUS.PENDING.display )        # 'Pending'
print( PAGE_STATUS.PENDING.help_text )      # 'This set status to pending'

'custom_on_hold' in PAGE_STATUS.VALID       # True
PAGE_STATUS.CREATED in PAGE_STATUS.VALID    # True

PAGE_STATUS.extract('CREATED', 'ON_HOLD')   # ~= PAGE_STATUS.VALID

for value, display in PAGE_STATUS:
    print( value, display )

PAGE_STATUS.get_help_text()
PAGE_STATUS.VALID.get_help_text()

And of course, it is fully supported by Django and Django Migrations:
class Page(models.Model):
    status = models.CharField(choices=PAGE_STATUS, default=PAGE_STATUS.CREATED)

Full documentation here: https://pypi.org/project/django-better-choices/


text:
Q: How to write a typed function that manages my api routes? Doing a little experiment to reduce code smell and in that effort I'm trying to write a typed function that would allow me to define my endpoints in one location within my application. The thought is, if I ever change or add routes, I can define them in one area which is then dispersed across the application.
The example below is where I'm at currently. While it does works, it's still a bit messy and not exactly DRY (repeating enum value as the path in the getApiAddress() function.)
Any thoughts how I can create a function that allows me to add n[] unique id:string params while ago getting rid of the {target: '', path: ''} and just have one value that can accept those id string values?
const apiAddress =
  process.env === 'PRODUCTION'
    ? 'https://some-address.com'
    : 'http://localhost:5000';

export enum targetsEnum {
  transcribe = '/services/transcribe',
  transcribeId = '/services/transcribe/:id',
}

export type ApiTargets = targetsEnum.transcribe | targetsEnum.transcribeId;

export const getApiAddress = (target: ApiTargets, id?: string[]): string => {
  const endpoints = [
    { target: targetsEnum.transcribe, path: '/services/transcribe' },
    {
      target: targetsEnum.transcribeId,
      path: `/services/transcribe/${id[0]}`,
    },
  ];
  const matchingEndpoint = endpoints.find(
    endpoint => endpoint.target === target
  );
  return `${apiAddress}${matchingEndpoint.path}`;
};

A: continued to work on this some more.
With the approach below, you can defined you endpoints in one location (targetsEnum) and pass that in anywhere in your application. Then, the second argument is an array of strings. They are injected into the enum's value using injectPathVariables().
example:
const endpoint = getApiAddress(ApiEndpointsEnum.youtubeId,['${youtubeId}']);
const apiAddress =
  process.env === 'PRODUCTION'
    ? 'https://some-endpoint.com'
    : 'http://localhost:5000';

export enum testApiEndpointsEnum {
  test = '/test',
  testId = '/test/:id',
  testIdtestId = '/test/:id/test/:id',
}

export enum ApiEndpointsEnum {
  youtube = '/services/youtube',
  youtubeId = '/services/youtube/:id',
  transcribe = '/services/transcribe',
  transcribeId = '/services/transcribe/:id',
}

export type ApiTargets =
  | testApiEndpointsEnum.test
  | testApiEndpointsEnum.testId
  | testApiEndpointsEnum.testIdtestId
  // * ^ the TWO above this comment are for testing.
  | ApiEndpointsEnum.youtube
  | ApiEndpointsEnum.youtubeId
  | ApiEndpointsEnum.transcribe
  | ApiEndpointsEnum.transcribeId

const injectPathVariables = (
  target: ApiTargets[1],
  ids: string[]
  ): string => {
  let newStr = target;
  ids.forEach(i => {
    newStr = newStr.replace(':id', i);
  });
  return newStr;
};

const getApiAddress = (target: ApiTargets, ids?: string[]): string => {
  // * no ids provided + confirmation target doesn't need ids.
  if (ids === undefined && target.includes(':id') === false) {
    return `${apiAddress}${target}`;
  }

  // * no ids provided, but target does need ids.
  if (
    (ids === undefined || ids.length === 0) &&
    target.includes(':id') === true
  ) {
    return `${apiAddress}`;
  }

  // * ids have been provided.
  const injectedOutput = injectPathVariables(target, ids);
  if (injectedOutput.includes(':id')) {
    // * but not enough ids were provided for complete injection.
    return apiAddress;
  }
  // * sufficient ids have been provided
  return `${apiAddress}${injectedOutput}`;
};


text:
Q: Javascript mongoose callback function when set data Hello my problem is when I post base 64 images, I want to return a photo URL that's inside of my schema set return value
It always returns null and not set to photoUrl column
here is my schema
const ProductSchema = new Schema({
    _id: {
        type: Schema.Types.ObjectId,
        default: require('mongodb').ObjectID
    },
    country: {
        type: String,
        required: [true, "country can't be null"]
    },
    photoUrl: {
        type: String,
        set: setImage
    }
})

this my setter function
function setImage(base64) {
    return uploadImage(base64,'/storage/products/');
}

and this is my uploadImage function on another page
const fs = require('fs');
const keys = require('../config/keys');
const mkdirp = require('mkdirp');
const uuidv4 = require('uuid/v4');

module.exports = {
    get: function() {
        let a = "Hello Node World!!!";
        return a;
    },
    uploadImage: function(base64,storageURI,callback) {
        const storagePathURI = '.' + storageURI;
        mkdirp(storagePathURI, function (err) {
            if (!err) {
                var base64Data = base64.replace(/^data:image\/png;base64,/, "");
                fs.writeFile(storagePathURI + uuidv4() + '.png', base64Data, 'base64')
                return keys.baseStorageURI + storageURI +  uuidv4() + '.png';
            }
        });
    }
}

how can I map this URL to my photoUrl column when I insert or update the object?


text:
Q: CMake cyclic dependency error when a custom library name is the same as a system library I'm writing a CMakeLists.txt file to build a C++ project of mine, which is composed of

*

*libhybris.so: A shared library with some exported functions.

*hybris: An executable which links to libhybris.so

*A set of various shared libraries which links to libhybris.so

The problem is that, libhybris.so depends on libpcre (for regular expression capabilities), so I have the following statements:
# libhybris.so generation
add_library( libhybris
             SHARED
             ${LIB_SOURCES} )

...

# Needed libraries
target_link_libraries( libhybris
                       dl
                       pcre
                       pthread
                       readline )

And one of the shared libraries from point 3, is called pcre.so, so I have the following too:
add_library( pcre SHARED ${PCRE_SOURCES} )

...

target_link_libraries( pcre
                       dl
                       pcre
                       curl
                       pthread
                       readline
                       ffi
                       libhybris )

So, when I run a "cmake .", I have the following error:
-- Configuring done
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
  "libhybris" of type SHARED_LIBRARY
    depends on "pcre"
  "pcre" of type SHARED_LIBRARY
    depends on "libhybris"
At least one of these targets is not a STATIC_LIBRARY.  Cyclic dependencies are allowed only among static libraries.

Because CMake thinks that the libhybris.so pcre dependency (system libpcre.so) is the same of my pcre.so which it is obviously not.
How can I solve this problem without changing the pcre.so name?

A: In CMake, the recommended way is to specify any link libraries with the full path. To get the full path for the system library, you can either use FIND_PACKAGE(...) if supported or simply FIND_LIBRARY(...)
For example,
FIND_LIBRARY( PCRE_SYSTEM_LIB pcre )

ADD_LIBRARY( libhybris SHARED ${LIB_SOURCES} )
TARGET_LINK_LIBRARIES( libhybris
                       ${PCRE_SYSTEM_LIB}
                       ......
                      )

This will prevent CMake from expanding something it recognizes as a target (nameley pcre) to the full path of that target.

A: It depends on your development environments. You can set a build path to overcome these difficulties.