Shopify liquid – get products by string

I have the slug of a collection. And I know that I can get the products of a collection by slug by doing:


However I have this slug as string assigned to a variable called collection_slug.

If I write:


It does not work. As the string does not get put into there…

How can I solve this?

Here is the code:

{% assign collection_url = block.settings.collection_url | split: '/' %} {% assign collection_slug = collection_url.last %}  {% for product in collections.collection_slug.products %}     product {% endfor %} 

Iterating over an array comparing input to a String

I have a string array holding words that I am converting to a char array. Also, I am taking users input as a string, then converting it to a char and adding it to an array. I am trying to check user input against the word and if it matches just println correct or incorrect. I am not certain how to code it.

private String[] wordsForGuessing = new String[] {"one", "david",                                           "storage", "unhelpful"}; private String ranWord = randomWord(wordsForGuessing); private char[] convertRanWordToACharArray = ranWord.toCharArray();  private int MAX_SIZE = countsHowManyLettersAreInAWord(ranWord); //adding three extra turns to guess private char[] letter = new char[MAX_SIZE + 3];  private String guess;  //Check user input to see if the letter is in the word private void checkUserInputToRanWord(char[] word, String guess) {     String message = "This is ";      for(int i = 0; i < word.length; i++)     {         if(guess.charAt(0) == word[i])         {             message += " correct guess";         }else{             message += " incorrect guess";         }     }  } 

Tasker, how to append a string to a variable

Tasker is making this simple task complicated.

I am doing a “Send Intent” action within a task and I need the extra 1 and extra 2 to be a string concatenated to a number variable concatenated to another string.

In most languages it’d be something like

extra1 = "str1:" + integer + "str2" 

It’d be easier if there were spaces between the strings; it’d just be str1 %integer str2, but there are no spaces to separate things out.

How do I accomplish this?

Fetch and print all properties of an object graph as string

Below I have setup an extension method that takes any object, cycles through its properties, and prints each out to a Console window in the format Name: Value.

public static string PropertiesToString<T>(this T obj, int tabs = 0) where T : class {     int initTabs = tabs;     string result = string.Empty;     PropertyInfo[] propertyInfo = obj.GetType().GetProperties();     foreach (PropertyInfo property in propertyInfo)     {         string name = property.Name;         object value = property.GetValue(obj, null);         Type valueType = value.GetType();         if (valueType.IsValueType || valueType.Name.Equals("String"))         {             for (int i = 0; i < tabs; i++)             {                result += "    ";             }             result += string.Format("{0}: {1}\n", name, value == null ? string.Empty : value.ToString());         }         else         {             result += string.Format("{0}:\n", name);             result += value.PropertiesToString(++tabs);         }         tabs = initTabs;     }    return result; } 

Here is a class I’m using to test this code, along with the lines responsible for creating an instance of the class and writing its properties to the Console:


public class Circle : IShape {     public Circle(double x, double y, double radius)     {         Center = new Point         {             X = x,             Y = y         };         Radius = radius;     }      public Point Center { get; set; }     public double Radius { get; set; }      public double Area(int precision = 2)     {         return Math.Round(Radius * Radius * Math.PI, precision);     } } 


public static void Main(string[] args) {     IShape circle = new Circle(5, 5, 10);     Console.WriteLine(circle.PropertiesToString());     Console.ReadLine(); } 

The above method will also cycle through nested objects and print those to the Console as well, adding in tabs for readability’s sake.

I’m kind of unfamiliar with System.Reflection and was wondering if there was a more efficient way I could approach doing something like this.

¿Cómo realizar consultas a campos string en firestore o firebase?

Inciando con firestore y angular 8, tengo el siguiente código:

