Unity: How to Retrieve Port Number Used for Test Build

There doesn’t seem to be a way to do this. I did a bit of digging on a fresh install of Unity 202.1.1f1. Note that on different versions the behaviour might be different, but I would assume that at least for reasonably recent versions the following holds:

A forum thread here mentioned that Unity starts <Version>EditorDataPlaybackEnginesWebGLSupportBuildToolsSimpleWebServer.exe to run the game locally. This executable accepts the port to start the server on is passed via a command line parameter, so we need to find the place where this is generated.

This happens to be in <Version>EditorDataPlaybackEnginesWebGLSupportUnityEditor.WebGL.Extensions.dll, under which a class called HttpServerEditorWrapper can be found via decompilation. This contains code for launching SimpleWebServer.exe, but unfortunately, it turns out that it uses a function named GetRandomUnusedPort(), which essentially uses the C# TcpListener to open a temporary connection with the default port 0, which the C# documentation says the following:

In this case, the service provider will assign an available port number between 1024 and 65535.

After opening the temporary connection, the opened port is queried, temporary connection is closed, and the available port is passed as a command line parameter to SimpleWebServer.exe.

As a result, it seems that you are at the mercy of the operating system. Perhaps you could look into hosting the built project via an alternative custom method where you can configure the port yourself? Search engines know more about this, but for an example Python comes with a ready to use HTTP server that one can start in a directory to serve its contents.

python – efficient way to retrieve objects from one model according multiple field values in Django

What I have

In my application I have a model called cases, which has three fields fulfilled, caducity and prescription; Which are used to keep deadlines for the case. It should be stressed that the three dates may seem at first sight to be the same but they are different terms used in the law. I need to retrieve those cases whose fields fulfilled, caducity and prescription values match a specific date.

class Case(TimeStampedModel, models.Model):
    """Representation of a legal case."""
    fulfillment = models.DateField(
        verbose_name=_("Fulfillment"),
        default=date.today,
        help_text=_("Select the case fulfillment date."),
    )
    caducity = models.DateField(
        verbose_name=_("Caducity"),
        default=date.today,
        help_text=_("Select the case caducity date."),
    )
    prescription = models.DateField(
        verbose_name=_("Prescription"),
        default=date.today,
        help_text=_("Select the case prescription date."),
    )

My solution

Create a custom manager in which I can filter those cases that match a specific date.

from datetime import date, timedelta

TODAY = date.today()
YESTERDAY = TODAY - timedelta(days=1)


class CaseManager(models.Manager):
    """Define a manager for Case model."""
    def all_expired(self) -> "QuerySet(Case)":
        """Get all fulfilled, caducated and prescribed cases."""
        return self.get_queryset().filter(
            Q(fulfillment__range=(YESTERDAY, TODAY))
            | Q(caducity__range=(YESTERDAY, TODAY))
            | Q(prescription__range=(YESTERDAY, TODAY))
        )

class Case(TimeStampedModel, models.Model):
    """Representation of a legal case."""
    # ...fields

    objects = CaseManager()

Then I can retrieve those cases whose expiration date is the same as today or yesterday like this: Case.objects.all_expired()

Problem

This solution may not be scalable, because if the fields that i need to filter go from 3 to 5 or 7 I would have to make the same comparison multiple times:

class CaseManager(models.Manager):
    """Define a manager for Case model."""
    def all_expired(self) -> "QuerySet(Case)":
        """Get all fulfilled, caducated and prescribed cases."""
        return self.get_queryset().filter(
            Q(fulfillment__range=(YESTERDAY, TODAY))
            | Q(caducity__range=(YESTERDAY, TODAY))
            | Q(prescription__range=(YESTERDAY, TODAY))
            | Q(another_field__range=(YESTERDAY, TODAY)) # another field to consider for filtering
            | Q(another_field__range=(YESTERDAY, TODAY)) # another field to consider for filtering
        )

Any suggestion about how to improve this code to make it more maintainable and scalable?.

c# – How to retrieve a device information (e.g. device name) via web page

What we want to do is very simple

