Assigning m balls to n buckets – recursive algorithm

I came across the following problem and the answer to that problem: “Give m balls and n bins. Find out how many ways to assign balls to bins. Notice the buckets has no order. Like (1,2,3) and (3,2,1) are considered the same. eg, m = 3, n = 2, return 2. (1, 2) and (3, 0)”

int assignBalls(int m, int n) {         if (m == 0 || n == 1) {             return 1;         }         if (n > m) {             return assignBalls(m, m);         } else {             return assignBalls(m, n - 1) + assignBalls(m - n, n);         }     } 

This solution seem to work. However I don’t understand how assignBalls(m, n - 1) + assignBalls(m - n, n); works. Why is it considering m-n balls into n bins ?

Assigning rank in another sheet based on Average

I have a list of names with an average beside it for every day Monday-Friday. A subgroup of names within this list will be highlighted. I want a macro to assign ranks of the highlighted individuals based on their average and place a value of their rank in a row of another sheet where each individual has a column. There is one row for each day.

Example. 5 people highlighted in a list of July 1st. Macro looks at other sheet (called Workbook) and finds row corresponding to July 1st. Then finds column corresponding to person with lowest average. Puts 1 in their cell. Repeats this with 2, 3, 4, 5. If 8 people highlighted would do this 1 through 8.

hope this makes sense

The image is not assigning to the correct attribute option after sorting – Magento 2.3.1

Summary of Issue:

I am looking to sort the color attribute options programmatically with input type ‘Visual Swatch’. I have made customization in below files to sort the attribute options:

File 1: vendor/magento/module-swatches/view/adminhtml/templates/catalog/product/attribute/Visual.phtml

in the above file, I have added code before last script tag. (after line 109)

<?php     $  values = [];     $  color = [];      foreach($  block->getOptionValues() as $  value) {         $  value = $  value->getData();         $  values[] = is_array($  value) ? array_map(function($  str) {             return htmlspecialchars_decode($  str, ENT_QUOTES);         }, $  value) : $  value;     }     foreach($  values as $  key => $  val) {       $  color[ucwords($  key)]  = ucwords($  val['store0']);     }     array_multisort($  color, SORT_ASC, $  values);     ?> 

also added the code in below file in getJsonConfig() after line 71


public function getJsonConfig()     {         $  values = [];         foreach ($  this->getOptionValues() as $  value) {             $  values[] = $  value->getData();         }         //custom code         foreach($  values as $  key => $  val) {           $  mid[ucwords($  key)]  = ucwords($  val['store0']);         }         array_multisort($  mid, SORT_ASC, $  values);         //custom code end         $  data = [             'attributesData' => $  values,             'uploadActionUrl' => $  this->getUrl('swatches/iframe/show'),             'isSortable' => (int)(!$  this->getReadOnly() && !$  this->canManageOptionDefaultOnly()),             'isReadOnly' => (int)$  this->getReadOnly()         ];          return json_encode($  data);     } 

after adding the above code, I am able to sort the attribute options. But the visual swatches don’t sort with respective options.

Please check the below images:

A) Below image is before adding the swatch option.

enter image description here

B) Below image is after adding the option. Here option is sorted correctly alphabet-wise but the image is not assigning to that option. See below image

enter image description here

  Steps to replicate:  (Before replicating the above issue, please add   above custom code)   - Go to Store >> Attribute >> Product    - Search for the color attribute    - Add swatch option with image.   - Check that option get sorted   - But image assigned to last option. 

Expected result: The image should assign to newly added option after sorting.

Actual result: The image does not assign against newly added option after sorting.

Is anything wrong happens after sorting the array?

Assigning PrivSep directory in sshd

I am having an issue while running multiple instances of sshd. I can start and stop the services manually without issue. The problem is during boot. Since the init.d is executing multiple threads simultaneously, the scripts interfere with each other since both of them want to make the /run/sshd directory. I have attempted to contact OpenSSH and request the ability to configure the /run/sshd (i.e. /var/empty in OpenBSD) on a per service basis. There is no provision in sshd to change the directory without a recompile. Has anyone found a hidden switch in sshd to change the path of this directory?

Can not access my VM from WAN, I am using bridge, and assigning IP from Modem [on hold]

I have a strange issue, and I believe it have something to do with modem/router. but i can’t put my finger on something.

Host Machine is connected to Modem/Router via LAN. 4 VMs in Host using qemu/virsh

I have setup bridge on Host’s first NIC (the one connected to Modem/Router), and I am using this bridge in VMs.

I can successfully get IP from Modem/Router for VMs.

I can ssh into VMs from my laptop on LAN connected via Wireless LAN.

