caching – Create cache context for anonymous users based on ip range

I have a form within a custom block that is displayed on the front page of a Drupal 9 site on Acquia Cloud. I want to be able to have different displays for users coming from certain ip ranges. Is this possible to do while leaving all Drupal caching such as dynamic page cache and internal page cache?

If it is possible, how do I create cache contexts for this custom block/form such that Drupal knows to cache different displays based on that context? any examples would be great.

I know I can possibly accomplish this on the client side or using ajax but I would like to avoid that.

In what sense is a CFDG grammar a context free grammar?

CFDG is described as a language for context free grammars which can generate images. It allows rules to have parameters, but places restrictions on them to ensure the grammar is context free rather than an indexed grammar.

In what sense can a CFDG grammar be interpreted as a context-free grammar, and how would this fail with unrestricted parameters?

For completeness, I will describe the relevant parts of CFDG. A CFDG grammar designates a starting shape name and provides a list of rules, each mapping a shape name to some number of children; each child has a shape name and a transform. Each referenced shape name must be a primitive shape (eg SQAURE, CIRCLE) or have at least one rule.

The rules for a shape name may also include parameters to be specified each time the shape name is referenced in a child. The parameters of a rule can appear in expressions in the transform or parameters passed to children. However there are restrictions as noted above; the parameter expressions passed to children must be one of:

  • an integer expression constructed using only integer operations,
  • a real number parameter forwarded directly from the encompassing rule, or
  • a real number expression without any reference to the parameters of the encompassing rule.

For example, the following should generate zero or more primitive shapes in a row with period 2, each rotated by 60 degrees:

startshape main
shape main
rule {
  zero_or_more(2) ()
shape zero_or_more(number dx)
rule {
  primitive (rotate by 60)
  zero_or_more(dx) (translate by dx)
rule {}

shape primitive
rule { SQUARE () }
rule { CIRCLE () }

Without parameters, I could interpret this as a context free grammar whose terminal symbols are the primitive shapes and every possible transformation. To generate an image, we could expand the start shape to terminal symbols and then process them sequentially, maintaining the current transformation. Each primitive shape would be drawn using the current transformation, and each transformation symbol would be applied to the current transformation. Thus the rules

shape squares
rule {
  SQUARE (rotate by 60)
  squares(dx) (translate by 1)
rule {}

would become production rules

squares -> (rotate by 60) SQUARE (rotate by -60) (translate by 1) squares (translate by -1)
squares -> ε

I guess a rule with a parameter would produce a production rule for each possible parameter value, and the restriction somehow ensures a finite number of production rules?

c# – What compiler logic is behind forcing `value type` parameter to be not null in generic methods | Nullable reference types context

Nullability of reference types can appear counterintuitive.

Considering example one can observe that for reference type argument is successfully converted to nullable parameter. For value type this fails.

(SuppressMessage ("Style", "IDE0059:Unnecessary assignment of a value", Justification = "Demostration!"))
T ReturnType__NOT_Nullable___MethodParam__IS_Nullable<T> ( T? t )
    int x2 = ReturnType__NOT_Nullable___MethodParam__IS_Nullable<int> (null); // Error  CS1503  Argument 1: cannot convert from '<null>' to 'int'
    // ↑↑↑↑ int <int>(int) ↑↑↑↑
    CancellationToken x8 = ReturnType__NOT_Nullable___MethodParam__IS_Nullable<CancellationToken> ((CancellationToken?)null); // Error  CS1503  Argument 1: cannot convert from 'System.Threading.CancellationToken?' to 'System.Threading.CancellationToken'
    // ↑↑↑↑ CancellationToken <CancellationToken>(CancellationToken) ↑↑↑↑
    object? x6 = ReturnType__NOT_Nullable___MethodParam__IS_Nullable<object> (null);
    // ↑↑↑↑ object <object>(object?) ↑↑↑↑
    string x7 = ReturnType__NOT_Nullable___MethodParam__IS_Nullable<string> ((string?) null);
    // ↑↑↑↑ string <string>(string?) ↑↑↑↑
    #pragma warning disable CS8603 // Possible null reference return.
    return t;
    #pragma warning restore CS8603 // Possible null reference return.

Even making return type nullable does not fix this.

(SuppressMessage ("Style", "IDE0059:Unnecessary assignment of a value", Justification = "Demostration!"))
static T? ReturnType__IS_Nullable___MethodParam__IS_Nullable<T> ( T? t )
    int? x2 = ReturnType__IS_Nullable___MethodParam__IS_Nullable<int> (null); // Error  CS1503  Argument 1: cannot convert from '<null>' to 'int'
    // ↑↑↑↑ int <int>(int) ↑↑↑↑
    CancellationToken? x8 = ReturnType__IS_Nullable___MethodParam__IS_Nullable<CancellationToken> ((CancellationToken?) null); // Error CS1503  Argument 1: cannot convert from 'System.Threading.CancellationToken?' to 'System.Threading.CancellationToken'
    // ↑↑↑↑ CancellationToken <CancellationToken>(CancellationToken) ↑↑↑↑
    return t;

Beside compiler inability overcome declaring respective constraint draws out unified and predictable code validity.

(SuppressMessage ("Style", "IDE0059:Unnecessary assignment of a value", Justification = "Demonstration."))
static void Test3 ()
    T? Method<T> ( T? t ) => t;

    object? t1  = Method<object> (null);
    object? t2  = Method<object?> (null);        
    object? t3  = Method ((object?) null);
    //int? t4     = Method<int> (null); // Error    CS1503  Argument 1: cannot convert from '<null>' to 'int'   
    int? t5     = Method<int?> (null);

    T? Method<T> ( T? t ) where T : struct => t;

    int? t1 = Method<int> (null);
    //int? t2 = Method<int?> (null); // Error   CS0453  The type 'int?' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Method<T>(T?)'
    T? Method<T> ( T? t ) where T : class => t;

    object? t1 = Method<object> (null);
    //object? t2 = Method<object?> (null); // Warning   CS8634  The type 'object?' cannot be used as type parameter 'T' in the generic type or method 'Method<T>(T?)'. Nullability of type argument 'object?' doesn't match 'class' constraint.
    object? t3 = Method ((object?) null);

scoping – Access to variables in surrounding context from within Manipulate

Suppose you want to access a variable defined in a “surrounding” context (scoped via Begin and End) from within Manipulate. The following naive attempt does not work.

x = 123;
Manipulate(x + y, {y, 0, 1})
x = 456; (* changes the value of Manipulate output *)

One way to fix this is by using Inactive and Activate as follows.

x = 123;
Activate@Manipulate(Inactive(x) + y, {y, 0, 1})
x = 456; (* does not change the value of Manipulate output *)
MyContext`x = 456; (* changes the value of Manipulate output *)

Is this a robust way to achieve the desired goal or do you see any problems using this pattern in more involved examples? If so which alternative solutions do you suggest?

formal languages – Context free Grammar (CFG ) for All strings must contain odd ‘a’ and ends with ‘ba’

Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

What is ‘funds parking’ in the context of UK visa applications?

One reason for income and funds requirements is that consulates want to know how solvent applicants are (to find out whether their plans are plausible and how likely they might be to work illegally or even choose not to return to their place of residence). That’s why consulates do not merely want to see some cash on hand but also assess an applicant’s financial situation over several months (income, etc.)

“Funds parking” implies getting money merely to disguise those circumstances. We are talking about money that is used to pad the account for a few days and would not even be available to the person during the trip. It’s really about defeating the whole process, which is after all intended to vet an applicant’s personal situation quite thoroughly. So you can’t expect the people who designed and manage this process to take that nicely.

Clearly people with no means, no income and no ties to their country (like a job or business…) are not particularly welcome in the UK and other rich countries. What consulates love to see is a stable job with a good income paid by bank transfer, something that shows without ambiguity you have enough money to make the trip and want to come back to your country. That’s not particularly “nice” but that’s the nature of the visa application process.

On the other hand, borrowing money from family is not forbidden per se but you still need to document your own income thoroughly and account for the sudden cash deposit. The problem here is that it looks a lot like you obtained money just to make yourself look richer than you really are and increase your chances of getting a visa. Also, the consulate wants to know that you (and your family) obtained the money legally, i.e. that you are not involved in criminal activities, money laundering, etc. And cash is much harder to trace so that’s another reason why large cash deposits are best avoided.

So it does not really make sense to claim that people “are free to do whatever they want with their bank account”. Simply said, they are not. If you want a visa, you have to submit yourself to a quite intrusive process and jump through many hoops. That’s not to say it’s pleasant or entirely fair but that’s the way the whole process is intended to work and the fact cash deposits are frowned upon is just one aspect of that larger process.

Incidentally, there is another subtle reason why getting money from family looks worse than you might think. In some countries, it’s not unheard of for a family to fund the education of its brightest children, hoping them to secure a visa to some European country, somehow get a better life there but also send money back. Even if that means starting from a student or visitor visa and looking for a way to secure another status or staying illegally in the country afterwards. And countries with restrictive immigration policies like the UK do not welcome that.

From this perspective, someone who already has money, kids they are leaving behind, etc. is a “low risk” applicant, they are most likely to be a regular tourist who will spend some money in the country and leave as planned. But someone who does not have a situation is more likely to be willing to try his or her luck any way they can. And because obtaining a visa and enough money to pay for the trip, etc. is not trivial, the rest of the family does expect something in return and you can be under a lot of pressure not to disappoint. For the consulate, the family loan you thought of as a harmless bit of help can therefore make you appear even more likely to violate the conditions of the visa.

spfx – Current user context in SharePoint modern page

If you want this for a particular site page, you can use the Modern Script editor web part.

After adding web part on your page, enable _spPageContextInfo option in Modern Script Editor Web Part:

enter image description here

Then you can add below code to get the current user name:

<p id="pWelcomeMsg"></p>

<script type="text/javascript">

    document.getElementById("pWelcomeMsg").innerHTML = "Hey " + _spPageContextInfo.userDisplayName + ", welcome to our site";



enter image description here

Check this article for installing this web part on your site: Add The Script Editor Webpart back to SharePoint Modern Experience

mvc – The right place for “app logic” in MVVM context

I hope this is the right place to ask.

I’m an experienced developer, and have used MVC for much time.
This question is in the context of iOS/macOS development for the most part, (SwiftUI).

Using MVC in iOS I always found the paradigm and architecture simple.

  • Views contained view related code (layout and reactive code)
  • Models were just stores
  • Controllers populated models, did all the business/app logic, held references to the the objects that did work (network handlers, data parsers, business logic)

In MVVM, (used in SwiftUI) I’m really struggling with where to put this code.

I see the right approach as:

  • Models are still stores they are dumb and get populated by the ViewModel
  • Views are pure in terms of their purpose, UI code only, declarative
  • ViewModels (I think) hold the logic, have references to objects that do the work, get results from these objects and populate the model, let the view know when things change.

Do I have this right, if not, where does the “controller code” go in MVVM?

context free – Does this grammar accept this words?

It looks the grammar indeed accepts all words of the form $(b+a)^nca^n$ (which means, all words that start with any sequence of $n$ $b$‘s and $a$‘s, and then a single $c$ and afterwards exactly $n$ times the letter $a$).

To show why, try to show the two following things:

  1. every word accepted by the grammar must be with such form

  2. every word with such form has a derivation sequence in the grammar.

The first statement can be easily proved by induction (over sequence derivation length), if you notice that each derivation of $S$ adds only one element to both sides.

The second statement can be much more easily proved, try to think of what derications are necessary to create such words.

Context Sensitive Grammar for the language ${a^{n+1} b ^n c^{n-1} mid ngeqslant 1}$

I have been trying to find a context sensitive grammar for the language ${a^{n+1} b ^n c^{n-1} mid ngeqslant 1}$ for some time but I cannot get it done. Any ideas?