sql – Is there a cleaner way to write this window function?

I have a query that returns a list of parts – some parts are required and some are substitutes for required parts. In some cases either the required part or the substitute is an assembly, so 2x required parts might be equivalent to 10 substitute parts, for example.

My goal is to get a single percentage that represents if the inventory for that part is complete.

  • Example 1: 1/1 required part, 0/1 substitute part=100%
  • Example 2: 0/1 required part, 3/5 substitute parts=60%
  • Example 3: 1/1 required part, 1/2 substitute parts=150%

I’m using 4 window functions to calculate this – it’s difficult to read and debug and I wonder if there’s a more straightforward way to wrote this:

select *,
    coalesce(1.0*sum(iif(Total_Req=0,Qty_Owned,0)) OVER (PARTITION BY ParentID, ParentColorID)/NULLIF(sum(iif(Total_Req=0,Total_In_Set,0)) OVER (PARTITION BY ParentID, ParentColorID),0),0) +
    1.0*sum(iif(Total_Req>0,Qty_Owned,0)) OVER (PARTITION BY ParentID, ParentColorID)/nullif(sum(iif(Total_Req>0,Total_In_Set,0)) OVER (PARTITION BY ParentID, ParentColorID),0) NetPctOwned
FROM Parts_Inventory_Owned_Parts_Query opq

That’s (Qty_Owned not required) / (TotalQty not required) + (Qty_Owned required) / (TotalQty required)

How to Write a Contact List Program In C++ That Pulls Out the Corresponding Phone Number for an Entered Contact Name

I have written a program in C++ that takes in string values for contact names and contact phone numbers into vectors. What I need to do is have the program output the corresponding phone number for the contact name entered.

(Note: The ‘3’ is supposed to tell the program how many values are to be stored in each vector. In this case, it is 3 contact names and 3 phone numbers. Also, the last ‘Frank’ indicates that the corresponding phone number printed should be for the contact name ‘Frank’.)

Ex. Input: 3 Joe 123-5432 Linda 983-4123 Frank 867-5309 Frank

Ex. Output: 867-5309

When I run the program instead of getting the desired phone number it outputs nothing.

Here is the program that I have written so far:

#include <iostream>
#include <vector>
using namespace std;