Here are IPs assigned via DHCP

Modem/Router : Laptop : Host : VM1 : VM2 :

Here are Port forwarding I have setup on Router/Modem, so that I can access my host and VMs from outside.

External Port : 64001, Internal Port : 22, IP : (ssh forwarding for Host)

External Port : 64002, Internal Port : 22, IP : (ssh forwarding for VM1)

External Port : 64003, Internal Port : 22, IP : (ssh forwarding for VM2)

I can successfully ssh into all machines i.e. host, vm1, vm2 from my laptop when connected to same router/modem. using port 22 for connection

I can successfully ssh into host from outside. using port 64001

But I can’t connect/ssh to VMs from outside. using 64002, 64003

Since I can ssh into VMs from my laptop (when connected to same LAN), I assume I have setup bridge network correctly as well Host is not blocking my requests to VMs

What could be wrong there.

P.S. I have tried connecting to host and VMs using public WAN IP with ports while connected to same router/modem on which host is connected, and I can connect to host, but can’t connect to VMs here too.

UPDATE: Here is a simplified version of tcpdump using “tcpdump -i br0 -x >tcpdump.102.log”

17:08:01.097275 IP host01.ssh > .47374: Flags [P.], seq 2974335894:2974336102, ack 3128654606, win 280, length 208 17:08:01.149120 IP .47374 > host01.ssh: Flags [.], ack 208, win 4136, length 0 17:08:02.083867 IP host01.60432 > _gateway.domain: 28525+ [1au] PTR? (57) 17:08:02.241925 IP _gateway.domain > host01.60432: 28525 NXDomain 0/1/1 (145) 17:08:02.242150 IP host01.60432 > _gateway.domain: 28525+ PTR? (46) 17:08:02.242694 IP _gateway.domain > host01.60432: 28525 NXDomain 0/0/0 (46) 17:08:02.243809 IP host01.35708 > _gateway.domain: 23749+ [1au] PTR? (56) 17:08:02.399458 IP _gateway.domain > host01.35708: 23749 NXDomain 0/1/1 (134) 17:08:02.399629 IP host01.35708 > _gateway.domain: 23749+ PTR? (45) 17:08:02.400273 IP _gateway.domain > host01.35708: 23749 NXDomain 0/0/0 (45) 17:08:03.107308 IP host01.54864 > _gateway.domain: 58281+ [1au] PTR? (54) 17:08:03.263611 IP _gateway.domain > host01.54864: 58281 NXDomain 0/1/1 (132) 17:08:03.263789 IP host01.54864 > _gateway.domain: 58281+ PTR? (43) 17:08:03.264478 IP _gateway.domain > host01.54864: 58281 NXDomain 0/0/0 (43) 17:08:05.480573 IP .45401 > lamp.grc.ssh: Flags [S], seq 4124347704, win 8192, options [mss 1412,nop,wscale 2,nop,nop,sackOK], length 0 17:08:06.179255 IP host01.58680 > _gateway.domain: 62377+ [1au] PTR? (56) 17:08:06.10.196 IP _gateway.domain > host01.58680: 62377* 1/0/1 PTR lamp.grc. (78) 17:08:08.480463 IP .45401 > lamp.grc.ssh: Flags [S], seq 4124347704, win 8192, options [mss 1412,nop,wscale 2,nop,nop,sackOK], length 0 17:08:13.586177 ARP, Request who-has tell _gateway, length 46 17:08:14.371276 IP host01.43673 > _gateway.domain: 58354+ [1au] PTR? (56) 17:08:14.485151 IP .45401 > lamp.grc.ssh: Flags [S], seq 4124347704, win 8192, options [mss 1412,nop,nop,sackOK], length 0 17:08:14.527017 IP _gateway.domain > host01.43673: 58354 NXDomain 0/1/1 (134) 17:08:14.527363 IP host01.43673 > _gateway.domain: 58354+ PTR? (45) 17:08:14.527859 IP _gateway.domain > host01.43673: 58354 NXDomain 0/0/0 (45) 17:08:15.607321 IP _gateway.bootps > BOOTP/DHCP, Reply, length 548 17:08:15.607387 ARP, Request who-has tell host01, length 28 17:08:16.610767 ARP, Request who-has tell host01, length 28 17:08:17.634768 ARP, Request who-has tell host01, length 28 17:08:10.658770 IP host01 > _gateway: ICMP host unreachable, length 556

Subrequests: Assigning Paragraphs entity to node

