答:
You can use the getPopup method inherited from L.Layer:

```<code>var popup = e.layer.getPopup();
</code>```

When you have the popup you can use the getContent method of L.Popup:

```<code>var content = popup.getContent();
</code>```

Reference:

http://leafletjs.com/reference-1.1.0.html#layer-getpopup

http://leafletjs.com/reference-1.1.0.html#popup-getcontent

Title: leaflet : how to get the popup content on marker click?

Body:
i cannot find the method to get the popup content on marker click?

http://jsfiddle.net/zpd6mjnb/

> //An extract of address points from the LINZ bulk extract:
> http://www.linz.govt.nz/survey-titles/landonline-data/landonline-bde
> //Should be this data set:
> http://data.linz.govt.nz/#/layer/779-nz-street-address-electoral/ var
> addressPoints = [ [-37.793167, 175.211862,"the one"], [-37.8210922667,
> 175.2209316333, "2"], [-37.8210819833, 175.2213903167, "3"], [-37.8210881833, 175.2215004833, "3A"], [-37.8211946833,
> 175.2213655333, "1"], [-37.8209458667, 175.2214051333, "5"], [-37.8208292333, 175.2214374833, "7"], [-37.8325816, 175.2238798667,
> "537"], [-37.8315855167, 175.2279767, "454"], [-37.8096336833,
> 175.2223743833, "176"], [-37.80970685, 175.2221815833, "178"], [-37.8102146667, 175.2211562833, "190"], [-37.8088037167, 175.2242227,
> "156"], [-37.8112330167, 175.2193425667, "210"], [-37.8116368667,
> 175.2193005167, "212"], [-37.80812645, 175.2255449333, "146"], [-37.8080231333, 175.2286383167, "125"], [-37.8089538667,
> 175.2222222333, "174"], [-37.8080905833, 175.2275400667, "129"], [-37.808811, 175.2227592833, "172"], [-37.80832975, 175.2276898167,
> "131"], [-37.8089395333, 175.2281710333, "133"], [-37.8093421,
> 175.2274883167, "135"], [-37.8084820833, 175.22601925, "137"], [-37.80881015, 175.22622865, "139"], [-37.8090947667, 175.2263585667,
> "141"], [-37.8092962333, 175.2244872333, "147"], [-37.8091016667,
> 175.2249140167, "145"], [-37.8088785167, 175.2253611667, "143"], [-37.80825965, 175.22530115, "148"], [-37.80995685, 175.2238554333,
> "153"], [-37.80975435, 175.2238417833, "151"], [-37.80950755,
> 175.2237912, "149"], [-37.8092772667, 175.2231980833, "170"], [-37.8082753833, 175.20672975, "4"], [-37.8078434833, 175.211822,
> "56"], [-37.8083775667, 175.2090812333, "30B"], [-37.8084588,
> 175.2058838167, "174"], [-37.8088788333, 175.2062702833, "175"], [-37.8091632833, 175.20514875, "182A"], [-37.8094891167, 175.20384695,
> "202"], [-37.8156715667, 175.2034881667, "277"], [-37.8109189333,
> 175.2024631, "220"], [-37.8108164333, 175.2039622, "219"], [-37.8125773667, 175.2026079667, "238"], [-37.8125799333, 175.2032824,
> "241A"], [-37.8125869, 175.2037423833, "241C"], [-37.8140266833,
> 175.2025706, "256"], [-37.80932, 175.2051094333, "182B"], [-37.8098799667, 175.2040444167, "197"], [-37.8094298833,
> 175.20561245, "189"], [-37.8172409333, 175.2035291167, "287"], [-37.8232166667, 175.22452865, "2028"], [-37.8225024333,
> 175.2249944667, "2022"], [-37.82334135, 175.2244748667, "2030"], [-37.8229725333, 175.2246809333, "2026"], [-37.8224034667,
> 175.22507345, "2020"], [-37.8227806, 175.2248285833, "2024"], [-37.8178801, 175.2181871667, "6"], [-37.81811315, 175.2180543667,
> "4"], [-37.8181739833, 175.21851995, "1"], [-37.81797515, 175.2186312,
> "3"], [-37.8181787, 175.2176995, "2A"], [-37.8183385333, 175.21812895,
> "2"], [-37.8293053167, 175.2105357833, "31"], [-37.8309444333,
> 175.21208735, "16"], [-37.8306726667, 175.2115020833, "19"], [-37.8300903, 175.2120791, "26"], [-37.8289416167, 175.2113778333,
> "33"], [-37.8274969167, 175.2113355167, "53"], [-37.8199192667,
> 175.2173622833, "5A"], [-37.8200392833, 175.2174100167, "3"], [-37.8196328, 175.2167642, "18"], [-37.81752585, 175.2155467667,
> "22C"], [-37.81766615, 175.2153714167, "22B"], [-37.8179022667,
> 175.2151616833, "22A"], [-37.8191980333, 175.21664245, "20A"], [-37.81799325, 175.21565925, "20C"], [-37.8187486333, 175.2165228667,
> "20B"], [-37.81964875, 175.2172874167, "7"], [-37.81925545,
> 175.2171617, "11"], [-37.8190491667, 175.2170928333, "13"], [-37.8194515667, 175.2172147167, "9"], [-37.81981045, 175.21733245,
> "5B"], [-37.81876595, 175.2172445167, "15B"], [-37.8185999167,
> 175.2172441, "17A"], [-37.81816745, 175.21725905, "21B"], [-37.8182157167, 175.2164626333, "24"], [-37.8180109667,
> 175.2173984167, "23A"], [-37.8179918, 175.217159, "23B"], [-37.8188473167, 175.2170330333, "15"], [-37.8186481333,
> 175.2169800667, "17"], [-37.8184132, 175.2169327333, "19"], [-37.8202288333, 175.2174746333, "1"], [-37.818193, 175.2169955667,
> "21"], [-37.8178000833, 175.21733275, "25"], [-37.8176839,
> 175.2168488333, "26"], [-37.8198172, 175.2204960667, "5"], [-37.819986, 175.22049635, "3"], [-37.8197666, 175.2200825, "4"],
> [-37.8193835833, 175.2191669667, "10"], [-37.8193426333,
> 175.2198626667, "11"], [-37.8192171667, 175.2191711, "12"], [-37.8192621333, 175.2196364167, "13"], [-37.8195289667,
> 175.2193943167, "8"], [-37.81946, 175.2201499167, "9"], [-37.8196037833, 175.219674, "6"], [-37.8194712, 175.2204032, "7A"],
> [-37.8196381, 175.2203709333, "7"], [-37.8200137667, 175.2201364333,
> "2"], [-37.8191725167, 175.2193772833, "14"], [-37.8214417333,
> 175.2256822167, "4"], [-37.8210291, 175.2259429667, "8"], [-37.8212328333, 175.2258132, "6"], [-37.8216819833, 175.2253209,
> "3"], [-37.8334697167, 175.2038651667, "326"], [-37.8322603667,
> 175.2028621167, "317"], [-37.8322013667, 175.2046802667, "1/341"], [-37.8320576167, 175.2165535833, "435"], [-37.8319540333,
> 175.20506915, "2/341"], [-37.8316975667, 175.2053442333, "3/341"], [-37.8328229833, 175.2062598, "346"], [-37.83161565, 175.2074915,
> "355"], [-37.83219305, 175.20629425, "347"], [-37.8328549,
> 175.2080619667, "362"], [-37.8321289667, 175.2084019333, "367"], [-37.8322225167, 175.2120427667, "397"], [-37.8321649, 175.21119325,
> "393"], [-37.8321458833, 175.2131246333, "407"], [-37.8327043833,
> 175.21377405, "416"], [-37.8321267167, 175.2144058167, "417"], [-37.83212555, 175.2096521333, "373"], [-37.8331028667, 175.20928495,
> "366"], [-37.82866875, 175.22177625, "563"], [-37.8295602,
> 175.21924335, "582"], [-37.8304707833, 175.2182986167, "590"], [-37.83086, 175.2180687667, "592"], [-37.8328604833, 175.2172892167,
> "618"], [-37.8342575667, 175.2168357833, "638"], [-37.8239713,
> 175.2245693667, "504"], [-37.8365260167, 175.2170911, "673"], [-37.8233928833, 175.2249669167, "492"], [-37.8248650167,
> 175.2246300833, "509"], [-37.8191798333, 175.2265331667, "435"], [-37.8143243333, 175.2310940167, "368"], [-37.81459255, 175.2320046,
> "363"], [-37.81127515, 175.2356499167, "311"], [-37.8126359667,
> 175.2340855167, "333"], [-37.8096158333, 175.2375218167, "293"], [-37.8315868667, 175.2177722833, "604"], [-37.8160177667,
> 175.2299268333, "391"], [-37.8204715667, 175.2265481833, "456"], [-37.8206352, 175.2265670333, "458"], [-37.8208412667, 175.2265323333,
> "460"], [-37.8210184333, 175.22648325, "462"], [-37.8212643833,
> 175.2270422167, "465"], [-37.82119945, 175.2264274333, "464"], [-37.82136485, 175.2263145667, "466"], [-37.8215261, 175.22684075,
> "467"], [-37.8215301833, 175.2262078, "468"], [-37.8217701667,
> 175.2266360167, "1/471"], [-37.8218376833, 175.22686725, "2/471"], [-37.8217084667, 175.2260839667, "472"], [-37.8219782333,
> 175.2265028333, "475"], [-37.8218988833, 175.2259723, "476"], [-37.8223939333, 175.2262447, "479"], [-37.8223048667, 175.2256582833,
> "480"], [-37.8226657, 175.2261230833, "481"], [-37.8224199,
> 175.2255487833, "482"], [-37.8229134167, 175.2259527833, "485"], [-37.8226937833, 175.2253693167, "486"], [-37.8231509667,
> 175.2258170333, "487"], [-37.82295265, 175.2252571167, "488"], [-37.8233779, 175.2256743833, "489"], [-37.8232052667, 175.2251109333,
> "490"], [-37.8236200333, 175.22553395, "493"], [-37.82385775,
> 175.2253390833, "495"], [-37.8203220167, 175.22650925, "454"], [-37.8179795333, 175.2262826, "428"], [-37.81038215, 175.2365298167,
> "303"], [-37.8161746667, 175.2297239833, "393"], [-37.8083635333,
> 175.233955, "294"], [-37.82029495, 175.2214968167, "39"], [-37.8204754333, 175.2247793333, "12B"], [-37.8205440833,
> 175.22344905, "23"], [-37.8195974333, 175.2254019333, "2"], [-37.8210801, 175.2237748667, "20A"], [-37.8209057333, 175.22389775,
> "18"], [-37.8208016833, 175.2221582833, "32"], [-37.8209372667,
> 175.2236919, "20"], [-37.8210586833, 175.22351925, "22B"], [-37.82092905, 175.2234855333, "22"], [-37.8208587333, 175.2231887667,
> "24"], [-37.8210241167, 175.2230882, "24B"], [-37.8208547833,
> 175.2229410667, "26"], [-37.8209917, 175.2228447667, "26B"], [-37.82097645, 175.2227176167, "28B"], [-37.8208099167,
> 175.2226765167, "28"], [-37.8207666833, 175.2224338833, "30"], [-37.8209508833, 175.2222094167, "32B"], [-37.82076515,
> 175.2219195167, "34A"], [-37.8207399667, 175.2218131667, "34B"], [-37.8203075833, 175.2240482833, "19"], [-37.8205368167,
> 175.2237746667, "21"], [-37.8205025833, 175.2231658, "25A"], [-37.820465, 175.2229733667, "27"], [-37.82043535, 175.2227387, "29"],
> [-37.8204582, 175.2225319667, "31"], [-37.82024115, 175.2224347833,
> "31B"], [-37.8203792333, 175.2222631667, "33"], [-37.82034095,
> 175.2219843, "35"], [-37.8201566167, 175.2219446, "35B"], [-37.82030575, 175.2217594333, "37"], [-37.8202966833, 175.2233158167,
> "25"], [-37.8192714167, 175.2253842667, "1"], [-37.81969695,
> 175.22516645, "4"], [-37.8194904667, 175.22468815, "5"], [-37.8198524333, 175.2249096667, "6"], [-37.8200581833, 175.2247122,
> "8"], [-37.8193447, 175.2244639667, "5C"], [-37.8208238,
> 175.2241340167, "16"], [-37.8193183667, 175.22515695, "1A"], [-37.81940575, 175.2249383333, "3"], [-37.8211855167, 175.2242545333,
> "18A"], [-37.8207094833, 175.22430275, "14"], [-37.82027725,
> 175.22488135, "10A"], [-37.8202305833, 175.2245652667, "10"], [-37.8205049667, 175.2244201333, "12"], [-37.8196320333, 175.2255586,
> "22"], [-37.8209711, 175.2250444667, "8"], [-37.82120665,
> 175.2252942833, "5"], [-37.8210184, 175.2254290333, "7"], [-37.8213430333, 175.2252086167, "3"], [-37.8207887833,
> 175.2251555667, "10"], [-37.82060805, 175.2257042333, "13"], [-37.8208330333, 175.22553905, "9"], [-37.8216988833, 175.2249665667,
> "1"], [-37.8215665833, 175.2246573333, "2"], [-37.8213729,
> 175.2247789333, "4"], [-37.8211700667, 175.2249324333, "6"], [-37.8205967667, 175.2252867, "12"], [-37.8204008833, 175.2254234667,
> "14"], [-37.82043265, 175.22582195, "15"], [-37.8202037333,
> 175.2255415833, "16"], [-37.8200154333, 175.2256547667, "18"], [-37.8197443167, 175.2256164833, "20"], [-37.8202814333, 175.22590955,
> "17"], [-37.8202967667, 175.21462555, "98"], [-37.82204485,
> 175.21819735, "61B"], [-37.8224241, 175.2179326667, "61C"], [-37.8215043167, 175.2227943833, "24"], [-37.8219082, 175.2255408167,
> "8"], [-37.8216963, 175.2240856667, "14"], [-37.8213418333,
> 175.2188135667, "55"], [-37.8204966333, 175.2183406333, "54A"], [-37.8221799833, 175.21122085, "139"], [-37.8217387, 175.22431625,
> "12"], [-37.8218650167, 175.2149734167, "107"], [-37.8214083333,
> 175.2220152667, "30"], [-37.8213738333, 175.2217301, "32"], [-37.8221598167, 175.2247839333, "9"], [-37.8216356, 175.2235610667,
> "18"], [-37.8212188167, 175.2221387333, "30B"], [-37.8200466667,
> 175.2166111, "84A"], [-37.8216679333, 175.2238393333, "16"], [-37.8211582833, 175.22031685, "34"], [-37.8221918667, 175.2250378333,
> "7"], [-37.8187410167, 175.2067290167, "170C"], [-37.8206532,
> 175.2170745667, "81"], [-37.8212348667, 175.2181024167, "67"], [-37.8213057667, 175.2185351167, "57"], [-37.8214571, 175.2145877333,
> "110"], [-37.82207085, 175.2136727167, "121"], [-37.82190125,
> 175.2123493, "130"], [-37.8207519667, 175.2102467333, "150"], [-37.8212159, 175.2096407, "159"], [-37.8208313833, 175.2067756,
> "172"], [-37.8214413333, 175.2222779833, "28"], [-37.8206921333,
> 175.2182549, "54"], [-37.82043975, 175.2181215, "56"], [-37.8218791, 175.2252452167, "10"], [-37.82029435, 175.2169818, "84"], [-37.8215885167, 175.22308725, "22"], [-37.8215897333, 175.2233113167,
> "20"], [-37.82167455, 175.2183345, "61A"], [-37.8217164667,
> 175.2179857333, "63"], [-37.82147385, 175.22253565, "26"], [-37.8206765333, 175.2160304333, "86"], [-37.8188941, 175.2069437,
> "170A"], [-37.8188068333, 175.2068104833, "170B"], [-37.8193742667,
> 175.2085580333, "170"], [-37.8214388167, 175.2200072, "45"], [-37.8209547167, 175.2157149167, "92"], [-37.82088565, 175.2164849333,
> "85"], [-37.82136235, 175.2159546667, "97"], [-37.8219607333,
> 175.2232987, "19"], [-37.8210501, 175.2179753833, "69"], [-37.8212466667, 175.2222175833, "28A"], [-37.8213836167,
> 175.22300555, "22A"], [-37.821339, 175.2227439167, "24A"], [-37.8208144333, 175.2173117167, "77"], [-37.8189363667,
> 175.2211582333, "25"], [-37.8196676167, 175.2209947333, "26B"], [-37.8194113, 175.2211991, "26"], [-37.81883205, 175.2209747, "27"],
> [-37.8186925833, 175.2207728833, "29"], [-37.8199931833,
> 175.2240802167, "2"], [-37.8191759333, 175.2208279333, "30"], [-37.81835395, 175.2196571667, "39"], [-37.8198807333, 175.2235938167,
> "6"], [-37.8194567833, 175.22349015, "7"], [-37.8200507833,
> 175.21933875, "58"], [-37.8197902167, 175.2182408, "59A"], [-37.81991635, 175.21797195, "59B"], [-37.8198223833, 175.2179361833,
> "59C"], [-37.8201049333, 175.2197347167, "60"], [-37.8199380333,
> 175.21836645, "61A"], [-37.82003775, 175.2182443833, "61B"], [-37.8200944167, 175.21803015, "61C"], [-37.8201259667,
> 175.2185610667, "63"], [-37.82026275, 175.2188001167, "65"], [-37.8188917833, 175.2203729333, "34"], [-37.8184921333, 175.2203832,
> "33"], [-37.8190387167, 175.2206181333, "32"], [-37.81968705,
> 175.2224253667, "16"], [-37.81981205, 175.223119, "10"], [-37.8193882833, 175.2229798333, "11"], [-37.8190901167,
> 175.2227829833, "13B"], [-37.8193593, 175.2227247833, "13"], [-37.81993935, 175.2226893333, "14B"], [-37.81842725, 175.2201474167,
> "35"], [-37.8187965833, 175.2200475333, "36"], [-37.8183878167,
> 175.2198735667, "37"], [-37.8188702167, 175.2196982333, "38B"], [-37.82027885, 175.2209890667, "82"], [-37.8199839667, 175.2190668,
> "56"], [-37.8187008333, 175.21973745, "38A"], [-37.8196820167,
> 175.22262455, "14"], [-37.8186528333, 175.2191018, "42"], [-37.8182912167, 175.21915535, "43"], [-37.81870525, 175.21945675,
> "40"], [-37.8195044333, 175.2214081833, "24"], [-37.81857075,
> 175.2205925167, "31"], [-37.8195656167, 175.2181396, "57"], [-37.8198411667, 175.2213911167, "24A"], [-37.8195851667,
> 175.2240869667, "3"], [-37.8192829167, 175.2239720167, "3A"], [-37.8193257, 175.2224725667, "15"], [-37.8197290167, 175.2224129833,
> "16A"], [-37.8196499333, 175.2221262667, "18"], [-37.8196755333,
> 175.2243193333, "1"], [-37.8192091667, 175.22166805, "21"], [-37.81957585, 175.22166585, "22"], [-37.8199106833, 175.2238436,
> "4"], [-37.81953715, 175.22372785, "5A"], [-37.8193377833,
> 175.22378105, "5"], [-37.8189702833, 175.2184597333, "46"], [-37.8185876167, 175.21821495, "47A"], [-37.8185706333,
> 175.2178869167, "47B"], [-37.8191945667, 175.21845965, "48"], [-37.8188482167, 175.2176680833, "49"], [-37.8194043667, 175.21852395,
> "50"], [-37.8196233333, 175.2186248333, "52"], [-37.81920055,
> 175.2179787167, "53"], [-37.8198255, 175.2188011167, "54"], [-37.8205994333, 175.2207248667, "81"], [-37.8193045333,
> 175.2222075667, "17"], [-37.8205621167, 175.2204520167, "79"], [-37.8180799333, 175.2194407, "41A"], [-37.8208301833, 175.2206735833,
> "81A"], [-37.8202558, 175.2206809333, "80"], [-37.81941275,
> 175.21804965, "55"], [-37.8190239, 175.2179808833, "51"], [-37.8187854, 175.2180712167, "47"], [-37.8187476667, 175.2186516333,
> "44"], [-37.8182977, 175.21889655, "45"], [-37.81831675,
> 175.2194069833, "41"], [-37.8192735167, 175.2219502167, "19"], [-37.8196219167, 175.22189825, "20"], [-37.81962665, 175.2216432667,
> "22A"], [-37.8192782833, 175.2209942, "28"], [-37.8208129833,
> 175.2209176833, "83A"], [-37.8206351167, 175.2209705667, "83"], [-37.8203109333, 175.2212402667, "84"], [-37.81909575, 175.22139795,
> "23"], [-37.8197787167, 175.2228814, "12"], [-37.8195628333,
> 175.21791605, "57A"], [-37.8198373833, 175.2233606833, "8"], [-37.8194342167, 175.22322975, "9"] ];
>
>
> var tiles =
> L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
> maxZoom: 18,   attribution: '©  href="https://www.openstreetmap.org/copyright">OpenStreetMap
> contributors, Points &copy 2012 LINZ' }),
>     latlng = L.latLng(-37.82, 175.24);
>
> var map = L.map('map', {center: latlng, zoom: 13, layers: [tiles]});
>
>
> var markers = L.markerClusterGroup();
>
> for (var i = 0; i < addressPoints.length; i++) {   var a =
> addressPoints[i];   var title = a[2];   var marker = L.marker(new
> L.LatLng(a[0], a[1]), {title: title});   marker.bindPopup(title);
> markers.addLayer(marker); }
>
> markers.on('clusterclick', function (a) {
>     console.log('cluster with ' + a.layer.getAllChildMarkers().length + ' markers in it'); });
>
> markers.on('click', function (a) {
>       //how to get the popup content here?
>        console.log(a.layer);
>      });
>
> map.addLayer(markers);
>
> map.on('popupopen', function(e) {   var popupContent = e;   //how to
> get the popup content here?   console.log(e);    });

