huawei – creating profile in Tasker

huawei – creating profile in Tasker – Android Enthusiasts Stack Exchange

performance – Creating a specific distribution of random numbers in Powershell

I originally posted this on StackOverflow but was requested to post it here instead as it relates to optimization/performance of the code rather than a specific problem.

TL;DR: Get-Random produces an even distribution of numbers where every number in the pool has an even chance of appearing. I’m looking for a way to generate random numbers where every individual number appears with a frequency that I myself specify.


If I run

for($i=1;$i -le 1000;$i++){
    Get-Random -Minimum 0 -Maximum 10
}

I get a very evenly distributed count for each number (roughly 100 for each number between 0 and 9). Using Get-Random allows me to get a random number every time but on average, every individual result will appear roughly an equal amount of times. I want to decide the frequency for how often any specific number appears, and then generate random numbers that fit that distribution. As an example:

Number   Probability
0        10
1        11
2        19
3        12
4        3
5        10
6        6
7        7
8        4
9        18

I’m looking for a way to use the above list to randomly generate a number between 0 to 9, but with the probability of each individual number appearing using the Probability column.

My very hard-coded and not so generic solution so far is that I thought of doing something like adding a cumulative percentage column:

Number   Probability   CumulativeProbability
0        10            10
1        11            21
2        19            40
3        12            52
4        3             55
5        10            65
6        6             71
7        7             78
8        4             82
9        18            100

And from here, run the object through a filter. Something like:

$RandomNumber = Get-Random -Minimum 0 -Maximum 100
$MyProbabilityObject | Where-Object {$RandomNumber -ge $_.CumulativeProbability}

This gives me all numbers with a lower Cumulative probability than the random number. Let’s say the $RandomNumber was 42, that would result in:

Number   Probability   CumulativeProbability
0        10            10
1        11            21
2        19            40

From here, I could pipe the result to

Select-Object CumulativeProbability | Measure-Object -Property CumulativeProbability -Maximum 

Which gives me the highest value, and then use that column as a reference to find the number with

Where-Object {$_.CumulativeProbability -eq $TheNumberIGetAbove}

While this kinda works, it feels like I’m doing several laps around a problem that should be easier and more straightforward to solve. Are there any better ways of generating random numbers that fit a distribution you specify yourself instead of using an even distribution such as Get-Random?

c++ – Creating an external tool to edit Unreal project optimization settings

INTRO

I am creating a C++ app that will help users to set up optimization settings in the Unreal game engine. I want to let the program make all this work on its own. This application is being written for Windows 10 platform (maybe it will be cross-platform in the future).


PROBLEM DESCRIPTION

To make the program working as intended, I must be able to change configuration files, add some UE objects to the project and call editor functions (e.g. rebuild lights).


MY SOLUTION

I can parse some of the .ini files and edit them. However, the real problem is with UE objects and editor functions. One of the possible ways is to get symbols from the .dll and run that function in a separate process. Another way is to use the actual UE4 code for these tasks.


QUESTION

Is there any easier and safer way to achieve what I need?

Creating a rule-based list of lists using Manipulate[…]

Given a list of lists:

list = {{x1, x2, x3}, {y1, y2, y3}, {z1, z2, z3}};

Some self-explanatory lists which I like to create using Manipulate():

(*picking the 1st elements from `x` abd `y` tuples and all elements of `z`*)
M11a = {
         {x1, y1, z1},
         {x1, y1, z2},
         {x1, y1, z3}
       }; 

(*picking the 1st and 2nd elements from `x` and `z` tuples and all elements of `y`*)
M1a2 = {
         {x1, y1, z2},
         {x1, y2, z2}, 
         {x1, y3, z2}
        };

(*picking the 3rd and 2nd elements from `x` and `z` tuples and all elements of `y`*)
M3a2 = {
         {x3, y1, z2},
         {x3, y2, z2},
         {x3, y3, z2}
        };

I like to create Manipulate() to automatically generate the above matrices with three controls. For example, when the values of 1st and 3rd controls (x and z, respectively) are fixed, the other control for y should take all the values in {y1, y2, y3}.

graphs – Creating Map of Unknown Space without being able to see obstacles

I’m trying to create a program where I have a user walking around a random space that contains obstacles, but I can’t see where the obstacles are. The point is that as a user walks around, based on where they are traveling, the program creates a rough map of places where there aren’t any obstacles (if the user is able to go over some point, there isn’t an obstacle there).

Anyone have any ideas of how to approach this, or could direct me to any sources? I’ve looked into how GPS and other forms of mapping work but the difficulty with this program is that I don’t have a pre-built map to go off of, I essentially have to create a map of a random space while blindfolded.

php – divide the editor text which have html attributes on every 500 th character length for creating text slider

I have to create the text slider , but that text have html attributes also,so supposed i have 1000 char length of text including html attribute and if i am dividing the text on every 500 character the html div tag will also get divide and my text will look like an simple text ,is there any solution ,hope you guyz get understand what im trying to do

                $msg  = $message;
                
                $xyz =  strip_tags($msg);
              
                $lentgh = strlen($xyz);
                
                $noOfDiv = round($lentgh/500);


                for($i = 1 ; $i <= $noOfDiv ;$i++){
                    $startPoint = $prevPoint;
                    $endPoint = $startPoint + 500;
                    $prevPoint = $endPoint;

                    $abc = substr($msg,  $startPoint, $endPoint);
                 

                    echo "<div class='mySlides '>
                        <div class='numbertext'>".$i." / ".$noOfDiv."</div>
                        <div class='message__text__container'>
                            <div class='text'> ".$abc."</div>
                        </div>
                    </div>";
               
                } 

         

office 365 – Cannot save changes when creating Custom tiles for O365 App Launcher in admin panel

i have came a cross a problem which is very mystical to me. I have be trying to create custom titles of Dynamic365 shortcut link to all users on Office365 portal landing page. I have a link do Dynamic365, i have name, link to icon which is 60×60 .jpg and Description set, but for some reason i just cannot save changes, the button is just grayed out. Can some one tell me, what am i doing wrong here? This should not be this hard as soo you have all this values set so, this is so odd.

I have been trying to test it in other tenant i have, but same thing.

python – Problem with creating pyQt5 app

I’m hoping that someone can help me out. I’ve made a box that contains a raspberry pi and some relays. It takes in readings from pH and ORP sensors and I’m almost at the stage where it’s running the pool for me. The last thing that I’m trying to get working is a python app to show me which of the relays (there are 4 of them and they control the power to the pump, the chlorinator, the sensors, plus a spare outlet) are “on” and which are “off”. What I’ve written so far contains 4 images, with each image being for one of the relays. When the python script is executed and the app opens, it interrogates the GPIO pins and then displays an image for each of the relays. The image is of either a red led or a green led, plus the name (eg Pump, Chlorinator, Sensors, Spare). The idea is that the app will start as a cron job when the raspberry pi boots, and then the app stays on at all times will give the up-to-date status. The raspberry pi runs headless and I connect to it via ssh and vnc.

I’ve spent ages searching on the internet for how to make the app update. The existing code is something that I’ve cobbled together (with help from others).

The current code is:

