Java – String Permutation – Code Review Stack Exchange

My permutation function is listed below and I would like to make it more elegant and efficient if possible.

The function should return a string that contains all permutations of the specified string (separated by commas).

private static String permutation(String prefix, String str) {
    int n = str.length();
    String toReturn = "";

    if (n == 0) {
        return prefix + ",";
    } else {
        for (int i = 0; i < n; i++) {
            toReturn +=  permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i + 1, n));
        }
    }
    return toReturn;
}

How do I search for an exact multi-word string in Bitbucket?

I want to search for Bitbucket public T get in exactly this order. Any words can be before public or after get but the full phrase public T get should be right.

But if I search with double quotes like "public T get" then I get all kinds of results that the words have or get publicly, but the exact relevant result that the whole phrase has is not even shown.

How do I remove spaces from a string in Python without removing breaks?

Hello everybody! I need to remove unnecessary spaces from strings, but don't break them between lines. I used the following command, which removes spaces, but also the & # 39; / n & # 39; away. Does anyone know how to solve?

" ".join("   minha  n string do python    ".split())

Console result:
& # 39; my python string & # 39;

Result I'm trying to do:
& # 39; my n python string & # 39;

unit – How to get multiple string values ​​by overriding ToString ()?

I want to get multiple string values ​​(selectedNameand selectedCurrency) individually public override string ToString()below.
How do I proceed?

    using System.Collections;
       using System.Collections.Generic;
       using UnityEngine;  

       (CreateAssetMenu(fileName = "Country", menuName = "Country/Country", order = 0))
       public class country : ScriptableObject
       {
           (System.Serializable)
           public class Item
           {
               public string Name;
               public string Currency;
               public string Capital;
               public string() City;

    public override string ToString()
    {
    string selectedName = this.name;
    string selectedCurrency = this.currency;
    return selectedName + selectedCurrency; 
    }

           }

           public Item() m_Items;
       public Item PickRandomly()
    {
        int index = Random.Range(0, m_Items.Length);
        return m_Items(index);
    }
}

I need to use the selected string values ​​in the following script.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class GameController: MonoBehaviour
    {   public country country; //This is the scriptable object country
    public Text countryText;
    public Text currencyText;

    void Start(){
    countryText.text = country.PickRandomly().ToString(); // This is where I need the country name string to show up.
currencyText.text = country.PickRandomly().ToString(); // This is where I need the currency string to show up.
    }
    }

At the moment, only a random country name and a random currency are displayed in both fields, e.g. B. USA USD.

Compress JSON string stored in PostgreSQL, e.g. B. MessagePack?

JSON strings are currently stored in a PostgreSQL 11 table in a text box. For example, a line can contain the text field asks with the string:

{"0.000295":1544.2,"0.000324":1050,"0.000325":40.1,"0.000348":0}

Question: Is it possible to save it in a format that takes up less space? The use of some CPU cycles to serialize / deserialize the JSON string is acceptable as a compromise for the use of less memory. The JSON data does not have to be searchable.

I am particularly interested in using JSON encoding / compression algorithms like MessagePack with zlib, but how can we use this when we insert the record into the PostgreSQL table?

Note: Also use Node.js with Knex.js to communicate with PostgreSQL. Currently, JSON objects are converted to strings using nodes JSON.stringify Function.

java – Is the size of the string pool affected by setting the maximum heap size?

I have a Java application with strange memory usage. I have found that memory usage is significantly higher than the maximum heap size (Xmx is 800mUse is 1.4g).

One of the most recent changes before that was a sharp increase in the number of unique strings used. So I thought that the many strings that I used a lot of memory outside of the heap for are possible. Is this possible?

I am using Java 11.

Performance #: Do you use plain for loops to search for (existing) strings in the string array?

I have defined a few ways to search for a string in a string array (with 82 elements in the example), case-sensitive and case-insensitive.

I am a little surprised that the level for grinding is faster than all other variants.

  1. Sure, there are no controls, but are there any other shortcomings here?
  2. Does Linq not do vectorization behind the scenes?
  3. Can I use these bows without hesitation?
  4. Any other notes?

code