Body:
You can use the getPopup method inherited from L.Layer:

var popup = e.layer.getPopup();

When you have the popup you can use the getContent method of L.Popup:

var content = popup.getContent();

Reference:

http://leafletjs.com/reference-1.1.0.html#layer-getpopup

http://leafletjs.com/reference-1.1.0.html#popup-getcontent


来源: stackexchange

问:
How might I find the largest number contained in a JavaScript array?
I have a simple JavaScript Array object containing a few numbers.

```<code>[267, 306, 108]
</code>```

Is there a function that would find the largest number in this array?

答:
I just started with JavaScript, but I think this method would be good:</p>
```<code>var array = [34, 23, 57, 983, 198];
var score = 0;

for(var i = 0; i = array.length; i++) {
  if(array[ i ] > score) {
    score = array[i];
  }
}
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I have a simple JavaScript Array object containing a few numbers.

[267, 306, 108]

Is there a function that would find the largest number in this array?

Body:
I just started with JavaScript, but I think this method would be good:

var array = [34, 23, 57, 983, 198];
var score = 0;

for(var i = 0; i = array.length; i++) {
  if(array[ i ] > score) {
    score = array[i];
  }
}

ContentLicense: CC BY-SA 4.0


问:
from multiple-dimension array double, to int
As the title says, I would like to know if there is a simple way to convert a multiple dimension array of double numbers to the same array, but in int numbers.

Of course we could have two(or more) for loops going to each number and convert them, but I was wondering if there is a simple method to do it? :)

(By the way I am truly sorry if this question has already been asked a lot, but I didn't find any answer!)

Edit: As I lack a lot of informations:
I have for example

```<code>double[,] tab1 = {{3.42,1.6523,42.42142},{42.124,932.241, 9.421}};
int[,] tab2;
</code>```

And I would like to have at the end

```<code>tab2 = {{3,1,42}{42,932,9}}
</code>```

Right now the code I have to do this is

```<code>for(int i=0; i<tab1.GetLength(0); i++){
    for (int j=0; j<tab1.GetLength(1); j++) {
        tab2[i,j] = (int)tab1[i,j];
    }
}
</code>```

答:
Well considering it's a two dimensional array, you can do it using a single for loop and using Array.ConvertAll() method. See an example below. hope gives a pointer

```<code>int[] convertedArray = Array.ConvertAll(myDoubleArray, x => (int)x);
</code>```

ContentLicense: CC BY-SA 3.0

Body:
As the title says, I would like to know if there is a simple way to convert a multiple dimension array of double numbers to the same array, but in int numbers.

Of course we could have two(or more) for loops going to each number and convert them, but I was wondering if there is a simple method to do it? :)

(By the way I am truly sorry if this question has already been asked a lot, but I didn't find any answer!)

Edit: As I lack a lot of informations:
I have for example

double[,] tab1 = {{3.42,1.6523,42.42142},{42.124,932.241, 9.421}};
int[,] tab2;

And I would like to have at the end

tab2 = {{3,1,42}{42,932,9}}

Right now the code I have to do this is

for(int i=0; i<tab1.GetLength(0); i++){
    for (int j=0; j<tab1.GetLength(1); j++) {
        tab2[i,j] = (int)tab1[i,j];
    }
}

Body:
Well considering it's a two dimensional array, you can do it using a single for loop and using Array.ConvertAll() method. See an example below. hope gives a pointer

int[] convertedArray = Array.ConvertAll(myDoubleArray, x => (int)x);


问:
Create csv based on a object property assigned dynamically
I need to build a csv string based on a specific property from an object stored in a list but I've got to do this for multiple properties:

The below works fine when "hardcoded":

```<code>var list = customers.Select(p => p.Email).ToArray();
csvString = string.Join(";", list1);
</code>```

but I obviously don't want to have to do this for every property I need. Is there a way for me to build a function and assign the property name I want to use to one of the parameters. Something similar to this:

```<code>var emails = ConvertCollectionToCsv(customers, "Email");
var names = ConvertCollectionToCsv(customers, "Name");
var mobile = ConvertCollectionToCsv(customers, "Mobile");
...
</code>```

I thought I'd try the following:

```<code>private string ConvertCollectionToCsv(List<Customer> customers, string propertyName)
{
   var prop = typeof(EmailAddress).GetProperties().FirstOrDefault
   (p => p.Name.ToLowerInvariant() == propertyName.ToLowerInvariant());

   var list = customers.Select(p => prop.Name).ToArray();
   return string.Join(";", list);
}
</code>```

but when called:

```<code>var emails = ConvertCollectionToCsv(customers, "Email");
</code>```

it returns Email;Email;Email instead of the email address which makes sense as the prop.Name is used. I'm trying to use the GetValue instead:

```<code>var list = customers.Select(p => prop.GetValue(p)).ToArray();
</code>```

but that's throwing the following error:

```<code>"Object does not match target type."
</code>```

Any suggestions?

Thanks

答:
You have to get the properties from the Customer, since that is were you get the value later on.

```<code>var prop = typeof(Customer).GetProperties().FirstOrDefault
(p => p.Name.ToLowerInvariant() == propertyName.ToLowerInvariant());
</code>```

and this seems odd:

```<code>var list = list.Select(p => prop.GetValue(p)).ToArray();
</code>```

list.Select - what is list?
isn't it rather:

```<code>var list = customers.Select(p => prop.GetValue(p)).ToArray();
</code>```

Body:
I need to build a csv string based on a specific property from an object stored in a list but I've got to do this for multiple properties:

The below works fine when "hardcoded":

var list = customers.Select(p => p.Email).ToArray();
csvString = string.Join(";", list1);

but I obviously don't want to have to do this for every property I need. Is there a way for me to build a function and assign the property name I want to use to one of the parameters. Something similar to this:

var emails = ConvertCollectionToCsv(customers, "Email");
var names = ConvertCollectionToCsv(customers, "Name");
var mobile = ConvertCollectionToCsv(customers, "Mobile");
...

I thought I'd try the following:

private string ConvertCollectionToCsv(List<Customer> customers, string propertyName)
{
   var prop = typeof(EmailAddress).GetProperties().FirstOrDefault
   (p => p.Name.ToLowerInvariant() == propertyName.ToLowerInvariant());

   var list = customers.Select(p => prop.Name).ToArray();
   return string.Join(";", list);
}

but when called:

var emails = ConvertCollectionToCsv(customers, "Email");

it returns Email;Email;Email instead of the email address which makes sense as the prop.Name is used. I'm trying to use the GetValue instead:

var list = customers.Select(p => prop.GetValue(p)).ToArray();

but that's throwing the following error:

"Object does not match target type."

Any suggestions?

Thanks

Body:
You have to get the properties from the Customer, since that is were you get the value later on.

var prop = typeof(Customer).GetProperties().FirstOrDefault
(p => p.Name.ToLowerInvariant() == propertyName.ToLowerInvariant());

and this seems odd:

var list = list.Select(p => prop.GetValue(p)).ToArray();

list.Select - what is list?
isn't it rather:

var list = customers.Select(p => prop.GetValue(p)).ToArray();


问:
AIF document services in axapta 2012 update operation response
Is there way to let the external system know that if an update operation was successful on certain record(s). As per the standard process the update operation in axapta 2012 R3 does not return anything.

Thanks

答:
You can modify update method in your service class to return a value. E.g.:

```<code>[AifDocumentUpdateAttribute, SysEntryPointAttribute(true)]
public AifEntityKeyList update(AifEntityKeyList _entityKeyList, CustCustomer _custCustomer)
{
    this.updateList(_entityKeyList, _custCustomer);

    return this.getCorrelationEntityKeys();
}
</code>```

Body:
You can modify update method in your service class to return a value. E.g.:

[AifDocumentUpdateAttribute, SysEntryPointAttribute(true)]
public AifEntityKeyList update(AifEntityKeyList _entityKeyList, CustCustomer _custCustomer)
{
    this.updateList(_entityKeyList, _custCustomer);

    return this.getCorrelationEntityKeys();
}


问:
Kindly provide the source code to determine the last item in the ListView
I am trying to implementing pagination in Android.
Currently I am displaying in ListView  , a list of 10 items where the data for the list items exist in the database.

Each list item contains an thumbnail Image Url , a text data

I have the following requirement.
i> When the user scrolls  to the 10 th list item , I am calling a webservice method of the server to fetch the next set of records.

My question is how can I determine when the user scrolls to the 10 th list item , what kind of validation can I make.

Kindly provide me the sample source code.

Warm Regards,

CB

答:
If you want to fetch the next set of records when 10th item is visible on the list then write a condition in OnScrollListener similar to this...

```<code>mListView.setOnScrollListener(new OnScrollListener()
    {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState)
        {
            // TODO Auto-generated method stub

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
        {
            if(view.getLastVisiblePosition() == 10)
            {
                // do operation to retrieve other data into listview
            }
        }
    });
