Prevent form regeneration when a callback function is called through ajax

Here is the code for the custom form with a field(field_B) that calls an function through ajax.

The issue is that I want the function (MY_MODULE_XYZ_function()) to be executed only once, when the page loads for the first time. But the function(MY_MODULE_XYZ_function()) is being executed for each ajax call through field_B because the whole form is being regenerated.

How can I prevent whole form regeneration(so that the function won’t be called more than once) for each ajax call? Thanks in advance.

function MY_MODULE_menu(){     $  items['abcd/xyz'] = array(         'title' => 'ABCD',         'page callback' => 'drupal_get_form',         'page arguments' => array('xyz_custom_form'),         'access arguments' => array('access content'),         'type' => MENU_CALLBACK,     );     return $  items; }  function xyz_custom_form($  form, &$  form_state){      MY_MODULE_XYZ_function($  arg1, $  arg2);      $  form['field_A'] = array(  .... );      $  form['field_B'] = array(         '#type' => 'radios',         '#options' => array("a"=>"A", "b"=>"B", "c"=>"C"),         '#prefix' => "<div id='customDiv'>",         '#suffix' => "</div>",         '#ajax' => array(         'callback' => 'MY_MODULE_custom_ajax_callback',             'wrapper' => 'customDiv',             'progress' => array( 'type' => 'throbber', 'message' => NULL),             'effect' => 'fade',         ),     ); }  function MY_MODULE_XYZ_function($  arg1, $  arg2){     //Some Query Execution }  function MY_MODULE_custom_ajax_callback($  form, &$  form_state){     //Some Callback code } 

Airline changes plane, boarding is done by calling names, my name not called, Service insists that I was late

Today my gf wanted to flight home (Berlin Tegel -> Minsk). She had booked a flight long ago with airbaltic and checked in 1h before depature. When boarding should habe started, there was a plane change all of a sudden. People panicked and where rushing the counters to know what was going on.

In the end, the boarding was done by calling the names on the fligth list one by one. At this point my gf asked one of the service workers there to help her out. She just replied that she needs to wait. So thats what she did.

After all names were called, 5 people were still there. The same service worker insisted that she called all names and therefore these 5 people were obviously late. This obviously was not true.

However, my gf and the other group of 4 called the airline hotline (no counter for airbaltic in Berlin Tegel). To my gf they responded that they will call back. While on phone, the group of 4 left (no traces, so no witnesses that she was indeed at the gate). At some point the hotline called back. Not unsurprisingly they only found, that the Service Workers at the gate had marked them as late and so there is nothig that they can do (ofc they cant -.-)

My gf is crushed. What can we do? The ticket was scanned at the security control but I am afraid thats the only proove we have that she was there in time.

// UPDATE: My gf was lucky and found the group of 4 and will exchange numbers. That at least gives me a bit of hope

LocationCallback() never gets called. What am i missing?

The onMapReady() contains code (mFusedLocationAPI-requestLcoationUpdates) which should call the LocationCallback() function that updates the current location. But it seems that the LocationCallback() never gets called at all.

All the permissions required have been given before calls to the Location related methods. The onMapReady() contains code to call the LocationCallback() to update the latest Location but we get a null instead.

public class CustomerMapActivity extends FragmentActivity implements OnMapReadyCallback{

private GoogleMap mMap; Location mlastLocation; LocationRequest mLocationRequest; private Button mRequest; private FusedLocationProviderClient mFusedLocationClient;  @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_customer_map);      mFusedLocationClient = LocationServices.getFusedLocationProviderClient(CustomerMapActivity.this);      SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(;     mapFragment.getMapAsync(this);       mRequest = (Button) findViewById(;     mRequest.setOnClickListener(new View.OnClickListener(){          @Override         public void onClick(View v){                      checkLocationPermission();                     mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());                     String userid = FirebaseAuth.getInstance().getCurrentUser().getUid();  //Getting the userid from FireBase and will be passed to GeoFire's setLocation method                      DatabaseReference ref = FirebaseDatabase.getInstance().getReference("customerRequests");   // Database reference passed to GeoFire                     GeoFire geoFire = new GeoFire(ref);                     geoFire.setLocation(userid, new GeoLocation(mlastLocation.getLatitude(), mlastLocation.getLongitude()));                  }          }     });  }  @Override public void onMapReady(GoogleMap googleMap) {     mMap = googleMap;      mLocationRequest = new LocationRequest();     mLocationRequest.setInterval(1000);     mLocationRequest.setFastestInterval(1000);     mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);        if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){         if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {          }else{             checkLocationPermission();         }     }        //            mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());          mMap.setMyLocationEnabled(true);  }    LocationCallback mLocationCallback = new LocationCallback(){     @Override     public void onLocationResult(LocationResult locationResult) {         for(Location location : locationResult.getLocations()){                 Toast.makeText(CustomerMapActivity.this,"CallbackDoe",Toast.LENGTH_SHORT).show();                 ActivityCompat.requestPermissions(CustomerMapActivity.this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION},1);             if(getApplicationContext() != null) {                 mlastLocation = location;                 LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());     //Updates the Location of the USER                 mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));                  mMap.animateCamera(CameraUpdateFactory.zoomTo(11));               }         }     } }; 


I expected the onMapReady() to call the LocationCallback() to update the Current Location to the Variable mLastLocation which is used to update it on FireBAse Database using the geoFire.setLocation(userid, new GeoLocation(mlastLocation.getLatitude(), mlastLocation.getLongitude())); at the mRequest.SetOnClickListener() But i get a null “mLastLocation” instead.

Azure function – should context.done be called after each loop or at end

In an Azure function say I have:

const cosmosDBTrigger: AzureFunction = async function (context: Context, documents: any[]): Promise<void> {     if (!!documents && documents.length > 0) {         documents.forEach(function (document) {             context.bindings.outputdocuments = document             //1 - SHOULD IT GO HERE         });      } //2 - SHOULD IT GO HERE } 

Is the correct place to place context.done be in position 1 or 2. Namely should be after each document in the loop at the very end?


What is an equilibrium called when a perturbation only moves it slightly?

In game theory, a equilibrium is:

Stable, if a perturbation form any of the players returns the equilibrium back to it’s original state

Unstable, if a perturbation moves the equilibrium away from the original state

Semi-stable if some of the players perturbations are acceptable.

What do you call an equilibrium if a perturbation merely moves it slightly.

Consider the following game: Two players must state a number. Each of them gets a payoff of $ 1 if they state the same number, otherwise there is no payoff. (1,1) is an equilibrium. If one of the players chooses a different strategy, say 1.01. Then the Equilibrium is (1.01, 1.01). This does not seem unstable – neither does this seem stable. What is this type of equilibrium called?

Should there not be methods intended to be only called from inside of the package, but from the outside of the class they’re defined in?

Note: This is a follow-up to this question on StackOverflow.

I have to write a wrapper in Python to an external API, accessible through HTTP. The code is supposed to be publicly available on GitHub.

For this reason, I thought, it would be nice if a person cloning this repository wouldn’t see tons of warnings. I opened my own code in PyCharm just to see if that was the case. It wasn’t.

However, since I’m afraid what these warnings are pointing at is a design issue, please let me start by showing (in a simplified way) the design I came with:

Firstly: There are two methods to authenticate the HTTP connection. For this reason, I have a ConnectionBase abstract class, that is implemented by two concrete classes, each using one of the two available authentication methods. So far so good.

But here problems start. There is an ApiClient class that is supposed to contain wrappers of all those API routes. This ApiClient class, of course, has to make use of an instance of ConnectionBase. In addition, since there are so many API calls to provide wrappers for, I thought I’d break them into categories.

Finally, this is how (roughly) the definition of ApiClient looks like:

class ApiClient:     def __init__(self, connection):         self._connection = connection      # forwarding method     async def _make_call(*args, **kwargs):         return await self._connection._make_call(*args, **kwargs)      class _Category:         def __init__(self, client):             self._client = client          # another forwarding method         async def _make_call(*args, **kwargs):             return await self._client._make_call(*args, **kwargs)      class _SomeCategory(_Category):         async def some_api_call(some_arg, other_arg):             return await self._make_call(blah blah)          async def other_api_call(some_arg, other_arg):             if some_arg.some_condition():                 other_arg.whatever_logic_here()             return await self._make_call(yadda yadda)      class _OtherCategory(_Category):         async def yet_another_api_call(some_arg, other_arg, yet_another_arg):             #...             return await self._make_call # etc etc      @property     def some_category(self):         return ApiClient._SomeCategory(self)      @property     def other_category(self):         return ApiClient._OtherCategory(self) 

In this fashion, assuming that the user of my lib wants to make a call to this external API and that client is an instance of ApiClient, they would type:

client.some_category.some_api_call(some_arg, other_arg) 

I believe that my use of underscores is clear: I’m preceding with an underscore all names that are not meant to be called by the end user of my lib. I thought this was the most important distinction: far more important than the distinction between variables private to a class: because the latter is nothing but an aesthetic issue, while the former is a usability issue: after all, exposing a (hopefully) clean, well-defined and intuitive public API is the very purpose of writing libraries!

Yet, PyCharm frequently complains that I’m accessing protected members of classes from outside of these classes. Apparently, and according to the linked SO question, the Pythonic understanding of a name preceded by an underscore is: This member is internal to this class and NOT the way I was understanding it, that is: This member is internal to this package.

So, all such lines are producing warnings:

await self._connection._make_call  await self._client._make_call 

etc etc in other places of my code.

But then: Am I supposed to clearly distinguish between methods supposed to be called by the user of my lib and methods supposed to be called only from within my lib (or users who know the internal workings of my package and know what they’re doing)?

If yes, then how if not by an underscore, which apparently means a different thing?


Well I don’t know, because as it is clear from my questions on this site, my knowledge of design patterns is underwhelming… But a hypothesis of how this situation should be understood rises up in my mind… A pretty radical hypothesis…

Maybe the correct interpretation is that there should be no methods that are intended to be called from outside of a class but not from outside of the package and/or by the end user?

I mean, I’m constantly seeing talks about the need to break dependencies, about how bad it is to have code that is so closely intermingled and tightly coupled… Perhaps such methods are examples of this unwanted coupling? And in all cases where I’d like to put an underscore in the beginning of a method name but PyCharm complains, this simply means that the existence of such a method constitutes a coupling in my code that should not be there and therefore there should not be such a method at all?

And I was so proud of myself that I made use of dependency injection 😛

On a more serious note: I have strong doubts if the above, dire interpretation is correct. In Uni I had a basic course on OO design. The instructor said something along the lines of, IIRC:

Please do remember that inheritance should be used in case of an is-a relationship, not a has-a relationship. An example of an extremely bad inheritance is a car inheriting from a wheel or from a gas pedal. Such cases should be handled by composition instead.

So, since an API client is not a connection used by this API client and since a category of an API call is not a client, I thought that it would be wrong to make API client inherit from a connection or to make a category inherit from the client – even though doing this would make PyCharm stop complaining and issuing warnings. Instead I used composition. However, if composition is used, I can’t see how can I get rid of methods that are intended to be called from within my lib, but not from within the class they’re defined in and not by the end user.

I suppose there must be a basic design principle I’m ignoring out of ignorance.

Could you enlighten me please?

A Band Called

Why are you selling this site?
Dont have time to develop it

How is it monetized?

Does this site come with any social media accounts?

How much time does this site take to run?

What challenges are there with running this site?

JS How to create object by method “new” that can be called like function

I’m trying to understand what a malicious JS script does. The script obfuscated, so I can not read on their own. I known that it creates an ActiveXObject object.

So I decided to declare my object with this name, which does nothing but output a log. The virus uses the construction

var x = new ActiveXObject('file_name') 

Google Scripts does not allow you to declare your own classes (is it?), so I declare a constructor function for the new AX object. Everything works fine until the virus tries to access the AX object as a function like

var AX = new ActiveXObject()   AX() 

This return type mismatch (Object!=Function).

There my code:

I comment line 195 to prevent error.

Run function doGet for test and view logs. Or just open