public static void StringArrayContains()
    {
        // Init timing
        var watch = Start();
        watch.Stop();
        watch.Reset();

        // Setup vars
        string query = "big";
        string() stringArray = GetStringArray();
        bool contains = false;
        int times = (int)1e6;

        Console.WriteLine("Case Sensitive Search");

        // Loop with case sensitive equal
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            for (int j = 0; j < stringArray.Length; j++)
            {
                if (string.CompareOrdinal(query, stringArray(j)) == 0)
                {
                    contains = true;
                    break;
                }
            }
        }
        Stop(watch, $"Loop with case sensitive equal", times);

        // Array.Exists + Equals
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            contains = Array.Exists(stringArray, item => string.CompareOrdinal(item, query) == 0);
        }
        Stop(watch, $"Array.Exists + Equals", times);

        // Array.Exists + ==
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            contains = Array.Exists(stringArray, item => item == query);
        }
        Stop(watch, $"Array.Exists + ==", times);

        // Array.IndexOf
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            contains = Array.IndexOf(stringArray, query) > -1;
        }
        Stop(watch, $"Array.IndexOf", times);


        Console.WriteLine("Case Insensitive Search");

        // Loop with case insensitive equal
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            for (int j = 0; j < stringArray.Length; j++)
            {
                if (string.Equals(query, stringArray(j), StringComparison.OrdinalIgnoreCase))
                {
                    contains = true;
                    break;
                }
            }
        }
        Stop(watch, $"Loop with case insensitive equal", times);

        // Array.Exists + EqualsIgnoreCase
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            contains = Array.Exists(stringArray, item => string.Equals(item, query, StringComparison.OrdinalIgnoreCase));
        }
        Stop(watch, $"Array.Exists + EqualsIgnoreCase", times);

        // Linq Contains: OrdinalIgnoreCase
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            contains = stringArray.Contains(query, StringComparer.OrdinalIgnoreCase);
        }
        Stop(watch, $"Linq Contains: OrdinalIgnoreCase", times);

        // Linq Contains: InvariantCultureIgnoreCase
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            contains = stringArray.Contains(query, StringComparer.InvariantCultureIgnoreCase);
        }
        Stop(watch, $"Linq Contains: InvariantCultureIgnoreCase", times);

        // Linq Contains: CurrentCultureIgnoreCase
        watch.Start();
        for (int i = 0; i < times; i++)
        {
            contains = stringArray.Contains(query, StringComparer.CurrentCultureIgnoreCase);
        }
        Stop(watch, $"Linq Contains: CurrentCultureIgnoreCase", times);


        if (!contains)
            throw new Exception();
    }

Result

Case Sensitive Search
                   Loop with case sensitive equal   took    323 ms to execute 1,000,000 times (0.3 us per exec).
                            Array.Exists + Equals   took    445 ms to execute 1,000,000 times (0.4 us per exec).
                                Array.Exists + ==   took    461 ms to execute 1,000,000 times (0.5 us per exec).
                                    Array.IndexOf   took    511 ms to execute 1,000,000 times (0.5 us per exec).

Case Insensitive Search
                 Loop with case insensitive equal   took    408 ms to execute 1,000,000 times (0.4 us per exec).
                  Array.Exists + EqualsIgnoreCase   took    543 ms to execute 1,000,000 times (0.5 us per exec).
                 Linq Contains: OrdinalIgnoreCase   took    827 ms to execute 1,000,000 times (0.8 us per exec).
        Linq Contains: InvariantCultureIgnoreCase   took  6,220 ms to execute 1,000,000 times (6.2 us per exec).
          Linq Contains: CurrentCultureIgnoreCase   took  6,249 ms to execute 1,000,000 times (6.2 us per exec).

spring boot – springboot2.2. * freemarker gets a string instead of a website, but I use the @Controller, what's the problem?

I tried to use freemarker to get a webpage with bootem2.2.6 but returned a form string instead of a webpage. The code is as follows:






${body}


but I inserted the card into the model:

map.put("body", payResponse.getBody());
return new ModelAndView(“test”, map);

How can I get a website?

SQL Server – T-SQL Update Random string value in column

I have a table that contains a file path column that contains such data.

C:ABCFilesAA.dat
C:ABCFilesAA.Unbound.qp
C:DEFAAGGG Build 1 ModulesRandom123.qpp
C:DEFAAGGG Build 1 ModulesRandom456.qpp
C:GHDC.Random789.qpp
C:IJKRandom987.qpp

I have to replace the file path with a generic path before the actual file name, so everything has to change before the final , but keep the same file names, something like that

D:FILESAA.dat
D:FILESAA.Unbound.qpp
D:FILESRandom123.qpp
D:FILESRandom456.qpp
D:FILESDC.Random789.qpp
D:FILESRandom987.qpp

The table has about 2000 rows and if possible I want to update it in a single script. If you are running SQL 2008R2, this is the first phase of the final upgrade. We would appreciate any help.

Checksum – If the site provides MD5 to check the file, can't the comparison string be changed either?

Basically, you have to forward the MD5 checksum via another trustworthy means of communication outside the band, e.g. B. that the other party sends them by registered mail or similar.

So the main thing is to check that the downloaded file is not corrupt, and it protects against some amateur attacks where a script child was able to change the file, but not the site where the download link is, for example.

To really protect yourself from such an attack, you need to use private / public key pairs, compute the hash, and encrypt with your private key. This would ensure that anyone with your public key can verify that the hash you are comparing the file for integrity with is still the hash you published because it is decrypted with your public key.