</code>```

Body:
If you want to fetch the next set of records when 10th item is visible on the list then write a condition in OnScrollListener similar to this...

mListView.setOnScrollListener(new OnScrollListener()
    {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState)
        {
            // TODO Auto-generated method stub

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
        {
            if(view.getLastVisiblePosition() == 10)
            {
                // do operation to retrieve other data into listview
            }
        }
    });


问:
How to depend on log4j in a Sonarqube plugin?
I am developing a SonarQube 5.6 plugin. This plugin depends on a library X (a third party library). Library X depends on Log4J. To resolve the dependency problem I am adding log4j dependency in pom.xml with provided scope as defined in SonarQube documentation. But at runtime I am getting class not found exceptions related to log4j.

When I change my third party library, so that it does not use log4j anymore (basically log4j related code is commented out), the problem is gone.

How should I add the log4j dependency in SonarQube or what should I do so that the problem with log4j is resolved in my SonarQube plugin? Or what is the best way to deal with such problem when container says it will provide the dependency but it is not?

The dependency is declared like this:

```<code><dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8.2</version>
</dependency>
</code>```

答:
You should exclude any log4j dependency, and instead rely on log4j-over-slf4j to redirect any log4j call to slf4j.

log4j-over-slf4j should be already provided in the runtime plugin classloader, so basically it should work out of the box. What kind of problem are you facing?

Body:
I am developing a SonarQube 5.6 plugin. This plugin depends on a library X (a third party library). Library X depends on Log4J. To resolve the dependency problem I am adding log4j dependency in pom.xml with provided scope as defined in SonarQube documentation. But at runtime I am getting class not found exceptions related to log4j.

When I change my third party library, so that it does not use log4j anymore (basically log4j related code is commented out), the problem is gone.

How should I add the log4j dependency in SonarQube or what should I do so that the problem with log4j is resolved in my SonarQube plugin? Or what is the best way to deal with such problem when container says it will provide the dependency but it is not?

The dependency is declared like this:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8.2</version>
</dependency>


问:
System.InvalidOperationException when reading values from xml file in C#
So i have this code sample... what it should do is... simple read a value from an xml file...

```<code>    XDocument xdoc = XDocument.Load(FileLoc);
    MessageBox.Show(xdoc.Descendants("energyPieces").First().Value);