Migrating a content type from D7 into a greenfield D8 app, so I’m using Subrequests and jsonapi modules. My first subrequest to create a simple Paragraph returns the new ID and it properly replaces my token in my node–person, until it gets wiped out at some point within the many calls to httpKernel->handle($ request) class. I’ve burned a few hours setting breakpoints to see how its losing the replaced Paragraph ID but I’ve not mastered the Symfony Http system.

I’ve tried adding an owner iid, attempted to derive a “meta” array for a target_revision_id from the drupal_internal_revision_id property but that returns a 500 error. Here’s a minimized code of the blueprint.

function bodyPerson($  person){$  data = ["data" =>       ['type' => 'node--person',        'attributes' =>         ['title' => 'ignored',         'status' =>"1",         'field_body' =>           ['value' => 'Highlights.',              'format' => 'full_html',              'summary' => ''],        'field_last_name' =>           'Walls'     'relationships'=>       [        'owner' => ['data' =>          ['type' => 'user--user',          'id' => '2061b881-d5ea-4daa-a006-616e47xxx']],        'field_title' =>['data' =>          ['type' => "paragraph--title",            'id' => "{{paragraph-title-1.body@$}}"]            ]       ]]];       return $  data;      } 
     $  bodyp = json_encode(["data" => ['type' => 'paragraph--title',        'attributes' => ['field_department' => ['value' => "my dept 1a"]],        ['field_title' => ['value' => "my title 1a"]]]]       ); 
     $  blueprint = json_encode([['action' => 'create', 'requestId' =>    'paragraph-title-1', 'body' => $  bodyp, 'uri' => '/jsonapi/paragraph/title', 'headers' => $  headers], ['action' => 'create', "waitFor" => ["paragraph-title-1"], "requestId" => "person-test", 'headers' => $  headers, 'uri' => "/jsonapi/node/person", 'body' => $  bodyPer]]); 

Passing the $ blueprint and the two body blocks into curl returns the new Paragraphs object, passing it to the final POST subrequest. The result is an empty “data” array where the Paragraphs’ link should be.

            "field_title": {                 "data": [],                 "links": {                     "self": {                         "href": "\/jsonapi\/node\/person\/9ebcdd24-d8ee-428d-8770-1ad62eexx\/relationships\/field_title?resourceVersion=id%3A1045"                     },                     "related": {                         "href": "\/jsonapi\/node\/person\/9ebcdd24-d8ee-428d-8770-1ad62exx\/field_title?resourceVersion=id%3A1045"                     }                 }             } 

Subrequests is working for other subrequests in this body.

Bash creating user and assigning existing folder as home wrong permissions

name=$  1 folder=$  2  useradd $  name echo "user $  name added successfully!" echo $  name:"123" | chpasswd echo "Password for user $  i changed successfully"  usermod -d ~/Projects/$  folder -m $  name echo "Home set for user"  sudo chown -R $  name:$  name ~/Projects/$  folder sudo chmod -R 755 ~/Projects/$  folder 

User gets added with password, and setting the home folder works perfectly. Problem is when SSH into the server with the newly created account and I get this error Could not chdir to home directory /root/Projects/project12: Permission denied. Have tried many different versions of chmod.

How can I fix the error in the best way? Please don’t mind the password, this is just for testing purposes.

Assigning test-data parameters by name

When creating data-driven tests with xUnit we can use the MemberDataAttribute to get the data from a member of this or other class. This is very nice but it has one disadvantage, you have to specify parameters in the same order as the test method so you need to be very careful. I prefer to use names for that purpose because my data-items already have them so I’d like to reuse them with the test signature.


In order to make it work this way I crated my own SmartMemberDataAttribute. I think it’s smart because it can not only match data-item and parameters by name but at the same time it’s case-insensitive and also validates whether data-item values can be assigned to the parameters or are optional.

Warning: DynamicExceptions at work here! Please ignore this question if you don’t like them ;-]

Yes, this code throws three DynamicExceptions to make debugging easier in case I made a mistake and gave properties or parameters non-matching names or used incompatible types.

