## Is there some mechanisms in PHP to assign “less trust” to scripts in a given dir? (not a duplicate) [closed]

Kindly stop redirecting my questions to that unrelated one which doesn’t answer my question whatsoever. I’ve already read every answer there and it doesn’t help at all. If it did, why would I ask this much more specific question?

This has been a continuous worry and problem for me for ages:

For practical and logical reasons, I am forced to trust some third-party PHP libraries. These are installed, updated and managed with Composer, and live in C:\PHP-untrusted-external, entirely separated from my own PHP scripts, which live in C:\PHP-my-own.

The scripts in C:\PHP-my-own include and make use of the libraries in C:\PHP-untrusted-external.

Since there is no way that anyone, especially not I, could ever vet all the third-party code, and all updates, I’m looking for some way to “secure” or “sandbox” these in some way, even if it’s just partial.

Basically, I’m worried that one day, an update will make an edit such as:

unlink('C:\'); 

Or:

phone_home_to_hacker_server(\$  contents_of_my_harddrive); 

If that happened, the scripts would happily run and do those actions. Nothing prevents them from doing so.

Is there really no way to specify in the php.ini configuration file, something like:

security.sandbox_dir = "C:\PHP-untrusted-external" 

Or:

security.refuse_network_connections_for_dir = "C:\PHP-untrusted-external" security.refuse_disk_io_for_dir = "C:\PHP-untrusted-external" 

… or something like that?

I don’t understand Docker. I have tried it countless times, and it makes no sense whatsoever to me. I don’t want Docker. I don’t want to deal with containers. Correction: I can’t deal with it. I’ve tried to, but didn’t understand it. Several times.

I just want PHP to support this in itself, and it seems more than reasonable to me. Doesn’t it seem reasonable to you?

The saying that “at some point, you have to trust other people” is way too generic/vague to apply here. It’s bypassing the problem. I don’t trust people at all, and for good reason. It seems idiotic that we are (apparently) just supposed to sit around and wait for the disaster to happen. At least if I could prevent the third-party scripts form doing anything with the file system and network, that would go some way toward mitigating this issue. It still won’t make the scripts unable to lie about the numbers/data they return to me, but at least they can’t directly “phone home” or delete random files.

## Assign resources that each have a certain amount of work they can provide to tasks that require a certain amount of work

I’m attempting to do a hobby automation project and have come to a roadblock. I have a certain problem I need to solve, but can’t think of the solution nor what the name for the problem would be.

Say we have n tasks where each task requires $$x_i$$ amount of work to be done and m resources where each resource can provide $$y_j$$ work. The total amount of work required will equal the the total amount of work the resources can provide, i.e. $$\sum_{i=1}^{n} y_i = \sum_{j=1}^{m}x_j$$. For all j from 1 to m, $$y_j \in \left \{1, 2, 6, 12, 24\right \}$$ and each $$x_i = a*1 +b *2 + c*6+d*12+e*24$$. I was looking at task assignment problems, but those seemed to be a bit overkill since they were concerned with optimization where I’m just simply trying to slot the correct blocks in the right place so that I don’t have tasks that are given too few or too many resources.

My current guess is that you can iterate over each task, and give it the largest resource available that doesn’t go over the amount of work that is left for the task to be completed. It’s almost analagous to filling a jar with different sized rocks; the best way is to start with the largest rocks and then go down in size from there, so that the smaller rocks fill in the space between the larger ones. Am I not taking something into consideration that complicates this problem further? I’m sorry if this is an obvious one, but I’m a hobbyist programmer and couldn’t think of the name of the problem or of a good set of keywords to google. The closest I could find is task assignment so far.

## Psycopg2 using value SET before assign to other column

I have a table with columns as below: (id, col1, col2, col3, col4). I need to insert new row to this table, with given data is a dict: data = {'id': 1, 'col1': 1, 'col2':1, 'col3':1, 'col4': 1} for example.

I want to use the query below to insert data into table if id not existed, or update the table if id existed:

query =  '''     INSERT INTO tablename (id, col1, col2, col3, col4)     VALUES (%(id)s, %(col1)s, %(col2)s, %(col3)s, %(col4)s)     ON CONFLICT (id) DO UPDATE SET     col2 = tablename.col2 + 1;     col3 = col2/100 ''' result = cur.execute(query, data) 

In the code above, I want to assign col3’s value to (value of col2 calculated before)/100. How can I do that?

## Encoding System that Assign Same Number of Bits for Each Character

I am trying to get a binary string that has been converted from text of a text file, I am able to get that but the problem is, I need each character to be represented by same number of bits, but that is not what I get (please see the below python code and corresponding output). For example, character i is represented by 1101001, which is 7 bits long, but character ! is represented by 100001, which is 6 bits long.

Is there any encoding/decoding system where each character takes same amount of bits?

content = open('a.txt', 'r').read() test_str = content # using join() + ord() + format()  ... Converting String to binary   Binary = ' '.join(format(ord(i), 'b') for i in test_str)  #Decimal=int(Binary, 2)    # printing original string   print("The original string is : " + str(test_str))  # printing result   print("The string after Binary conversion : \n" + str(Binary)) 

Output:

The original string is : Hi! Is there a solution? The string after Binary conversion :  1001000 1101001 100001 100000 1001001 1110011 100000 1110100 1101000 1100101 1110010 1100101 100000 1100001 100000 1110011 1101111 1101100 1110101 1110100 1101001 1101111 1101110 111111 

## How to assign a big integer struct to a long n

I have the following code, it does not work properly: void assignInt(bint res ,long n) { int i; / counter / int t; / int to work with */

if (n >= 0)     res->sign = PLUS; else     res->sign = MINUS;  for (i=0; i<MAX_SIZE; i++)     res->digits[i] = (char) 0;  res->size = -1;  t = labs(n);  while (t > 0) {     res->size++;     res->digits[res->size] = (t % 10);     t = t / 10; }  if (n == 0)     res->size = 0; 

} // initialzes a bint to value n

## Assign 100 materials of different shaders with their respective 2D textures to one shader automatically?

Is there an editor script to assign all materials to one shader specifically including copying the texture? I have found an editor script that changes the shader but does not copy its texture. How can I achieve this?

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor;   public class MAT_Change : MonoBehaviour {     [MenuItem("Editor/Material/Change Shader to ShaderTest")]     static void Change1()     {         Shader newshader = Shader.Find("Custom/ShaderTest" );         ChangeShaders(newshader);     }       static Object[] GetSelectedMaterials()     {         return Selection.GetFiltered(typeof(Material), SelectionMode.DeepAssets);     }         static void ChangeShaders(Shader newShader)    {       int counter = 0;        if (Selection.objects.Length > 0)         {             Object[] materiales = GetSelectedMaterials();             if (materiales.Length > 0)             {                 foreach( Material mat in materiales )                 {                       mat.shader = newShader;                     counter++;                 }              }         }       EditorUtility.DisplayDialog( "Message", "materials changed: " + counter, "OK" );    } }  

## How does Timescale assign chunk ids?

Timescale allows us to query for chunk sizes in with something like

SELECT * FROM chunk_relation_size('....');

I am trying to monitor the chunk sizes so that if any of them reaches a size that is dangerous to be kept in the memory, we can scale the DB as needed.

I am assuming the latest created chunk will be the most read heavy, thus most likely to be kept in memory.

However the chunk_relation_size table doesn’t expose any timestamps or information on when the chunk was created.

I am wondering if the chunk_ids are assigned incrementally or are they completely random? In the former case, I can infer which chunks are latest.

Docs doesn’t specify anything. I have skimmed through the source code but have been unable to find any clues.

## Assign n people to m rooms of different sizes, such that noone is alone and people are in largest rooms possible

I’m looking for an efficient way to assign n people to m rooms in a very specific way.

INPUT:

The program receives two sets of people (set of males and set of females), as well as a set of available rooms (rooms can have different sizes, ranging from 2 to 6).

ASSIGNMENT CONDITIONS:

The algorithm must assign people to the rooms in a way, that:

• Males can be in a room with only males (same for females)
• Noone can be alone
• The algorithm must maximize groups (one room of 4 is preferred over 2 rooms of 2, etc)

OUTPUT:

The algorithm must return the assignment

I’ve tried to do it, but all of the sollutions I come up with are at least O(n^3). Does anyone know an efficient way to do this?

## Best UI pattern to allow the user to assign 1 level nested items to two groups

My issue is something similar to this one – Best UI pattern for letting a user assign items to groups

I am looking for a good UI design for mapping items between 2 groups (only one-to-one mapping). These items can be under a parent or by itself. I thought of drag-and-drop/ having checkboxes (or switch like) to turn on for any one group.

Items Group 1 Group 2

Item A
Item A1 checkbox checkbox

Item B checkbox checkbox