</code>```

But in the second line i ALWAYS get System.InvalidOperationException... WHILE the xml file IS valid: i checked it with a game(it's actually a game's save file) and checked it with multiple online checkers... Here is the XML file:

<?xml version="1.0" encoding="utf-8"?>
<Save xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DumaLegend">
  <saveInfo>
    <energyPieces>0</energyPieces>
    <fullEnergyCells>4</fullEnergyCells>
    <fullHearts>4</fullHearts>
    <globalSwitches xmlns:d3p1="a">
      <d3p1:switchList xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
    </globalSwitches>
    <gold>0</gold>
    <hasBigFireball>false</hasBigFireball>
    <hasCombo>false</hasCombo>
    <hasCrossbow>false</hasCrossbow>
    <hasDash>false</hasDash>
    <hasDashUpgrade>false</hasDashUpgrade>
    <hasDoubleJump>false</hasDoubleJump>
    <hasFireball>false</hasFireball>
    <hasHookshot>false</hasHookshot>
    <hasInvisPot>false</hasInvisPot>
    <hasSecondCombo>false</hasSecondCombo>
    <hasShieldUpgrade>false</hasShieldUpgrade>
    <hasSmallFireball>false</hasSmallFireball>
    <heartPieces>0</heartPieces>
    <heroPosOnMap>0</heroPosOnMap>
    <heroTokens>0</heroTokens>
    <itemSlot1 xmlns:d3p1="http://schemas.datacontract.org/2004/07/DumaLegend.Objects.Consumables" i:nil="true" />
    <itemSlot2 xmlns:d3p1="http://schemas.datacontract.org/2004/07/DumaLegend.Objects.Consumables" i:nil="true" />
    <lives>3</lives>
    <worldsUnlocked>0</worldsUnlocked>
    <worldsUnlockedOnMap>0</worldsUnlockedOnMap>
  </saveInfo>
  <saveSlot>0</saveSlot>
</Save>```

Note: Sorry for copy-pasting it as html code I actually failed to put it in a code sample!

Edit: expected output: 0

答:
You need a fully qualified name (i.e. including the namespace). Thus

```<code>XDocument xdoc = XDocument.Load(FileLoc);
MessageBox.Show(xdoc.Descendants(XName.Get("energyPieces", "http://schemas.datacontract.org/2004/07/DumaLegend")).First().Value);
</code>```

or, if you prefer

```<code>XDocument xdoc = XDocument.Load(FileLoc);
MessageBox.Show(xdoc.Descendants("{http://schemas.datacontract.org/2004/07/DumaLegend}energyPieces").First().Value);
</code>```

Body:
So i have this code sample... what it should do is... simple read a value from an xml file...

    XDocument xdoc = XDocument.Load(FileLoc);
    MessageBox.Show(xdoc.Descendants("energyPieces").First().Value);

But in the second line i ALWAYS get System.InvalidOperationException... WHILE the xml file IS valid: i checked it with a game(it's actually a game's save file) and checked it with multiple online checkers... Here is the XML file:

<?xml version="1.0" encoding="utf-8"?>
<Save xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/DumaLegend">
  <saveInfo>
    <energyPieces>0</energyPieces>
    <fullEnergyCells>4</fullEnergyCells>
    <fullHearts>4</fullHearts>
    <globalSwitches xmlns:d3p1="a">
      <d3p1:switchList xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
    </globalSwitches>
    <gold>0</gold>
    <hasBigFireball>false</hasBigFireball>
    <hasCombo>false</hasCombo>
    <hasCrossbow>false</hasCrossbow>
    <hasDash>false</hasDash>
    <hasDashUpgrade>false</hasDashUpgrade>
    <hasDoubleJump>false</hasDoubleJump>
    <hasFireball>false</hasFireball>
    <hasHookshot>false</hasHookshot>
    <hasInvisPot>false</hasInvisPot>
    <hasSecondCombo>false</hasSecondCombo>
    <hasShieldUpgrade>false</hasShieldUpgrade>
    <hasSmallFireball>false</hasSmallFireball>
    <heartPieces>0</heartPieces>
    <heroPosOnMap>0</heroPosOnMap>
    <heroTokens>0</heroTokens>
    <itemSlot1 xmlns:d3p1="http://schemas.datacontract.org/2004/07/DumaLegend.Objects.Consumables" i:nil="true" />
    <itemSlot2 xmlns:d3p1="http://schemas.datacontract.org/2004/07/DumaLegend.Objects.Consumables" i:nil="true" />
    <lives>3</lives>
    <worldsUnlocked>0</worldsUnlocked>
    <worldsUnlockedOnMap>0</worldsUnlockedOnMap>
  </saveInfo>
  <saveSlot>0</saveSlot>
</Save>

Note: Sorry for copy-pasting it as html code I actually failed to put it in a code sample!

Edit: expected output: 0

Body:
You need a fully qualified name (i.e. including the namespace). Thus

XDocument xdoc = XDocument.Load(FileLoc);
MessageBox.Show(xdoc.Descendants(XName.Get("energyPieces", "http://schemas.datacontract.org/2004/07/DumaLegend")).First().Value);

or, if you prefer

XDocument xdoc = XDocument.Load(FileLoc);
MessageBox.Show(xdoc.Descendants("{http://schemas.datacontract.org/2004/07/DumaLegend}energyPieces").First().Value);


问:
Invalid SDK settings. Configure app.server.parent.dir property in build.xxx.properties to point to Liferay home
I have the following directory structure

The circled directories are the paths of the liferay tomcat server and the sdk respectively.

and I have the file build.osama.properties with the following settings :

app.server.parent.dir=D:\sources\lr_bundles\liferay_tomcat\liferay-ce-portal-7.0-ga3
app.server.tomcat.dir=${app.server.parent.dir}/tomcat-8.0.32

and when I try to create a liferay plugin project it keeps saying :

I am using LR 7 ga3 with tomcat 8 and sdk 7 ga3