import RPi.GPIO as GPIO
import sys
import time
from time import sleep
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class window:

   def __init__(self):
      app = QApplication(sys.argv)
      win = QWidget()
      # setup vars for Qlabel and set to initial state = off
      self.img1 = QLabel()
      self.img1.setPixmap(QPixmap("/home/pi/Pictures/PumpOff.png").scaled(250, 50))
      self.img2 = QLabel()
      self.img2.setPixmap(QPixmap("/home/pi/Pictures/ChlorinatorOff.png").scaled(250, 50))
      self.img3 = QLabel()
      self.img3.setPixmap(QPixmap("/home/pi/Pictures/SensorsOff.png").scaled(250, 50))
      self.img4 = QLabel()
      self.img4.setPixmap(QPixmap("/home/pi/Pictures/SpareOff.png").scaled(250, 50))

      # setup window
      self.vbox = QVBoxLayout()
      self.vbox.addWidget(self.img1)
      self.vbox.addWidget(self.img2)
      self.vbox.addWidget(self.img3)
      self.vbox.addWidget(self.img4)
      win.setLayout(self.vbox)
      win.setWindowTitle("Pool Status")
      win.setGeometry(300,300,200,200)
      win.show()
      #sys.exit(app.exec_())

   def update_status(self):
      GPIO.setmode(GPIO.BCM)
      GPIO.setwarnings(False)
      GPIO.setup(22, GPIO.OUT)
      # To read the Pump outlet state
      state = GPIO.input(22)
      if state:
         self.img1.setPixmap(QPixmap("/home/pi/Pictures/PumpOn.png").scaled(250, 50))
      else:
         self.img1.setPixmap(QPixmap("/home/pi/Pictures/PumpOff.png").scaled(250, 50))

      GPIO.setup(23, GPIO.OUT)
      # To read the Chlorinator outlet state
      state = GPIO.input(23)
      if state:
         self.img2.setPixmap(QPixmap("/home/pi/Pictures/ChlorinatorOn.png").scaled(250, 50))
      else:
         self.img2.setPixmap(QPixmap("/home/pi/Pictures/ChlorinatorOff.png").scaled(250, 50))

      GPIO.setup(24, GPIO.OUT)
      # To read the Sensors outlet state
      state = GPIO.input(24)
      if state:
         self.img3.setPixmap(QPixmap("/home/pi/Pictures/SensorsOn.png").scaled(250, 50))
      else:
         self.img3.setPixmap(QPixmap("/home/pi/Pictures/SensorsOff.png").scaled(250, 50))

      GPIO.setup(25, GPIO.OUT)
      # To read the Spare outlet state
      state = GPIO.input(25)
      if state:
         self.img4.setPixmap(QPixmap("/home/pi/Pictures/SpareOn.png").scaled(250, 50))
      else:
         self.img4.setPixmap(QPixmap("/home/pi/Pictures/SpareOff.png").scaled(250, 50))

      # Re-draw screen
      #self.win.show()
      self.win.update()
      #self.win.show()

if __name__ == '__main__':

   # Create an instance of window
   new_window = window()
   #new_window.show()

   # Now loop and update the status
   while True:
      # Update the initial off status with current status every X seconds
      new_window.update_status()
      #new_window.show()
      sleep(5)

If I uncomment the “sys.exit(app.exec_())” at the bottom of the def init(self): section, the app shows the images at the initial stage (with all images showing as “off”) and the app image is persistent (it doesn’t just flash on the screen very briefly), but it is obviously not updating. But as soon as I comment that line out (in order to try and get the updating working), I get an error of one sort or another. Running the code as shown gives the following error:
“AttributeError: ‘window’ object has no attribute ‘win'”

unity – Problems creating a biomes map

I am working on an infinite procedural terrain generator and at the moment I am trying to generate a proper heightmap from a biomes map.

I’m not sure what is the best way in creating a proper biomes map, but I decided to use a cellular noise.

enter image description here

I have setup a simple biomes by providing a threshold and a noise generator for each of the biome.

When I generate a heightmap, I sample a biomes map and I get a biomes index by using a sampled value.
Once I retrieve an index, I use a biome sample function to get a noise value at the position.

Currently this is the result I am getting

enter image description here

Which is expected, however I am currently struggling in blending these biomes seamlessly together. Also at the moment the biomes map defines these sharp regions, but instead I would like to make it more organic. I tried to blend the sampled cellular noise with a perlin noise, however it resulted in the same map.

I use this library in my code to generate noise maps:
https://github.com/Auburn/FastNoiseLite/tree/master/CSharp

This is the whole code:

using System;
using UnityEngine;
using UnityEngine.UI;

public class BiomesMap : MonoBehaviour
{
    (SerializeField) RawImage output;

    const int size = 512;

    (SerializeField) int seed = 5;

    (SerializeField) Biome() biomes;

    void Start()
    {
        for (int i = 0; i < biomes.Length; i++)
        {
            biomes(i).InitNoise(seed);
        }
        GenerateMap();
    }

