问:
loop through laravel object and read data and assign to a another variable
i want to read laravel  object and assign it in to a another variable

i want to read those markets[] and products[] and assign to a another variable please some one help

```<code>{
   "1006032":{
      "id":1006032,
      "name":"Germany Regionalliga North East 22",
      "start_date":"2020-02-20 18:00:00",
      "icon":null,
      "display_flag":1,
      "base_competition_id":1000028,
      "events":[
         {
            "id":1051919,
            "name":"Hertha Berlin II & ZFC Meuselwitz",
            "display_flag":1,
            "start_date":"2020-02-20 18:00:00",
            "competition_id":1006032,
            "market_count":1,
            "dst_uri":"",
            "teams":[
               {
                  "id":3106,
                  "name":"Hertha Berlin II",
                  "icon":null,
                  "display_flag":0,
                  "position":"home",
                  "requested_at":15821738127576
               },
               {
                  "id":3107,
                  "name":"ZFC Meuselwitz",
                  "icon":null,
                  "display_flag":0,
                  "position":"away",
                  "requested_at":15821738127578
               }
            ],
            "markets":[
               {
                  "id":1051560,
                  "name":"Match Winner",
                  "line":0,
                  "market_status":"O",
                  "display_flag":1,
                  "market_type_id":1000022,
                  "event_id":1051919,
                  "note":"",
                  "boost_available":false,
                  "selections":[
                     {
                        "id":455957,
                        "name":"Home",
                        "line":0,
                        "price":5,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127597
                     },
                     {
                        "id":455958,
                        "name":"Draw",
                        "line":0,
                        "price":8,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127601
                     },
                     {
                        "id":455959,
                        "name":"Away",
                        "line":0,
                        "price":4,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127604
                     }
                  ],
                  "markettypegroup":{
                     "id":1,
                     "name":"More Markets",
                     "description":"Markets Types that have not been grouped",
                     "display_flag":1,
                     "icon":null,
                     "requested_at":15821738127606
                  },
                  "requested_at":15821738127606
               }
            ],
            "products":[
               {
                  "product_id":10,
                  "bet_type":null,
                  "product_code":"TBF",
                  "product_name":"TopBetta Fixed",
                  "fixed":true,
                  "available":true,
                  "product_image":null,
                  "ribbon_image":null,
                  "has_pool":false,
                  "product_description":"Guarantees to pay at least the best of the 3 TAB dividends",
                  "product_note":null,
                  "product_tooltip":null,
                  "background_colour":null,
                  "multi_available":false,
                  "ordinal":0,
                  "margin":0,
                  "product_type":"standard",
                  "price_id":0,
                  "pool_total":0,
                  "first_leg":null,
                  "requested_at":15821738127616
               }
            ],
            "requested_at":15821738127616
         }
      ],
      "base_competition":{
         "id":1000028,
         "name":"Germany Regionalliga North East",
         "icon":null,
         "display_flag":1,
         "sport_id":19,
         "order":0,
         "sport":{
            "id":19,
            "name":"Soccer",
            "icon":null,
            "display_flag":1,
            "order":0,
            "requested_at":15821738127621
         },
         "requested_at":15821738127621
      },
      "requested_at":15821738127621
   },
   "1005312":{
      "id":1005312,
      "name":"WNCAAB ",
      "start_date":"1970-01-01 00:00:00",
      "icon":null,
      "display_flag":1,
      "base_competition_id":1000215,
      "events":[
         {
            "id":1051924,
            "name":"Fordham Women & Davidson Women",
            "display_flag":1,
            "start_date":"2020-02-23 00:00:00",
            "competition_id":1005312,
            "market_count":1,
            "dst_uri":"",
            "teams":[
               {
                  "id":810,
                  "name":"Fordham Women",
                  "icon":null,
                  "display_flag":0,
                  "position":"home",
                  "requested_at":15821738127629
               },
               {
                  "id":2610,
                  "name":"Davidson Women",
                  "icon":null,
                  "display_flag":0,
                  "position":"away",
                  "requested_at":15821738127631
               }
            ],
            "markets":[
               {
                  "id":1051565,
                  "name":"Match Winner",
                  "line":0,
                  "market_status":"O",
                  "display_flag":1,
                  "market_type_id":1000022,
                  "event_id":1051924,
                  "note":"",
                  "boost_available":false,
                  "selections":[
                     {
                        "id":455973,
                        "name":"Draw",
                        "line":0,
                        "price":2,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127649
                     },
                     {
                        "id":455974,
                        "name":"Away",
                        "line":0,
                        "price":3,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127652
                     }
                  ],
                  "markettypegroup":{
                     "id":1,
                     "name":"More Markets",
                     "description":"Markets Types that have not been grouped",
                     "display_flag":1,
                     "icon":null,
                     "requested_at":15821738127654
                  },
                  "requested_at":15821738127654
               }
            ],
            "products":[
               {
                  "product_id":10,
                  "bet_type":null,
                  "product_code":"TBF",
                  "product_name":"TopBetta Fixed",
                  "fixed":true,
                  "available":true,
                  "product_image":null,
                  "ribbon_image":null,
                  "has_pool":false,
                  "product_description":"Guarantees to pay at least the best of the 3 TAB dividends",
                  "product_note":null,
                  "product_tooltip":null,
                  "background_colour":null,
                  "multi_available":false,
                  "ordinal":0,
                  "margin":0,
                  "product_type":"standard",
                  "price_id":0,
                  "pool_total":0,
                  "first_leg":null,
                  "requested_at":15821738127662
               }
            ],
            "requested_at":15821738127662
         },
         {
            "id":1051923,
            "name":"NC State Women & Louisville Women",
            "display_flag":1,
            "start_date":"2020-02-23 01:00:00",
            "competition_id":1005312,
            "market_count":1,
            "dst_uri":"",
            "teams":[
               {
                  "id":3114,
                  "name":"NC State Women",
                  "icon":null,
                  "display_flag":0,
                  "position":"home",
                  "requested_at":15821738127668
               },
               {
                  "id":3115,
                  "name":"Louisville Women",
                  "icon":null,
                  "display_flag":0,
                  "position":"away",
                  "requested_at":15821738127670
               }
            ],
            "markets":[
               {
                  "id":1051564,
                  "name":"Match Winner",
                  "line":0,
                  "market_status":"O",
                  "display_flag":1,
                  "market_type_id":1000022,
                  "event_id":1051923,
                  "note":"",
                  "boost_available":false,
                  "selections":[
                     {
                        "id":455970,
                        "name":"Draw",
                        "line":0,
                        "price":2,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127688
                     },
                     {
                        "id":455971,
                        "name":"Away",
                        "line":0,
                        "price":3,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127691
                     }
                  ],
                  "markettypegroup":{
                     "id":1,
                     "name":"More Markets",
                     "description":"Markets Types that have not been grouped",
                     "display_flag":1,
                     "icon":null,
                     "requested_at":15821738127693
                  },
                  "requested_at":15821738127693
               }
            ],
            "products":[
               {
                  "product_id":10,
                  "bet_type":null,
                  "product_code":"TBF",
                  "product_name":"TopBetta Fixed",
                  "fixed":true,
                  "available":true,
                  "product_image":null,
                  "ribbon_image":null,
                  "has_pool":false,
                  "product_description":"Guarantees to pay at least the best of the 3 TAB dividends",
                  "product_note":null,
                  "product_tooltip":null,
                  "background_colour":null,
                  "multi_available":false,
                  "ordinal":0,
                  "margin":0,
                  "product_type":"standard",
                  "price_id":0,
                  "pool_total":0,
                  "first_leg":null,
                  "requested_at":15821738127701
               }
            ],
            "requested_at":15821738127701
         }
      ],
      "base_competition":{
         "id":1000215,
         "name":"WNCAAB",
         "icon":null,
         "display_flag":1,
         "sport_id":13,
         "order":0,
         "sport":{
            "id":13,
            "name":"Basketball",
            "icon":null,
            "display_flag":1,
            "order":0,
            "requested_at":15821738127706
         },
         "requested_at":15821738127706
      },
      "requested_at":15821738127706
   },
   "1006033":{
      "id":1006033,
      "name":"Iran Pro League 20",
      "start_date":"2020-02-23 12:00:00",
      "icon":null,
      "display_flag":null,
      "base_competition_id":1000161,
      "events":[
         {
            "id":1051925,
            "name":"Peykan & Foolad Khuzestan",
            "display_flag":1,
            "start_date":"2020-02-23 12:00:00",
            "competition_id":1006033,
            "market_count":1,
            "dst_uri":"",
            "teams":[
               {
                  "id":3116,
                  "name":"Peykan",
                  "icon":null,
                  "display_flag":0,
                  "position":"home",
                  "requested_at":15821738127713
               },
               {
                  "id":696,
                  "name":"Foolad Khuzestan",
                  "icon":null,
                  "display_flag":0,
                  "position":"away",
                  "requested_at":15821738127716
               }
            ],
            "markets":[
               {
                  "id":1051566,
                  "name":"Match Winner",
                  "line":0,
                  "market_status":"O",
                  "display_flag":1,
                  "market_type_id":1000022,
                  "event_id":1051925,
                  "note":"",
                  "boost_available":false,
                  "selections":[
                     {
                        "id":455976,
                        "name":"Draw",
                        "line":0,
                        "price":2,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127733
                     },
                     {
                        "id":455977,
                        "name":"Away",
                        "line":0,
                        "price":3,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127736
                     }
                  ],
                  "markettypegroup":{
                     "id":1,
                     "name":"More Markets",
                     "description":"Markets Types that have not been grouped",
                     "display_flag":1,
                     "icon":null,
                     "requested_at":15821738127739
                  },
                  "requested_at":15821738127739
               }
            ],
            "products":[
               {
                  "product_id":10,
                  "bet_type":null,
                  "product_code":"TBF",
                  "product_name":"TopBetta Fixed",
                  "fixed":true,
                  "available":true,
                  "product_image":null,
                  "ribbon_image":null,
                  "has_pool":false,
                  "product_description":"Guarantees to pay at least the best of the 3 TAB dividends",
                  "product_note":null,
                  "product_tooltip":null,
                  "background_colour":null,
                  "multi_available":false,
                  "ordinal":0,
                  "margin":0,
                  "product_type":"standard",
                  "price_id":0,
                  "pool_total":0,
                  "first_leg":null,
                  "requested_at":15821738127747
               }
            ],
            "requested_at":15821738127747
         }
      ],
      "base_competition":{
         "id":1000161,
         "name":"Iran Pro League",
         "icon":null,
         "display_flag":"1",
         "sport_id":19,
         "order":0,
         "sport":{
            "id":19,
            "name":"Soccer",
            "icon":null,
            "display_flag":1,
            "order":0,
            "requested_at":15821738127751
         },
         "requested_at":15821738127751
      },
      "requested_at":15821738127751
   }
}
</code>```