答: In my case I had to combine previous answers ('/' instead of Windows' default '\') AND move liferay portal directory to C:/ (and point build.Username.Properties file to this directory).</p>


问:
Convert Json response to HTML Table
How do I display all the points in this Json return statement to an HTML table on my view?</p>

```<code>return Json(
    new
    {
        vol = exposure.Volatility,
        points =
            from point in exposure.ExposurePointCollection
            select new
            {
                date = point.ExposureDate,
                val = point.MaximumExposure
            }
    });
</code>```

答:
If this is the result of an ajax call, you will need to iterate over the collection (presumably the "points" value) and add them to the DOM via javascript.  jQuery can help with this, but there are also plug-ins for jQuery that will do virtually all of the work for you, something like jqGrid comes to mind.

Looping through the json result (assuming "points" is what you are looping over)

```<code>success: function(data){
  jquery.each(data.points, function(index, value){
    //index is the index of the array, value is the actual value
  });
}
</code>```

Look here for using jQuery to modify the DOM: http://api.jquery.com/html/#html2

Title: Convert Json response to HTML Table

Body:
How do I display all the points in this Json return statement to an HTML table on my view?

return Json(
    new
    {
        vol = exposure.Volatility,
        points =
            from point in exposure.ExposurePointCollection
            select new
            {
                date = point.ExposureDate,
                val = point.MaximumExposure
            }
    });

Body:
If this is the result of an ajax call, you will need to iterate over the collection (presumably the "points" value) and add them to the DOM via javascript.  jQuery can help with this, but there are also plug-ins for jQuery that will do virtually all of the work for you, something like jqGrid comes to mind.

Looping through the json result (assuming "points" is what you are looping over)

success: function(data){
  jquery.each(data.points, function(index, value){
    //index is the index of the array, value is the actual value
  });
}

Look here for using jQuery to modify the DOM: http://api.jquery.com/html/#html2


问:
Electron - running into some issues with start command and window sizing
So I've built a trivial application using Electron.

I can start the app using the command 'electron index.html, but not the command 'electron .', even though this is explicitly declared in the package.json

```<code>{
  "name": "remind-me",
  "version": "1.0.0",
  "description": "information management tool",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  },
  "repository": {
    "type": "git",
    "url": "tokumk"
  },
  "dependencies": {
    "electron": "^1.6.11"
  }
}
</code>```

a second issue related to window sizing. my BrowserWindow is always the same size regardless of setting it to something else. Here is an example of my index.js. The setting background color is also completely ignored.

index.html

```<code>    <html>
    <head>
    </head>

    <body>
        <div id="container">
            <h3>remind me</h3>
            <form>
                <input type = text action="post"></input>
                <input type="submit" value="send" name="submit">
            <form>
        </div>
    </body>

    <script>
        require('./renderer.js');
    </script>

</html>
</code>```

index.js

```<code>const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = ('url');

// window object
let win;

function createWindow(){

    // set window size and background color
    win = new BrowserWindow({
        width: 450,
        height: 400,
        backgroundColor: '#2e2c29'
    });

    win.loadURL(url.format({
        pathname: path.join(__dir, 'index.html'),
        protocol: 'file',
        slashes: true
    }));

    win.webContents.openDevTools();

    win.on('closed', ()=> {
        win = null;
    });

    app.on('ready', createWindow);

    app.on('window-all-closed', ()=>{
        if(process.platform !== 'darwin'){
            app.quit();
        }
    });

}
</code>```

答: I think the problem is that you're running the application like electron index.html which just loads index.html in a window and nothing else so if you run electron like: electron index.js I think it would work

Body:
So I've built a trivial application using Electron.

I can start the app using the command 'electron index.html, but not the command 'electron .', even though this is explicitly declared in the package.json

{
  "name": "remind-me",
  "version": "1.0.0",
  "description": "information management tool",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  },
  "repository": {
    "type": "git",
    "url": "tokumk"
  },
  "dependencies": {
    "electron": "^1.6.11"
  }
}

a second issue related to window sizing. my BrowserWindow is always the same size regardless of setting it to something else. Here is an example of my index.js. The setting background color is also completely ignored.

index.html

remind me

            <form>
                <input type = text action="post"></input>
                <input type="submit" value="send" name="submit">
            <form>

index.js

const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = ('url');

// window object
let win;

function createWindow(){

    // set window size and background color
    win = new BrowserWindow({
        width: 450,
        height: 400,
        backgroundColor: '#2e2c29'
    });

    win.loadURL(url.format({
        pathname: path.join(__dir, 'index.html'),
        protocol: 'file',
        slashes: true
    }));

    win.webContents.openDevTools();

    win.on('closed', ()=> {
        win = null;
    });

    app.on('ready', createWindow);

    app.on('window-all-closed', ()=>{
        if(process.platform !== 'darwin'){
            app.quit();
        }
    });

}


问:
T-SQL set trailing numbers to zeros
I'm working on a stored procedure on SQL Server 2014.

I have a variable:

```<code>DECLARE @VersionNumber DECIMAL(18,1);
</code>```

This VersionNumber can have values such as 1.0 or 1.4.

In my logic, I increase the number +0.1 if there is a minor change and +1 if there is a major change.

If there is a major change though, I want to reset the trailing numbers to 0.

Example: Version 1.4 should become 2.0 after a major change

My current query looks like this:

```<code>IF @IsMajor = 'true'
BEGIN
    SELECT @VersionNumber = COALESCE(1 + MAX([VersionNumber]), 1)
    FROM [MySchema].[Project]
END
IF @IsMajor = 'false'
BEGIN
    SELECT @VersionNumber = COALESCE(0.1 + MAX([VersionNumber]), 1)
    FROM [MySchema].[Project]
END
</code>```

Do you know how to reset the trailing number to 0 on a decimal number?

Thank you!

答:
or ceiling</p>

```<code>IF @IsMajor = 'true'
BEGIN
    SELECT @VersionNumber = ceiling(MAX([VersionNumber])+.1)
    FROM [MySchema].[Project]
</code>```

Title: T-SQL set trailing numbers to zeros

Body:
I'm working on a stored procedure on SQL Server 2014.

I have a variable:

DECLARE @VersionNumber DECIMAL(18,1);

This VersionNumber can have values such as 1.0 or 1.4.

In my logic, I increase the number +0.1 if there is a minor change and +1 if there is a major change.

If there is a major change though, I want to reset the trailing numbers to 0.

Example: Version 1.4 should become 2.0 after a major change

My current query looks like this:

IF @IsMajor = 'true'
BEGIN
    SELECT @VersionNumber = COALESCE(1 + MAX([VersionNumber]), 1)
    FROM [MySchema].[Project]
END
IF @IsMajor = 'false'
BEGIN
    SELECT @VersionNumber = COALESCE(0.1 + MAX([VersionNumber]), 1)
    FROM [MySchema].[Project]
END

Do you know how to reset the trailing number to 0 on a decimal number?

Thank you!

Body:
or ceiling

IF @IsMajor = 'true'
BEGIN
    SELECT @VersionNumber = ceiling(MAX([VersionNumber])+.1)
    FROM [MySchema].[Project]


问:
State and status of AvalonDock, options to AvalonDock
I'm working on a WPF interface that could use AvalonDock, or a similar dockable windows interface. My understanding is that AvalonDock is a pretty good dockable window interface, but I'm a bit worried about the ongoing status of it. Is it honestly active? Many comments on the site discussion and bug tracker mention the developer being too busy, i.e.

I've decided to shuthdown my blog site (youdev.net) as I'm too busy for now to update it with regularity. Anyway I created a getting started tutorial for AvalonDock (1.3) that can be accessed from here.
  I'll try to answer any question you may have into the discussion section.

And there are a number of "Is this still active?" questions in the discussion section.

Thus, my question: Is anyone actually using this in production software? What issues are there with it that would be problematic.

Likewise, if anyone has pointers to a decent dockable window library, free or commercial, I'd be interested in taking a look.

Edit: I'm using C# and .NET 4 in VS2010.

答:
As much research as I did on AvalonDock before coming here, I still found something afterward, specifically Sofa, which is a wrapper for AvalonDock making it easier to work with. Sofa was last updated less than a month ago, so activity- at least at the moment- seems high.

This, and some of the comments from the WPF Docking Libraries question makes me think that AvalonDock might be just stable enough, but that Actipro is a good choice if we need support and a commercial project.

I'll mark this as wiki since the "similar to" quotient is really high, but it might still help someone.


问:
RewriteRule redirects to unexpected page
I am trying to change my url through .htaccess in the following way

```<code>Original URL: http://www.example.com/latest-news.php?id=2/topic=testing
Rewritten URL:http://www.example.com/2/testing
Rule for .htaccess
RewriteRule ^([^/]*)/([^/]*)$ /latest-news.php?id=$1&topic=$2 [L]
</code>```

This is working fine but the other files which are existing in a folder are not opening. The url is opening as www.example.com/testing/foo.php but content of the page is of http://www.example.com/2/testing

答:
```<code>RewriteEngine On
RewriteRule ^([0-9]+)/([^/]*)$  /latest-news.php?id=$1&url=$2 [L]
</code>```

Since second part consists characters and digits So I modify the answer of stoica. Thanks @stoica

Body:
I am trying to change my url through .htaccess in the following way

Original URL: http://www.example.com/latest-news.php?id=2/topic=testing
Rewritten URL:http://www.example.com/2/testing
Rule for .htaccess
RewriteRule ^([^/]*)/([^/]*)$ /latest-news.php?id=$1&topic=$2 [L]

This is working fine but the other files which are existing in a folder are not opening. The url is opening as www.example.com/testing/foo.php but content of the page is of http://www.example.com/2/testing

Body:
RewriteEngine On
RewriteRule ^([0-9]+)/([^/]*)$  /latest-news.php?id=$1&url=$2 [L]

Since second part consists characters and digits So I modify the answer of stoica. Thanks @stoica


问:
Django: Database returned an invalid datetime value. Are time zone definitions for your database and pytz installed
I currently execute the following code:

```<code>statistics = Statistic.objects
.filter(id=1)
.annotate(timestamp=Trunc('timestamp_start','day', output_field=DateTimeField()))
.values('timestamp')
.annotate(usage_start = Min('usage_start'))
</code>```

I have 1 record in that statisitc table, the value for timestamp_start is:

```<code>2016-12-22T06:00:00+02:00
</code>```

I do have pytz installed. I'm running sqlite database. Any idea how to resolve this?

答: Removing the timezone info (+2:00) resolved it.</p>

Body:
I currently execute the following code:

statistics = Statistic.objects
.filter(id=1)
.annotate(timestamp=Trunc('timestamp_start','day', output_field=DateTimeField()))
.values('timestamp')
.annotate(usage_start = Min('usage_start'))

I have 1 record in that statisitc table, the value for timestamp_start is:

2016-12-22T06:00:00+02:00

I do have pytz installed. I'm running sqlite database. Any idea how to resolve this?


问:
Convert json_objects to array
I have this query

```<code>SELECT json_object('image_name', image_name, 'iid', iid)
FROM `posts_images`
WHERE `pid` = '62'
</code>```

That result in this

Image:

can I convert these result into one line JSON array in same query?

Title: Convert json_objects to array

Body:
I have this query

SELECT json_object('image_name', image_name, 'iid', iid)
FROM `posts_images`
WHERE `pid` = '62'

That result in this

Image:

can I convert these result into one line JSON array in same query?

Body:
I figure it out

SELECT CONCAT(
    '[',
            GROUP_CONCAT(json_object('image_name', image_name, 'iid', iid)),
    ']'
)
FROM posts_images WHERE pid = '62'

[{"iid": 99, "image_name": "6_1499203101812.jpg"},{"iid": 98,
  "image_name": "6_1499203101708.jpg"},{"iid": 97, "image_name":
  "6_1499203101651.jpg"},{"iid": 96, "image_name":
  "6_1499203101574.jpg"},{"iid": 95, "image_name":
  "6_1499203101472.jpg"},{"iid": 100, "image_name":
  "6_1499203101886.jpg"},{"iid": 101, "image_name":
  "6_1499203101960.jpg"},{"iid": 102, "image_name":
  "6_1499203102020.jpg"}]