buscarAfiliado(nombre:string):Observable<any[]>{      return this._afs.collection<Afiliado>('Afiliados', ref=> {         let cursorQueryRef : firebase.firestore.CollectionReference | firebase.firestore.Query = ref;         //buscar nombre exacto:         cursorQueryRef = cursorQueryRef.where('nombre', '==', nombre);         //buscar letras iniciales:         //----Falta construir---------         return cursorQueryRef;     })     .snapshotChanges()     .pipe(         map(actions => => {         const data = as Afiliado;         const id =;         return { id, };         }))     );  }   

Funciona muy bien para buscar documentos en la colección Afiliados siempre y cuando el nombre recibido en el método buscarAfiliado(nombre:string){…} sea exactamente igual al almacenado en la colección.

Pero, ¿como se debería construir la consultar para que busque por ejemplo los nombres que empiecen con una letra en particular (o que terminen o que contenga una o algunas letras)?.


portable hashable string representation of data object

I have a class of (flat) objects that are going to be passed around between three different parties, each possibly running a different software stack.

my_object:   item: "string_a"   money:     amount: 99.9     currency: "EUR"   metadata: 5   origin: "" 

These objects will need to be signed and the signatures will need to be verifiable.
In order for the signed hash to be stable from one party to another, there has to be an exact canonical string representation.

For example, both the following are valid string representations of the above object, but they’ll have different hashes.

<my_object xmlns="">   <item>string_a</item>   <money>     <amount>99.9</amount>     <currency>EUR</currency>   </money>   <metadata>5</metadata>   <origin></origin> </my_object> 
<my_object xmlns="">   <item>string_a</item>   <money><amount>99.9</amount><currency>EUR</currency></money>   <metadata>5.0</metadata>   <origin></origin> </my_object> 

All parties will be parsing the objects, so it’s the values that need to be verifiable in the signature process. In the above example, the data that needs to be signed is
{“string_a”, 99.9, “EUR”, 5, “”}.
Of course there must be no ambiguity about which value goes with which key; for example it must be clear that 5 is the metadata and not the amount.
That said, it seems reasonable to have the original serialization of the data treated as a data-value in-itself, and the contained data parsed out of it as needed. This would solve the above problem of a byte-perfect canonical version.

I think it’s a good idea to define the “outer” signed object in XML.

<signed_object xmlns="">   <data>string representation of the inner data object</data>   <signature>RSA signature of the SHA512 hash of the value in `data`</signature> </signed_object> 

Clearly I have a variety of options for what should go in that inner <data> tag.

  • An escaped XML string would work.
    • We know all the parties have xml parsing set up.
    • We could help with verification by providing an XSD.
    • The relatively large size of an xml string isn’t a big deal because this will all get compressed.
    • On the other hand, it would be a pain for a human to look at an xml-escaped xml string and understand what was going on.
    • Also, a naive implementer might try to rebuild the XML from the contained data, get a different hash, and decline a valid signature.
  • JSON and Yaml might be slightly better than XML for human readability, but would have the same problem that “equivalent” objects could have different hashes.
  • A delimited string (with commas, pipes, etc) would more be human-readable, and would clearly be string data in itself.
  • Taking that idea even farther, we could provide a canonical regex with capture groups for unambiguously validating and parsing these strings.
  • And finally, we could decide not to worry about having a canonical string version of each such object, and instead have a really well defined process for serializing the data for hashing.
    • This would look the best.
    • This would be the easiest to screw up.

Expanding on that last option (because it’s the one I’ve actually seen done in the wild):

  • Simply concatenating the values in an explicit order probably won’t work: what if item ends with numeric characters?
  • Concatenating the keys and values in an explicit order would probably work, the only problems I can think of are ambiguities in how to represent numbers (5 vs 5.0), or possibly conversions between UTF-8/UTF-32/ASCII.

I like the idea of defining the string format using a regex. Is that a bad idea for any reason?

EDIT: I’ll be asking other people to implement parts of this system, on a variety of platforms. What system will be the easiest and/or most reliable to implement, in general?

Get a Type from a String

I am trying to switch my code to a component-oriented design.

My point of contention is the following function do() which matches its s argument with some priorily known Strings and calls compute() with the adequate type parameter.

   def do(s: String, summoner: Summoner): String = {       s match {         case "a" => summoner.compute[Type_A](outOfScopeVal)         case "b" => summoner.compute[Type_B](outOfScopeVal)         case _   => ""       }     } 

I would like to transpose it to a generic trait that can be extended if any new Type_x is required.

This problem can be reduced to getting a generic tool that returns (some kind of) a type based on an input String.

This question:, nears the expected solution but I can not match the requirement of “know[ing] the type of object mapping names ahead of time”…

Also, Shapeless might be the path to follow, but I merely started going down that path.

Is it even possible?

Shortest way to form a string out of subsequence of a string

The task

is taken from LeetCode

From any string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions).

Given two strings source and target, return the minimum number of subsequences of source such that their concatenation equals target. If the task is impossible, return -1.

Example 1:

Input: source = "abc", target = "abcbc" Output: 2 // Explanation: The target "abcbc" can be formed by "abc" and "bc", which are subsequences of source "abc". 

Example 2:

Input: source = "abc", target = "acdbc" Output: -1 // Explanation: The target string cannot be constructed from the subsequences of source string due to the character "d" in target // string. 

Example 3:

Input: source = "xyz", target = "xzyxz" Output: 3 // Explanation: The target string can be constructed as follows "xz" + "y" + "xz". 


Both the source and target strings consist of only lowercase English letters from “a”-“z”. The lengths of source and target string are between 1 and 1000.

My solution

has time and space complexity of O(n) (I think…)

/**  * @param {string} source  * @param {string} target  * @return {number}  */ var shortestWay = function(source, target) {     const map = new Map();     for (let i = 0; i < source.length; i++) {         if (map.get(source[i])) {             const arr = map.get(source[i]);             arr.push(i);             map.set(source[i], arr);                     } else {             map.set(source[i], [i]);         }     }     let occurrences = 0;     for (let i = 0; i < target.length; i++) {         const indexes = map.get(target[i]);         if (indexes === void 0) return -1;         occurrences++;         let max = 0;         indexes.forEach(index => {             let j = 0;             let ignore = 0;             while(source[index + j + ignore] !== void 0) {                 if(target[i + j] !== source[index + j + ignore]) {                     ignore++                 } else {                     max = Math.max(max, j++);                 }             }         });         i += max;     }     return occurrences; };