答:
try this you

```<code>$markets = []; $products = [];
foreach($yourdata as $key => $data){

if(isset($data['events'][0]['markets']))
 $markets[$key][] = $data['events'][0]['markets'];

 //if you want get only one data insight markets in 0
 // then use $markets[$key][] = $data['events'][0]['markets'][0];
 if(isset($data['events'][0]['products']))
 $products[$key][] = $data['events'][0]['products'];

 // $products[$key][] = $data['events'][0]['products'][0];

}
</code>```

if you have multiple events in single object use like this

```<code> foreach($yourdata as $key => $data){

          if(isset($data['events']))
         foreach($data['events'] as $event){
          if(isset($data['markets']))
          $markets[$key][] = $event['markets'];
          if(isset($data['products']))
          $products[$key][] = $event['products'];
         }

        }

        dd($markets,$products);
</code>```

Body:
i want to read laravel  object and assign it in to a another variable

i want to read those markets[] and products[] and assign to a another variable please some one help

{
   "1006032":{
      "id":1006032,
      "name":"Germany Regionalliga North East 22",
      "start_date":"2020-02-20 18:00:00",
      "icon":null,
      "display_flag":1,
      "base_competition_id":1000028,
      "events":[
         {
            "id":1051919,
            "name":"Hertha Berlin II & ZFC Meuselwitz",
            "display_flag":1,
            "start_date":"2020-02-20 18:00:00",
            "competition_id":1006032,
            "market_count":1,
            "dst_uri":"",
            "teams":[
               {
                  "id":3106,
                  "name":"Hertha Berlin II",
                  "icon":null,
                  "display_flag":0,
                  "position":"home",
                  "requested_at":15821738127576
               },
               {
                  "id":3107,
                  "name":"ZFC Meuselwitz",
                  "icon":null,
                  "display_flag":0,
                  "position":"away",
                  "requested_at":15821738127578
               }
            ],
            "markets":[
               {
                  "id":1051560,
                  "name":"Match Winner",
                  "line":0,
                  "market_status":"O",
                  "display_flag":1,
                  "market_type_id":1000022,
                  "event_id":1051919,
                  "note":"",
                  "boost_available":false,
                  "selections":[
                     {
                        "id":455957,
                        "name":"Home",
                        "line":0,
                        "price":5,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127597
                     },
                     {
                        "id":455958,
                        "name":"Draw",
                        "line":0,
                        "price":8,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127601
                     },
                     {
                        "id":455959,
                        "name":"Away",
                        "line":0,
                        "price":4,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127604
                     }
                  ],
                  "markettypegroup":{
                     "id":1,
                     "name":"More Markets",
                     "description":"Markets Types that have not been grouped",
                     "display_flag":1,
                     "icon":null,
                     "requested_at":15821738127606
                  },
                  "requested_at":15821738127606
               }
            ],
            "products":[
               {
                  "product_id":10,
                  "bet_type":null,
                  "product_code":"TBF",
                  "product_name":"TopBetta Fixed",
                  "fixed":true,
                  "available":true,
                  "product_image":null,
                  "ribbon_image":null,
                  "has_pool":false,
                  "product_description":"Guarantees to pay at least the best of the 3 TAB dividends",
                  "product_note":null,
                  "product_tooltip":null,
                  "background_colour":null,
                  "multi_available":false,
                  "ordinal":0,
                  "margin":0,
                  "product_type":"standard",
                  "price_id":0,
                  "pool_total":0,
                  "first_leg":null,
                  "requested_at":15821738127616
               }
            ],
            "requested_at":15821738127616
         }
      ],
      "base_competition":{
         "id":1000028,
         "name":"Germany Regionalliga North East",
         "icon":null,
         "display_flag":1,
         "sport_id":19,
         "order":0,
         "sport":{
            "id":19,
            "name":"Soccer",
            "icon":null,
            "display_flag":1,
            "order":0,
            "requested_at":15821738127621
         },
         "requested_at":15821738127621
      },
      "requested_at":15821738127621
   },
   "1005312":{
      "id":1005312,
      "name":"WNCAAB ",
      "start_date":"1970-01-01 00:00:00",
      "icon":null,
      "display_flag":1,
      "base_competition_id":1000215,
      "events":[
         {
            "id":1051924,
            "name":"Fordham Women & Davidson Women",
            "display_flag":1,
            "start_date":"2020-02-23 00:00:00",
            "competition_id":1005312,
            "market_count":1,
            "dst_uri":"",
            "teams":[
               {
                  "id":810,
                  "name":"Fordham Women",
                  "icon":null,
                  "display_flag":0,
                  "position":"home",
                  "requested_at":15821738127629
               },
               {
                  "id":2610,
                  "name":"Davidson Women",
                  "icon":null,
                  "display_flag":0,
                  "position":"away",
                  "requested_at":15821738127631
               }
            ],
            "markets":[
               {
                  "id":1051565,
                  "name":"Match Winner",
                  "line":0,
                  "market_status":"O",
                  "display_flag":1,
                  "market_type_id":1000022,
                  "event_id":1051924,
                  "note":"",
                  "boost_available":false,
                  "selections":[
                     {
                        "id":455973,
                        "name":"Draw",
                        "line":0,
                        "price":2,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127649
                     },
                     {
                        "id":455974,
                        "name":"Away",
                        "line":0,
                        "price":3,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127652
                     }
                  ],
                  "markettypegroup":{
                     "id":1,
                     "name":"More Markets",
                     "description":"Markets Types that have not been grouped",
                     "display_flag":1,
                     "icon":null,
                     "requested_at":15821738127654
                  },
                  "requested_at":15821738127654
               }
            ],
            "products":[
               {
                  "product_id":10,
                  "bet_type":null,
                  "product_code":"TBF",
                  "product_name":"TopBetta Fixed",
                  "fixed":true,
                  "available":true,
                  "product_image":null,
                  "ribbon_image":null,
                  "has_pool":false,
                  "product_description":"Guarantees to pay at least the best of the 3 TAB dividends",
                  "product_note":null,
                  "product_tooltip":null,
                  "background_colour":null,
                  "multi_available":false,
                  "ordinal":0,
                  "margin":0,
                  "product_type":"standard",
                  "price_id":0,
                  "pool_total":0,
                  "first_leg":null,
                  "requested_at":15821738127662
               }
            ],
            "requested_at":15821738127662
         },
         {
            "id":1051923,
            "name":"NC State Women & Louisville Women",
            "display_flag":1,
            "start_date":"2020-02-23 01:00:00",
            "competition_id":1005312,
            "market_count":1,
            "dst_uri":"",
            "teams":[
               {
                  "id":3114,
                  "name":"NC State Women",
                  "icon":null,
                  "display_flag":0,
                  "position":"home",
                  "requested_at":15821738127668
               },
               {
                  "id":3115,
                  "name":"Louisville Women",
                  "icon":null,
                  "display_flag":0,
                  "position":"away",
                  "requested_at":15821738127670
               }
            ],
            "markets":[
               {
                  "id":1051564,
                  "name":"Match Winner",
                  "line":0,
                  "market_status":"O",
                  "display_flag":1,
                  "market_type_id":1000022,
                  "event_id":1051923,
                  "note":"",
                  "boost_available":false,
                  "selections":[
                     {
                        "id":455970,
                        "name":"Draw",
                        "line":0,
                        "price":2,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127688
                     },
                     {
                        "id":455971,
                        "name":"Away",
                        "line":0,
                        "price":3,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127691
                     }
                  ],
                  "markettypegroup":{
                     "id":1,
                     "name":"More Markets",
                     "description":"Markets Types that have not been grouped",
                     "display_flag":1,
                     "icon":null,
                     "requested_at":15821738127693
                  },
                  "requested_at":15821738127693
               }
            ],
            "products":[
               {
                  "product_id":10,
                  "bet_type":null,
                  "product_code":"TBF",
                  "product_name":"TopBetta Fixed",
                  "fixed":true,
                  "available":true,
                  "product_image":null,
                  "ribbon_image":null,
                  "has_pool":false,
                  "product_description":"Guarantees to pay at least the best of the 3 TAB dividends",
                  "product_note":null,
                  "product_tooltip":null,
                  "background_colour":null,
                  "multi_available":false,
                  "ordinal":0,
                  "margin":0,
                  "product_type":"standard",
                  "price_id":0,
                  "pool_total":0,
                  "first_leg":null,
                  "requested_at":15821738127701
               }
            ],
            "requested_at":15821738127701
         }
      ],
      "base_competition":{
         "id":1000215,
         "name":"WNCAAB",
         "icon":null,
         "display_flag":1,
         "sport_id":13,
         "order":0,
         "sport":{
            "id":13,
            "name":"Basketball",
            "icon":null,
            "display_flag":1,
            "order":0,
            "requested_at":15821738127706
         },
         "requested_at":15821738127706
      },
      "requested_at":15821738127706
   },
   "1006033":{
      "id":1006033,
      "name":"Iran Pro League 20",
      "start_date":"2020-02-23 12:00:00",
      "icon":null,
      "display_flag":null,
      "base_competition_id":1000161,
      "events":[
         {
            "id":1051925,
            "name":"Peykan & Foolad Khuzestan",
            "display_flag":1,
            "start_date":"2020-02-23 12:00:00",
            "competition_id":1006033,
            "market_count":1,
            "dst_uri":"",
            "teams":[
               {
                  "id":3116,
                  "name":"Peykan",
                  "icon":null,
                  "display_flag":0,
                  "position":"home",
                  "requested_at":15821738127713
               },
               {
                  "id":696,
                  "name":"Foolad Khuzestan",
                  "icon":null,
                  "display_flag":0,
                  "position":"away",
                  "requested_at":15821738127716
               }
            ],
            "markets":[
               {
                  "id":1051566,
                  "name":"Match Winner",
                  "line":0,
                  "market_status":"O",
                  "display_flag":1,
                  "market_type_id":1000022,
                  "event_id":1051925,
                  "note":"",
                  "boost_available":false,
                  "selections":[
                     {
                        "id":455976,
                        "name":"Draw",
                        "line":0,
                        "price":2,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127733
                     },
                     {
                        "id":455977,
                        "name":"Away",
                        "line":0,
                        "price":3,
                        "won":false,
                        "display_flag":1,
                        "selection_status_id":1,
                        "requested_at":15821738127736
                     }
                  ],
                  "markettypegroup":{
                     "id":1,
                     "name":"More Markets",
                     "description":"Markets Types that have not been grouped",
                     "display_flag":1,
                     "icon":null,
                     "requested_at":15821738127739
                  },
                  "requested_at":15821738127739
               }
            ],
            "products":[
               {
                  "product_id":10,
                  "bet_type":null,
                  "product_code":"TBF",
                  "product_name":"TopBetta Fixed",
                  "fixed":true,
                  "available":true,
                  "product_image":null,
                  "ribbon_image":null,
                  "has_pool":false,
                  "product_description":"Guarantees to pay at least the best of the 3 TAB dividends",
                  "product_note":null,
                  "product_tooltip":null,
                  "background_colour":null,
                  "multi_available":false,
                  "ordinal":0,
                  "margin":0,
                  "product_type":"standard",
                  "price_id":0,
                  "pool_total":0,
                  "first_leg":null,
                  "requested_at":15821738127747
               }
            ],
            "requested_at":15821738127747
         }
      ],
      "base_competition":{
         "id":1000161,
         "name":"Iran Pro League",
         "icon":null,
         "display_flag":"1",
         "sport_id":19,
         "order":0,
         "sport":{
            "id":19,
            "name":"Soccer",
            "icon":null,
            "display_flag":1,
            "order":0,
            "requested_at":15821738127751
         },
         "requested_at":15821738127751
      },
      "requested_at":15821738127751
   }
}