问:
Accessing Object attributes
```<code><html>
  <head>
    <script>
      function User(name,age){
        this.name=name;
        this.age=age;
      }
      var user = new User('Daniel', 45 );
      document.write(user[name]+' '+'is'+' '); //line 1
      document.write(user[age]+' '+'years old!'); // line 2
    </script>
  </head>
  <body>

  </body>
</html>
</code>```

In above code,
              When i tried accessing properties of object user
              For name, i got 'undefined' as output
              For age, i got Error saying that age is Not defined
         Not able to understand why I'm getting Error for line 2
         and 'undefined' value for line 1. Both should give same Error Right?
    Please clarify my doubt here.

答:
You should specify as name and age as string . it should be like this user['name']

        ```
</div>
</div>
</p>

<p>OR just use . notation </p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><html>
            <head>
                <script>
                    function User(name,age){
                        this.name=name;
                        this.age=age;
                    }
                    var user = new User('Daniel', 45 );
                    document.write(user.name+' '+'is'+' '); //line 1
                    document.write(user.age+' '+'years old!'); // line 2
                </script>
            </head>
            <body>

            </body>
        </html></code>```

Title: Accessing Object attributes

Body:
You should specify as name and age as string . it should be like this user['name']

<html>
            <head>
                <script>
                    function User(name,age){
                        this.name=name;
                        this.age=age;
                    }
                    var user = new User('Daniel', 45 );
                    document.write(user["name"]+' '+'is'+' '); //line 1
                    document.write(user["age"]+' '+'years old!'); // line 2
                </script>
            </head>
            <body>

            </body>
        </html>

OR just use . notation

<html>
            <head>
                <script>
                    function User(name,age){
                        this.name=name;
                        this.age=age;
                    }
                    var user = new User('Daniel', 45 );
                    document.write(user.name+' '+'is'+' '); //line 1
                    document.write(user.age+' '+'years old!'); // line 2
                </script>
            </head>
            <body>

            </body>
        </html>


问:
38 Million records - Deleting duplicate rows basis column name and keeping just one
Disclaimer - I've read many fantastic questions & their answers already and have given it a try too. The only issue is that considering the database size, the system gets stuck at "loading" and it just sits there. By looking at the total number of rows, I've seen changes happening but its just not significant when it doesn't give a warning or do it in pieces. I do have a fair idea of tweaking available code and make it work but I'm not a full time/advance developer (yet!)

Question - I've been working on a database that comprises of product information but has duplicate values (was foolish to not make "Product code" column as unique while importing multiple CVS into the database). I need help with removing the duplicate basis the "product code" but want to "keep one" which has maximum information under "specification" column.

Database - MySQL
Total records - 36 Million +
Total columns - Not more than 15 (but are of less relevance)
Problem - Multiple duplicate values basis "product code" but keep one that has maximum number of characters in the "specifications column"

Database details;
Table name - pro

Columns names are as;
productid - VARCHAR,
manPartId - VARCHAR,
specification - TEXT

So far, I've picked the following code from and have given it a try, but the system gets stuck at "loading" and nothing happens. I assume this is because of the huge number of records it has.

Code that I had tried running in the phpMyAdmin "SQL" section is;

```<code>--------------------------------------------
      delete pro
      from pro
      inner join (
         select max(productid) as lastId, manPartId
           from pro
          group by manPartId
         having count(*) > 1) duplic on duplic.manPartId = pro.manPartId
         where pro.productid < duplic.lastId;
--------------------------------------------
</code>```

The above code has been tweaked from the original available at MySQL delete duplicate records but keep latest

Please do help and understand on where am I going wrong. Please also note that I do understand that above code only works around "deleting all but keeping one" and is not "keeping one basis total text available in Specification column".

Many thanks in advance!

EDIT - As per recommendations from aendeerei, I've made some edits to the details.

```<code>-------------------------------------------------------
productid  | manPartId    |  specification
-------------------------------------------------------
1            ABC1           5MP camera, 2500 MaH, Steel body
2            ABC2           2MP camera, Steel body
3            ABC3           5MP, 6500 MaH, Red
4            ABC1           2500 MaH, Steel body
5            ABC2           5MP camera, plastic body
6            ABC4           5MP camera, 2500 MaH, Steel body
7            ABC5           15MP camera, 4500 MaH
8            ABC2           5MP camera
9            ABC3           15MP, 6500 MaH, Blue body
10           ABC5           2500 MaH, Steel body
-------------------------------------------
</code>```

In the above case, I'm looking at removing the duplicates basis manPartId but want to keep one record that has the maximum (characters) in the specification field.

After running the query, I'd like to see the following updated data having unique manPartId with max text under specification column;

```<code>-------------------------------------------------------
productid  | manPartId    |  specification
---------------------------------------------------------------
1            ABC1           5MP camera, 2500 MaH, Steel body
5            ABC2           5MP camera, plastic body
6            ABC4           5MP camera, 2500 MaH, Steel body
7            ABC5           15MP camera, 4500 MaH, Long life
9            ABC3           15MP, 6500 MaH, Blue body
---------------------------------------------------------------
</code>```

Please accept my apologies if its still unclear!