We have a check-in kiosk website (C# ASP.NET MVC), and we are trying to set up 30 kiosk stations at each building (each building is about 200 ft away from each other).
Every time a person checks in at a building, we want to collect the time and the location of the check-in. (e.g. Person-A checked in at 10:00AM at Building-B).

What I’d like to know is

The most reliable way to detect/find the location given the background below:

  • the check-in system itself is a web application
  • all the 30 devices are in one OU
  • each device has a unique machine name

Method 1 : Get the domain name with Reverse DNS

Since each device has a unique machine name, I’m currently getting the host name using reverse DNS.
The code used here is

    string IP = Request.UserHostName;
    IPAddress myIP = IPAddress.Parse(IP);
    IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
    List<string> deviceName = GetIPHost.HostName.ToString().Split('.').ToList();

This method is working for most cases, but we are aware that this method is not always reliable. We do have one case where the retrieved deviceName doesn’t match the actual device name.

Method 2 : Each device specifies the location in URL

This can work. The website can take the LocationID via URL (e.g. https://sample.com/1, https://sample.com/2) and save the ID in a session or cookie. The only slight issue is that the device team will have to physically work with the device to set up each device for each URL, which I don’t think is a big problem because the location won’t change so often. The initial work is a bit of work for the device team because all the devices are under the same OU.

Method 3: Each device stores the location in cookie

This is similar to Method 2, and it will work. Again, the only slight issues is the initial work and the maintenance work (e.g. cookie got wiped, etc) by the device team.

Method 4: Find the actual location (i.e. latitude and longitude)

I haven’t tried this yet but I should be able to use GoogleMap Geolocation to find the current location of each device, and figure out the check-in building based on the location. Unless there are some obvious issues that I’m missing, this may be more reliable and would not require any initial/maintenance work to the device team??

Which one would be a better method or are there any other methods that I should explore?

bip 32 hd wallets – How to retrieve extended private key from extended public key + master seed / root private master key

I have a master seed (I use a hardware wallet).
I know how to transform it into a (root) private key.
I have also several public keys, which all was obtained by derived a private/public keys of the root private key.

Questions:

  • How can I get all the private keys corresponding to the public keys mentioned above?
  • What is the best tool to do this thing ?

In otherm term, I want to retrive derivated private key like that:

derivated private key = function(derivated public key, master root key)

My ultimate goals is then to import all these private keys in a Electrum wallet for instance.

How to retrieve the values of a sub-field in the first and last row of an (ACF) repeater inside function?

I’m using a function that changes the front-end and back-end post title for a custom post type according to what you put in certain custom fields.

    //Save ACF fields as post_content for back-end
add_action('save_post', 'change_title_cars');

function change_title_cars($post_id) {
    global $_POST;
    if('cars'== get_post_type()){

      $car_name = get_post_meta($post_id,'car_name',true);
      $first_car_model = ????????????;
      $last_car_model = ????????????;

      $my_post = array();
            $my_post('ID') = $post_id;
            $my_post('post_title') = $car_name . ' - ' . $first_car_model . ' ~ ' . $last_car_model;

remove_action('save_post', 'change_title_cars');
                    wp_update_post( $my_post );
add_action('save_post', 'change_title_cars');
    }   
   }


//Save ACF fields as post_content for front-end
add_action('acf/save_post', 'change_title_frontend_cars');

function change_title_frontend_cars($post_id) {
    global $_POST;
    if('cars'== get_post_type()){

      $car_name = get_post_meta($post_id,'car_name',true);
      $first_car_model = ????????????;
      $last_car_model = ????????????;

      $my_post = array();
            $my_post('ID') = $post_id;
            $my_post('post_title') = $car_name . ' - ' . $first_car_model . ' ~ ' . $last_car_model;

    remove_action('acf/save_post', 'change_title_frontend_cars');
                    wp_update_post( $my_post );
    add_action('acf/save_post', 'change_title_frontend_cars');
        }
    }

I’m using a repeater which has a sub-field named “car_model”. I’m trying to have the title changed into something like this:

(car_name) – (first “car_model” in the repeater) ~ (last “car_model” in the repeater)

but I couldn’t get values of the repeater sub-fields inside the function.

Note: the repeater has random number of rows.

visual studio – Can´t Retrieve folder from Sharepoint to VSCode using the SPGo extension (error related to credentials)

I´m trying to “pull” a remote folder from my sharepoint site to my local directory, so that I can edit my pages and whatnot directly from Visual Studio Code. For that, I´ve been using an extension called “SPGo”. Basically, When I use SPGo´s “Configure workspace”, it apparently works fine, but when I use “Retrieve folder” command, I put in my sharepoint username, password, and I´m shown the error:

“Invalid user credentials. Please reset your credentials via the command menu and try again.”

However, it seems like both username and password are correct. Bellow there are some information I think might be useful/necessary for solving this. Thanks in advance!

  • My Visual Studio Version: 1.47.0
  • SPGo´s version: 1.6.3
  • SPGo.json file:
{
    "sourceDirectory": "src",
    "sharePointSiteUrl":"https://dominioqualquer.sharepoint.com/sites/cursodois",
    "workspaceRoot":"c:\Users\14378\Desktop\CursoAngular_API_Sharepoint\Projeto(Curso Angular - Sharepoint)3",
    
    "publishWorkspaceOptions": 
    {
        "destinationFolder": "/",
              "globPattern":"c:\Users\14378\Desktop\CursoAngular_API_Sharepoint\Projeto(Curso Angular - Sharepoint)3\src\**\*.*",
          "localRoot":"c:\Users\14378\Desktop\CursoAngular_API_Sharepoint\Projeto(Curso Angular - Sharepoint)3\src"
    },
    
    "publishingScope": "Major",
    "authenticationType": "Digest"
}
  • Sharepoint usernames I´ve tried to use to log in (both of them have Owner permissions in the Site (full control permission)): RichardDiasRibeiro@dominioQualquer.onmicrosoft.com
    carl.johnson@dominioQualquer.onmicrosoft.com
  • I´m using Office 365 E3 free trial

How to retrieve category NAME instead of ID in a function with a taxonomy custom field?

I’m trying to change the post title (both back-end and front-end) for a specific post type through custom field. The custom field I’m using is a taxonomy field where you I choose from different categories (cars). I’m using this code:

    //Save ACF field as post_content for back-end
add_action('save_post', 'change_title_cars');

function change_title_cars($post_id) {
    global $_POST;
    if('cars'== get_post_type())
    {
        $post_custom_title = get_post_meta($post_id,'car_name',true);
        $my_post = array();
                $my_post('ID') = $post_id;
                $my_post('post_title') = $post_custom_title;
remove_action('save_post', 'change_title_cars');
                    wp_update_post( $my_post );
add_action('save_post', 'change_title_cars');
    }
   }

//Save ACF field as post_content for front-end
add_action('acf/save_post', 'change_title_frontend_cars');

function change_title_frontend_cars($post_id) {
    global $_POST;
    if('cars'== get_post_type())
    {
        $post_custom_title = get_post_meta($post_id,'car_name',true);
        $my_post = array();
                $my_post('ID') = $post_id;
                $my_post('post_title') = $post_custom_title;
remove_action('acf/save_post', 'change_title_frontend_cars');
                    wp_update_post( $my_post );
add_action('acf/save_post', 'change_title_frontend_cars');
    } 
}

And it works fine, except that it shows the category ID (number) in the title instead of the name.

I tried changing Return Value in the custom field setting from Term ID to Term Object, but it didn’t work.

sql – Bigquery: Retrieve information given unique combinations

Currently I have the following R data.table object with product/cities combinations:

product_code       place
product1_code      city1
product2_code      city1
product3_code      city1
product4_code      city1
product1_code      city2
product6_code      city2
product9_code      city3

What I would like to do is to pass the previous product_code/city combinations to a query string and then pass it to bigrquery. Something like the following:

SELECT *
FROM my.table
WHERE city AND product_code in (list.with.unique.previous.combinations)

However I don’t any idea of how I can pass the unique combinations as a list so it only retreives the information for those specific combinations. I know that I can use glue library to pass single elements to the query string something like this:

SELECT *
FROM my.table
WHERE city = {city.selected} AND product_code = {product.code.selected} 

but that would only work for 1 combination.

If anyone could give me an idea of how I could pass the entire list of combinations I would appreciate it.

Is it possible to retrieve a web template (not a site template) in SharePoint Online?

A web template is persisted in the SharePoint database as a Microsoft SharePoint Foundation Solution, which is a file that has a .wsp extension. The .wsp file is stored in the Solutions Gallery of the site collection. The solution can also be deployed as a sandboxed solution.

Users create web templates on the Save as Template page (or through code that uses the SaveAsTemplate method of the Microsoft.SharePoint.SPWeb class).

Source: Web Templates

Issue: Unfortunately, the SaveAsTemplate method is not available in SharePoint Online.

Solution:

In SharePoint Online, you can use Get-PnPProvisioningTemplate using PnP PowerShell to generate a provisioning site template from a web.

References:

  1. Get-PnPProvisioningTemplate
  2. Introducing the PnP provisioning engine

php – Retrieve First Name, then show custom name if the first name is not settle

I’m creating a code that retrieves the user Avatar and First Name/username using Shortcodes, but I noticed that if the user has no name settle, it will display a blank space. How can I set a custom name to show up when the user has no name settle? Something like this “Hi >Mister Anderson<, is that actually your name? Please configure your name in your account.”

THE CODE

Display Avatar, this part is not really necessary in this question, but I’m going to leave it here as a contribution, just in case someone else is interested in the code:

// show user avatar if logged in
function colaborator_avatar($atts)
{
    if (is_user_logged_in() && !is_feed()) {
        return get_avatar(get_the_author_meta( 'user_email' ));
    }
}
add_shortcode('colaborator_avatar', 'colaborator_avatar');

Display first name (this is the part related to my question):

// show first name if logged in
function colaborator_nome($atts)
{
    if (is_user_logged_in() && !is_feed()) {
    return get_user_meta( $new_user->ID, 'first_name', true );

    }
}
add_shortcode('colaborator_nome', 'colaborator_nome');

Or display Username (also here in case someone needs the code):

function colaborator_nome($atts) {     
    if (is_user_logged_in() && !is_feed()) {    
        $current_user = wp_get_current_user();
        echo $current_user->user_login;
    } 
} 

add_shortcode('colaborator_nome', 'colaborator_nome');