Body:
try this you

$markets = []; $products = [];
foreach($yourdata as $key => $data){

if(isset($data['events'][0]['markets']))
 $markets[$key][] = $data['events'][0]['markets'];

 //if you want get only one data insight markets in 0
 // then use $markets[$key][] = $data['events'][0]['markets'][0];
 if(isset($data['events'][0]['products']))
 $products[$key][] = $data['events'][0]['products'];

 // $products[$key][] = $data['events'][0]['products'][0];

}

if you have multiple events in single object use like this

 foreach($yourdata as $key => $data){

          if(isset($data['events']))
         foreach($data['events'] as $event){
          if(isset($data['markets']))
          $markets[$key][] = $event['markets'];
          if(isset($data['products']))
          $products[$key][] = $event['products'];
         }

        }

        dd($markets,$products);


来源: stackexchange

问:
Too many open files even with O_EXCL
I am trying to write a function that is able to determine if a process that calls it is the first to do so, without the use of any locks.

This is my current implementation.

```<code>def is_first_process(path):
    filename = os.path.join(path, "first.file")
    try:
        fd = os.open(filename, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
        os.close(fd)
        return True
    except FileExistsError:
        return False
</code>```

I test the above function like this:

```<code>def test_is_first_process():
    path = "/tmp/first_process"
    shutil.rmtree(path, ignore_errors=True)
    process_list = []

    def helper(fn, arg, shared_list):
        shared_list.append(fn(arg))

    for _ in range(1000):
        makedirs(path)
        manager = Manager()
        results = manager.list()
        for i in range(1000):
            p = Process(target=helper, args=(is_first_process, path, results))
            p.start()
            process_list.append(p)

        for p in process_list:
            p.join()

        assert results.count(True) == 1
        shutil.rmtree(path, ignore_errors=True)
</code>```

For large m*n the test errors out with the following error:

E OSError: [Errno 24] Too many open files

But not for smaller values (m*n < 100).

My understanding of the os.O_EXCL flag is that it raises the FileExistsError if it already exists.

Is my understanding of this flag incorrect?
How do I correctly implement and test a function that can determine the first process that writes to a directory?

答:
I think you may be misinterpreting the error you're seeing. The error message about Too many open files means what it says, that you're opening too many files at the same time. It does not necessarily that your one file is being opened more than once at a time.

It may be that the multiprocessing code that's handling the inter-process communication is causing problems with the 1000 separate processes that you're trying to start all at once. That's a lot of processes!

Many operating systems limit how many files each process can have open, and often also limit each user logged in, so even opening only a few files in each of a huge number processes might be a problem. It may be that you could modify the limits on your system, using ulimit -n or a similar configuration program.

But the real question is, why do you think you need to test with 1000 processes at a time? Even on a large system, you're probably not going to have that many CPU cores, so most of those processes will necessarily be sleeping, while only a few of them run. I'd suggest doing your testing with a number of processes that is at most a small multiple (e.g. 2x) of your system's number of cores, any more is just wasting your time.

ContentLicense: CC BY-SA 4.0

Title: Too many open files even with O_EXCL

Body:
I am trying to write a function that is able to determine if a process that calls it is the first to do so, without the use of any locks.

This is my current implementation.

def is_first_process(path):
    filename = os.path.join(path, "first.file")
    try:
        fd = os.open(filename, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
        os.close(fd)
        return True
    except FileExistsError:
        return False

I test the above function like this:

def test_is_first_process():
    path = "/tmp/first_process"
    shutil.rmtree(path, ignore_errors=True)
    process_list = []

    def helper(fn, arg, shared_list):
        shared_list.append(fn(arg))

    for _ in range(1000):
        makedirs(path)
        manager = Manager()
        results = manager.list()
        for i in range(1000):
            p = Process(target=helper, args=(is_first_process, path, results))
            p.start()
            process_list.append(p)

        for p in process_list:
            p.join()

        assert results.count(True) == 1
        shutil.rmtree(path, ignore_errors=True)

For large m*n the test errors out with the following error:

E OSError: [Errno 24] Too many open files

But not for smaller values (m*n < 100).

My understanding of the os.O_EXCL flag is that it raises the FileExistsError if it already exists.

Is my understanding of this flag incorrect?
How do I correctly implement and test a function that can determine the first process that writes to a directory?


问:
Rewrite URL with query string .htaccess or route.php
I have developed an application with Codeigniter and

I want to Rewrite my GET Query String from this -

```<code>https://www.example.com/search?state=American%20Samoa
</code>```

to this

```<code>https://www.example.com/job-vacancies-in-American-Samoa
</code>```

I am ok to go for any of the solutions either with .htaccess or CI route.php

My current .htaccess contatin

```<code>RewriteOptions inherit
RewriteEngine on

#Force https:
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#CI index.php removal

RewriteCond $1 !^(index\.php|public|\.txt)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?$1

RewriteRule ^admin/(.*)$ /$1 [L,NC,R]
</code>```

答:
Try this way In your controller

```<code>public function search(){
   if(!empty($this->input->get('search'))){
   $search = $this->input->get('search');
   $joined_search='job-vacancies-in-'.$search;
  redirect($joined_search);
  }
}
</code>```

In you routes.php consider if default controller is welcome

```<code>$routes['(:any)']="welcome/search/$1";
</code>```

Body:
I have developed an application with Codeigniter and

I want to Rewrite my GET Query String from this -

https://www.example.com/search?state=American%20Samoa

to this

https://www.example.com/job-vacancies-in-American-Samoa

I am ok to go for any of the solutions either with .htaccess or CI route.php

My current .htaccess contatin

RewriteOptions inherit
RewriteEngine on

#Force https:
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#CI index.php removal

RewriteCond $1 !^(index\.php|public|\.txt)

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?$1

RewriteRule ^admin/(.*)$ /$1 [L,NC,R]

Body:
Try this way In your controller

public function search(){
   if(!empty($this->input->get('search'))){
   $search = $this->input->get('search');
   $joined_search='job-vacancies-in-'.$search;
  redirect($joined_search);
  }
}

In you routes.php consider if default controller is welcome

$routes['(:any)']="welcome/search/$1";


问:
cannot find cert for ngrok websocket secure
When I connect my embedded board's WSS client to wss://echo.websocket.org, i can use the cert i find using firefox's security tab, the "Let's Encrypt Authority X3" cert. I am able to authenticate on my board and echo information.

but if i use my server's https://*.ngrok.io/ in my WSS client, with the cert i find on the ngrok.io website, my board tells me that it fails to verify peer certificate.

But I have no problem connecting websocket.org's echo client to my https://*.ngrok.io/ server. what's going on?

答: Turns out I have to use openssl to extract the cert.</p>


问:
Regex not giving output as desired
I am using the regex - [{]{[}][}] for the input {{id}}
The output I expect is id. But I am getting {{id}}.

My java code is as below:

```<code>  String string = "\"{\n" +
                "    \"id\": {{dsm_id}},\n" +
                "    \"title\": \"Automation Test\",\n" +
                "    \"code\": \"aut_test\",\n" +
                "    \"companyId\": 286,\n" +
                "    \"enabled\": true,\n" +
                "    \"enableAdvanceFilter\": false,\n" +
                "    \"deleteAfterScheduledTime\": false,\n" +
                "    \"enableDataStoreLog\": false\n" +
                "}\"";
        String patternString = "[{][{](.*)[}][}]";
        Pattern pattern = Pattern.compile(patternString);
        Matcher matcher = pattern.matcher(string);
        List<String> allMatches = new ArrayList<String>();
        while (matcher.find()) {
            allMatches.add(matcher.group());
        }
        System.out.println(allMatches);
</code>```

The only solution I need is having the right regex. I cannot use or don't want to use DTO or Json parser here.

答:
You use patter group incorrectly. Try this one:

```<code>String patternString = "[{][{](?<id>.*)[}][}]";
// String patternString = "\\{\\{(?<id>[^}]+)}}";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(string);
List<String> allMatches = new ArrayList<>();
while (matcher.find()) {
    allMatches.add(matcher.group("id"));
}
</code>```

In case you do not want to use name group:

```<code>String patternString = "[{][{](.*)[}][}]";
//String patternString = "\\{\\{([^}]+)}}";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(string);
List<String> allMatches = new ArrayList<>();
while (matcher.find()) {
    allMatches.add(matcher.group(1));
}
</code>```

But I recommend you use another approach: using e.g. Jackson to convert this JSON to Map<String, Object> and retrieve required fields.

Title: Regex not giving output as desired

Body:
I am using the regex - [{]{[}][}] for the input {{id}}
The output I expect is id. But I am getting {{id}}.

My java code is as below:

  String string = "\"{\n" +
                "    \"id\": {{dsm_id}},\n" +
                "    \"title\": \"Automation Test\",\n" +
                "    \"code\": \"aut_test\",\n" +
                "    \"companyId\": 286,\n" +
                "    \"enabled\": true,\n" +
                "    \"enableAdvanceFilter\": false,\n" +
                "    \"deleteAfterScheduledTime\": false,\n" +
                "    \"enableDataStoreLog\": false\n" +
                "}\"";
        String patternString = "[{][{](.*)[}][}]";
        Pattern pattern = Pattern.compile(patternString);
        Matcher matcher = pattern.matcher(string);
        List<String> allMatches = new ArrayList<String>();
        while (matcher.find()) {
            allMatches.add(matcher.group());
        }
        System.out.println(allMatches);

The only solution I need is having the right regex. I cannot use or don't want to use DTO or Json parser here.

Body:
You use patter group incorrectly. Try this one:

String patternString = "[{][{](?<id>.*)[}][}]";
// String patternString = "\\{\\{(?<id>[^}]+)}}";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(string);
List<String> allMatches = new ArrayList<>();
while (matcher.find()) {
    allMatches.add(matcher.group("id"));
}

In case you do not want to use name group:

String patternString = "[{][{](.*)[}][}]";
//String patternString = "\\{\\{([^}]+)}}";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(string);
List<String> allMatches = new ArrayList<>();
while (matcher.find()) {
    allMatches.add(matcher.group(1));
}

But I recommend you use another approach: using e.g. Jackson to convert this JSON to Map<String, Object> and retrieve required fields.


问:
Can't get innerHTML of tag on IE8
I am trying to get the innerhtml of class name current_page_item[0]... And this is working  fine in FF and even in IE9 also. But in IE 8 it seems to be some javascript error in line" var classelem=document.getElementsByClassName('current_page_item')[0].innerHTML;.

I tried to put alert after the above line. But it is not displaying the message "Hello again".

Any idea how to solve the browser issue for this? Is it something that document.getElementsByClassName wont work in IE8?

```<code><html>
<head>
<script type="text/javascript">
function updatesidebar()
{
alert("Hello");
var classelem=document.getElementsByClassName('current_page_item')[0].innerHTML;

alert("Hello again");

}
</script>

</head>
<body>
<div id="main">

<div class="menu_main">

                      <ul class='mainmenu' id='root'>
<li><a href="/home" class="">Home</a></li>
<li><a href="/solutions" class="">Solutions</a>
</li><li><a href="/services" class="">Services</a></li>
<li><a href="/about-us" class="current_page_item">About Us</a></li>
<li><a href="/news" class="">News and Events</a></li>
<li><a href="/careers" class="">Careers</a></li>
<li><a href="/contact-us" class="">Contact Us</a></li>
</ul>

                </div>

</div>
<script type="text/javascript">
window.onload=updatesidebar();
</script>

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

答: getElementsByClassName is not a JS native function you must refer to any library including it</p>

ContentLicense: CC BY-SA 3.0

Title: Can't get innerHTML of tag on IE8

Body:
I am trying to get the innerhtml of class name current_page_item[0]... And this is working  fine in FF and even in IE9 also. But in IE 8 it seems to be some javascript error in line" var classelem=document.getElementsByClassName('current_page_item')[0].innerHTML;.

I tried to put alert after the above line. But it is not displaying the message "Hello again".

Any idea how to solve the browser issue for this? Is it something that document.getElementsByClassName wont work in IE8?

Home

Solutions

Services

About Us

News and Events

Careers

Contact Us


问:
Execute Setup with admin rights
I have a windows forms app developed in c# and have created a setup file for it.
.Net Framework used is 3.0.

Now, setup should force for admin rights for installation and then proceed else not.

I found articles on creating manifest file which works fine but when program is launched after installation it again asks for admin rights which is not i want.

And this prompt should also work on Windows XP SP 1 and above OS.

答:
To prompt Installer to invoke the UAC prompt to the user you can do the following:

Right click your Setup Project > View > Launch Conditions.

Right click Launch Conditions > Add a new Condition in your Launch Conditions.

Right click the Condition, choose Properties Window.

Set Condition to AdminUser. (You can also try setting Privileged property)

Build and install

OR

  Edit your .vdproj, change requiresElevation attribute to true

```<code>"MsiBootstrapper"
{

    "RequiresElevation" = "11:TRUE"
}
</code>```

Title: Execute Setup with admin rights

Body:
To prompt Installer to invoke the UAC prompt to the user you can do the following:

Right click your Setup Project > View > Launch Conditions.

Right click Launch Conditions > Add a new Condition in your Launch Conditions.

Right click the Condition, choose Properties Window.

Set Condition to AdminUser. (You can also try setting Privileged property)

Build and install

OR

  Edit your .vdproj, change requiresElevation attribute to true

"MsiBootstrapper"
{

    "RequiresElevation" = "11:TRUE"
}


问:
Managing devices from powershell
What are the commands to enable or disable network adapters in powershell 2.0 in windows 7?  In windows 10 there are enable-netadapter and disable-netadapter commands, are there any analogues of these commands in powershel 2.0?</p>

答:
Do it using Wmi.

Enable or disable

```<code>$netadapter = Get-WmiObject -Class Win32_NetworkAdapter -filter "Name LIKE '%Wireless%'"

$netadapter.disable() or $netadapter.enable()
</code>```

Title: Managing devices from powershell

Body:
Do it using Wmi.

Enable or disable

$netadapter = Get-WmiObject -Class Win32_NetworkAdapter -filter "Name LIKE '%Wireless%'"

$netadapter.disable() or $netadapter.enable()


问:
Not able to throw exception for @override method
```<code>@Override
protected void configure() throws IOException{

        Properties props = new Properties();
        props.load(new FileInputStream(System.getProperty("user.dir")+"/src/properties/android.properties"));
        Names.bindProperties(binder(), props);

}
</code>```

I am not able to throw any Exception for the above-overridden method. I'm getting error remove throw Exception. This is the implementation of a Guice module.

答:
Have you added same throws IOException on parent Method ?

If you override the method and if original method signature don't have Throws IOException then it will not work .

i.e

interface A {

  void A() throws Exception;

}

class B implements A{

  @override
  public void A() throws Exception{
  }

}
```

the above format will work.

Body:
@Override
protected void configure() throws IOException{

        Properties props = new Properties();
        props.load(new FileInputStream(System.getProperty("user.dir")+"/src/properties/android.properties"));
        Names.bindProperties(binder(), props);

}

I am not able to throw any Exception for the above-overridden method. I'm getting error remove throw Exception. This is the implementation of a Guice module.

Body:
Have you added same throws IOException on parent Method ?

If you override the method and if original method signature don't have Throws IOException then it will not work .

i.e

interface A {

  void A() throws Exception;

}

class B implements A{

  @override
  public void A() throws Exception{
  }

}

the above format will work.


问:
ijson fails with trailing garbage parse error
```<code>for prefix, event, value in parser:
    print(prefix)
</code>```

I get the following error after executing the above code , I dont understand what the error is.

ijson.common.IncompleteJSONError: parse error: trailing garbage
          nt":19485,"verified":false}} {"user_id":1408970940,"id":4496
                     (right here) ------^

答: Seems you are trying to parse a JSON document with more than one top-level object, which is not standard. ijson allows for this though if you give the multiple_values=True flag to the method you are using.

Body:
for prefix, event, value in parser:
    print(prefix)

I get the following error after executing the above code , I dont understand what the error is.

ijson.common.IncompleteJSONError: parse error: trailing garbage
          nt":19485,"verified":false}} {"user_id":1408970940,"id":4496
                     (right here) ------^


问:
How can I set my local date in javaScript
I'm using this code to get the difference between today date and my data date from database

I notice every day at 3 pm . next day start
( for example if today is 20 . at 3 pm the date will be 21 )

```<code>  const oneDay = 24 * 60 * 60 * 1000;
  var serverDate = new Date(value)
  let todayDate = new Date()
  const difference = Math.round(Math.abs((todayDate - serverDate) / oneDay));
  return difference
</code>```

How can I set my local date or there is better way to solve this problem

答:
You can get your local time by passing your location with localeString.

```<code>var asiaTime = new Date().toLocaleString("en-US", { timeZone: "Asia/Shanghai"
});
asiaTime = new Date(asiaTime);
console.log('Asia time in string: ' + asiaTime.toLocaleString())
console.log('Asia time in Date format', asiaTime)

var aestTime = new Date().toLocaleString("en-US", {timeZone:
"Australia/Brisbane"});
aestTime = new Date(aestTime);
console.log('AEST time: '+aestTime.toLocaleString())
console.log('AEST time in Date format', aestTime)

var indiaTime = new Date().toLocaleString("en-US", {timeZone:
"Asia/Kolkata"});
indiaTime = new Date(indiaTime);
console.log('India time: '+indiaTime.toLocaleString())
console.log('Inida time in Date format', indiaTime)
</code>```

Hope this Helps . GOOD LUCK.

Body:
I'm using this code to get the difference between today date and my data date from database

I notice every day at 3 pm . next day start
( for example if today is 20 . at 3 pm the date will be 21 )

  const oneDay = 24 * 60 * 60 * 1000;
  var serverDate = new Date(value)
  let todayDate = new Date()
  const difference = Math.round(Math.abs((todayDate - serverDate) / oneDay));
  return difference

How can I set my local date or there is better way to solve this problem

Body:
You can get your local time by passing your location with localeString.

var asiaTime = new Date().toLocaleString("en-US", { timeZone: "Asia/Shanghai"
});
asiaTime = new Date(asiaTime);
console.log('Asia time in string: ' + asiaTime.toLocaleString())
console.log('Asia time in Date format', asiaTime)

var aestTime = new Date().toLocaleString("en-US", {timeZone:
"Australia/Brisbane"});
aestTime = new Date(aestTime);
console.log('AEST time: '+aestTime.toLocaleString())
console.log('AEST time in Date format', aestTime)

var indiaTime = new Date().toLocaleString("en-US", {timeZone:
"Asia/Kolkata"});
indiaTime = new Date(indiaTime);
console.log('India time: '+indiaTime.toLocaleString())
console.log('Inida time in Date format', indiaTime)

Hope this Helps . GOOD LUCK.


问:
Number of bytes used for Unicode characters in varchar

A common misconception is to think that CHAR(n) and VARCHAR(n), the n defines the number of characters. But in CHAR(n) and VARCHAR(n) the n defines the string length in bytes (0-8,000). n never defines numbers of characters that can be stored

According to this statement from Microsoft, I assume, n is the data length of a string and when we store unicode characters in varchar, a single character should take 2 bytes. But, when I try with a sample as below, I see varchar data taking 1 byte instead of 2 bytes.

```<code>declare @varchar varchar(6), @nvarchar nvarchar(6)

set @varchar = 'Ø'

select @varchar as VarcharString, len(@varchar) as VarcharStringLength, DATALENGTH(@varchar) as VarcharStringDataLength

</code>```

Could someone explain the reason behind it?

答:
```<code>declare @char varchar(4)
declare @nvarchar nvarchar(4)

Set @char = '@'
Set @nvarchar = '@'

select @char as charString,
LEN(@char) as charStringLength,
DATALENGTH(@char) as charStringDataLength

select @nvarchar as nvarcharString,
LEN(@nvarchar) as nvarcharStringLength,
DATALENGTH(@nvarchar) as nvarcharStringDataLength
</code>```

Body:
A common misconception is to think that CHAR(n) and VARCHAR(n), the n defines the number of characters. But in CHAR(n) and VARCHAR(n) the n defines the string length in bytes (0-8,000). n never defines numbers of characters that can be stored

According to this statement from Microsoft, I assume, n is the data length of a string and when we store unicode characters in varchar, a single character should take 2 bytes. But, when I try with a sample as below, I see varchar data taking 1 byte instead of 2 bytes.

declare @varchar varchar(6), @nvarchar nvarchar(6)

set @varchar = 'Ø'

select @varchar as VarcharString, len(@varchar) as VarcharStringLength, DATALENGTH(@varchar) as VarcharStringDataLength

Could someone explain the reason behind it?


问:
Excel unable to copy paste across two workbooks
I'm trying to copy some data from one excel workbook to another but I am unable to. I can getting some useless message like "unable to copy data"

When I copy into a new sheet in the same workbook then the copying works. What am I doing wrong? It would be very helpful to get this fixed.

Here are screenshots of what I am trying to do:

I have restarted my computer twice but that doesn't seem to have changed the problem. I have tried copying entire worksheets or just a cell and I get the same error.

This one time, somehow, "keep source formatting" option showed up while pasting but when I tried to paste, I got this message: "Microsoft is waiting for another application to complete an OLE action" . I only have google Chrome, Adobe, and Paint running on my computer right now.

答:
Could be config corruption, try this:

Right click on a sheet tab and select "View Code"

  From the "View" menu select "Immediate Window" if it's not already displayed.

  Paste the following into the "Immediate Window" and press enter: Commandbars("Cell").Reset

  Of course, deleting the per-user configuration in Excel will delete the user's customizations.

From: http://www.whitemiceconsulting.com/msexcelgreycutnpaste201508


问:
Spring Cloud Stream with AWS MSK - How can I use and deploy on AWS?
I have been using Spring Cloud Stream with Kafka for a while now. I have a sample SCS-Producer which pumps out data to an output topic.

Below is my producer code:-

```<code>@EnableBinding(Source.class)
public class SampleProducer {

      @InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "7000", maxMessagesPerPoll = "1"))
public Employee MessageSource() {

Employee emp = new Employee();
emp.setName("Jack");
emp.setType("Dev");

return emp;
}
}
</code>```

2) App.yml

```<code>spring:
  cloud:
    stream:
      defaultBinder: kafka
      bindings:
        output:
          destination: topic1
          content-type: application/json
      kafka:
        binder:
          brokers: someIp:somePort
          zkNodes: someIp:somePort
server:
  port: 0
</code>```

Request:- Never deployed an AWS Application which used AWS Native services. In the above code everything works fine if I use Kafka and the app on my Local. BUT I now I need to deploy my App on EC2 Cluster, and also I have to use AWS MSK ( this is also provisioned for my team).

I have been using pipelines created by DevOps engineers until now so never really integrated anything by myself and there is very less or rather No documentation or demo projects that I helps me in this situation. I am very much stuck and I need your help. Could anyone help me to a page or a link or any resource wherein I can follow steps to 1. have all the configuration info for the provisioned AWS MSK info in my code so that I can deploy this app on AWS ? Much appreciated.

Thank you.

答:
You can follow the AWS MSK official step-by-step guide here https://docs.aws.amazon.com/msk/latest/developerguide/getting-started.html and then use the same EC2 instance/machine created in step #4, to deploy your own Spring Cloud Stream app and test it.

If, by following the guide, you are able to produce and consume data as mentioned in the step #6, then your Spring Cloud Stream app should also be able to connect as well.

I didn't used Spring Cloud Stream with AWS MSK before, but I have successfully deployed and ran Spring Boot applications on EC2 and Elastic Beanstalk talking to AWS MSK cluster(s). And, in doing so, I followed the official AWS MSK documentation and it worked for me, (with just one hiccup though AWS Elastic Beanstalk unable to access AWS MSK).

Body:
I have been using Spring Cloud Stream with Kafka for a while now. I have a sample SCS-Producer which pumps out data to an output topic.

Below is my producer code:-

@EnableBinding(Source.class)
public class SampleProducer {

      @InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "7000", maxMessagesPerPoll = "1"))
public Employee MessageSource() {

Employee emp = new Employee();
emp.setName("Jack");
emp.setType("Dev");

return emp;
}
}

2) App.yml

spring:
  cloud:
    stream:
      defaultBinder: kafka
      bindings:
        output:
          destination: topic1
          content-type: application/json
      kafka:
        binder:
          brokers: someIp:somePort
          zkNodes: someIp:somePort
server:
  port: 0

Request:- Never deployed an AWS Application which used AWS Native services. In the above code everything works fine if I use Kafka and the app on my Local. BUT I now I need to deploy my App on EC2 Cluster, and also I have to use AWS MSK ( this is also provisioned for my team).

I have been using pipelines created by DevOps engineers until now so never really integrated anything by myself and there is very less or rather No documentation or demo projects that I helps me in this situation. I am very much stuck and I need your help. Could anyone help me to a page or a link or any resource wherein I can follow steps to 1. have all the configuration info for the provisioned AWS MSK info in my code so that I can deploy this app on AWS ? Much appreciated.

Thank you.


问:
HttpClient Angular don't work on iOS device
I want to take data from a web site to a mobile application in a project with angular.

I found the plugin HttpClient that work's fine into browser and into Android device but, not into iOS device.

Here is the code:

data.service.ts file:

```<code>import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})

export class DataService {

  constructor(private httpClient: HttpClient) {
    //
  }

  getDescription() {
    return this.httpClient.get('https://mywebsite.com');
  }
}
</code>```

page.ts where I take the data:

```<code>import { Component, OnInit } from '@angular/core';
import { DataService } from '../service/data.service';

@Component({
  selector: 'app-batik-motifs',
  templateUrl: './batik-motifs.page.html',
  styleUrls: ['./batik-motifs.page.scss'],
})

export class BatikMotifsPage implements OnInit {

  description$: Object;

  constructor(private dataService: DataService) {
    //
  }

  ngOnInit() {
    this.dataService.getDescription().subscribe(descriptions => this.description$ = descriptions);
  }

}
</code>```

page.html where I show data:

```<code><ion-list>

    <ion-item *ngFor="let descriptions of description$" lines="none">
      <ion-card>
        <ion-card-header>
          <ion-card-subtitle [innerHTML]="descriptions.title.rendered"></ion-card-subtitle>
        </ion-card-header>
        <ion-card-content>
          <ion-row>
            <ion-col size="4">
              <img [src]="descriptions.image.guid" />
            </ion-col>
            <ion-col size="8">
              <p [innerHTML]="descriptions.content.rendered"></p>
            </ion-col>
          </ion-row>
        </ion-card-content>
        <ion-row class="cardfooter">
          <ion-col>
            <ion-button>Read More</ion-button>
          </ion-col>
        </ion-row>
      </ion-card>
    </ion-item>

  </ion-list>
</code>```

I try already to add some properties on config.xml as

```<code><access origin="*" />
<allow-navigation href="*" />
<allow-navigation href="http://localhost:8080/*" />
<allow-navigation href="https://mywebsite.com/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
</code>```

And in the index.html

```<code><meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
</code>```

The problem is that in the browser and in the Android device I can see data, but in iOS device I can't see anything (even if the HTTP request work's fine because I don't have errors).

答:
make sure that Your API is deployed in same domain of your angular app ,not even sub-domain.

I face the same problem and after a lot of search this is the only way worked for me

I Think it is related to this issues.

Angular GET request error, but only on safari iOS

Body:
I want to take data from a web site to a mobile application in a project with angular.

I found the plugin HttpClient that work's fine into browser and into Android device but, not into iOS device.

Here is the code:

data.service.ts file:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})

export class DataService {

  constructor(private httpClient: HttpClient) {
    //
  }

  getDescription() {
    return this.httpClient.get('https://mywebsite.com');
  }
}

page.ts where I take the data:

import { Component, OnInit } from '@angular/core';
import { DataService } from '../service/data.service';