[DataDiscoverer("Xunit.Sdk.MemberDataDiscoverer", "xunit.core")] [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class SmartMemberDataAttribute : MemberDataAttributeBase {     public SmartMemberDataAttribute(string memberName, params object[] parameters) : base(memberName, parameters) { }      protected override object[] ConvertDataItem(MethodInfo testMethod, object item)     {         try         {             return CreateDataItem(testMethod, item);         }         catch (Exception inner)         {             throw DynamicException.Create             (                 $  "DataItemConversion",                 $  "Could not convert '{item.GetType().ToPrettyString()}' for '{GetTestMethodInfo()}'. See the inner exception for details.",                 inner             );         }          // Creates text: MyTest.TestMethod         string GetTestMethodInfo() => $  "{testMethod.DeclaringType.ToPrettyString()}.{testMethod.Name}";     }      private static object[] CreateDataItem(MethodInfo testMethod, object item)     {         var itemProperties = item.GetType().GetProperties().ToDictionary(p => p.Name, p => p, SoftString.Comparer);         var testMethodParameters = testMethod.GetParameters();         var dataItem = new object[testMethodParameters.Length];          // We need the index to set the correct item in the result array.         foreach (var (testMethodParameter, i) in testMethodParameters.Select((x, i) => (x, i)))         {             if (itemProperties.TryGetValue(testMethodParameter.Name, out var itemProperty))             {                 if (testMethodParameter.ParameterType.IsAssignableFrom(itemProperty.PropertyType))                 {                     dataItem[i] = itemProperty.GetValue(item);                 }                 else                 {                     throw DynamicException.Create                     (                         $  "ParameterTypeMismatch",                                                     $  "Cannot assign value of type '{itemProperty.PropertyType.ToPrettyString()}' " +                         $  "to the parameter '{testMethodParameter.Name}' of type '{testMethodParameter.ParameterType.ToPrettyString()}'."                     );                 }             }             else             {                 if (testMethodParameter.IsOptional)                 {                     dataItem[i] = testMethodParameter.DefaultValue;                 }                 else                 {                     throw DynamicException.Create                     (                         $  "ParameterNotOptional",                         $  "Data item does not specify the required parameter '{testMethodParameter.Name}'."                     );                 }             }         }          return dataItem;          // Creates text: MyTest.TestMethod         string GetTestMethodInfo() => $  "{testMethod.DeclaringType.ToPrettyString()}.{testMethod.Name}";     } } 


I use it the same way as the original attribute:

[Theory] [SmartMemberData(nameof(GetData))] public void Can_evaluate_supported_expressions(string useCaseName, object expected, bool throws) {     var useCase = _helper.GetExpressions().Single(e => e.Name == useCaseName);     ExpressionAssert.Equal(expected, useCase, ctx => ctx.WithReferences(_helper.GetReferences()), _output, throws); } 

It gets the data from anonymous-objects like this one that I create from tuples:

public static IEnumerable<object> GetData() => new (string UseCaseName, object Expected, bool Throws)[] {     ("Any", true, false),     ("Sum", 3.0, false),     ("ToDouble", 1.0, false),     ("True.Not", false, false),     ("Double.ToDouble", 1.0, true),     // ... more use cases }.Select(uc => new { uc.UseCaseName, uc.Expected, uc.Throws }); 

What do you say? Is this solution robust enough and debug-friendly? Can it be even smarter?

Assigning Task to Group using REST and SharePoint JavaScript API

I found myself in an unfortunate position of being unable to use SharePoint Designer to build workflows and thus am having to rebuild an approval workflow in JavaScript. I am using REST to insert a new task item but need to expand it to assign the task to all users in a group and make it so that whoever in the group is the first to approve or reject the task will set the task status.

Do I simply need to replace the userId in AssignedToId: userId with groupId? Or would I use the REST API to GET a list of users (and their IDs) from the group name using url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getbyname('" + strSPGroupName + "')/users" and then create an array of the user ids for use in this:

data: JSON.stringify({     __metadata: { "type": "SP.Data.TasksListItem" },     Title: "Sample Task",     AssignedToId: { 'results': [11,22] },     DueDate: due,     Status: "In Progress" }) 

I have my Task list AssignedTo column set to Allow Multiple Selections: Yes and Allow Selection Of: People and Groups

In scrum, if tasks are estimated in hours, how to avoid assigning the task in sprint planning?

I’ve been reading up a lot on the subject, and from what I can gather the following statements ‘should’ be true in scrum:

1) Estimate user stories in story points at the product backlog level. This allows abstraction of the estimates, and the team can estimate together without dispute – e.g. one developer may complete the story much quicker than another, but for both, the estimate is 3 story points.

2) You ideally shouldn’t assign tasks during sprint planning. While it helps with indivdual accountability, it reduces team accountability

3) In sprint planning, flesh out the tasks involved for each story, and estimate these in hours.

My question is this, how can you estimate the tasks in hours, yet still not assign the task to a specific developer (points 2 and 3)? Surely the whole point of using story points is to avoid the expert developer saying it’ll take 1 hour, and the junior dev saying it will take 8 hours.

If you are now estimating tasks within sprint planning in hours, how do you reach an estimate which is good for all team members of varying levels of expertise, without assigning the task to the specific dev who’s estimated it?