string GetPhoneNumber(vector<string> nameVec, vector<string> phoneNumberVec, string contactName)  {
   string theName;
   string thePhoneNum;
   string theContName;
   string correctPhonNum;
   int N;
   int nElements;
   cin >> N;
   cin >> theName;
   cin >> thePhoneNum;
   cin >> theName;
   cin >> thePhoneNum;
   cin >> theName;
   cin >> thePhoneNum;
   cin >> contactName;
   nElements = phoneNumberVec.size(); 
   for (int i = 0; i < nElements; i++)  {
      if (i == N-1)  {
         return phoneNumberVec.at(i); 
   return "";

int main() {
   vector<string> nameVec;
   vector<string> phoneNumberVec;
   string contactName;
   string correctPhonNum;
   GetPhoneNumber(nameVec, phoneNumberVec, contactName);
   cout << correctPhonNum << endl;

   return 0;

glsl – How to write shaders that can be compiled for DirectX, OpenGL, and Vulkan

This problem is often solved through the use of a transpiler, a program that can translate a shader written in one language into another.

HLSL2GLSL is one such example that was used in Unity up until 2016. Shaders could be authored in a standard HLSL syntax, then transpiled at build time into corresponding GLSL code.

SPIRV-Cross is another transpiler maintained by the Unity team that can serve as a bridge between HLSL, GLSL, MSL, and Vulkan.

Using an existing shader language as your source helps you avoid the overhead of designing a brand new one from scratch, and you can leverage a lot of work shared by other teams via projects like the ones linked above.

There are some extra considerations though, as outlined in the SPIRV-Cross Readme:

Implementation notes

When using SPIR-V and SPIRV-Cross as an intermediate step for cross-compiling between high level languages there are some considerations to take into account, as not all features used by one high-level language are necessarily supported natively by the target shader language. SPIRV-Cross aims to provide the tools needed to handle these scenarios in a clean and robust way, but some manual action is required to maintain compatibility.

The areas they call out include:

  • HLSL source to GLSL
    • HLSL entry points
    • Vertex/Fragment interface linking
  • HLSL source to legacy GLSL/ESSL
    • Separate image samplers (HLSL/Vulkan) for backends which do not support it (GLSL)
    • Descriptor sets (Vulkan GLSL) for backends which do not support them (HLSL/GLSL/Metal)
    • Linking by name for targets which do not support explicit locations (legacy GLSL/ESSL)
    • Clip-space conventions
    • Reserved identifiers

See the linked document for all the gory details of how to handle these situations.

I will write 1000+ SEO friendly & plagiarism free content for $3

I will write 1000+ SEO friendly & plagiarism free content

Blogging is one of the most effective ways to build brand awareness and convert traffic

into customers. But you need the quality content that propels your blog or site

to the top of the food chain.

As an experienced marketing expert, I understand the importance of enhancing inbound

traffic through blogging, to get more website visitors and more sales!

I can guarantee that my articles will be delivered well-structured and fully

optimized for search engines.

This gig includes:

  • 1000+words SEO optimized content
  • 100%unique, original, informative
  • NoSpelling & Grammar error
  • Deeply researched
  • 100%plagiarism free genuine content
  • Readability
  • Unlimited revision
  • Keyword focused

Why hire me:

  • Fluent in English
  • Well-optimized content
  • On-time delivery
  • 24/7hours service

It’s your time to rank on Google’s no 1 page. Now, Let’s create something different



8 – Do i need write access to the files directory to migrate d7_file?

I’m migrating a site from drupal 7 to 8. It has many many media files. Something like 6TB worth. And adding daily. So i want to do the db migration on my machine (not the webserver), work out kinks and modify custom code to work w/ d8, then do the real thing on the live machine over a slow weekend when i have all the steps worked out.

In the migration process, i’ve gotten to drush migrate-upgrade d7_node, and it (on initial run, with only a token few files in /sites/default/files) created a handful of db entries in file_managed. So i sshfs mounted the live files directory read only from my machine and re-ran migrate-upgrade d7_node from the restored db. Now it doesn’t create anything in the file_managed table, so i suspect it’s not working, but it gives no errors, and some grepping doesn’t readily yield the code that does this work. I wouldn’t mind hacking for this part only.

Hence the question. And what can i do alternatively to avoid copying 6TB of files for the preparatory migration?


house rules – How can I write a formula for this houseruled roll in AnyDice?

The trick to modelling these kinds of dice pool mechanics efficiently in AnyDice is to make use of the fact that each die in the pool is rolled and counted (and possibly rerolled) independently of the others.

This allows us to first calculate the probability distribution of successes for a single die of each size, and save it as an AnyDice “custom die”. We can then add together any combination of these custom dice to get the distribution of successes for any dice pool.

So, let’s see how to actually do that. First, we need a function that will calculate the success distribution for one die. If we didn’t have the explosion mechanic, this would be really easy to do — just something like:

function: roll ROLL:n target TARGET:n {
  result: ROLL >= TARGET

output (roll d6 target 5) named "single d6, no explosions"

The trick here is that, when you call a function expecting a numeric parameter (i.e. one marked with :n) but actually pass in a die (like d6) instead, AnyDice will automatically call your function for every possible result of rolling the die and collect the results into a new custom die.

Actually, for the simple example above we could’ve just done output d6 >= 5 and skipped the function entirely. But we’re going to need a function to implement the explosion mechanic anyway. The new trick there is that we can have the function call itself recursively when an explosion occurs, e.g. like this:

function: roll ROLL:n target TARGET:n explode MAX:n limit LIMIT:n { 
  if ROLL = MAX & LIMIT > 0 {
    result: (ROLL >= TARGET) + (roll dMAX target TARGET explode MAX limit LIMIT-1)
  } else {
    result: (ROLL >= TARGET)

output (roll d6 target 5 explode 6 limit 3) named "single d6, max 3 explosions"

Note how I’m reducing the LIMIT parameter by one for every nested function call, thus ensuring that the rerolls will stop when the limit goes down to 0. Also note that I’m using the MAX parameter for two different purposes: both to specify the roll on which a reroll should happen and to define the size of the die used for the reroll. I could’ve used separate parameters for those, but that would’ve made the function call even more verbose.

Anyway, now that we have a function that lets us roll a single die of any size and count the number of successes, we can do the for each of the die sizes and save the results as custom dice:


SIX: (roll d6 target 5 explode 6 limit PROTAGONISM)
EIGHT: (roll d8 target 5 explode 8 limit PROTAGONISM)
TEN: (roll d10 target 5 explode 10 limit PROTAGONISM)

And then we can roll any combination of those custom dice that we want to get the distribution of success counts:

output 2dSIX + 2dEIGHT + 1dTEN named "2d6 + 2d8 + 1d10, protagonism (PROTAGONISM)"

And there we have it. Here’s what the output of the complete program looks like:

AnyDice screenshot

One minor detail worth noting in the complete program linked above is that I also added in the line:

set "maximum function depth" to PROTAGONISM + 1

Normally AnyDice limits the number of nested function calls to 10, and it turns out that this isn’t quite enough if you set PROTAGONISM to 10. Setting the limit to one more than the protagonism value is sufficient for our purposes.

However, it also turns out that the protagonism value really doesn’t have all that much effect is practice. For example, if we run the code above in a loop for all protagonism values from 1 to 5 and plot the results as graphs, they look like this:

AnyDice graph mode screenshot

Notice how all the graphs are basically drawn right on top of each other, and that the mean success count shown in the legend is also almost the same for all of them (approximately 2.56 for protagonism 1, 2.60 for protagonism 2 and 2.61 for all higher values).

Basically this is because getting more than one reroll in a row is very unlikely — a one in 36 chance for two consecutive rerolls on a d6, less for bigger dice and much less for longer chains of rerolls. So basically, while it might feel really awesome to get the rare triple explosion on a roll, it happens so rarely that it doesn’t really make any difference to the averages. And with your success counting mechanic, the reward isn’t even all that much — all a reroll gives you is a (chance for) a single extra success point, which may not even make any difference if you’re not just under the difficulty target.

Honestly, I’d recommend either rethinking the protagonism mechanic to give better rewards, or get rid of it completely and just allow unlimited rerolls.

I will write a SEO optimized unique content and article for $10

I will write a SEO optimized unique content and article

Are you looking for a content writer?

Blog Articles: I have generated topics, researched, written, and edited many blog articles for a wide variety of industries.

✔️Web Content: By taking a research-oriented approach, I have an established process for creating customized web content for business sites. Web content can include Home pages, About Us, FAQs, Meet the Staff, service and product descriptions, and more.

✔️ SEO Writing: With a strong foundation in search engine optimization, I take appropriate keywords and use them to create effective yet engaging content for sites and blogs.

Industries served include:

– Technology

– Health and Wellbeing

– Education

– Real Estate

– Marketing

– Automotive

– Sports (Especially football, baseball, basketball)

– Fishing (Freshwater, saltwater, fly fishing)

Here are the reasons why you should order articles from me! I’m not just limited to article writing, but also to website content writing, press release writing, eBook writing, and many more!

  • SEO friendly
  • Well-researched
  • 100% unique and Copyscape safe
  • Professional writing
  • Customer satisfaction guaranteed


I will write 5 brilliant 500 word SEO articles for $20

I will write 5 brilliant 500 word SEO articles

If your looking well-researched Articles, SEO Articles or blog post for your website with correct grammar and entirely original content then you are at right place.

There are no worries about plagiarism because the content will be entirely produced by me.

I can write articles on Travel, Food, Creative Business, Lifestyle, Entertainment, Beauty, Fashion, Health, Internet, Technology, Sports, Football, Adult, Recreation, Retail and Commerce, or Finance and Law.

You will NOT regret handing me an order, trust me.