@Component({
  selector: 'app-batik-motifs',
  templateUrl: './batik-motifs.page.html',
  styleUrls: ['./batik-motifs.page.scss'],
})

export class BatikMotifsPage implements OnInit {

  description$: Object;

  constructor(private dataService: DataService) {
    //
  }

  ngOnInit() {
    this.dataService.getDescription().subscribe(descriptions => this.description$ = descriptions);
  }

}

page.html where I show data:

<ion-list>

    <ion-item *ngFor="let descriptions of description$" lines="none">
      <ion-card>
        <ion-card-header>
          <ion-card-subtitle [innerHTML]="descriptions.title.rendered"></ion-card-subtitle>
        </ion-card-header>
        <ion-card-content>
          <ion-row>
            <ion-col size="4">

            </ion-col>
            <ion-col size="8">

            </ion-col>
          </ion-row>
        </ion-card-content>
        <ion-row class="cardfooter">
          <ion-col>
            <ion-button>Read More</ion-button>
          </ion-col>
        </ion-row>
      </ion-card>
    </ion-item>

  </ion-list>

I try already to add some properties on config.xml as

<access origin="*" />
<allow-navigation href="*" />
<allow-navigation href="http://localhost:8080/*" />
<allow-navigation href="https://mywebsite.com/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />

And in the index.html

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

The problem is that in the browser and in the Android device I can see data, but in iOS device I can't see anything (even if the HTTP request work's fine because I don't have errors).


问:
Part of the text should change in Carousel using pure html css no JavaScript or jQuery
I have a Carousel where part of the text should change at a fixed interval. need to change the text from WEB to mobile IoT application development transport products etc
I'm using aurelia framework

https://www.codeply.com/p/7k0uDOyaf3

$('#carouselExampleSlidesOnly').carousel({
  interval: 500
})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active"><img class="d-block w-100" src="https://worldtransfer.online/wp-content/uploads/2016/09/worldmap-bg.jpg" alt="First slide">
      <div class="carousel-caption big clearfix p-5" style="width:fit-content">
        <div class="d-flex">
          <h1 class="text-uppercase text-white">We Architect,</h1>
          <h3 class="pt-2 pl-2">Design and Develop</h3>
        </div>
        <h1 class="text-uppercase"><span class="text-warning pr-3">Web</span>Application</h1>
      </div>
      <div class="carousel-caption d-none d-md-block"><img class="d-block w-75 image-left" src="https://cdn2.hubspot.net/hub/145335/file-407477601-gif/blog-files/the-importance-of-mobile-responsive-web-design.gif" alt="system Image"></div>
    </div>
  </div>
</div></code>```

答:
Move your jQuery script to top of all scrips, check the snippet

var $ = jQuery;
$('#carouselExampleSlidesOnly').carousel({
  interval: 2000
})```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.carousel-inner {
  background-image: url("https://worldtransfer.online/wp-content/uploads/2016/09/worldmap-bg.jpg");
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  height: 250px
}

.carousel-caption {
  top: 1em;
}

.carousel {
  position: relative
}

.d_flex {
  position: absolute;
  z-index: 99;
  justify-content: center;
  top: 10%;
  text-align: center;
  align-items: center;
  width: 100%;
}

.carousel-text {
  position: absolute;
  z-index: 99;
  height:100%;
  top:100%
}</code>```

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

We Architect,

Design and Develop

            WebApplication

            MobileApplication

            DesktopApplication

```

Body:
I have a Carousel where part of the text should change at a fixed interval. need to change the text from WEB to mobile IoT application development transport products etc
I'm using aurelia framework

https://www.codeply.com/p/7k0uDOyaf3

$('#carouselExampleSlidesOnly').carousel({
  interval: 500
})

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

We Architect,

Design and Develop

WebApplication

Body:
Move your jQuery script to top of all scrips, check the snippet

var $ = jQuery;
$('#carouselExampleSlidesOnly').carousel({
  interval: 2000
})

.carousel-inner {
  background-image: url("https://worldtransfer.online/wp-content/uploads/2016/09/worldmap-bg.jpg");
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  height: 250px
}

.carousel-caption {
  top: 1em;
}

.carousel {
  position: relative
}

.d_flex {
  position: absolute;
  z-index: 99;
  justify-content: center;
  top: 10%;
  text-align: center;
  align-items: center;
  width: 100%;
}

.carousel-text {
  position: absolute;
  z-index: 99;
  height:100%;
  top:100%
}

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
  <div class="d_flex d-flex">
    <h2 class="text-uppercase text-white">We Architect,</h2>
    <h3 class="text-white">Design and Develop</h3>
  </div>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <div class="carousel-caption" >
        <div class="carousel-text">
          <h1 class="text-uppercase">
            <span class="text-warning pr-3">Web</span>Application
          </h1>
        </div>
      </div>
    </div>
    <div class="carousel-item">
      <div class="carousel-caption">
        <div class="carousel-text">
          <h1 class="text-uppercase">
            <span class="text-warning pr-3">Mobile</span>Application
          </h1>
        </div>
      </div>
    </div>
    <div class="carousel-item">
      <div class="carousel-caption" >
        <div class="carousel-text">
          <h1 class="text-uppercase">
            <span class="text-warning pr-3">Desktop</span>Application
          </h1>
        </div>
      </div>
    </div>
  </div>

</div>


问:
Discordjs | DiscordAPIError: Cannot send messages to this user
I'm making a discord.js bot for a server. When i write !ayuda the bot won't send it at all and it will spit out an error

"UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send
  messages to this user"

Here is my code for the help command

```<code>    switch (args[0]) {
    case 'ayuda':
        const Embed = new RichEmbed()
        .setColor(0x06d6fe)
        .setFooter("© Capital Wolf", "https://i.imgur.com/0nn2u7q.gif" )
        .setTimestamp()
        .setImage("https://i.imgur.com/vU2PFJv.png")
        .setTitle("⚠ Has solicitado los comandos del Discord de **Capital Wolf** ⚠")
        .addField('!cache',
  "Muestra como borrar la cache de **Fivem**")
        .addField('!staff',
  "Muestra una lista de los miembros que pertenecen al **STAFF** de **Capital Wolf**")
        .addField('!invitacion',
  "Muestra una invitacion del servidor de Discord de **Capital Wolf**")
        .addField('!ip',
  "Muestra la ip del servidor de **Fivem** de **Capital Wolf**")
        message.member.send(Embed);
    break;
}
</code>```

答:
Member can not allowed to send DM message to him from this server members. You can handle it with add .catch() block to message.member.send().

```<code>    switch (args[0]) {
    case 'ayuda':
        const Embed = new RichEmbed()
        .setColor(0x06d6fe)
        .setFooter("© Capital Wolf", "https://i.imgur.com/0nn2u7q.gif" )
        .setTimestamp()
        .setImage("https://i.imgur.com/vU2PFJv.png")
        .setTitle("⚠ Has solicitado los comandos del Discord de **Capital Wolf** ⚠")
        .addField('!cache',
  "Muestra como borrar la cache de **Fivem**")
        .addField('!staff',
  "Muestra una lista de los miembros que pertenecen al **STAFF** de **Capital Wolf**")
        .addField('!invitacion',
  "Muestra una invitacion del servidor de Discord de **Capital Wolf**")
        .addField('!ip',
  "Muestra la ip del servidor de **Fivem** de **Capital Wolf**")
        message.member.send(Embed).catch(console.error)
    break;
}
</code>```

Body:
I'm making a discord.js bot for a server. When i write !ayuda the bot won't send it at all and it will spit out an error

"UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send
  messages to this user"

Here is my code for the help command

    switch (args[0]) {
    case 'ayuda':
        const Embed = new RichEmbed()
        .setColor(0x06d6fe)
        .setFooter("© Capital Wolf", "https://i.imgur.com/0nn2u7q.gif" )
        .setTimestamp()
        .setImage("https://i.imgur.com/vU2PFJv.png")
        .setTitle("⚠ Has solicitado los comandos del Discord de **Capital Wolf** ⚠")
        .addField('!cache',
  "Muestra como borrar la cache de **Fivem**")
        .addField('!staff',
  "Muestra una lista de los miembros que pertenecen al **STAFF** de **Capital Wolf**")
        .addField('!invitacion',
  "Muestra una invitacion del servidor de Discord de **Capital Wolf**")
        .addField('!ip',
  "Muestra la ip del servidor de **Fivem** de **Capital Wolf**")
        message.member.send(Embed);
    break;
}

Body:
Member can not allowed to send DM message to him from this server members. You can handle it with add .catch() block to message.member.send().

    switch (args[0]) {
    case 'ayuda':
        const Embed = new RichEmbed()
        .setColor(0x06d6fe)
        .setFooter("© Capital Wolf", "https://i.imgur.com/0nn2u7q.gif" )
        .setTimestamp()
        .setImage("https://i.imgur.com/vU2PFJv.png")
        .setTitle("⚠ Has solicitado los comandos del Discord de **Capital Wolf** ⚠")
        .addField('!cache',
  "Muestra como borrar la cache de **Fivem**")
        .addField('!staff',
  "Muestra una lista de los miembros que pertenecen al **STAFF** de **Capital Wolf**")
        .addField('!invitacion',
  "Muestra una invitacion del servidor de Discord de **Capital Wolf**")
        .addField('!ip',
  "Muestra la ip del servidor de **Fivem** de **Capital Wolf**")
        message.member.send(Embed).catch(console.error)
    break;
}


问:
notify user if he dont have flash player in android phone apps is build using phone gap
i have build my android apps using phone gap in this i wanted to add one more feature when my apps gets install it also check for flash player if flash player is not there ask to install through showing link how can i do this ??

i am new for phone gap

Please help me if possible share code with me

答:
User following code </p>

```<code>boolean flashInstalled = false;
try {
  PackageManager pm = getPackageManager();
  ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
  if (ai != null)
    flashInstalled = true;
} catch (NameNotFoundException e) {
  flashInstalled = false;
}
</code>```

Body:
User following code

boolean flashInstalled = false;
try {
  PackageManager pm = getPackageManager();
  ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
  if (ai != null)
    flashInstalled = true;
} catch (NameNotFoundException e) {
  flashInstalled = false;
}