答:
First, basis, find all parts longest length (Query #1)

```<code>SELECT
      manPartID,
      MAX( CHAR_LENGTH( specification )) longestLength
   from
      pro
   group by
      manPartID
</code>```

WITH that as the baseline, now look for all parts that have that same longest length.  But in the case where there are more than one with the exact same length, you need to pick one, such as the first ProductID or the most recent ProductID to be kept...  (Query #2)

```<code>SELECT
      p.manPartID,
      MAX( p.productid ) as ProductID
   from
      pro p
         JOIN
            ( Entire Query #1 above ) byLen
          ON p.manPartID = byLen.manPartID
          AND char_length( p.specification ) = byLen.LongestLength
   group by
      p.manPartID
</code>```

So at this point, you have only one "ProductID" for a single "manPartID" based on the longest specification...  Now, you can delete from the main table where it is NOT one of the above such as below.  I am doing a LEFT JOIN to the #2 query because I want all records compared and delete only those that are NOT FOUND in the keep result set.

```<code>DELETE FROM Pro
   LEFT JOIN (entire query #2 above) Keep
      ON Pro.ProductID = Keep.ProductID
   where Keep.ProductID IS NULL
</code>```

Now, on a table of 36 million records, you PROBABLY want to ensure the above works before blowing away your data.  So instead of deleting, I would create a new secondary table of products and insert into that just to confirm you are getting what you are hoping for...

```<code>INSERT INTO SomeTempTable
SELECT p1.*
   from Pro p1
      JOIN ( query #2 above ) Keep
         ON p1.ProductID = Keep.ProductID
</code>```

Notice this one is a JOIN (not left-join as used in the delete) as I WANT only those products I expect to keep

I am sure there are other elements on the table as described, so to help the query performance, I would have the following index on your "Pro"duct table.

```<code>(manPartID, specification, productID)
</code>```

This way the work can be done off the indexes and not have to go through all the data pages for every record.

Body:
Disclaimer - I've read many fantastic questions & their answers already and have given it a try too. The only issue is that considering the database size, the system gets stuck at "loading" and it just sits there. By looking at the total number of rows, I've seen changes happening but its just not significant when it doesn't give a warning or do it in pieces. I do have a fair idea of tweaking available code and make it work but I'm not a full time/advance developer (yet!)

Question - I've been working on a database that comprises of product information but has duplicate values (was foolish to not make "Product code" column as unique while importing multiple CVS into the database). I need help with removing the duplicate basis the "product code" but want to "keep one" which has maximum information under "specification" column.

Database - MySQL
Total records - 36 Million +
Total columns - Not more than 15 (but are of less relevance)
Problem - Multiple duplicate values basis "product code" but keep one that has maximum number of characters in the "specifications column"

Database details;
Table name - pro

Columns names are as;
productid - VARCHAR,
manPartId - VARCHAR,
specification - TEXT

So far, I've picked the following code from and have given it a try, but the system gets stuck at "loading" and nothing happens. I assume this is because of the huge number of records it has.

Code that I had tried running in the phpMyAdmin "SQL" section is;

--------------------------------------------
      delete pro
      from pro
      inner join (
         select max(productid) as lastId, manPartId
           from pro
          group by manPartId
         having count(*) > 1) duplic on duplic.manPartId = pro.manPartId
         where pro.productid < duplic.lastId;
--------------------------------------------

The above code has been tweaked from the original available at MySQL delete duplicate records but keep latest

Please do help and understand on where am I going wrong. Please also note that I do understand that above code only works around "deleting all but keeping one" and is not "keeping one basis total text available in Specification column".

Many thanks in advance!

EDIT - As per recommendations from aendeerei, I've made some edits to the details.

-------------------------------------------------------
productid  | manPartId    |  specification
-------------------------------------------------------
1            ABC1           5MP camera, 2500 MaH, Steel body
2            ABC2           2MP camera, Steel body
3            ABC3           5MP, 6500 MaH, Red
4            ABC1           2500 MaH, Steel body
5            ABC2           5MP camera, plastic body
6            ABC4           5MP camera, 2500 MaH, Steel body
7            ABC5           15MP camera, 4500 MaH
8            ABC2           5MP camera
9            ABC3           15MP, 6500 MaH, Blue body
10           ABC5           2500 MaH, Steel body
-------------------------------------------

In the above case, I'm looking at removing the duplicates basis manPartId but want to keep one record that has the maximum (characters) in the specification field.

After running the query, I'd like to see the following updated data having unique manPartId with max text under specification column;

-------------------------------------------------------
productid  | manPartId    |  specification
---------------------------------------------------------------
1            ABC1           5MP camera, 2500 MaH, Steel body
5            ABC2           5MP camera, plastic body
6            ABC4           5MP camera, 2500 MaH, Steel body
7            ABC5           15MP camera, 4500 MaH, Long life
9            ABC3           15MP, 6500 MaH, Blue body
---------------------------------------------------------------

Please accept my apologies if its still unclear!

Body:
First, basis, find all parts longest length (Query #1)

SELECT
      manPartID,
      MAX( CHAR_LENGTH( specification )) longestLength
   from
      pro
   group by
      manPartID

WITH that as the baseline, now look for all parts that have that same longest length.  But in the case where there are more than one with the exact same length, you need to pick one, such as the first ProductID or the most recent ProductID to be kept...  (Query #2)

SELECT
      p.manPartID,
      MAX( p.productid ) as ProductID
   from
      pro p
         JOIN
            ( Entire Query #1 above ) byLen
          ON p.manPartID = byLen.manPartID
          AND char_length( p.specification ) = byLen.LongestLength
   group by
      p.manPartID

So at this point, you have only one "ProductID" for a single "manPartID" based on the longest specification...  Now, you can delete from the main table where it is NOT one of the above such as below.  I am doing a LEFT JOIN to the #2 query because I want all records compared and delete only those that are NOT FOUND in the keep result set.

DELETE FROM Pro
   LEFT JOIN (entire query #2 above) Keep
      ON Pro.ProductID = Keep.ProductID
   where Keep.ProductID IS NULL

Now, on a table of 36 million records, you PROBABLY want to ensure the above works before blowing away your data.  So instead of deleting, I would create a new secondary table of products and insert into that just to confirm you are getting what you are hoping for...

INSERT INTO SomeTempTable
SELECT p1.*
   from Pro p1
      JOIN ( query #2 above ) Keep
         ON p1.ProductID = Keep.ProductID

Notice this one is a JOIN (not left-join as used in the delete) as I WANT only those products I expect to keep

I am sure there are other elements on the table as described, so to help the query performance, I would have the following index on your "Pro"duct table.

(manPartID, specification, productID)

This way the work can be done off the indexes and not have to go through all the data pages for every record.


问:
How can I render html page of Django after the background celery task is completed
Problems: I am using rabbitmq server with celery

I need to run multiple tasks in the background. That i am able to do

When each task is completed, i need to render the html page, to run html page i need request object as arguement, which celery task can't access

By the time celery task is completed i am out of the function that is having the request object

from future import unicode_literals, absolute_import
    from django.shortcuts import render
    from celDemo.celery import app
    import time
    from django.http.response import HttpResponseRedirect
    # Create your views here.

```<code>dictionary = {}
msg = "Hello!"

def testing(request):

    print 'In 1st page:'
    return render(request,'index.html')

def testcelery(request):

    print 'In testcelery'

    if request.method == 'POST':
        print 'On click event'
        value = str(request.POST['variable'])
        print request
        dictionary[value] = request
        print dictionary[value]
        try:
            make_wait.delay(value)
            return render(request,'index.html')
        except:
            return render(request,'nothing.html')

@app.task
def make_wait(value):
    print dictionary
    print msg
    print 'Started sleeping :)'
    actual2()
    print 'Slept :D'
    #request = dictionary[value]
    print value
    print 'before initiaing the request'
    return render('nothing.html')
    print 'after initiating the request'
    #return value

def actual2():
    result = actual()
    return result

def actual():
    time.sleep(25)
    return 'slept :D'
</code>```

答:
You can use AJAX to get the contents of nothing.html before actually making the POST request. Replace the body with the contents of nothing.html fetched and then, make the POST request which will return the contents of index.html. Replace the body with the final html of index.html received.

Example code:

```<code>// js
<script>
  $.ajax({
    url: 'url_to_get_nothing_html',
    type: 'GET',
    success: function(data) {
      $('body').html(data);
      $.ajax({
        url: 'url_to_index_html',
        type: 'POST',
        data: <data>,
        success: function(data) {
          $('body').html(data);
        }
    }
</script>
</code>```

Body:
Problems: I am using rabbitmq server with celery

I need to run multiple tasks in the background. That i am able to do

When each task is completed, i need to render the html page, to run html page i need request object as arguement, which celery task can't access

By the time celery task is completed i am out of the function that is having the request object

from future import unicode_literals, absolute_import
    from django.shortcuts import render
    from celDemo.celery import app
    import time
    from django.http.response import HttpResponseRedirect
    # Create your views here.

dictionary = {}
msg = "Hello!"

def testing(request):

    print 'In 1st page:'
    return render(request,'index.html')

def testcelery(request):

    print 'In testcelery'

    if request.method == 'POST':
        print 'On click event'
        value = str(request.POST['variable'])
        print request
        dictionary[value] = request
        print dictionary[value]
        try:
            make_wait.delay(value)
            return render(request,'index.html')
        except:
            return render(request,'nothing.html')

@app.task
def make_wait(value):
    print dictionary
    print msg
    print 'Started sleeping :)'
    actual2()
    print 'Slept :D'
    #request = dictionary[value]
    print value
    print 'before initiaing the request'
    return render('nothing.html')
    print 'after initiating the request'
    #return value

def actual2():
    result = actual()
    return result

def actual():
    time.sleep(25)
    return 'slept :D'

Body:
You can use AJAX to get the contents of nothing.html before actually making the POST request. Replace the body with the contents of nothing.html fetched and then, make the POST request which will return the contents of index.html. Replace the body with the final html of index.html received.

Example code:

// js
<script>
  $.ajax({
    url: 'url_to_get_nothing_html',
    type: 'GET',
    success: function(data) {
      $('body').html(data);
      $.ajax({
        url: 'url_to_index_html',
        type: 'POST',
        data: <data>,
        success: function(data) {
          $('body').html(data);
        }
    }
</script>


问:
I need to fix file names on PO invoice generator when we upload file

```<code>    <cfif NOT DirectoryExists(ExpandPath(lv_upload_path))>
        <cfdirectory action="create"  directory="#ExpandPath(lv_upload_path)#">
    </cfif>

    <cfset lv_file_ext = listLast(FORM.filename_inv, ".") />

    <!--- replace special chars in comapny name except space, then replace space with underscore --->
    <cfset company_name = replaceSpecialChars(
        textString=FORM.company_name,
        replaceTheseChars="33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,58,59,60,61,62,63,64,91,92,93,94,95,96,123,124,125,126"
    )>
    <cfset company_name = Replace( company_name, "#Chr(32)#", "_", "All" )>

    <cfset lv_file_name = company_name & "_Factura_" & replaceSpecialChars(FORM.in_supplier_inv) & "_" & DateFormat(FORM.in_when_inv, "dd.mm.yyyy") >
    <cfset lv_file_name_out = lv_file_name & "." & replaceSpecialChars(lv_file_ext)>

    <cffile action="upload" filefield="pickfiles_inv" destination="#ExpandPath(lv_upload_path & '/' & lv_file_name_out)#" nameconflict="MakeUnique">

    <cfset lv_document_name = CFFILE.serverfile />

    <cfset new_id = APPLICATION.po_management.f_savePOInvDocuments(
        p_po_inv_id=URL.id,
        p_supplier_number=FORM.in_supplier_inv,
        p_when_created=FORM.in_when_inv,
        p_amount=FORM.in_amount_inv,
        p_document_name=lv_document_name
</code>```

Im new so if I make incorrect question, just help with how make it more good in future.

When upload a file give error back

Element FILENAME_INV is undefined in FORM.

答:
Use the following line instead:</p>

```<code><cfset lv_file_ext = listLast(FORM.pickfiles_inv, ".") />
</code>```

Body:
    <cfif NOT DirectoryExists(ExpandPath(lv_upload_path))>
        <cfdirectory action="create"  directory="#ExpandPath(lv_upload_path)#">
    </cfif>

    <cfset lv_file_ext = listLast(FORM.filename_inv, ".") />

    <cfset company_name = replaceSpecialChars(
        textString=FORM.company_name,
        replaceTheseChars="33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,58,59,60,61,62,63,64,91,92,93,94,95,96,123,124,125,126"
    )>
    <cfset company_name = Replace( company_name, "#Chr(32)#", "_", "All" )>

    <cfset lv_file_name = company_name & "_Factura_" & replaceSpecialChars(FORM.in_supplier_inv) & "_" & DateFormat(FORM.in_when_inv, "dd.mm.yyyy") >
    <cfset lv_file_name_out = lv_file_name & "." & replaceSpecialChars(lv_file_ext)>

    <cffile action="upload" filefield="pickfiles_inv" destination="#ExpandPath(lv_upload_path & '/' & lv_file_name_out)#" nameconflict="MakeUnique">

    <cfset lv_document_name = CFFILE.serverfile />

    <cfset new_id = APPLICATION.po_management.f_savePOInvDocuments(
        p_po_inv_id=URL.id,
        p_supplier_number=FORM.in_supplier_inv,
        p_when_created=FORM.in_when_inv,
        p_amount=FORM.in_amount_inv,
        p_document_name=lv_document_name

Im new so if I make incorrect question, just help with how make it more good in future.

When upload a file give error back

Element FILENAME_INV is undefined in FORM.

Body:
Use the following line instead:

<cfset lv_file_ext = listLast(FORM.pickfiles_inv, ".") />


问:
Hyperledger Composer :error Authenticating to the REST server
I have been following this Hyperledger Composer tutorial
 here and when I try to authenticate to the rest server via http://localhost:3000/auth/github I am not being redirected to the GitHub site to perform the OAuth web server authentication flow. Instead of redirecting, I am getting a 404 error message.
Expected Behavior

According to the Composer tutorial, I would expect being redirected to the Github site to perform the OAuth.
Actual Behavior

When I enter http://localhost:3000/auth/github I am getting a 404 error

My environment:

docker --version
Docker version 17.03.1-ce, build c6d412e

docker-compose --version
docker-compose version 1.13.0, build 1719ceb

node --version
v6.11.0

Adding more details for reference...

[

EDIT:

here is complete error stack trace:

Unhandled error for request GET /explorer/auth/github: Error: Cannot GET /explorer/auth/github
    at raiseUrlNotFoundError (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/loopback/server/middleware/url-not-found.js:21:17)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:260:14)
    at Function.handle (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:174:3)
    at router (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at Immediate. (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15)
Unhandled error for request GET /explorer/auth/github: Error: Cannot GET /explorer/auth/github
    at raiseUrlNotFoundError (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/loopback/server/middleware/url-not-found.js:21:17)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:260:14)
    at Function.handle (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:174:3)
    at router (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at Immediate. (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15)
Unhandled error for request GET /explorer/auth/github: Error: Cannot GET /explorer/auth/github
    at raiseUrlNotFoundError (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/loopback/server/middleware/url-not-found.js:21:17)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:260:14)
    at Function.handle (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:174:3)
    at router (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at Immediate. (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15)
Unhandled error for request GET /explorer/auth/github: Error: Cannot GET /explorer/auth/github
    at raiseUrlNotFoundError (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/loopback/server/middleware/url-not-found.js:21:17)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:260:14)
    at Function.handle (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:174:3)
    at router (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at Immediate. (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15)
Unhandled error for request GET /explorer/auth/github: Error: Cannot GET /explorer/auth/github
    at raiseUrlNotFoundError (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/loopback/server/middleware/url-not-found.js:21:17)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15
    at next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:260:14)
    at Function.handle (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:174:3)
    at router (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:47:12)
    at Layer.handle [as handle_request] (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13)
    at /home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10)
    at Immediate. (/home/brankoterzic/.nvm/versions/node/v6.11.1/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:635:15)

答: in your COMPOSER_PROVIDERS stanza - specifically the callbackURL setting - you don't need the localhost:3000 - you just need the URL path as "/auth/github/callback" shown in the docs : https://hyperledger.github.io/composer/integrating/enabling-rest-authentication.html . The REST server will take care of..the rest.. . Then stop and restart the composer REST server composer-rest-server -p hlfv1 -n my-network -i admin -s adminpw -S true etc  - from the command line where you export the configuration variable COMPOSER_PROVIDERS (above). cheers Paul


问:
Android Textview Scrolling Issue
Firstly, I am new to android so if I have missed something basic I do apologise.

I have created a GridView to store some information. The GridView consists of a 3x6 grid. In each cell, there is an image and text directly under the image. As the GridView is so large I have implemented a scrollbar.

This is how the page should look normally and is when first loaded/selected :

Everything looks wonderful, however, when I scroll down to the bottom and then back up, the text seems to wrap up and then push the image out of place. I am not sure why this is?

This is how the page looks after I have scrolled down and they scroll back up :

For the GridView, I have an XML file with the GridView itself along with a TextView at the very top called content_rewards.xml. I have also create an XML file for each picture/text in the grid itself called relics_gridlayout.xml. I believe I am probably missing a property of the TextViews in either one of these files, however, I am not sure which one or which property. I don't think it has anything to do with the grid or adapter itself hence I will not include that code.

content_rewards.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="25dp">

<GridView
    android:id="@+id/customgrid"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_below="@+id/os_texts"
    android:columnWidth="100dp"
    android:numColumns="auto_fit"
    android:stretchMode="spacingWidthUniform"
    android:verticalSpacing="35dp"
    android:scrollbars="horizontal"
    tools:layout_constraintTop_creator="1"
    android:layout_marginTop="116dp"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

<TextView
    android:id="@+id/textView4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="B = 0   S = 0   G = 0"
    android:textSize="24sp"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintBottom_creator="1"
    app:layout_constraintBottom_toTopOf="@+id/customgrid"
    app:layout_constraintRight_toRightOf="parent"
    tools:layout_constraintLeft_creator="1"
    android:layout_marginBottom="8dp"
    app:layout_constraintLeft_toLeftOf="parent"/>
</android.support.constraint.ConstraintLayout>
</code>```

relics_gridlayout.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="3dp">

<ImageView
    android:id="@+id/os_images"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher" />

<TextView
    android:layout_below="@+id/os_images"
    android:id="@+id/os_texts"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="This is Just Dummy Text"
    android:textAlignment="center"
    android:textSize="18dp"
    android:textStyle="bold"/>

</RelativeLayout>
</code>```

Any help would be great. Thanks.

答:
you can use LinearLayout and assign weights so that every item in your grid view occupy same space

Update the relics_gridlayout.xml with below code ( you may need to adjust gravity and layout weights)Try this

```<code><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/linearLayout_root_single_home_option"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

<ImageView
    android:id="@+id/os_images"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher"
    android:layout_weight="9" />

<TextView
    android:id="@+id/os_texts"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This is Just Dummy Text"
    android:textSize="18dp"
    android:textStyle="bold"
    android:layout_weight="1" />

</LinearLayout>
</code>```

Title: Android Textview Scrolling Issue

Body:
Firstly, I am new to android so if I have missed something basic I do apologise.

I have created a GridView to store some information. The GridView consists of a 3x6 grid. In each cell, there is an image and text directly under the image. As the GridView is so large I have implemented a scrollbar.

This is how the page should look normally and is when first loaded/selected :

Everything looks wonderful, however, when I scroll down to the bottom and then back up, the text seems to wrap up and then push the image out of place. I am not sure why this is?

This is how the page looks after I have scrolled down and they scroll back up :

For the GridView, I have an XML file with the GridView itself along with a TextView at the very top called content_rewards.xml. I have also create an XML file for each picture/text in the grid itself called relics_gridlayout.xml. I believe I am probably missing a property of the TextViews in either one of these files, however, I am not sure which one or which property. I don't think it has anything to do with the grid or adapter itself hence I will not include that code.

content_rewards.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:fitsSystemWindows="true"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="25dp">

<GridView
    android:id="@+id/customgrid"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_below="@+id/os_texts"
    android:columnWidth="100dp"
    android:numColumns="auto_fit"
    android:stretchMode="spacingWidthUniform"
    android:verticalSpacing="35dp"
    android:scrollbars="horizontal"
    tools:layout_constraintTop_creator="1"
    android:layout_marginTop="116dp"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

<TextView
    android:id="@+id/textView4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="B = 0   S = 0   G = 0"
    android:textSize="24sp"
    tools:layout_constraintRight_creator="1"
    tools:layout_constraintBottom_creator="1"
    app:layout_constraintBottom_toTopOf="@+id/customgrid"
    app:layout_constraintRight_toRightOf="parent"
    tools:layout_constraintLeft_creator="1"
    android:layout_marginBottom="8dp"
    app:layout_constraintLeft_toLeftOf="parent"/>
</android.support.constraint.ConstraintLayout>

relics_gridlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="3dp">

<ImageView
    android:id="@+id/os_images"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher" />

<TextView
    android:layout_below="@+id/os_images"
    android:id="@+id/os_texts"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="This is Just Dummy Text"
    android:textAlignment="center"
    android:textSize="18dp"
    android:textStyle="bold"/>

</RelativeLayout>

Any help would be great. Thanks.

Body:
you can use LinearLayout and assign weights so that every item in your grid view occupy same space

Update the relics_gridlayout.xml with below code ( you may need to adjust gravity and layout weights)Try this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/linearLayout_root_single_home_option"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

<ImageView
    android:id="@+id/os_images"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher"
    android:layout_weight="9" />

<TextView
    android:id="@+id/os_texts"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This is Just Dummy Text"
    android:textSize="18dp"
    android:textStyle="bold"
    android:layout_weight="1" />

</LinearLayout>


问:
Run Bash Command At X Time and Terminate for X Time
Hi im working on a simple bash coding i don't know how to accomplish this and this might be easy for you guys please help.

I have a simple program on file.sh

```<code>#!/bin/bash

./program
</code>```

This ./program is a compiled version of C program which i complied using GCC im trying to use at in bash script to execute this program for few seconds and then terminate that after x interval time and restart again.

I hope you got my point?

Example: Run file.sh for 10 sec and I'll display the result from ./program C program and then after 10 sec it will restart again.

答:
The answer is, if I understand correctly, a combination of sleep and timout:

```<code>while :; do
    timout 10s ./program
    # display some results
    sleep 10
done
</code>```

Body:
Hi im working on a simple bash coding i don't know how to accomplish this and this might be easy for you guys please help.

I have a simple program on file.sh

#!/bin/bash

./program

This ./program is a compiled version of C program which i complied using GCC im trying to use at in bash script to execute this program for few seconds and then terminate that after x interval time and restart again.

I hope you got my point?

Example: Run file.sh for 10 sec and I'll display the result from ./program C program and then after 10 sec it will restart again.

Body:
The answer is, if I understand correctly, a combination of sleep and timout:

while :; do
    timout 10s ./program
    # display some results
    sleep 10
done


问:
How would I eliminate spacing, line breaks to have a space-delimited string for each string within my list python
Hi everyone I am pretty new to python and wanted some help. I have some sample data and wanted to know how would I get rid of spacing for each string within each list.

```<code>data = [
 ['In dolore     .'], ['Voluptatum.    '],
 ['Veniam hic non minima.         '],
 ['Dolores       Quis enim'],
 ['     sequi ducimus']
 ]
 print data
</code>```

The Output I desire:

```<code>data = [
 ['In dolore.'], ['Voluptatum.'],
 ['Veniam hic non minima.'],
 ['Dolores Quis enim'],
 ['sequi ducimus']
 ]
</code>```

Here are the two ways I thought would work but didn't

```<code>for i in data:
str = ''.join(data)
final_data = str.replace("  ","")
print final_data
</code>```

my final attempt was this:

```<code>final_data = ''.join(data)
final_data.replace("  ", "")
print final_data
</code>```

答: print [[s.replace("  ","")] for l in data for s in l ]

Body:
Hi everyone I am pretty new to python and wanted some help. I have some sample data and wanted to know how would I get rid of spacing for each string within each list.

data = [
 ['In dolore     .'], ['Voluptatum.    '],
 ['Veniam hic non minima.         '],
 ['Dolores       Quis enim'],
 ['     sequi ducimus']
 ]
 print data

The Output I desire:

data = [
 ['In dolore.'], ['Voluptatum.'],
 ['Veniam hic non minima.'],
 ['Dolores Quis enim'],
 ['sequi ducimus']
 ]

Here are the two ways I thought would work but didn't

for i in data:
str = ''.join(data)
final_data = str.replace("  ","")
print final_data

my final attempt was this:

final_data = ''.join(data)
final_data.replace("  ", "")
print final_data


答:
Because you are accessing them wrong. user[name] is not the right syntax to access object property.

Should be:

```<code>user['name']
</code>```

or even simpler:

```<code>user.name
</code>```

Further reading about accessing properties on objects:

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors

Title: Accessing Object attributes

Body:
In above code,
              When i tried accessing properties of object user
              For name, i got 'undefined' as output
              For age, i got Error saying that age is Not defined
         Not able to understand why I'm getting Error for line 2
         and 'undefined' value for line 1. Both should give same Error Right?
    Please clarify my doubt here.

Body:
Because you are accessing them wrong. user[name] is not the right syntax to access object property.

Should be:

user['name']

or even simpler:

user.name

Further reading about accessing properties on objects:

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors