Magento 2 – Area code not set when running script via command line CLI

I have created module for exporting my product data to script outside of Magento2.

This is my Data.php

<?php namespace Oktarin\Nabavanet\Helper;  class Data extends \Magento\Framework\App\Helper\AbstractHelper {    protected $  markup=1.03;   protected $  markup_extra=1.02;   protected $  price_limit=1500.00;   protected $  pricefile;   protected $  prices;   protected $  pdv=0.25;   protected $  base_url="https://domain.com/index.php/catalog/product/view/id/";   protected $  base_image_url="https://domain.com/pub/media/catalog/product";   protected $  shipping_cost=35.00;   protected $  cats;   protected $  appState; /*   public function __construct(\Magento\Framework\App\Helper\Context $  context,\Magento\Framework\App\State $  state) {     $  this->appState = $  state;      parent::__construct($  context);   }      public function execute() {     $  originalArea = $  this->state->getAreaCode();     $  this->appState->setAreaCode('frontend');     //reset original code     $  this->appState->setAreaCode($  originalArea);   } */    public function getProductCollection()     {         $  collection = $  this->_productCollectionFactory->create();         return $  collection;     } // end of function getProductCollection     public function makeXml(){ /* */   //  $  originalArea = $  this->state->getAreaCode();       $  objectManager = \Magento\Framework\App\ObjectManager::getInstance();     $  this->appState= $  objectManager->create('Magento\Framework\App\State');     $  this->appState->setAreaCode('frontend');     $  productCollection = $  objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');     $  collection = $  productCollection->create()                 ->addAttributeToSelect('*')                // ->addAttributeToFilter('sku', array('like' => '%702638%'))                 ->load();  $  product=array();     foreach ($  collection as $  product_data){       if(!empty($  product_data->getEntity_id())){           //Load the product categories         $  categories1 = $  product_data->getCategoryIds();         //Select the last category in the list         $  categoryId = end($  categories1);         $  categoryObject=\Magento\Framework\App\ObjectManager::getInstance();         $  category=$  categoryObject->create('Oktarin\Nabavanet\Helper\CategoryTree');         $  categoryTreepath=$  category->getTreeByCategoryId($  categoryId);          if(!empty($  product_data->getspecial_price())){             $  price=$  product_data->getspecial_price();             $  regular_price=$  product_data->getprice();          }         else{           $  price=$  product_data->getprice();           $  regular_price=false;         }          // Dostupnost proizvoda           switch($  product_data->getproduct_availability()){               case "3929":                 // Po narudžbi                 $  availability="Po narudžbi";                 break;               case "3930":                 // Na stanju                 $  availability="Raspoloživo";                 break;               case "3931":                 // Zalihe pri kraju                 $  availability="Raspoloživost potrebno provjeriti";                 break;                   }            $  product[]=array(             "internal_product_id" => $  product_data->getEntity_id(),             "sku" => $  product_data->getsku(),             "ean" => $  product_data->getean(),             "name" => $  product_data->getName(),             "url" => $  this->base_url.$  product_data->getEntity_id()."/s/".$  product_data->geturl_key()."/",             "availability" => $  availability,             "category" => $  categoryTreepath,             "image_url" => $  this->base_image_url.$  product_data->getimage(),             "additional_image_url" => $  this->base_image_url.$  product_data->getsmall_image(),             "description" => $  product_data->getshort_description(),             "shipping_cost" => $  this->shipping_cost,             "regular_price" => $  regular_price,             "brand" => $  product_data->getbrand(),             "part_number" => $  product_data->getpart_number(),             "warranty" => $  product_data->getgarancija_proizvoda(),             "price" => $  price,             "specialPrice" => $  product_data->getspecial_price(),             "tehnickaSpecifikacija" => $  product_data->getdescription()           );         } // end of of entity_id isnt empty       } // end of foreach          //reset original code     $  this->appState->setAreaCode($  originalArea);         return $  product;   } // end of function makeXml  } // end class 

Method makeXml() I am calling from another script in file nabavanet-export.php that is designed to be run from cron/CLI/command line:

#!/usr/bin/php <?php (PHP_SAPI !== 'cli' || isset($  _SERVER['HTTP_USER_AGENT'])) && die('cli only'); require_once __DIR__ . "/include.php";  $  nabavanet=new Xml();    /* MAGENTO start */   // calling on Magento Helpers   use Magento\Framework\App\Bootstrap;   require '../app/bootstrap.php';   $  params = $  _SERVER;   $  bootstrap = Bootstrap::create(BP, $  params);   $  obj = $  bootstrap->getObjectManager();   $  nabava = $  obj->get('\Oktarin\Nabavanet\Helper\Data');   // end of Magento Helpers   /* END Magento */  try{   $  filename="nabavaexport";   $  xml=$  nabavanet->createNabavanetXMLfile($  nabava->createXml(),$  filename); if($  xml==1){     echo "XML ".$  filename.".xml generated!\n";   copy($  filename.".xml", "../nabavanet/".$  filename.".xml"); } else{     echo "XML ".$  filename.".xml not generated\n"; }   } catch (PDOException $  e) {     // detaljan ispis grešaka slanjem     // PDOException objekta preko varijable $  e     // PDO objekta preko varijable $  db     // PDOStatement objekta preko varijable $  stmt     showPDOErrors($  e, $  db_read, $  stmt_read);     showPDOErrors($  e, $  db_write, $  stmt_write); }             ?> 

Script nabavanet-export.php was working fine when run through browser, however when I run it through command line I get this:

Fatal error: Uncaught Magento\Framework\Exception\LocalizedException: Area code is not set in /usr/www/users/shopyb/vendor/magento/framework/App/State.php:152 Stack trace: #0 /usr/www/users/shopyb/vendor/magento/framework/Session/SessionManager.php(173): Magento\Framework\App\State->getAreaCode() #1 /usr/www/users/shopyb/generated/code/Magento/Framework/Session/Generic/Interceptor.php(50): Magento\Framework\Session\SessionManager->start() #2 /usr/www/users/shopyb/vendor/magento/framework/Session/SessionManager.php(130): Magento\Framework\Session\Generic\Interceptor->start() #3 /usr/www/users/shopyb/generated/code/Magento/Framework/Session/Generic/Interceptor.php(14): Magento\Framework\Session\SessionManager->__construct(Object(Magento\Framework\App\Request\Http), Object(Magento\Framework\Session\SidResolver\Proxy), Object(Magento\Framework\Session\Config), Object(Magento\Framework\Session\SaveHandler), Object(Magento\Framework\Session\Validator), Object(Magento\Framework\Session\Storage), Object(Magento\Framework\Stdlib\C in /usr/www/users/shopyb/vendor/magento/framework/Session/SessionManager.php on line 175 

As you can see I have tried implementing fix as said many times:

  public function __construct(\Magento\Framework\App\State $  state, $  name=null) {     $  this->appState = $  state;      parent::__construct($  name);   } 

But this also generated error

So I have tried modifing it like this but without success:

  public function __construct(\Magento\Framework\App\Helper\Context $  context,\Magento\Framework\App\State $  state) {     $  this->appState = $  state;      parent::__construct($  context);   } 

I hope someone can give me pointers how to make file nabavanet-export.php run as command line. I need that outside script because it is depending on other methods required for generating xml.

Run a code only on theme activation only during first activation

function clearwidgets(){   //stuff here only runs once, when the theme is activated for the 1st time }  register_activation_hook(__FILE__, 'clearwidgets'); 

And the code I am trying to execute is this:

    add_filter( 'sidebars_widgets', 'unset_sidebar_widget' );  function unset_sidebar_widget( $  sidebars_widgets ) { unset( $  sidebars_widgets[ '$  sidebar_id' ] ); return $  sidebars_widgets; } 

That means when the first time the theme is installed it should clear away all the default widget set by WordPress.

Where am I going wrong because the desired result is not achieved? Please suggest me the fix or direct me in the direction so that I can troubleshoot.

Python pong with parabolas code glitching [on hold]

I’m making 2 player pong on python using the turtle module and I added parabolas when you hit the ball with the paddles moving, but in specific circumstances, when I curve the ball with the right paddle, and I don’t move the left paddle, it goes right through it. I’ve tried everything. Here is my code:

def jeu2joueurs():  import turtle  import time  sc = turtle.Screen() sc.bgcolor("black") sc.reset() sc.screensize(1000,560) sc.tracer(0)  # Creation des mannettes  mannette1 = turtle.Turtle() mannette1.pu() mannette1.shape("square") mannette1.shapesize(10,1) mannette1.color("white") mannette1.setx(940)  mannette2 = turtle.Turtle() mannette2.pu() mannette2.shape("square") mannette2.shapesize(10,1) mannette2.color("white") mannette2.setx(-947)  # Creation de la balle  balle = turtle.Turtle() balle.pu() balle.shape("circle") balle.color("white")  # Fonctions et definitions  def up1():     mannette1.sety(mannette1.ycor()+150)  def down1():     mannette1.sety(mannette1.ycor()-150)  def up2():     mannette2.sety(mannette2.ycor()+150)  def down2():     mannette2.sety(mannette2.ycor()-150)  movx = 2 movy = 0  pointman1 = 0 pointman2 = 0 score = 0  time.sleep(3)  # Jeu  while True:     a = mannette1.ycor()     s = mannette2.ycor()      sc.update()     sc.listen()     sc.onkeypress(up1, "Up")     sc.onkeypress(down1, "Down")     sc.onkeypress(up2, "w")     sc.onkeypress(down2, "s")      # Mouvement de la balle      yvel = balle.ycor()+movy     xvel = balle.xcor()+movx     balle.sety(yvel)     balle.setx(xvel)      # Rebondissement de la balle: Plafond et Plancher      if balle.ycor() > 495:         balle.sety(495)         movy = movy*-1      if balle.ycor() < -490:         balle.sety(-490)         movy = movy*-1      # Rebondissement de la balle: Ouest et Est      if balle.xcor() > 999:         balle.setpos(0,0)         mannette1.sety(0)         mannette2.sety(0)         time.sleep(0.5)         movx = 2         movy = 0          pointman2 += 1          if pointman2 == 1 and pointman1 == 1:             score = sc.textinput("Pointage", str(pointman2) +" point, vs "+str(pointman1)+" point")          elif pointman2 != 1 and pointman1 == 1:             score = sc.textinput("Pointage", str(pointman2) +" points, vs "+str(pointman1)+" point")          elif pointman2 == 1 and pointman1 != 1:             score = sc.textinput("Pointage", str(pointman2) +" point, vs "+str(pointman1)+" points")          elif pointman2 != 1 and pointman1 != 1:             score = sc.textinput("Pointage", str(pointman2) +" points, vs "+str(pointman1)+" points")      if balle.xcor() < -999:         balle.setpos(0,0)         mannette1.sety(0)         mannette2.sety(0)         time.sleep(0.5)         movx = -2         movy = 0          pointman1 += 1          if pointman2 == 1 and pointman1 == 1:             score = sc.textinput("Pointage", str(pointman2) +" point, vs "+str(pointman1)+" point")          elif pointman2 != 1 and pointman1 == 1:             score = sc.textinput("Pointage", str(pointman2) +" points, vs "+str(pointman1)+" point")          elif pointman2 == 1 and pointman1 != 1:             score = sc.textinput("Pointage", str(pointman2) +" point, vs "+str(pointman1)+" points")          elif pointman2 != 1 and pointman1 != 1:             score = sc.textinput("Pointage", str(pointman2) +" points, vs "+str(pointman1)+" points")      # Mannette out of bounds verification      if mannette1.xcor() != 940:         mannette1.setx(940)     if mannette2.xcor() != -947:         mannette2.setx(-947)      # Courbure de la balle: MANNETTE VELOCITY CHECK: Mannette1      b = mannette1.ycor()     distance_man1 = a-b     if distance_man1 != 0:         distance_man1 = -distance_man1         mannette1_velocity = float(distance_man1)/20     else:         mannette1_velocity = 0      # Courbure de la balle: Mannette1      if mannette1_velocity != 0:         if balle.xcor() > 930 and balle.xcor() < 935 and balle.ycor() < mannette1.ycor()+110 and balle.ycor() > mannette1.ycor()-110:             balle.setx(930)             movx = movx * -1              # Pour que la balle va dans la direction du "velocity" de la mannette.              if mannette1_velocity < 0:                 movy = -1             if mannette1_velocity > 0:                 movy = 1              while not (balle.xcor() < -927 and balle.xcor() > -935 and balle.ycor() < mannette2.ycor()+110 and balle.ycor() > mannette2.ycor()-110):                 time.sleep(0.00000005)                 sc.update()                  # Mouvement de la balle                  movy = movy-mannette1_velocity/100                  yvel = balle.ycor()+movy                 xvel = balle.xcor()+movx                 balle.sety(yvel)                 balle.setx(xvel)                  # Rebondissement de la balle: Plafond et Plancher                  if balle.ycor() > 495:                     balle.sety(495)                     movy = movy*-1                  if balle.ycor() < -490:                     balle.sety(-490)                     movy = movy*-1                  # Pour que les mannettes restes dans leurs axe                    if mannette1.xcor() != 940:                     mannette1.setx(940)                 if mannette2.xcor() != -947:                     mannette2.setx(-947)                  # Mannette out of bounds check                  if mannette1.ycor() > 405:                     mannette1.sety(404)                  if mannette1.ycor() < -395:                     mannette1.sety(-394)                  if mannette2.ycor() > 405:                     mannette2.sety(404)                  if mannette2.ycor() < -395:                     mannette2.sety(-394)                  # Rebondissement de la balle: Ouest et Est                  if balle.xcor() > 999 or balle.xcor() < -999:                     mannette1.sety(0)                     mannette2.sety(0)                     break      # Courbure de la balle: MANNETTE VELOCITY CHECK: Mannette2      t = mannette2.ycor()     distance_man2 = s-t     if distance_man2 != 0:         distance_man2 = -distance_man2         mannette2_velocity = float(distance_man2)/20     else:         mannette2_velocity = 0      # Courbure de la balle: Mannette2      if mannette2_velocity != 0:         if balle.xcor() < -927 and balle.xcor() > -935 and balle.ycor() < mannette2.ycor()+110 and balle.ycor() > mannette2.ycor()-110:             balle.setx(-927)             movx=movx*-1              # Pour que la balle va dans la direction du "velocity" de la mannette.              if mannette2_velocity < 0:                 movy = -1             if mannette2_velocity > 0:                 movy = 1              while not (balle.xcor() > 925 and balle.xcor() < 930 and balle.ycor() < mannette1.ycor()+110 and balle.ycor() > mannette1.ycor()-110):                 time.sleep(0.00000005)                 sc.update()                  # Mouvement de la balle                  movy = movy-mannette2_velocity/100                  yvel = balle.ycor()+movy                 xvel = balle.xcor()+movx                 balle.sety(yvel)                 balle.setx(xvel)                  # Rebondissement de la balle: Plafond et Plancher                  if balle.ycor() > 495:                     balle.sety(495)                     movy = movy*-1                  if balle.ycor() < -490:                     balle.sety(-490)                     movy = movy*-1                  # Pour que les mannettes restes dans leurs axe                    if mannette1.xcor() != 940:                     mannette1.setx(940)                 if mannette2.xcor() != -947:                     mannette2.setx(-947)                  # Mannette out of bounds check                  if mannette1.ycor() > 405:                     mannette1.sety(404)                  if mannette1.ycor() < -395:                     mannette1.sety(-394)                  if mannette2.ycor() > 405:                     mannette2.sety(404)                  if mannette2.ycor() < -395:                     mannette2.sety(-394)                  # Rebondissement de la balle: Ouest et Est                  if balle.xcor() > 999 or balle.xcor() < -999:                     mannette1.sety(0)                     mannette2.sety(0)                     break      # Rebondissement de la balle: Mannette1      elif balle.xcor() > 930 and balle.xcor() < 935 and balle.ycor() < mannette1.ycor()+110 and balle.ycor() > mannette1.ycor()-110:         balle.setx(930)         movx = movx*-1      # Rebondissement de la balle: Mannette2      elif balle.xcor() < -927 and balle.xcor() > -935 and balle.ycor() < mannette2.ycor()+110 and balle.ycor() > mannette2.ycor()-110:         balle.setx(-927)         movx = movx*-1      # Mannette out of bounds check      if mannette1.ycor() > 405:         mannette1.sety(404)      if mannette1.ycor() < -395:         mannette1.sety(-394)      if mannette2.ycor() > 405:         mannette2.sety(404)      if mannette2.ycor() < -395:         mannette2.sety(-394)      # Mannette avec souris      mannette1.ondrag(mannette1.goto)     mannette2.ondrag(mannette2.goto)  jeu2joueurs()  ```  

magento 2.3.0 shipping method based coupon code not working in cart page

We have a special coupon code , it should work only for “Fedex Ground Shipping method”. This shopping cart price rule is worked in checkout page but it is not worked for cart page.

In cart page : We fill data in Estimate Shipping Tax details (country, postal code) then selecting the shipping method (Fedex Ground) and then submitting the coupon button. It gives error message like ‘The coupon code “xxxxx” is not valid and also selected shipping method , postal code detail are magento 2.3vanished.

Why this happening? how can resolve this issue? please give your valid reply… ‘

A 10 lines code change takes several days, how to improve efficiency?

A new comer to a project was assigned with a simple code change, and pointed out where the code should be changed. I expect the code change shall be finished within half day.

Yet it took several days to finish, and brought in production. That’s below expectation.

Are there any ways to improve efficiency at this scenario? 10 lines of code change took several days for a new comer is too much.

I wrote some code in JQuery while using formidable forms and WordPress

This code is for calculation of price, which isn’t possible through the form itself. This also gives some conditionality. Now, this code was working fine, when I was defining this code within the trigger functions. This isn’t working now that I have made separate user defined functions and I am trying to call them on various triggers.

I’ll be much obliged if someone can help me understand the problem with this code! As you all can see, I’m not really a programmer…

jQuery(function($ ) {

function cakecostcalc (){     var price;     var quant = $  ('#field_b4xx2').val();     var kindofcake = $  ( "input[name='item_meta[302]']").filter(":checked").val() || 0;     var caketopper = $  ( "input[name='item_meta[325]']").filter(":checked").val() || 0;     var tiers2 = $  ( "input[name='item_meta[308]']").filter(":checked").val() || 0;     var tiers3 = $  ( "input[name='item_meta[309]']").filter(":checked").val() || 0;     var tiers4 = $  ( "input[name='item_meta[310]']").filter(":checked").val() || 0;     if (Number.isInteger(+quant))     {          if(kindofcake == 1100)         {             price = (Math.floor(quant)*1900)+Math.floor(caketopper)+Math.floor(tiers2)+Math.floor(tiers3)+Math.floor(tiers4);             $  ('#field_serv3').val(price);         }          else         {             price = (Math.floor(quant)*1700)+Math.floor(caketopper)+Math.floor(tiers2)+Math.floor(tiers3)+Math.floor(tiers4);             $  ('#field_serv3').val(price);         }     }     else     {         if(kindofcake == 1100)         {             price = (Math.floor(quant)*1900)+1100+Math.floor(caketopper)+Math.floor(tiers2)+Math.floor(tiers3)+Math.floor(tiers4);             $  ('#field_serv3').val(price);         }          else         {             price = (Math.floor(quant)*1700)+1000+Math.floor(caketopper)+Math.floor(tiers2)+Math.floor(tiers3)+Math.floor(tiers4);             $  ('#field_serv3').val(price);         }        } }  function tierselector(){      var quant = $  ('#field_b4xx2').val();      do {          $  ('#frm_field_310_container').removeClass('no-display');              if (quant >= 2.5 && quant < 6) {break};             {                 $  ('#frm_radio_310-0').css('display','block');                 $  ('#frm_radio_310-1').css('display','block');                 $  ('#frm_radio_310-2').css('display','none');                 $  ('#frm_radio_310-3').css('display','none');             }             if (quant >= 6 && quant < 12) {break};             {                 $  ('#frm_radio_310-0').css('display','block');                 $  ('#frm_radio_310-1').css('display','block');                 $  ('#frm_radio_310-2').css('display','block');                 $  ('#frm_radio_310-3').css('display','none');             }             if (quant >= 12) {break};             {                 $  ('#frm_radio_310-0').css('display','block');                 $  ('#frm_radio_310-1').css('display','block');                 $  ('#frm_radio_310-2').css('display','block');                 $  ('#frm_radio_310-3').css('display','block');             }          break;      } while(Math.floor(quant) > 2);  }  function togglesinglemultiflavour(){     var tiernos = $  ("input[name='item_meta[310]']").filter(":checked").val() || 0;      if (Math.floor(tiernos) == 0)     {         $  ('#frm_field_311_container').removeClass('no-display');         $  ('#frm_field_335_container').addClass('no-display');     }     else     {         $  ('#frm_field_335_container').removeClass('no-display');         $  ('#frm_field_311_container').addClass('no-display');     } }  function difftiersmultiflavour(){     var difftiers = $  ("input[name='item_meta[335]']").filter(":checked").val();     var tiernos = $  ("input[name='item_meta[310]']").filter(":checked").val();     console.log(tiernos);      if (Math.floor(tiernos) == 500 && Math.floor(difftiers) == 1)     {         $  ('#frm_field_337_container').removeClass('no-display');         $  ('#frm_field_337_container').addClass('2tiers');         $  ('#field_ywsfg_label').text('Please select any two flavours');         $  ('#frm_field_311_container').addClass('no-display');     }     else if (Math.floor(tiernos) == 1000 && Math.floor(difftiers) == 1)     {         $  ('#frm_field_337_container').removeClass('no-display');         $  ('#frm_field_337_container').addClass('3tiers');         $  ('#field_ywsfg_label').text('Please select any three flavours');         $  ('#frm_field_311_container').addClass('no-display');     }     else if (Math.floor(tiernos) == 1500 && Math.floor(difftiers) == 1)     {         $  ('#frm_field_337_container').removeClass('no-display');         $  ('#frm_field_337_container').addClass('4tiers');         $  ('#field_ywsfg_label').text('Please select any four flavours');         $  ('#frm_field_311_container').addClass('no-display');     }     else     {         $  ('#frm_field_311_container').removeClass('no-display');         $  ('#frm_field_337_container').addClass('no-display');     } }   $  ('#field_b4xx2').on('input', cakecostcalc()); $  ('#field_b4xx2').on('input', tierselector()); $  ('#frm_field_310_container').click(togglesinglemultiflavour()); $  ('#frm_field_335_container').click(difftiersmultiflavour());  }); 

Optimize code for a grid of radio buttons

I want to display multiple radio buttons multiline style in an item of a recyclerview. Below is the code I am using.

How can I make it more efficient or optimize it?

xml

   <RadioButton                     android:id="@+id/rb_rad1"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_marginTop="@dimen/dp_10"                     android:checked="true"                     android:text="@string/text1"                     app:layout_constraintLeft_toLeftOf="parent"                     app:layout_constraintTop_toBottomOf="@+id/xyz" />                   <RadioButton                     android:id="@+id/rb_rad2"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_marginLeft="@dimen/dp_34"                     android:checked="false"                     android:text="@string/text2"                     app:layout_constraintBaseline_toBaselineOf="@+id/rb_rad1"                     app:layout_constraintLeft_toRightOf="@+id/rb_rad1" />                  <RadioButton                     android:id="@+id/rb_rad3"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:checked="false"                     android:text="@string/text3"                     app:layout_constraintLeft_toLeftOf="@+id/rb_rad1"                     app:layout_constraintTop_toBottomOf="@+id/rb_rad1" />                  <RadioButton                     android:id="@+id/rb_rad4"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:checked="false"                     android:text="@string/text4"                     app:layout_constraintLeft_toLeftOf="@+id/rb_rad2"                     app:layout_constraintTop_toBottomOf="@+id/rb_rad2" /> 

onBindViewHolder

holder.binding.rbRad1.setOnClickListener(object : View.OnClickListener {             override fun onClick(view: View?) {                  holder.binding.rbRad2.isChecked = false                 holder.binding.rbRad4.isChecked = false                 holder.binding.rbRad3.isChecked = false                 notifyDataSetChanged()             }         })          holder.binding.rbRad3.setOnClickListener(object : View.OnClickListener {             override fun onClick(view: View?) {                  holder.binding.rbRad2.isChecked = false                 holder.binding.rbRad4.isChecked = false                 holder.binding.rbRad1.isChecked = false                 notifyDataSetChanged()             }         })          holder.binding.rbRad2.setOnClickListener(object : View.OnClickListener {             override fun onClick(view: View?) {                  holder.binding.rbRad3.isChecked = false                 holder.binding.rbRad4.isChecked = false                 holder.binding.rbRad1.isChecked = false                 notifyDataSetChanged()             }         })          holder.binding.rbRad4.setOnClickListener(object : View.OnClickListener {             override fun onClick(view: View?) {                  holder.binding.rbRad2.isChecked = false                 holder.binding.rbRad3.isChecked = false                 holder.binding.rbRad1.isChecked = false                 notifyDataSetChanged()             }         }) 

Is frequency vector a good choice for minimizing chain code derivative vector?

I’m trying to implement a feedforward neural network that recognize a type of cable based on chain codes derivative vector. The size of my chain codes derivative vectors is variable, and I would like them to converge to the same length. As a solution I’m thinking about a frequency vector that will contain each direction(8 in total). So from a variable length, all the vectors will converge to vectors of length 8. Is this approach ok?

How to use if else statement correctly in my code?

I have used conditional statement but here is only else statement working while if statement is not working. Why and how to solve it?

import csv  entry = input('Enter the name: ') with open('file.csv','r') as csv_file:     csv_reader = csv.reader(csv_file)     for line in csv_reader:         if entry in line[0]:             print('Name is already present in collection.')         if entry not in line[0]:             print('This name is New in collection.')             break 

I can’t find where is wrong of my GLSL code?

I am an iOS developer, use Xcode to compile some GLSL code. The shaderv.vsh code likes below:

attribute vec4 position; attribute vec4 positionColor; attribute vec2 textCoordinate; uniform mat4 projectionMatrix; uniform mat4 modelViewMatrix; varying lowp vec2 varyTextCoord; varying lowp vec4 varyColor;  void main() {     varyTextCoord = textCoordinate;     varyColor = positionColor;      vec4 vPos;     vPos = projectionMatrix * modelViewMatrix * position;     gl_Position = vPos; }  

And the shaderf.fsh code likes below:

precision lowp float;  varying lowp vec2 varyTextCoord; varying lowp vec4 varyColor; uniform sampler2D colorMap;  void main() {     vec4 cs = texture2D(colorMap,varyTextCoord);     vec4 cd = varyColor;     float s = 0.2;     float d = 0.5;     vec4 color = (cs * s) + (cd * d);     gl_FragColor = color; }  

When compile this code, it will be come into some error:

ERROR: 0:15: 'premature EOF' : syntax error syntax error  ERROR: 0:5: 'premature EOF' : syntax error syntax error 

I can’t find where is wrong. It has troubled me for a long time. Help me!