问:
Calling Controller method from javascript using CodeIgniter
I am using CodeIgniter ..I can't access the method from the controller

I have this script in my view

```<code><script>
  function showHint(str){
    if (str.length==0){
        document.getElementById("txtHint").innerHTML="";
        return;
    }
    var xmlhttp=new XMLHttpRequest();
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
               document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
         }
    }
    xmlhttp.open("GET","ajax/ajaxSearch",true);
    xmlhttp.send();
  }
  </script>
</code>```

and i have a controller named ajax with a method ajaxSearch()

```<code>public function ajaxSearch(){
    echo "received";
}
</code>```

Folder Structure

```<code>htdocs/
     AjaxTry/
        AjaxSearchingMVC/
            application/
                controller/
                    ajax.php                //controller
                          ajaxSearch()      //method
                views/
                    view_ajax.php           // here is where the script is written
</code>```

What could be the possible problem here?

答:
Add the following function in the JS script

```<code>function FetchData() {
    var valueFromClient = document.getElementById("ReplaceWithID").value;

alert("Received from client:"+valueFromClient );

    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for modern browsers
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for old IE browsers
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            alert("Received from server:"+this.responseText);
        }
    };

    xmlhttp.open("POST", "http://localhost:52322/ControllerName/MethodName?CurrentC=" + valueFromClient , true);
    xmlhttp.send();
}
</code>```

Change the Port : 52322 according to your port number.

Its a localhost. So you may have to change it once your site goes online.

on the View. Add onChange(FetchData())

For Example:

```<code><select id="AnyIDHERE" onchange="updateProvince()"> </select>
</code>```

Body:
I am using CodeIgniter ..I can't access the method from the controller

I have this script in my view

and i have a controller named ajax with a method ajaxSearch()

public function ajaxSearch(){
    echo "received";
}

Folder Structure

htdocs/
     AjaxTry/
        AjaxSearchingMVC/
            application/
                controller/
                    ajax.php                //controller
                          ajaxSearch()      //method
                views/
                    view_ajax.php           // here is where the script is written

What could be the possible problem here?

Body:
Add the following function in the JS script

function FetchData() {
    var valueFromClient = document.getElementById("ReplaceWithID").value;

alert("Received from client:"+valueFromClient );

    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for modern browsers
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for old IE browsers
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            alert("Received from server:"+this.responseText);
        }
    };

    xmlhttp.open("POST", "http://localhost:52322/ControllerName/MethodName?CurrentC=" + valueFromClient , true);
    xmlhttp.send();
}

Change the Port : 52322 according to your port number.

Its a localhost. So you may have to change it once your site goes online.

on the View. Add onChange(FetchData())

For Example:

<select id="AnyIDHERE" onchange="updateProvince()"> </select>


问:
how to iterate over array[string] in spark scala?
enter image description herehere is my sample input:

```<code>val list=List("a;bc:de;f","uvw:xy;z","123:456")
</code>```

I am applying following operation

val upper=list.map(x=>x.split(":")).map(x=>x.split(";"))

but it is throwing error-
error: value split is not a member of Array[String]

can anyone help how to use both split so that i can get answer!

Thank you in advance.

答:
Here is the code i have tried and it worked:

```<code>val upper=list.map(x=>x.split(":")).map(x=>x.map(x=>x.split(";")))
</code>```

which gives the output:

```<code>upper: List[Array[Array[String]]] = List(Array(Array(a, bc), Array(de, f)), Array(Array(uvw), Array(xy, z)), Array(Array(123), Array(456)))
</code>```

Body:
enter image description herehere is my sample input:

val list=List("a;bc:de;f","uvw:xy;z","123:456")

I am applying following operation

val upper=list.map(x=>x.split(":")).map(x=>x.split(";"))

but it is throwing error-
error: value split is not a member of Array[String]

can anyone help how to use both split so that i can get answer!

Thank you in advance.

Body:
Here is the code i have tried and it worked:

val upper=list.map(x=>x.split(":")).map(x=>x.map(x=>x.split(";")))

which gives the output:

upper: List[Array[Array[String]]] = List(Array(Array(a, bc), Array(de, f)), Array(Array(uvw), Array(xy, z)), Array(Array(123), Array(456)))


问:
Fetch all the posts of all the users from Cloud Firestore
I am building a Flutter app. Cloud firestore database structure is given in the picture. I want to get all the posts of all the users using a StreamBuilder. How can I do that? So far I have tried this :

```<code>Stream<List<PostModel>> jobs() {
    return usersCollection.snapshots().map((snapshot) {
      return snapshot.documents.map((doc) {
        doc['posts'].map((docu) {
          return PostModel.fromSnapshot(docu);
        });
      }).toList();
    });
  }
</code>```

答:
If you want all the document in all of the subcollections called "posts" (for all users), then you probably want a collection group query using collectionGroup():

```<code>db.collectionGroup("posts").snapshots()...
</code>```

This will give you all documents in any collection or subcollection called "posts", no matter where it's nested.

Body:
I am building a Flutter app. Cloud firestore database structure is given in the picture. I want to get all the posts of all the users using a StreamBuilder. How can I do that? So far I have tried this :

Stream<List<PostModel>> jobs() {
    return usersCollection.snapshots().map((snapshot) {
      return snapshot.documents.map((doc) {
        doc['posts'].map((docu) {
          return PostModel.fromSnapshot(docu);
        });
      }).toList();
    });
  }

Body:
If you want all the document in all of the subcollections called "posts" (for all users), then you probably want a collection group query using collectionGroup():

db.collectionGroup("posts").snapshots()...

This will give you all documents in any collection or subcollection called "posts", no matter where it's nested.


问:
copy files from one AWS s3 bucket/folder to another AWS/S3 folder and also keep the deepest sub-folder name by pythons on databricks
My question is relevant to the previous one copy files from one AWS/S3 bucket to another bucket on databricks.
I created a new thread because this question is different from the previous one.

This post AWS S3 copy files and folders between two buckets does not help me.

I need to copy some files from one AWS/S3 bucket/folder to another AWS/S3 bucket folder by python on databricks.

My source S3 bucket/folder is like :

```<code>   source_s3_bucket
      folder_name1
        folder_name2
           folder_name3
             folder_name4
                 deepest_folder_name
                      file1
                      file2
                       ....
                      file11500
</code>```

The destination s3 bucket/folder:

```<code>   destination_s3_bucket
      dest_folder_name1
        dest_folder_name2
           dest_folder_name3
             deepest_folder_name (this folder name must be exactly same as the source one "deepest_folder_name")
                      file1
                      file2
                       ....
                      file11500
</code>```

Also, the "dest_folder_nameX" are all different from the sources ones and also the depth of the source and destination folders are also different. But, the deepest folder name in source bucket must be kept in destination bucket.

All files must be exactly copied and keep the same names.

I have tried to do the python3 coding:

```<code>import boto3
s3 = boto3.client('s3')
s3_resource = boto3.resource('s3')
for key in s3.list_objects(Bucket=source_bucket, Prefix=source_prefix)['Contents']:
    files = key['Key']
    copy_source = {'Bucket': source_bucket,'Key': files}
    s3_resource.meta.client.copy(CopySource=copy_source, Bucket=dest_bucket, Key=dest_prefix)
</code>```

But, no files are copied to the destination folder and also how I can keep the "deepest_folder_name" ?

UPDATE
"The deepest folder" means that I have to keep that layer's sub-folders' names and copy them and the files located in them to the destination.

for example,
      in source bucket:

```<code>  folder_name_abc
     folder_name_dfr
        folder_name_typ # this folder names must be kept
            file1
            file2

  In destination bucket:
       folder_name_typ # this folder names must be exactly same as the source
           file1
           file2
</code>```

thanks

答:
The tricky part is manipulating the 'path' portion of the object Keys.

You could use something like this:

import boto3

s3_client = boto3.client('s3')

SOURCE_BUCKET = 'bucket1'
SOURCE_PREFIX = 'folder_name_abc/folder_name_dfr/' # Where is Folder located? (Leave blank if root level, include slash at end if Prefix specified)
FOLDER_TO_COPY = 'folder_name_typ'

DESTINATION_BUCKET = 'bucket2'
DESTINATION_PREFIX = '' # (Leave blank if root level, include slash at end if Prefix specified)

# List objects in source directory
bucket_listing = s3_client.list_objects_v2(Bucket=SOURCE_BUCKET,Prefix=f'{SOURCE_PREFIX}{FOLDER_TO_COPY}/')

for object in bucket_listing['Contents']:
    print(f'Copying from {object['Key']} to {DESTINATION_PREFIX + object['Key'][len(SOURCE_PREFIX):]}')
    s3_client.copy_object(
        CopySource = {'Bucket': SOURCE_BUCKET, 'Key': object['Key']},
        Bucket = DESTINATION_BUCKET,
        Key = DESTINATION_PREFIX + object['Key'][len(SOURCE_PREFIX):] # Remove source prefix, add destination prefix
        )
```

Body:
My question is relevant to the previous one copy files from one AWS/S3 bucket to another bucket on databricks.
I created a new thread because this question is different from the previous one.

This post AWS S3 copy files and folders between two buckets does not help me.

I need to copy some files from one AWS/S3 bucket/folder to another AWS/S3 bucket folder by python on databricks.

My source S3 bucket/folder is like :

   source_s3_bucket
      folder_name1
        folder_name2
           folder_name3
             folder_name4
                 deepest_folder_name
                      file1
                      file2
                       ....
                      file11500

The destination s3 bucket/folder:

   destination_s3_bucket
      dest_folder_name1
        dest_folder_name2
           dest_folder_name3
             deepest_folder_name (this folder name must be exactly same as the source one "deepest_folder_name")
                      file1
                      file2
                       ....
                      file11500

Also, the "dest_folder_nameX" are all different from the sources ones and also the depth of the source and destination folders are also different. But, the deepest folder name in source bucket must be kept in destination bucket.

All files must be exactly copied and keep the same names.

I have tried to do the python3 coding:

import boto3
s3 = boto3.client('s3')
s3_resource = boto3.resource('s3')
for key in s3.list_objects(Bucket=source_bucket, Prefix=source_prefix)['Contents']:
    files = key['Key']
    copy_source = {'Bucket': source_bucket,'Key': files}
    s3_resource.meta.client.copy(CopySource=copy_source, Bucket=dest_bucket, Key=dest_prefix)

But, no files are copied to the destination folder and also how I can keep the "deepest_folder_name" ?

UPDATE
"The deepest folder" means that I have to keep that layer's sub-folders' names and copy them and the files located in them to the destination.

for example,
      in source bucket:

  folder_name_abc
     folder_name_dfr
        folder_name_typ # this folder names must be kept
            file1
            file2

  In destination bucket:
       folder_name_typ # this folder names must be exactly same as the source
           file1
           file2

thanks


问:
Handling multiple error types via either/disjunction Scala
I have 3 distinct modules each with its own error type. Following is a very simplified version.

```<code>object ModuleA {
  case class ErrorA(msg: String)
  def getA: ErrorA \/ String = "1".right
}