    float(,) GenerateBiomesMap()
    {
        var noise = new FastNoiseLite(seed);

        noise.SetFractalType(FastNoiseLite.FractalType.None);
        noise.SetDomainWarpType(FastNoiseLite.DomainWarpType.BasicGrid);
        noise.SetFrequency(0.005f);
        noise.SetCellularJitter(1f);

        noise.SetNoiseType(FastNoiseLite.NoiseType.Cellular);
        noise.SetCellularDistanceFunction(FastNoiseLite.CellularDistanceFunction.EuclideanSq);
        noise.SetCellularReturnType(FastNoiseLite.CellularReturnType.CellValue);

        float(,) map = new float(size, size);

        for (int y = 0; y < size; y++)
        {
            for (int x = 0; x < size; x++)
            {
                map(x, y) = (noise.GetNoise(x, y) + 1) * .5f;
            }
        }
        return map;
    }

    void GenerateMap()
    {
        float(,) biomesMap  = GenerateBiomesMap();

        float(,) heightmap = new float(size, size);
        for (int y = 0; y < size; y++)
        {
            for (int x = 0; x < size; x++)
            {
                var value = biomesMap(x, y);
                int biomesIndex = GetBiomeIndex(value);

                if (biomesIndex == -1) { Debug.LogErrorFormat("Biome not found. {0}", value); return; }

                heightmap(x, y) = biomes(biomesIndex).Sample(x, y);
            }
        }
        Output(heightmap);
    }

    int GetBiomeIndex(float value)
    {
        for (int i = 0; i < biomes.Length; i++)
        {
            if (value <= biomes(i).threshold)
            {
                return i;
            }
        }
        return -1;
    }

    void Output(float(,) heightmap)
    {
        Color() pixels = new Color(size * size);

        for (int y = 0; y < size; y++)
        {
            for (int x = 0; x < size; x++)
            {
                float value = heightmap(x, y);

                pixels(x + (y * size)) = new Color(value, value, value, 1);
            }
        }
        Texture2D result = new Texture2D(size, size);
        result.SetPixels(pixels);
        result.Apply();

        output.texture = result;
    }
}
(Serializable())
public class Biome
{
    public string name;

    (Range(0, 1))
    public float threshold;
    public NoiseGenerator noiseParameters = new NoiseGenerator();

    FastNoiseLite noise;

    public void InitNoise(int seed)
    {
        noise = new FastNoiseLite();

        noise.SetSeed(seed);
        noise.SetNoiseType(noiseParameters.noiseType);
        noise.SetFrequency(noiseParameters.frequency);

        noise.SetFractalType(noiseParameters.fractalType);
        if (noiseParameters.fractalType != FastNoiseLite.FractalType.None)
        {
            noise.SetFractalOctaves(noiseParameters.octaves);
            noise.SetFractalLacunarity(noiseParameters.lacunarity);
            noise.SetFractalGain(noiseParameters.gain);
            noise.SetFractalWeightedStrength(noiseParameters.weightedStrength);
            noise.SetFractalPingPongStrength(noiseParameters.pingPongStrength);
        }
        if (noiseParameters.noiseType == FastNoiseLite.NoiseType.Cellular)
        {
            noise.SetCellularDistanceFunction(noiseParameters.distanceFunction);
            noise.SetCellularReturnType(noiseParameters.cellularReturn);
            noise.SetCellularJitter(noiseParameters.cellularJitter);
        }
        noise.SetDomainWarpType(noiseParameters.domainWarpType);
        noise.SetDomainWarpAmp(noiseParameters.amplitude);
    }
    public float Sample(float x, float y)
    {
        return (noise.GetNoise(x, y) + 1) * .5f;
    }
}
(Serializable())
public class NoiseGenerator
{
    (Header("General"))
    public FastNoiseLite.NoiseType noiseType;
    public float frequency;

    (Header("Fractal Noise"))
    public FastNoiseLite.FractalType fractalType;
    (Range(1, 10))
    public int octaves;
    public float lacunarity;
    public float gain;
    public float weightedStrength;
    public float pingPongStrength;

    (Header("Cellular Noise"))
    public FastNoiseLite.CellularDistanceFunction distanceFunction;
    public FastNoiseLite.CellularReturnType cellularReturn;
    public float cellularJitter;

    (Header("Domain Wrap"))
    public FastNoiseLite.DomainWarpType domainWarpType;
    public float amplitude;
}

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123