object ModuleB {
  case class ErrorB(msg: String)
  def getB(s: String): ErrorB \/ Int = 1.right
}

object ModuleC {
  case class ErrorC(msg: String)
  def getC(s: String, i: Int): ErrorC \/ Long = 1L.right
}
</code>```

As a client of these modules what's the best way to chain these calls.

First - deeply nested, complex return type, but has all the types required.

```<code>def call1: ModuleA.ErrorA \/ (ModuleB.ErrorB \/ (ModuleC.ErrorC \/ Long)) = {
  ModuleA.getA.map { s =>
    ModuleB.getB(s).map { i =>
      ModuleC.getC(s, i)
    }
  }
}
</code>```

Second - Very readable, but the error types are lost (Inferred return type is Product \/ Long). Ideally would want something similar with the error types

```<code>def call2  =
  for {
    s  <- ModuleA.getA
    i  <- ModuleB.getB(s)
    l  <- ModuleC.getC(s, i)
  } yield l
</code>```

Third - Define new error types to encapsulate the existing ones. This seems unfeasible for different combinations

Lastly, tried to use EitherT, but seemed to get complex

答:
Consider creating an algebraic data type out of the errors, for example

```<code>sealed abstract class Error(val message: String)
case class ErrorA(msg: String) extends Error(msg)
case class ErrorB(msg: String) extends Error(msg)
case class ErrorC(msg: String) extends Error(msg)
</code>```

and then change the left side of returned \/ to Error

```<code>import scalaz.\/
import scalaz.syntax.either._

object ModuleA {
  def getA: Error \/ String = "1".right
}

object ModuleB {
  def getB(s: String): Error \/ Int = ErrorB("boom").left
}

object ModuleC {
  def getC(s: String, i: Int): Error \/ Long = 1L.right
}

for {
  s  <- ModuleA.getA
  i  <- ModuleB.getB(s)
  l  <- ModuleC.getC(s, i)
} yield l
</code>```

which gives

```<code>res0: Error \/ Long = -\/(ErrorB(boom))
</code>```

If you cannot create ADT, consider leftMap to change the error type to a common type like so

```<code>case class ErrorWrapper(m: String)

for {
  s  <- ModuleA.getA.leftMap { e: ModuleA.ErrorA => ErrorWrapper(e.msg) }
  i  <- ModuleB.getB(s).leftMap { e: ModuleB.ErrorB => ErrorWrapper(e.msg) }
  l  <- ModuleC.getC(s, i).leftMap { e: ModuleC.ErrorC => ErrorWrapper(e.msg) }
} yield l
// res0: ErrorWrapper \/ Long = -\/(ErrorWrapper(boom))
</code>```

or maybe even, unusually, via structural typing

```<code>implicit class CommonErrorWrapper[A <: Product { def msg: String }](e: A) {
  def toErrorWrapper: ErrorWrapper = ErrorWrapper(e.msg)
}

for {
  s  <- ModuleA.getA.leftMap(_.toErrorWrapper)
  i  <- ModuleB.getB(s).leftMap(_.toErrorWrapper)
  l  <- ModuleC.getC(s, i).leftMap(_.toErrorWrapper)
} yield l
// res1: ErrorWrapper \/ Long = -\/(ErrorWrapper(boom))
</code>```

leftMap is useful not only for changing the error type, but also we can enrich the error by adding locally available contextual information.

Note EitherT monad transformer may be used when the shape of type is F[A \/ B], for example, Future[Error \/ B], however in your case it is just A \/ B, hence EitherT is might not be the right tool. Related question EitherT with multiple return types

Body:
I have 3 distinct modules each with its own error type. Following is a very simplified version.

object ModuleA {
  case class ErrorA(msg: String)
  def getA: ErrorA \/ String = "1".right
}

object ModuleB {
  case class ErrorB(msg: String)
  def getB(s: String): ErrorB \/ Int = 1.right
}

object ModuleC {
  case class ErrorC(msg: String)
  def getC(s: String, i: Int): ErrorC \/ Long = 1L.right
}

As a client of these modules what's the best way to chain these calls.

First - deeply nested, complex return type, but has all the types required.

def call1: ModuleA.ErrorA \/ (ModuleB.ErrorB \/ (ModuleC.ErrorC \/ Long)) = {
  ModuleA.getA.map { s =>
    ModuleB.getB(s).map { i =>
      ModuleC.getC(s, i)
    }
  }
}

Second - Very readable, but the error types are lost (Inferred return type is Product \/ Long). Ideally would want something similar with the error types

def call2  =
  for {
    s  <- ModuleA.getA
    i  <- ModuleB.getB(s)
    l  <- ModuleC.getC(s, i)
  } yield l

Third - Define new error types to encapsulate the existing ones. This seems unfeasible for different combinations

Lastly, tried to use EitherT, but seemed to get complex

Body:
Consider creating an algebraic data type out of the errors, for example

sealed abstract class Error(val message: String)
case class ErrorA(msg: String) extends Error(msg)
case class ErrorB(msg: String) extends Error(msg)
case class ErrorC(msg: String) extends Error(msg)

and then change the left side of returned \/ to Error

import scalaz.\/
import scalaz.syntax.either._

object ModuleA {
  def getA: Error \/ String = "1".right
}

object ModuleB {
  def getB(s: String): Error \/ Int = ErrorB("boom").left
}

object ModuleC {
  def getC(s: String, i: Int): Error \/ Long = 1L.right
}

for {
  s  <- ModuleA.getA
  i  <- ModuleB.getB(s)
  l  <- ModuleC.getC(s, i)
} yield l

which gives

res0: Error \/ Long = -\/(ErrorB(boom))

If you cannot create ADT, consider leftMap to change the error type to a common type like so

case class ErrorWrapper(m: String)

for {
  s  <- ModuleA.getA.leftMap { e: ModuleA.ErrorA => ErrorWrapper(e.msg) }
  i  <- ModuleB.getB(s).leftMap { e: ModuleB.ErrorB => ErrorWrapper(e.msg) }
  l  <- ModuleC.getC(s, i).leftMap { e: ModuleC.ErrorC => ErrorWrapper(e.msg) }
} yield l
// res0: ErrorWrapper \/ Long = -\/(ErrorWrapper(boom))

or maybe even, unusually, via structural typing

implicit class CommonErrorWrapper[A <: Product { def msg: String }](e: A) {
  def toErrorWrapper: ErrorWrapper = ErrorWrapper(e.msg)
}

for {
  s  <- ModuleA.getA.leftMap(_.toErrorWrapper)
  i  <- ModuleB.getB(s).leftMap(_.toErrorWrapper)
  l  <- ModuleC.getC(s, i).leftMap(_.toErrorWrapper)
} yield l
// res1: ErrorWrapper \/ Long = -\/(ErrorWrapper(boom))

leftMap is useful not only for changing the error type, but also we can enrich the error by adding locally available contextual information.

Note EitherT monad transformer may be used when the shape of type is F[A \/ B], for example, Future[Error \/ B], however in your case it is just A \/ B, hence EitherT is might not be the right tool. Related question EitherT with multiple return types


问:
Artist profile information not getting from spotify api
Artist profile information not getting from api.

Im calling this URL

```<code>url=https://api.spotify.com/v1/artists/****7vxl9s3awf7hz4rr
</code>```

Endpoint(s):
GET /v1/artists/{id}

Scope(s):

Not required as per the dev doc.

Steps to reproduce:

Authenticate user - get Oauth Token

Call GET /v1/me - get user info (id,display_name etc)

CAll GET /v1/artists/{id} - Get the artist information.

Expected behaviour:
Artist object as described on;
https://developer.spotify.com/console/get-artist/?id= {id}.

Actual behaviour:

```<code>Response{protocol=h2, code=400, message=, url=https://api.spotify.com/v1/artists/****7vxl9s3awf7hz4rr*****}
</code>```

Response Body

```<code>{"error":{"status":400,"message":"invalid id"}}
</code>```

Questions - How to get artist information from spotify API?

答:
I think you should do like this.

Step 1: Get the Display name from spotify using spotify SDK or GET ME API.

GET https://api.spotify.com/v1/me

Step 2: Using that Display name search for the artist in Artist API.

GET https://api.spotify.com/v1/search

You will get the result of that artist.

Step 3: Compare the result what you get with the display name.(Because thier might be other artist also with matching one word of that user's display name).
You need to compare it in your code.

Step 4: When you get the result, it will give type as artist and also the artist Id.

Now you know that when a user login in your application, weather he has artist account or not.

Body:
Artist profile information not getting from api.

Im calling this URL

url=https://api.spotify.com/v1/artists/****7vxl9s3awf7hz4rr

Endpoint(s):
GET /v1/artists/{id}

Scope(s):

Not required as per the dev doc.

Steps to reproduce:

Authenticate user - get Oauth Token

Call GET /v1/me - get user info (id,display_name etc)

CAll GET /v1/artists/{id} - Get the artist information.

Expected behaviour:
Artist object as described on;
https://developer.spotify.com/console/get-artist/?id= {id}.

Actual behaviour:

Response{protocol=h2, code=400, message=, url=https://api.spotify.com/v1/artists/****7vxl9s3awf7hz4rr*****}

Response Body

{"error":{"status":400,"message":"invalid id"}}

Questions - How to get artist information from spotify API?