text:
Q: Why aren't class template constructor arguments automatically determined? Consider the following class:
template<typename T1, typename T2>
class Pair
{
     public:
         T1 First;
         T2 Second;
         Pair(const T1 &First, const T2 &Second) : First(First), Second(Second) { }
}

The following is not allowed in c++:
auto p = Pair(10, 10);

Why isn't that allowed? the types can be completely determined from the constructor call.
I know there are workaround for that like:
template<typename T1, typename T2>
Pair<T1, T2> MakePair(const T1 &First, const T2 &Second)
{
    return Pair<T1, T2>(First, Second);
}

But why is that needed? Why doesn't the compiler just determine the type from the arguments just like it does from function template? You might say its because the standard doesn't allow it, so why doesn't the standard allow it?
Edit:
For those who say this is an example why this shouldn't be allowed:
template<typename T1, typename T2>
class Pair
{
     public:
         T1 First;
         T2 Second;
         Pair(const T1 &First, const T2 &Second) : First(First), Second(Second) { }
         Pair(const T2 &Second, const T1 &First) : First(First), Second(Second) { }
};

auto p = Pair(10,1.0);

I can do exactly this with function templates overloading:
template<typename T1, typename T2>
Pair<T1, T2> MakePair(const T1 &First, const T2 &Second)
{
    return Pair<T1, T2>(First, Second);
}
template<typename T1, typename T2>
Pair<T1, T2> MakePair(const T2 &Second, const T1 &First)
{
    return Pair<T1, T2>(First, Second);
}

Why is this allowed for functions but not for classes?

A: Consider the following.
template<typename T1, typename T2>
class Pair
{
     public:
         T1 First;
         T2 Second;
         Pair(const T1 &First, const T2 &Second) : First(First), Second(Second) { }
         Pair(const T2 &Second, const T1 &First) : First(First), Second(Second) { }
};

auto p = Pair(10,1.0);

Should p be a Pair<int,double> or a Pair<double,int>?

A: More is not generally better. When you have to design a system, you have to be careful with how the different features interact, and should opt for the cleanest simplest solution that provides the most to the users. The typical questions start with, what will the feature offer the users, what cost will the feature require and what problems might the feature bring.
In this case, providing type deduction helps in that you can skip providing the type when declaring a variable or when calling a constructor directly:
pair p = pair( 10, 20 );

The declaration of the variable can be done with auto, so it is no longer a problem, but it could have been the motivating reason for this feature. In the case of the call to the constructor the added value is quite limited, you can provide a named constructor, as there is in the standard library:
auto p = make_pair( 10, 20 );

So at the end of the day, the added value on being able to call the constructor directly is actually limited, as you can always provide a named function that will create the object for you. Note that the potential extra copies are optimized away, which means that there is no extra cost in calling make_pair vs. directly calling the constructor `pair(10,20)
Now, focus on the negative implications that the feature can have in user code. The feature would be usable in only some cases, where there are no competing constructor overloads, in the same way that it finds the best overload for a function template, but more importantly specializations. The compiler would have to lookup all potential specializations of the class template, and determine the set of constructors that each one of them offers, and then it would have to resolve the best constructor overload and the enclosing class template.
Looking back to the particular example that you provided, there are no specializations for std::pair, so we are in the simple case, and yet the example code above would fail:
pair p = pair( 10, 20 );

Why? Well, this is actually the problem, this feature would bring quite a bit of confusion to users. As I mentioned, the right-hand-side of the expression can be easily resolved with plain overload resolution (assuming that there are no specializations), and it would deduce the arguments to be int, both of them. So the first step would deduce the expression to:
pair p = pair<int,int>(10,20);

Now, that is equivalent to pair p( pair<int,int>( 10, 20 ) ), and we need the second step of resolution, and at this point, the compiler will see that there is a templated constructor:
template <typename first_type, typename second_type>
struct pair {
   first_type first;
   second_type second;

   template <typename U, typename V>
   pair( U f, V s ) : first(f), second(s) {}
};

That means that every potential instantiation of std::pair<T,U> has a perfect match for that constructor call, and the compiler cannot select, nor provide any sensible error message other than ambiguous in too many ways.
Now imagine coming to your favorite Q&A forum on the internet and guess how many questions would arise from this type of details. Ignoring the cost of implementing the feature, the result of having it in the language is that the language would be more complex and harder to write, it would impose an even steeper learning curve, and all that for basically no real value: in the cases where deduction can be applied, it is trivial to write a helper function that will provide the same advantages, like make_pair with no added cost.
The fact that you must provide the types takes away complexity from the user: there is no need to think on whether the compiler will be able to deduce the correct type for me. Not having to focus on these details leaves you more time to think on the actual problem that you want to solve.
Sometimes less is better.
BTW, auto resolves this in the most trivial way: it does not need to find a constructor that will match and guess the type from it, but just use the type of the right-hand-side expression, which is much simpler: only works with a single object, and uses that type for the new object. And even then, with the much simplified use case, it was discussed back and forth until a solution was agreed upon, with the details being whether deduction for auto could be used to create references, or whether const or volatile would be part of the deduced type...
Just a thought: without using a compiler, what is the type of the expression std::min( 10, 5.0 )?

A: This is what Bjarne Stroustrup has to say on the matter:

Note that class template arguments are never deduced. The reason is
  that the flexibility provided by several constructors for a class
  would make such deduction impossible in many cases and obscure in many
  more.


text:
Q: Set a cookie in jQuery How can I set a cookie when a background color is changed? I created a basic switcher which  changes the body color, but I want to save the changed color in a cookie.
Any Idea?
jQuery code:
    $('.first li').click(function(){
        var src = $(this).find('img').attr('src');
       $('body').css('background','url('+src+')');
     });

Demo here

A: Please add the following plugin to your page: https://github.com/carhartl/jquery-cookie
Now you can do the following:
Create cookie:
$.cookie('the_cookie', 'the_value');

Read cookie:
$.cookie('the_cookie');

A: You can use an HTML5 localStorage and will works
    window.localStorage.setItem("color_fondo",color);
    document.body.style.backgroundColor =  color;

A: Insert this line at the end of your function.
document.cookie = 'userColor="' + document.body.style.background + '"';

redpajama_set_name: RedPajamaStackExchange


text:
Q: Oracle- relying on ROLLBACK for data validation Is relying on the oracle ROLLBACK command good practice for importing data, validating the data and THEN performing a ROLLBACK?
I've had a data import program built for our ERP, and looking at the code, they insert the data into the real tables, validate, and if it fails validation, they perform a ROLLBACK. I've always validated data before inserting, but just curious if this is an accepted method to rely on?

A: There are a few things to remember here-

*

*Constraints enable us preserve data integrity. This means that constraints allow us to enforce business rules (or at least the most basic of those) at the database level itself.

*A commit or a rollback is a method of preserving or undoing the changes made in a transaction. If you issue a commit after a series of successfully run DML statements, the changes are preserved. The rollback statement would undo the changes.

*If, in a series of DML statements, if one of those fails, the effects of that particular statement are rolled back. E.g., if an UPDATE statement updates 10 rows and one of those violates a vital constraint, any of the 10 rows are not updated. Yet, the effects of its preceding statements are not implicitly rolled back.

*In order to preserve data integrity and keep the data as per the business requirements, you must issue a manual ROLLBACK statement if any of the DMLs fail.

*What you are seeing in your program is the same practice. It doesn't issue a ROLLBACK after a successful transaction, but only after a failed DML, if you look at the code closely. This is indeed a good practice to roll back on failure and commit only if everything goes right.

*Front end checks on data are indeed an essential part of any application. This ensures that the data being entered conforms to the business roles. Even in this case, constraints must be applied to perform checks at the database level. This is particularly helpful when some rookie makes changes to the front end and tries to enter invalid data. This is also helpful when someone is bypassing the application and entering data manually. Hence putting constraints on the database level is always necessary.


text:
Q: Bootstrap popover top-right corner always on top How can I make my popover display in the top-right corner of the page, without it being connected with an arrow to the button, kind of like a popup? Should I use something else than a popover?
<button type="button" class="btn btn-default" title="Help" data-toggle="popover"  data-content="423241421453453"></button>

A: You can do this:
CSS
.popover{
    position: absolute;
    top:0;
    right:0;
    left: 80% !important;

}

.popover .arrow{
    display:none;
}

Adjust your needs
DEMO HERE

A: You can only use the following positions for popovers:
Left positioned popover:
data-placement="left"

Right positioned popover:
data-placement="right"

Top positioned popover:
data-placement="top"

Bottom positioned popover:
data-placement="bottom"

See: http://getbootstrap.com/javascript/#popovers
Or change the CSS to
.popover{
    position: absolute;
    top:0;
    right:0;
    left: 80% !important;
}

.popover .arrow{
    display:none;
}


text:
Q: How I Can Search Unknown Folders in S3 Bucket. I Have millions of object in my bucket I only want Folder List? I Have a bucket with 3 million objects. I Even don't know how many folders are there in my S3 bucket and even don't know the names of folders in my bucket.I want to show only list of folders of AWS s3. Is there any way to get list of all folders ?

A: I would use AWS CLI for this. To get started - have a look here.
Then it is a matter of almost standard linux commands (ls):
aws s3 ls s3://<bucket_name>/path/to/search/folder/ --recursive | grep '/$' > folders.txt

where:
grep command just reads what aws s3 ls command has returned and searches for entries with ending /.
ending  > folders.txt saves output to a file.
Note: grep (if I'm not wrong) is unix only utility command. But I believe, you can achieve this on windows as well.
Note 2: depending on the number of files there this operation might (will) take a while.
Note 3: usually in systems like AWS S3, term folder is there only for user to maintain visual similarity with standard file systems however inside it does treat it as a part of a key. You can see in your (web) console when you filter by "prefix".

A: Amazon S3 buckets with large quantities of objects are very difficult to use. The API calls that list bucket contents are limited to returning 1000 objects per API call. While it is possible to request 'folders' (by using Delimiter='/' and looking at CommonPrefixes), this would take repeated calls to obtain the hierarchy.
Instead, I would recommend using Amazon S3 Inventory, which can provide a daily or weekly CSV file listing all objects. You can then play with that CSV file from code (or possibly Excel? Might be too big?) to obtain your desired listings.
Just be aware that doing anything on that bucket will not be fast.


text:
Q: Efficiently dividing unsigned value by a power of two, rounding up I want to implement unsigneda integer division by an arbitrary power of two, rounding up, efficiently. So what I want, mathematically, is ceiling(p/q)0. In C, the strawman implementation, which doesn't take advantage of the restricted domain of q could something like the following function1:
/** q must be a power of 2, although this version works for any q */
uint64_t divide(uint64_t p, uint64_t q) {
  uint64_t res = p / q;
  return p % q == 0 ? res : res + 1;
}

... of course, I don't actually want to use division or mod at the machine level, since that takes many cycles even on modern hardware. I'm looking for a strength reduction that uses shifts and/or some other cheap operation(s) - taking advantage of the fact that q is a power of 2.
You can assume we have an efficient lg(unsigned int x) function, which returns the base-2 log of x, if x is a power-of-two.
Undefined behavior is fine if q is zero.
Please note that the simple solution: (p+q-1) >> lg(q) doesn't work in general - try it with p == 2^64-100 and q == 2562 for example.
Platform Details
I'm interested in solutions in C, that are  likely to perform well across a variety of platforms, but for the sake of concreteness, awarding the bounty and because any definitive discussion of performance needs to include a target architecture, I'll be specific about how I'll test them:

*

*Skylake CPU

*gcc 5.4.0 with compile flags -O3 -march=haswell
Using gcc builtins (such as bitscan/leading zero builtins) is fine, and in particular I've implemented the lg() function I said was available as follows:
inline uint64_t lg(uint64_t x) {
  return 63U - (uint64_t)__builtin_clzl(x);
}

inline uint32_t lg32(uint32_t x) {
  return 31U - (uint32_t)__builtin_clz(x);
}

I verified that these compile down to a single bsr instruction, at least with -march=haswell, despite the apparent involvement of a subtraction. You are of course free to ignore these and use whatever other builtins you want in your solution.
Benchmark
I wrote a benchmark for the existing answers, and will share and update the results as changes are made.
Writing a good benchmark for a small, potentially inlined operation is quite tough. When code is inlined into a call site, a lot of the work of the function may disappear, especially when it's in a loop3.
You could simply avoid the whole inlining problem by ensuring your code isn't inlined: declare it in another compilation unit. I tried to that with the bench binary, but really the results are fairly pointless. Nearly all implementations tied at 4 or 5 cycles per call, but even a dummy method that does nothing other than return 0 takes the same time. So you are mostly just measuring the call + ret overhead. Furthermore, you are almost never really going to use the functions like this - unless you messed up, they'll be available for inlining and that changes everything.
So the two benchmarks I'll focus the most on repeatedly call the method under test in a loop, allowing inlining, cross-function optmization, loop hoisting and even vectorization.
There are two overall benchmark types: latency and throughput. The key difference is that in the latency benchmark, each call to divide is dependent on the previous call, so in general calls cannot be easily overlapped4:
uint32_t bench_divide_latency(uint32_t p, uint32_t q) {
    uint32_t total = p;
    for (unsigned i=0; i < ITERS; i++) {
      total += divide_algo(total, q);
      q = rotl1(q);
    }
    return total;
  }

Note that the running total depends so on the output of each divide call, and that it is also an input to the divide call.
The throughput variant, on the other hand, doesn't feed the output of one divide into the subsequent one. This allows work from one call to be overlapped with a subsequent one (both by the compiler, but especially the CPU), and even allows vectorization:
uint32_t bench_divide_throughput(uint32_t p, uint32_t q) {
    uint32_t total = p;
    for (unsigned i=0; i < ITERS; i++) {
      total += fname(i, q);
      q = rotl1(q);
    }
    return total;
  }

Note that here we feed in the loop counter as the the dividend - this is variable, but it doesn't depend on the previous divide call.
Furthermore, each benchmark has three flavors of behavior for the divisor, q:

*

*Compile-time constant divisor. For example, a call to divide(p, 8). This is common in practice, and the code can be much simpler when the divisor is known at compile time.

*Invariant divisor. Here the divisor is not know at compile time, but is constant for the whole benchmarking loop. This allows a subset of the optimizations that the compile-time constant does.

*Variable divisor. The divisor changes on each iteration of the loop. The benchmark functions above show this variant, using a "rotate left 1" instruction to vary the divisor.

Combining everything you get a total of 6 distinct benchmarks.
Results
Overall
For the purposes of picking an overall best algorithm, I looked at each of 12 subsets for the proposed algorithms: (latency, throughput) x (constant a, invariant q, variable q) x (32-bit, 64-bit) and assigned a score of 2, 1, or 0 per subtest as follows:

*

*The best algorithm(s) (within 5% tolerance) receive a score of 2.

*The "close enough" algorithms (no more than 50% slower than the best) receive a score of 1.

*The remaining algorithms score zero.

Hence, the maximum total score is 24, but no algorithm achieved that. Here are the overall total results:
╔═══════════════════════╦═══════╗
║       Algorithm       ║ Score ║
╠═══════════════════════╬═══════╣
║ divide_user23_variant ║    20 ║
║ divide_chux           ║    20 ║
║ divide_user23         ║    15 ║
║ divide_peter          ║    14 ║
║ divide_chrisdodd      ║    12 ║
║ stoke32               ║    11 ║
║ divide_chris          ║     0 ║
║ divide_weather        ║     0 ║
╚═══════════════════════╩═══════╝

So the for the purposes of this specific test code, with this specific compiler and on this platform, user2357112 "variant" (with ... + (p & mask) != 0) performs best, tied with chux's suggestion (which is in fact identical code).
Here are all the sub-scores which sum to the above:
╔══════════════════════════╦═══════╦════╦════╦════╦════╦════╦════╗
║                          ║ Total ║ LC ║ LI ║ LV ║ TC ║ TI ║ TV ║
╠══════════════════════════╬═══════╬════╬════╬════╬════╬════╬════╣
║ divide_peter             ║     6 ║  1 ║  1 ║  1 ║  1 ║  1 ║  1 ║
║ stoke32                  ║     6 ║  1 ║  1 ║  2 ║  0 ║  0 ║  2 ║
║ divide_chux              ║    10 ║  2 ║  2 ║  2 ║  1 ║  2 ║  1 ║
║ divide_user23            ║     8 ║  1 ║  1 ║  2 ║  2 ║  1 ║  1 ║
║ divide_user23_variant    ║    10 ║  2 ║  2 ║  2 ║  1 ║  2 ║  1 ║
║ divide_chrisdodd         ║     6 ║  1 ║  1 ║  2 ║  0 ║  0 ║  2 ║
║ divide_chris             ║     0 ║  0 ║  0 ║  0 ║  0 ║  0 ║  0 ║
║ divide_weather           ║     0 ║  0 ║  0 ║  0 ║  0 ║  0 ║  0 ║
║                          ║       ║    ║    ║    ║    ║    ║    ║
║ 64-bit Algorithm         ║       ║    ║    ║    ║    ║    ║    ║
║ divide_peter_64          ║     8 ║  1 ║  1 ║  1 ║  2 ║  2 ║  1 ║
║ div_stoke_64             ║     5 ║  1 ║  1 ║  2 ║  0 ║  0 ║  1 ║
║ divide_chux_64           ║    10 ║  2 ║  2 ║  2 ║  1 ║  2 ║  1 ║
║ divide_user23_64         ║     7 ║  1 ║  1 ║  2 ║  1 ║  1 ║  1 ║
║ divide_user23_variant_64 ║    10 ║  2 ║  2 ║  2 ║  1 ║  2 ║  1 ║
║ divide_chrisdodd_64      ║     6 ║  1 ║  1 ║  2 ║  0 ║  0 ║  2 ║
║ divide_chris_64          ║     0 ║  0 ║  0 ║  0 ║  0 ║  0 ║  0 ║
║ divide_weather_64        ║     0 ║  0 ║  0 ║  0 ║  0 ║  0 ║  0 ║
╚══════════════════════════╩═══════╩════╩════╩════╩════╩════╩════╝

Here, each test is named like XY, with X in {Latency, Throughput} and Y in {Constant Q, Invariant Q, Variable Q}. So for example, LC is "Latency test with constant q".
Analysis
At the highest level, the solutions can be roughly divided into two categories: fast (the top 6 finishers) and slow (the bottom two). The difference is larger: all of the fast algorithms were the fastest on at least two subtests and in general when they didn't finish first they fell into the "close enough" category (they only exceptions being failed vectorizations in the case of stoke and chrisdodd). The slow algorithms however scored 0 (not even close) on every test.  So you can mostly eliminate the slow algorithms from further consideration.
Auto-vectorization
Among the fast algorithms, a large differentiator was the ability to auto-vectorize.
None of the algorithms were able to auto-vectorize in the latency tests, which makes sense since the latency tests are designed to feed their result directly into the next iteration. So you can really only calculate results in a serial fashion.
For the throughput tests, however, many algorithms were able to auto-vectorize for the constant Q and invariant Q case. In both of these tests tests the divisor q is loop-invariant (and in the former case it is a compile-time constant). The dividend is the loop counter, so it is variable, but predicable (and in particular a vector of dividends can be trivially calculated by adding 8 to the previous input vector: [0, 1, 2, ..., 7] + [8, 8, ..., 8] == [8, 9, 10, ..., 15]).
In this scenario, gcc was able to vectorize peter, stoke, chux, user23 and user23_variant. It wasn't able to vectorize chrisdodd for some reason, likely because it included a branch (but conditionals don't strictly prevent vectorization since many other solutions have conditional elements but still vectorized). The impact was huge: algorithms that vectorized showed about an 8x improvement in throughput over variants that didn't but were otherwise fast.
Vectorization isn't free, though! Here are the function sizes for the "constant" variant of each function, with the Vec? column showing whether a function vectorized or not:
Size Vec? Name
 045    N bench_c_div_stoke_64
 049    N bench_c_divide_chrisdodd_64
 059    N bench_c_stoke32_64
 212    Y bench_c_divide_chux_64
 227    Y bench_c_divide_peter_64
 220    Y bench_c_divide_user23_64
 212    Y bench_c_divide_user23_variant_64

The trend is clear - vectorized functions take about 4x the size of the non-vectorized ones. This is both because the core loops themselves are larger (vector instructions tend to be larger and there are more of them), and because loop setup and especially the post-loop code is much larger: for example, the vectorized version requires a reduction to sum all the partial sums in a vector. The loop count is fixed and a multiple of 8, so no tail code is generated - but if were variable the generated code would be even larger.
Furthermore, despite the large improvement in runtime, gcc's vectorization is actually poor. Here's an excerpt from the vectorized version of Peter's routine:
  on entry: ymm4 == all zeros
  on entry: ymm5 == 0x00000001 0x00000001 0x00000001 ...
  4007a4:       c5 ed 76 c4             vpcmpeqd ymm0,ymm2,ymm4
  4007ad:       c5 fd df c5             vpandn   ymm0,ymm0,ymm5
  4007b1:       c5 dd fa c0             vpsubd   ymm0,ymm4,ymm0
  4007b5:       c5 f5 db c0             vpand    ymm0,ymm1,ymm0

This chunk works independently on 8 DWORD elements originating in ymm2. If we take x to be a single DWORD element of ymm2, and y the incoming value of ymm1 these foud instructions correspond to:
                    x == 0   x != 0
x  = x ? 0 : -1; //     -1        0
x  = x & 1;      //      1        0
x  = 0 - x;      //     -1        0
x  = y1 & x;     //     y1        0

So the first three instructions could simple be replaced by the first one, as the states are identical in either case. So that's two cycles added to that dependency chain (which isn't loop carried) and two extra uops. Evidently gcc's optimization phases somehow interact poorly with the vectorization code here, since such trivial optimizations are rarely missed in scalar code. Examining the other vectorized versions similarly shows a lot of performance dropped on the floor.
Branches vs Branch-free
Nearly all of the solutions compiled to branch-free code, even if C code had conditionals or explicit branches. The conditional portions were small enough that the compiler generally decided to use conditional move or some variant. One exception is chrisdodd which compiled with a branch (checking if p == 0) in all the throughput tests, but none of the latency ones. Here's a typical example from the constant q  throughput test:
0000000000400e60 <bench_c_divide_chrisdodd_32>:
  400e60:       89 f8                   mov    eax,edi
  400e62:       ba 01 00 00 00          mov    edx,0x1
  400e67:       eb 0a                   jmp    400e73 <bench_c_divide_chrisdodd_32+0x13>
  400e69:       0f 1f 80 00 00 00 00    nop    DWORD PTR [rax+0x0]
  400e70:       83 c2 01                add    edx,0x1
  400e73:       83 fa 01                cmp    edx,0x1
  400e76:       74 f8                   je     400e70 <bench_c_divide_chrisdodd_32+0x10>
  400e78:       8d 4a fe                lea    ecx,[rdx-0x2]
  400e7b:       c1 e9 03                shr    ecx,0x3
  400e7e:       8d 44 08 01             lea    eax,[rax+rcx*1+0x1]
  400e82:       81 fa 00 ca 9a 3b       cmp    edx,0x3b9aca00
  400e88:       75 e6                   jne    400e70 <bench_c_divide_chrisdodd_32+0x10>
  400e8a:       c3                      ret
  400e8b:       0f 1f 44 00 00          nop    DWORD PTR [rax+rax*1+0x0]

The branch at 400e76 skips the case that p == 0. In fact, the compiler could have just peeled the first iteration out (calculating its result explicitly) and then avoided the jump entirely since after that it can prove that p != 0. In these tests, the branch is perfectly predictable, which could give an advantage to code that actually compiles using a branch (since the compare & branch code is essentially out of line and close to free), and is a big part of why chrisdodd wins the throughput, variable q case.
Detailed Test Results
Here you can find some detailed test results and some details on the tests themselves.
Latency
The results below test each algorithm over 1e9 iterations. Cycles are calculated simply by multiplying the time/call by the clock frequency. You can generally assume that something like 4.01 is the same as 4.00, but the larger deviations like 5.11 seem to be real and reproducible.
The results for divide_plusq_32 use (p + q - 1) >> lg(q) but are only shown for reference, since this function fails for large p + q. The results for dummy are a very simple function: return p + q, and lets you estimate the benchmark overhead5 (the addition itself should take a cycle at most).
==============================
Bench: Compile-time constant Q
==============================
                  Function         ns/call    cycles
           divide_peter_32            2.19      5.67
           divide_peter_64            2.18      5.64
                stoke32_32            1.93      5.00
                stoke32_64            1.97      5.09
              stoke_mul_32            2.75      7.13
              stoke_mul_64            2.34      6.06
              div_stoke_32            1.94      5.03
              div_stoke_64            1.94      5.03
            divide_chux_32            1.55      4.01
            divide_chux_64            1.55      4.01
          divide_user23_32            1.97      5.11
          divide_user23_64            1.93      5.00
  divide_user23_variant_32            1.55      4.01
  divide_user23_variant_64            1.55      4.01
       divide_chrisdodd_32            1.95      5.04
       divide_chrisdodd_64            1.93      5.00
           divide_chris_32            4.63     11.99
           divide_chris_64            4.52     11.72
         divide_weather_32            2.72      7.04
         divide_weather_64            2.78      7.20
           divide_plusq_32            1.16      3.00
           divide_plusq_64            1.16      3.00
           divide_dummy_32            1.16      3.00
           divide_dummy_64            1.16      3.00

==============================
Bench: Invariant Q
==============================
                  Function         ns/call    cycles
           divide_peter_32            2.19      5.67
           divide_peter_64            2.18      5.65
                stoke32_32            1.93      5.00
                stoke32_64            1.93      5.00
              stoke_mul_32            2.73      7.08
              stoke_mul_64            2.34      6.06
              div_stoke_32            1.93      5.00
              div_stoke_64            1.93      5.00
            divide_chux_32            1.55      4.02
            divide_chux_64            1.55      4.02
          divide_user23_32            1.95      5.05
          divide_user23_64            2.00      5.17
  divide_user23_variant_32            1.55      4.02
  divide_user23_variant_64            1.55      4.02
       divide_chrisdodd_32            1.95      5.04
       divide_chrisdodd_64            1.93      4.99
           divide_chris_32            4.60     11.91
           divide_chris_64            4.58     11.85
         divide_weather_32           12.54     32.49
         divide_weather_64           17.51     45.35
           divide_plusq_32            1.16      3.00
           divide_plusq_64            1.16      3.00
           divide_dummy_32            0.39      1.00
           divide_dummy_64            0.39      1.00

==============================
Bench: Variable Q
==============================
                  Function         ns/call    cycles
           divide_peter_32            2.31      5.98
           divide_peter_64            2.26      5.86
                stoke32_32            2.06      5.33
                stoke32_64            1.99      5.16
              stoke_mul_32            2.73      7.06
              stoke_mul_64            2.32      6.00
              div_stoke_32            2.00      5.19
              div_stoke_64            2.00      5.19
            divide_chux_32            2.04      5.28
            divide_chux_64            2.05      5.30
          divide_user23_32            2.05      5.30
          divide_user23_64            2.06      5.33
  divide_user23_variant_32            2.04      5.29
  divide_user23_variant_64            2.05      5.30
       divide_chrisdodd_32            2.04      5.30
       divide_chrisdodd_64            2.05      5.31
           divide_chris_32            4.65     12.04
           divide_chris_64            4.64     12.01
         divide_weather_32           12.46     32.28
         divide_weather_64           19.46     50.40
           divide_plusq_32            1.93      5.00
           divide_plusq_64            1.99      5.16
           divide_dummy_32            0.40      1.05
           divide_dummy_64            0.40      1.04

Throughput
Here are the results for the throughput tests. Note that many of the algorithms here were auto-vectorized, so the performance is relatively very good for those: a fraction of a cycle in many cases. One result is that unlike most latency results, the 64-bit functions are considerably slower, since vectorization is more effective with smaller element sizes (although the gap is larger that I would have expected).
==============================
Bench: Compile-time constant Q
==============================
                  Function         ns/call    cycles
                stoke32_32            0.39      1.00
            divide_chux_32            0.15      0.39
            divide_chux_64            0.53      1.37
          divide_user23_32            0.14      0.36
          divide_user23_64            0.53      1.37
  divide_user23_variant_32            0.15      0.39
  divide_user23_variant_64            0.53      1.37
       divide_chrisdodd_32            1.16      3.00
       divide_chrisdodd_64            1.16      3.00
           divide_chris_32            4.34     11.23
           divide_chris_64            4.34     11.24
         divide_weather_32            1.35      3.50
         divide_weather_64            1.35      3.50
           divide_plusq_32            0.10      0.26
           divide_plusq_64            0.39      1.00
           divide_dummy_32            0.08      0.20
           divide_dummy_64            0.39      1.00

==============================
Bench: Invariant Q
==============================
                  Function         ns/call    cycles
                stoke32_32            0.48      1.25
            divide_chux_32            0.15      0.39
            divide_chux_64            0.48      1.25
          divide_user23_32            0.17      0.43
          divide_user23_64            0.58      1.50
  divide_user23_variant_32            0.15      0.38
  divide_user23_variant_64            0.48      1.25
       divide_chrisdodd_32            1.16      3.00
       divide_chrisdodd_64            1.16      3.00
           divide_chris_32            4.35     11.26
           divide_chris_64            4.36     11.28
         divide_weather_32            5.79     14.99
         divide_weather_64           17.00     44.02
           divide_plusq_32            0.12      0.31
           divide_plusq_64            0.48      1.25
           divide_dummy_32            0.09      0.23
           divide_dummy_64            0.09      0.23

==============================
Bench: Variable Q
==============================
                  Function         ns/call    cycles
                stoke32_32            1.16      3.00
            divide_chux_32            1.36      3.51
            divide_chux_64            1.35      3.50
          divide_user23_32            1.54      4.00
          divide_user23_64            1.54      4.00
  divide_user23_variant_32            1.36      3.51
  divide_user23_variant_64            1.55      4.01
       divide_chrisdodd_32            1.16      3.00
       divide_chrisdodd_64            1.16      3.00
           divide_chris_32            4.02     10.41
           divide_chris_64            3.84      9.95
         divide_weather_32            5.40     13.98
         divide_weather_64           19.04     49.30
           divide_plusq_32            1.03      2.66
           divide_plusq_64            1.03      2.68
           divide_dummy_32            0.63      1.63
           divide_dummy_64            0.66      1.71

a At least by specifying unsigned we avoid the whole can of worms related to the right-shift behavior of signed integers in C and C++.
0 Of course, this notation doesn't actually work in C where / truncates the result so the ceiling does nothing. So consider that pseudo-notation rather than straight C.
1 I'm also interested solutions where all types are uint32_t rather than uint64_t.
2 In general, any p and q where p + q >= 2^64 causes an issue, due to overflow.
3 That said, the function should be in a loop, because the performance of a microscopic function that takes half a dozen cycles only really matters if it is called in a fairly tight loop.
4 This is a bit of a simplification - only the dividend p is dependent on the output of the previous iteration, so some work related to processing of q can still be overlapped.
5 Use such estimates with caution however - overhead isn't simply additive. If the overhead shows up as 4 cycles and some function f takes 5, it's likely not accurate to say the cost of the real work in f is 5 - 4 == 1, because of the way execution is overlapped.

A: The efficient way of dividing by a power of 2 for an unsigned integer in C is a right shift -- shifting right one divides by two (rounding down), so shifting right by n divides by 2n (rounding down).
Now you want to round up rather than down, which you can do by first adding 2n-1, or equivalently subtracting one before the shift and adding one after (except for 0).  This works out to something like:
unsigned ceil_div(unsigned d, unsigned e) {
    /* compute ceil(d/2**e) */
    return d ? ((d-1) >> e) + 1 : 0;
}

The conditional can be removed by using the boolean value of d for addition and subtraction of one:
unsigned ceil_div(unsigned d, unsigned e) {
    /* compute ceil(d/2**e) */
    return ((d - !!d) >> e) + !!d;
}

Due to its size, and the speed requirement, the function should be made static inline. It probably won't make a different for the optimizer, but the parameters should be const. If it must be shared among many files, define it in a header:
static inline unsigned ceil_div(const unsigned d, const unsigned e){...

A:
Efficiently dividing unsigned value by a power of two, rounding up

[Re-write] given OP's clarification concerning power-of-2.
The round-up or ceiling part is easy when overflow is not a concern.  Simple add q-1, then shift.
Otherwise as the possibility of rounding depends on all the bits of p smaller than q, detection of those bits is needed first before they are shifted out.
uint64_t divide_A(uint64_t p, uint64_t q) {
  bool round_up = p & (q-1);
  return (p >> lg64(q)) + round_up;
}

This assumes code has an efficient lg64(uint64_t x) function, which returns the base-2 log of x, if x is a power-of-two.`

A: My old answer didn't work if p was one more than a power of two (whoops). So my new solution, using the __builtin_ctzll() and __builtin_ffsll() functions0 available in gcc (which as a bonus, provides the fast logarithm you mentioned!):
uint64_t divide(uint64_t p,uint64_t q) {
    int lp=__builtin_ffsll(p);
    int lq=__builtin_ctzll(q);
    return (p>>lq)+(lp<(lq+1)&&lp);
}

Note that this is assuming that a long long is 64 bits. It has to be tweaked a little otherwise.
The idea here is that if we need an overflow if and only if p has fewer trailing zeroes than q. Note that for a power of two, the number of trailing zeroes is equal to the logarithm, so we can use this builtin for the log as well.
The &&lp part is just for the corner case where p is zero: otherwise it will output 1 here.
0 Can't use __builtin_ctzll() for both because it is undefined if p==0.

A: If the dividend/divisor can be guaranteed not to exceed 63 (or 31) bits, you can use the following version mentioned in the question.  Note how p+q could overflow if they use all 64 bit.  This would be fine if the SHR instruction shifted in the carry flag, but AFAIK it doesn't.
uint64_t divide(uint64_t p, uint64_t q) {
  return (p + q - 1) >> lg(q);
}

If those constraints cannot be guaranteed, you can just do the floor method and then add 1 if it would round up.  This can be determined by checking if any bits in the dividend are within the range of the divisor.
Note: p&-p extracts the lowest set bit on 2s complement machines or the BLSI instruction
uint64_t divide(uint64_t p, uint64_t q) {
  return (p >> lg(q)) + ( (p & -p ) < q );
}

Which clang compiles to:
    bsrq    %rax, %rsi
    shrxq   %rax, %rdi, %rax
    blsiq   %rdi, %rcx
    cmpq    %rsi, %rcx
    adcq    $0, %rax
    retq

That's a bit wordy and uses some newer instructions, so maybe there is a way to use the carry flag in the original version.  Lets see:
The RCR instruction does but seems like it would be worse ... perhaps the SHRD instruction... It would be something like this (unable to test at the moment)
    xor     edx, edx     ;edx = 0 (will store the carry flag)
    bsr     rcx, rsi     ;rcx = lg(q) ... could be moved anywhere before shrd
    lea     rax, [rsi-1] ;rax = q-1 (adding p could carry)
    add     rax, rdi     ;rax += p  (handle carry)
    setc    dl           ;rdx = carry flag ... or xor rdx and setc
    shrd    rax, rdx, cl ;rax = rdx:rax >> cl
    ret

1 more instruction, but should be compatible with older processors (if it works ... I'm always getting a source/destination swapped - feel free to edit)
Addendum:

I've implemented the lg() function I said was available as follows:
inline uint64_t lg(uint64_t x) {
  return 63U - (uint64_t)__builtin_clzl(x);
}

inline uint32_t lg32(uint32_t x) {
  return 31U - (uint32_t)__builtin_clz(x);
}

The fast log functions don't fully optimize to bsr on clang and ICC but you can do this:
#if defined(__x86_64__) && (defined(__clang__) || defined(__INTEL_COMPILER))
static inline uint64_t lg(uint64_t x){
  inline uint64_t ret;
  //other compilers may want bsrq here
  __asm__("bsr  %0, %1":"=r"(ret):"r"(x));
  return ret;
}
#endif

#if defined(__i386__) && (defined(__clang__) || defined(__INTEL_COMPILER))
static inline uint32_t lg32(uint32_t x){
  inline uint32_t ret;
  __asm__("bsr  %0, %1":"=r"(ret):"r"(x));
  return ret;
}
#endif

A: There has already been a lot of human brainpower applied to this problem, with several variants of great answers in C along with Peter Cordes's answer which covers the best you could hope for in asm, with notes on trying to map it back to C.
So while the humans are having their kick at the can, I thought see what some brute computing power has to say! To that end, I used Stanford's STOKE superoptimizer to try to find good solutions to the 32-bit and 64-bit versions of this problem.
Usually, a superoptimizer is usually something like a brute force search through all possible instruction sequences until you find the best one by some metric. Of course, with something like 1,000 instructions that will quickly spiral out of control for more than a few instructions1. STOKE, on the hand, takes a guided randomized approach: it randomly makes mutations to an existing candidate program, evaluating at each step a cost function that takes both performance and correctness into effect. That's the one-liner anyway - there are plenty of papers if that stoked your curiosity.
So within a few minutes STOKE found some pretty interesting solutions. It found almost all the high-level ideas in the existing solutions, plus a few unique ones. For example, for the 32-bit function, STOKE found this version:
neg rsi
dec rdi
pext rax, rsi, rdi
inc eax
ret

It doesn't use any leading/trailing-zero count or shift instructions at all. Pretty much, it uses neg esi to turn the divisor into a mask with 1s in the high bits, and then pext effectively does the shift using that mask. Outside of that trick it's using the same trick that user QuestionC used: decrement p, shift, increment p - but it happens to work even for zero dividend because it uses 64-bit registers to distinguish the zero case from the MSB-set large p case.
I added the C version of this algorithm to the benchmark, and added it to the results. It's competitive with the other good algorithms, tying for first in the "Variable Q" cases. It does vectorize, but not as well as the other 32-bit algorithms, because it needs 64-bit math and so the vectors can process only half as many elements at once.
Even better, in the 32-bit case it came up with a variety of solutions which use the fact that some of the intuitive solutions that fail for edge cases happen to "just work" if you use 64-bit ops for part of it. For example:
tzcntl ebp, esi
dec esi
add rdi, rsi
sarx rax, rdi, rbp
ret

That's the equivalent of the return (p + q - 1) >> lg(q) suggestion I mentioned in the question. That doesn't work in general since for large p + q it overflows, but for 32-bit p and q this solution works great by doing the important parts in 64-bit.  Convert that back into C with some casts and it actually figures out that using lea will do the addition in one instruction1:
stoke_32(unsigned int, unsigned int):
        tzcnt   edx, esi
        mov     edi, edi          ; goes away when inlining
        mov     esi, esi          ; goes away when inlining
        lea     rax, [rsi-1+rdi]
        shrx    rax, rax, rdx
        ret

So it's a 3-instruction solution when inlined into something that already has the values zero-extended into rdi and rsi.  The stand-alone function definition needs the mov instructions to zero-extend because that's how the SysV x64 ABI works.

For the 64-bit function it didn't come up with anything that blows away the existing solutions but it did come up with some neat stuff, like:
  tzcnt  r13, rsi
  tzcnt  rcx, rdi
  shrx   rax, rdi, r13
  cmp    r13b, cl
  adc    rax, 0
  ret

That guy counts the trailing zeros of both arguments, and then adds 1 to the result if q has fewer trailing zeros than p, since that's when you need to round up. Clever!
In general, it understood the idea that you needed to shl by the tzcnt really quickly (just like most humans) and then came up with a ton of other solutions to the problem of adjusting the result to account for rounding. It even managed to use blsi and bzhi in several solutions. Here's a 5-instruction solution it came up with:
tzcnt r13, rsi
shrx  rax, rdi, r13
imul  rsi, rax
cmp   rsi, rdi
adc   rax, 0
ret

It's a basically a "multiply and verify" approach - take the truncated res = p \ q, multiply it back  and if it's different than p add one: return res * q == p ? ret : ret + 1. Cool. Not really better than Peter's solutions though. STOKE seems to have some flaws in its latency calculation - it thinks the above has a latency of 5 - but it's more like 8 or 9 depending on the architecture. So it sometimes narrows in solutions that are based on its flawed latency calculation.

1 Interestingly enough though this brute force approach reaches its feasibility around 5-6 instructions: if you assume you can trim the instruction count to say 300 by eliminating SIMD and x87 instructions, then you would need ~28 days to try all 300 ^ 5 5 instruction sequences at 1,000,000 candidates/second. You could perhaps reduce that by a factor of 1,000 with various optimizations, meaning less than an hour for 5-instruction sequences and maybe a week for 6-instruction. As it happens, most of the best solutions for this problem fall into that 5-6 instruction window...
2 This will be a slow lea, however, so the sequence found by STOKE was still optimal for what I optimized for, which was latency.

A: You can do it like this, by comparing dividing n / d with dividing by (n-1) / d.
#include <stdio.h>

int main(void) {
    unsigned n;
    unsigned d;
    unsigned q1, q2;
    double actual;

    for(n = 1; n < 6; n++) {
        for(d = 1; d < 6; d++) {
            actual = (double)n / d;
            q1 = n / d;
            if(n) {
                q2 = (n - 1) / d;
                if(q1 == q2) {
                    q1++;
                }
            }
            printf("%u / %u = %u (%f)\n", n, d, q1, actual);
        }
    }

    return 0;
}

Program output:
1 / 1 = 1 (1.000000)
1 / 2 = 1 (0.500000)
1 / 3 = 1 (0.333333)
1 / 4 = 1 (0.250000)
1 / 5 = 1 (0.200000)
2 / 1 = 2 (2.000000)
2 / 2 = 1 (1.000000)
2 / 3 = 1 (0.666667)
2 / 4 = 1 (0.500000)
2 / 5 = 1 (0.400000)
3 / 1 = 3 (3.000000)
3 / 2 = 2 (1.500000)
3 / 3 = 1 (1.000000)
3 / 4 = 1 (0.750000)
3 / 5 = 1 (0.600000)
4 / 1 = 4 (4.000000)
4 / 2 = 2 (2.000000)
4 / 3 = 2 (1.333333)
4 / 4 = 1 (1.000000)
4 / 5 = 1 (0.800000)
5 / 1 = 5 (5.000000)
5 / 2 = 3 (2.500000)
5 / 3 = 2 (1.666667)
5 / 4 = 2 (1.250000)
5 / 5 = 1 (1.000000)

Update
I posted an early answer to the original question, which works, but did not consider the efficiency of the algorithm, or that the divisor is always a power of 2. Performing two divisions was needlessly expensive.
I am using MSVC 32-bit compiler on a 64-bit system, so there is no chance that I can provide a best solution for the required target. But it is an interesting question so I have dabbled around to find that the best solution will discover the bit of the 2**n divisor. Using the library function log2 worked but was so slow. Doing my own shift was much better, but still my best C solution is
unsigned roundup(unsigned p, unsigned q)
{
    return p / q + ((p & (q-1)) != 0);
}

My inline 32-bit assembler solution is faster, but of course that will not answer the question. I steal some cycles by assuming that eax is returned as the function value.
unsigned roundup(unsigned p, unsigned q)
{
    __asm {
        mov eax,p
        mov edx,q
        bsr ecx,edx     ; cl = bit number of q
        dec edx         ; q-1
        and edx,eax     ; p & (q-1)
        shr eax,cl      ; divide p by q, a power of 2
        sub edx,1       ; generate a carry when (p & (q-1)) == 0
        cmc
        adc eax,0       ; add 1 to result when (p & (q-1)) != 0
    }
}                       ; eax returned as function value

A: This seems efficient and works for signed if your compiler is using arithmetic right shifts (usually true).
#include <stdio.h>

int main (void)
{
    for (int i = -20; i <= 20; ++i) {
        printf ("%5d %5d\n", i, ((i - 1) >> 1) + 1);
    }
    return 0;
}

Use >> 2 to divide by 4, >> 3 to divide by 8, &ct.  Efficient lg does the work there.
You can even divide by 1!  >> 0

A: This answer is about what's ideal in asm; what we'd like to convince the compiler to emit for us.  (I'm not suggesting actually using inline asm, except as a point of comparison when benchmarking compiler output.  https://gcc.gnu.org/wiki/DontUseInlineAsm).
I did manage to get pretty good asm output from pure C for ceil_div_andmask, see below.  (It's worse than a CMOV on Broadwell/Skylake, but probably good on Haswell.  Still, the user23/chux version looks even better for both cases.)  It's mostly just worth mentioning as one of the few cases where I got the compiler to emit the asm I wanted.

It looks like Chris Dodd's general idea of return ((p-1) >> lg(q)) + 1 with special-case handling for d=0 is one of the best options.  I.e. the optimal implementation of it in asm is hard to beat with an optimal implementation of anything else.  Chux's (p >> lg(q))  +  (bool)(p & (q-1)) also has advantages (like lower latency from p->result), and more CSE when the same q is used for multiple divisions.  See below for a latency/throughput analysis of what gcc does with it.
If the same e = lg(q) is reused for multiple dividends, or the same dividend is reused for multiple divisors, different implementations can CSE more of the expression.  They can also effectively vectorize with AVX2.
Branches are cheap and very efficient if they predict very well, so branching on d==0 will be best if it's almost never taken.  If d==0 is not rare, branchless asm will perform better on average.  Ideally we can write something in C that will let gcc make the right choice during profile-guided optimization, and compiles to good asm for either case.
Since the best branchless asm implementations don't add much latency vs. a branchy implementation, branchless is probably the way to go unless the branch would go the same way maybe 99% of the time.  This might be likely for branching on p==0, but probably less likely for branching on p & (q-1).

It's hard to guide gcc5.4 into emitting anything optimal.  This is my work-in-progress on Godbolt).
I think the optimal sequences for Skylake for this algorithm are as follows.  (Shown as stand-alone functions for the AMD64 SysV ABI, but talking about throughput/latency on the assumption that the compiler will emit something similar inlined into a loop, with no RET attached).

Branch on carry from calculating d-1 to detect d==0, instead of a separate test & branch.  Reduces the uop count nicely, esp on SnB-family where JC can macro-fuse with SUB.
ceil_div_pjc_branch:
 xor    eax,eax          ; can take this uop off the fast path by adding a separate xor-and-return block, but in reality we want to inline something like this.
 sub    rdi, 1
 jc    .d_was_zero       ; fuses with the sub on SnB-family
 tzcnt  rax, rsi         ; tzcnt rsi,rsi also avoids any false-dep problems, but this illustrates that the q input can be read-only.
 shrx   rax, rdi, rax
 inc    rax
.d_was_zero:
 ret

*

*Fused-domain uops: 5 (not counting ret), and one of them is an xor-zero (no execution unit)

*HSW/SKL latency with successful branch prediction:

*

*(d==0): No data dependency on d or q, breaks the dep chain.  (control dependency on d to detect mispredicts and retire the branch).

*(d!=0): q->result: tzcnt+shrx+inc = 5c

*(d!=0): d->result: sub+shrx+inc = 3c

*Throughput: probably just bottlenecked on uop throughput

I've tried but failed to get gcc to branch on CF from the subtract, but it always wants to do a separate comparison.  I know gcc can be coaxed into branching on CF after subtracting two variables, but maybe this fails if one is a compile-time constant.  (IIRC, this typically compiles to a CF test with unsigned vars: foo -= bar;  if(foo>bar) carry_detected = 1;)

Branchless with ADC / SBB to handle the d==0 case.  Zero-handling adds only one instruction to the critical path (vs. a version with no special handling for d==0), but also converts one other from an INC to a sbb rax, -1 to make CF undo the -= -1.  Using a CMOV is cheaper on pre-Broadwell, but takes extra instructions to set it up.
ceil_div_pjc_asm_adc:
 tzcnt  rsi, rsi
 sub    rdi, 1
 adc    rdi, 0          ; d? d-1 : d.  Sets CF=CF
 shrx   rax, rdi, rsi
 sbb    rax, -1         ; result++ if d was non-zero
 ret

*

*Fused-domain uops: 5 (not counting ret) on SKL.  7 on HSW

*SKL latency:

*

*q->result: tzcnt+shrx+sbb = 5c

*d->result: sub+adc+shrx(dep on q begins here)+sbb = 4c

*Throughput: TZCNT runs on p1.  SBB, ADC, and SHRX only run on p06.  So I think we bottleneck on 3 uops for p06 per iteration, making this run at best one iteration per 1.5c.

If q and d become ready at the same time, note that this version can run SUB/ADC in parallel with the 3c latency of TZCNT.  If both are coming from the same cache-miss cache line, it's certainly possible.  In any case, introducing the dep on q as late as possible in the d->result dependency chain is an advantage.
Getting this from C seems unlikely with gcc5.4.  There is an intrinsic for add-with-carry, but gcc makes a total mess of it.  It doesn't use immediate operands for ADC or SBB, and stores the carry into an integer reg between every operation.  gcc7, clang3.9, and icc17 all make terrible code from this.
#include <x86intrin.h>
// compiles to completely horrible code, putting the flags into integer regs between ops.
T ceil_div_adc(T d, T q) {
  T e = lg(q);
  unsigned long long dm1;  // unsigned __int64
  unsigned char CF = _addcarry_u64(0, d, -1, &dm1);
  CF = _addcarry_u64(CF, 0, dm1, &dm1);
  T shifted = dm1 >> e;
  _subborrow_u64(CF, shifted, -1, &dm1);
  return dm1;
}
    # gcc5.4 -O3 -march=haswell
    mov     rax, -1
    tzcnt   rsi, rsi
    add     rdi, rax
    setc    cl
    xor     edx, edx
    add     cl, -1
    adc     rdi, rdx
    setc    dl
    shrx    rdi, rdi, rsi
    add     dl, -1
    sbb     rax, rdi
    ret

CMOV to fix the whole result: worse latency from q->result, since it's used sooner in the d->result dep chain.
ceil_div_pjc_asm_cmov:
 tzcnt  rsi, rsi
 sub    rdi, 1
 shrx   rax, rdi, rsi
 lea    rax, [rax+1]     ; inc preserving flags
 cmovc  rax, zeroed_register
 ret

*

*Fused-domain uops: 5 (not counting ret) on SKL.  6 on HSW

*SKL latency:

*

*q->result: tzcnt+shrx+lea+cmov = 6c (worse than ADC/SBB by 1c)

*d->result: sub+shrx(dep on q begins here)+lea+cmov = 4c

*Throughput: TZCNT runs on p1.  LEA is p15.  CMOV and SHRX are p06.  SUB is p0156.  In theory only bottlenecked on fused-domain uop throughput, so one iteration per 1.25c.  With lots of independent operations, resource conflicts from SUB or LEA stealing p1 or p06 shouldn't be a throughput problem because at 1 iter per 1.25c, no port is saturated with uops that can only run on that port.

CMOV to get an operand for SUB: I was hoping I could find a way to create an operand for a later instruction that would produce a zero when needed, without an input dependency on q, e, or the SHRX result.  This would help if d is ready before q, or at the same time.
This doesn't achieve that goal, and needs an extra 7-byte mov rdx,-1 in the loop.
ceil_div_pjc_asm_cmov:
 tzcnt  rsi, rsi
 mov    rdx, -1
 sub    rdi, 1
 shrx   rax, rdi, rsi
 cmovnc rdx, rax
 sub    rax, rdx       ; res += d ? 1 : -res
 ret

Lower-latency version for pre-BDW CPUs with expensive CMOV, using SETCC to create a mask for AND.
ceil_div_pjc_asm_setcc:
 xor    edx, edx        ; needed every iteration

 tzcnt  rsi, rsi
 sub    rdi, 1

 setc   dl              ; d!=0 ?  0 : 1
 dec    rdx             ; d!=0 ? -1 : 0   // AND-mask

 shrx   rax, rdi, rsi
 inc    rax
 and    rax, rdx        ; zero the bogus result if d was initially 0
 ret

Still 4c latency from d->result (and 6 from q->result), because the SETC/DEC happen in parallel with the SHRX/INC.  Total uop count: 8.  Most of these insns can run on any port, so it should be 1 iter per 2 clocks.
Of course, for pre-HSW, you also need to replace SHRX.
We can get gcc5.4 to emit something nearly as good: (still uses a separate TEST instead of setting mask based on sub rdi, 1, but otherwise the same instructions as above).  See it on Godbolt.
T ceil_div_andmask(T p, T q) {
    T mask = -(T)(p!=0);  // TEST+SETCC+NEG
    T e = lg(q);
    T nonzero_result = ((p-1) >> e) + 1;
    return nonzero_result & mask;
}

When the compiler knows that p is non-zero, it takes advantage and makes nice code:
// http://stackoverflow.com/questions/40447195/can-i-hint-the-optimizer-by-giving-the-range-of-an-integer
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
#define assume(x) do{if(!(x)) __builtin_unreachable();}while(0)
#else
#define assume(x) (void)(x) // still evaluate it once, for side effects in case anyone is insane enough to put any inside an assume()
#endif

T ceil_div_andmask_nonzerop(T p, T q) {
  assume(p!=0);
  return ceil_div_andmask(p, q);
}
    # gcc5.4 -O3 -march=haswell
    xor     eax, eax             # gcc7 does tzcnt in-place instead of wasting an insn on this
    sub     rdi, 1
    tzcnt   rax, rsi
    shrx    rax, rdi, rax
    add     rax, 1
    ret

Chux / user23_variant
only 3c latency from p->result, and constant q can CSE a lot.
T divide_A_chux(T p, T q) {
  bool round_up = p & (q-1);  // compiles differently from user23_variant with clang: AND instead of
  return (p >> lg(q)) + round_up;
}

    xor     eax, eax           # in-place tzcnt would save this
    xor     edx, edx           # target for setcc
    tzcnt   rax, rsi
    sub     rsi, 1
    test    rsi, rdi
    shrx    rdi, rdi, rax
    setne   dl
    lea     rax, [rdx+rdi]
    ret

Doing the SETCC before TZCNT would allow an in-place TZCNT, saving the xor eax,eax.  I haven't looked at how this inlines in a loop.

*

*Fused-domain uops: 8 (not counting ret) on HSW/SKL

*HSW/SKL latency:

*

*q->result: (tzcnt+shrx(p) | sub+test(p)+setne) + lea(or add) = 5c

*d->result: test(dep on q begins here)+setne+lea = 3c.  (the shrx->lea chain is shorter, and thus not the critical path)

*Throughput: Probably just bottlenecked on the frontend, at one iter per 2c.  Saving the xor eax,eax should speed this up to one per 1.75c (but of course any loop overhead will be part of the bottleneck, because frontend bottlenecks are like that).

A: uint64_t exponent = lg(q);
uint64_t mask = q - 1;
//     v divide
return (p >> exponent) + (((p & mask) + mask) >> exponent)
//                       ^ round up

The separate computation of the "round up" part avoids the overflow issues of (p+q-1) >> lg(q). Depending on how smart your compiler is, it might be possible to express the "round up" part as ((p & mask) != 0) without branching.


text:
Q: gatttool characteristic write in non-interactive mode I want to use gatttool in a shell script.
What I want to achieve is similar to these:

*

*Gatttool non-interactive mode --char-write

*Gatttool in non interactive mode

*How to use gatttool non-interactive mode

*Gatttool Non-Interactive mode, multiple char-write-req

*GATTTool fails to read/write characteristics
In interactive mode I can do this:
# gatttool -b xx:xx:xx:xx:xx:xx -I
[xx:xx:xx:xx:xx:xx][LE]> connect
Attempting to connect to xx:xx:xx:xx:xx:xx
Connection successful
[xx:xx:xx:xx:xx:xx][LE]> char-write-cmd 0x0025 aabbcc
Notification handle = 0x0025 value: aa bb cc

Now if I run non-interactively:
# gatttool -b xx:xx:xx:xx:xx:xx --char-write --handle=0x0025 --value=aabbcc

It just hangs I need to break it with CTRL+C and does not send anything to the device.
Now, all questions above are recommending to use --char-write-req instead of --char-write.
But that it is misleading, as request and command mean different things.
My device does not accept request, only commands (even in interactive mode!). So trying to send the same data with request will fail:
# gatttool -b xx:xx:xx:xx:xx:xx -I
[xx:xx:xx:xx:xx:xx][LE]> connect
Attempting to connect to xx:xx:xx:xx:xx:xx
Connection successful
[xx:xx:xx:xx:xx:xx][LE]> char-write-req 0x0025 aabbcc
Error: Characteristic Write Request failed: Attribute can't be written

Now of course using the recommendations from the above questions (--char-write-req) will fail:
# gatttool -b xx:xx:xx:xx:xx:xx --char-write-req --handle=0x0025 --value=aabbcc
Characteristic Write Request failed: Attribute can't be written

So what is the non-interactive alternative of writing a characteristic command,
If I don't want to use any Python or similar overkills for this?


text:
Q: JpGraph xaxis scale in overlaps chart I'm using JpGraph and PHP to generate a chart. I want to show the temperature over time. The code is:
<?php
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_line.php');
require_once( "jpgraph/jpgraph_date.php" );

$servername = "localhost";
$username = "root";
$password = "*********";
$db_name = "temperatures";

$conn = new PDO("mysql:host=$servername;dbname=$db_name", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query_temp = "SELECT * FROM `INSIDE` ORDER BY `INSIDE`.`ID` DESC LIMIT 0 , 30";
$temp = $conn -> query($query_temp);
$temp_final = $temp -> fetchALL(PDO::FETCH_ASSOC);

$xdata = array ();
$ydata = array ();

for($x = 0; $x < 30; $x++) {
    $datetime_unix = strtotime($temp_final[$x]["DATE"] . $temp_final[$x]["TIME"]);
    $xdata[] = $datetime_unix;
}

for($x = 0; $x < 30; $x++) {
    $ydata[] = $temp_final[$x]["VALUE"];
}

// Size of the overall graph
$width=1800;
$height=900;

// Create the graph and set a scale.
// These two calls are always required
$graph = new Graph($width,$height);
$graph->SetScale('datelin');

$graph -> yaxis -> title -> set("Temperature C");
$graph -> xaxis -> title -> set("");
$graph->yaxis->title->SetFont(FF_FONT2);
$graph -> xaxis -> title -> SetFont(FF_FONT2);
$graph->xaxis->SetLabelAngle(45);
$graph->xaxis->scale->SetDateFormat( 'H:i d.m.Y' );
$graph->SetMargin(50,10,40,100);

// Create the linear plot
$lineplot=new LinePlot($ydata, $xdata);

// Add the plot to the graph
$graph->Add($lineplot);

// Display the graph
$graph->Stroke();

?>

My problem is, that the scale on the xaxis overlaps the graph. I would like to move it a little bit down.
Image of the problem:

A: I solved the problem myself. If someone is interested, I had to add one line:
$graph->xaxis->SetPos( 'min' );


text:
Q: Share Windows Phone 8.1 application developed with Visual Studio to friends I want to know how is possible to share a Windows Phone 8.1 applications, developed in Visual Studio, to friends, without publish it on the Store. Is it possible like Android with .apk? What is the procedure to export it from Visual Studio ?

A: You can create App packages:

*

*Right click on your solution

*Select "Store"

*Select "Create App Packages"

*"Do you want to build packages to upload to the Windows Phone store?" Select "No"

From that on it is straightforward. You can than install this package on an unlocked Windows Phone. Another approach is to register on https://dev.windows.com/en-us, and upload your app as a beta version, than add your friends as beta testers, so they can donwload it from the store  (it will be hidden from the store, only testers can download it).


text:
Q: Scrape select headings and inner text from a webpage using BeautifulSoup? Source - a blog post URL
I want to get the inner text of both the Heading tags AND the body copy within that tag into a table output that looks like this
H2;{H2 tag inner tex}; {p tag(s) inner text}
H3;{H2 tag inner tex}; {p tag(s) inner text}
H2;{H2 tag inner tex}; {p tag(s) inner text}
H3;{H2 tag inner tex}; {p tag(s) inner text}
H4;{H2 tag inner tex}; {p tag(s) inner text}
...

Content of H2, H3, H4 tags are desired
And there might be multiple paragraphs within these tags, so getting them separated by a new line would be awesome.
Can BeautifulSoup do this?
I can get the innertext of the tags out, but don't know how to get the inner text of p tags out, especially when they are more than one. Or to format this so I can save as a CSV.
from bs4 import BeautifulSoup
import requests
website = requests.get('https://venngage.com/blog/landing-page-examples/')
preString =  {'h1': '', 'h2': '\t', 'h3':'\t\t', 'h4':'\t\t\t'}
soup = BeautifulSoup(website.content, 'html.parser')
tags = soup.find_all(['h1', 'h2', 'h3'])
for soups in tags:
    preStr = preString[soups.name] if soups.name in preString else ''
    print(preStr+soups.string)

Thanks in advance for your help.

A: I'm not sure I understand exactly how you want your table organized (which paragraphs you want for each heading? are overlaps ok for nested headings?), but the following suggested solution will set a row for each header tag, and then loop through its siblings collecting all p tags until it hits another header tag:
from bs4 import BeautifulSoup
import requests
import pandas

website = requests.get('https://venngage.com/blog/landing-page-examples/')
preString =  {'h1': '', 'h2': '\t', 'h3':'\t\t', 'h4':'\t\t\t'}

htagNames = [k for k in preString.keys()]
htags = soup.find_all(htagNames)
# if you want from within a particular section
# htags = soup.select_one('article.post').find_all(htagNames)

for h in htags:
    pStrings = []
    for tag in h.find_next_siblings(htagNames+['p']):
        if tag.name == 'p' and tag.string is not None:
            pStrings.append(tag.string)
        if tag.name in htagNames: break

    headingRows.append({
        'headingType': h.name, # 'headingText': h.string,
        'headingText': preString[h.name] + h.get_text(' ' , strip=True),
        'paragraphs': '\n'.join(pStrings)
    })

# can filter out heading with no paragraphs with
# headingRows = [hr for hr in headingRows if hr['paragraphs']]

# save as csv
pandas.DataFrame(headingRows).to_csv('hRows.csv', index=False)

or, if you're not sure that the p tags you want will share a parent tag with the header, then you can just blindly collect all the paragraphs until the next header:
tags = soup.find_all(htagNames+['p'])

lastTag = tags[-1]
headingRows = []
hInit = {'headingType': None, 'headingText': None, 'paragraphs': []}
curHeading = dict(hInit) # copy

for i, t in enumerate(tags):
    if t.name == 'p' and t.string is not None:
        curHeading['paragraphs'].append(t.string)

    if t.name in preString:
        curHeading['headingType'] = t.name
        #curHeading['preStr'] = preString[t.name]
        curHeading['headingText'] = preString[t.name] + t.get_text(' ' , strip=True) # + t.string

    if t == lastTag or tags[i+1].name in preString:
        # if you want possible paras before 1st heading, remove if condition
        if curHeading['headingType'] is not None :
            curHeading['paragraphs'] ='\n'.join(curHeading['paragraphs'])
            headingRows.append(curHeading)

        curHeading = dict(hInit) # copy
        curHeading['paragraphs'] = []

although, this runs the risk of getting paragraphs from a header-less section below...

results will look something like

[excel automatically hides leading whitespaces, but dw the indents are still there for the headingtext column]


text:
Q: Dynamic data manipulation in word online I am trying to build a task-pane add-in for word online which can do mail merge like desktop office. Now I understand that word online does not support mail merge out of the box, so I thought about the following steps -

*

*Create a template (DOTX) using desktop office which will contain Region or something like a merge field etc. Upload the template to one drive.

*Open a blank doc and add a task pane add-in in word online. This is temporary step for now.

*Click a button on the add-in.

*This click will stream the template (DOTX) from server using an app service call.

*Render the stream into word online web page.

*Edit and save.

*Close word online and reopen.

*Click the doc link.

*This will render the doc in word online.

*Add the add-in in the task pane (temp step).

*Click edit button.

*Call app service to fetch the latest merge data source.

*Traverse through the word xml and replace the values corresponding to the region or special keys.

*Re-render the doc.

My users will have E1 subscription of office 365.
Is this thought process logical and achievable with word online? Thanks in advance!...

A: I think your approach is much more complicated than it needs to be. Word Online supports Add-ins created using the JavaScript APIs, as supported by the information in this article: https://msdn.microsoft.com/EN-US/library/office/dn833104.aspx
It should be possible for you to create the "template" on the Desktop (Word 2013 or 2016 is required - but only 2016 supports the current full scope of the JS API) and "insert" your add-in, which links it to the document. Opening the document in Word online should automatically load the add-in, that can then link to the data source and fill in the data.
As data targets ("merge fields"), I recommend you use Content Controls.


text:
Q: server side rendering 404 not found on all my images I am rendering my react app on my server but I get a 404 not found when trying to retrieve images. When I try to go to the directory of my images I get a 404. Why? 404 Not found on localhost:8000/src/img this is where my images live.
server.js
app.use(express.static(path.join(__dirname, './src', '/img')));

app.get('*', (req, res) => {

  const error = () => res.status(404).send('404');
  const htmlFilePath = path.join(__dirname, './', 'index.html');
  fs.readFile(htmlFilePath, 'utf8', (err, htmlData) => {

    if(err) {
      error()
    } else {
      match({ routes, location: req.url }, (err, redirect, renderProps) => {

        if(err) {
          error()
        } else if(redirect) {
          res.redirect(302, redirect.pathname + redirect.search);
        } else if(renderProps) {
          const createStoreWithMiddleware = applyMiddleware(promise)(createStore);
          const store = createStoreWithMiddleware(reducers);
          const RouterContext = react.createElement(reactRouter.RouterContext, renderProps);
          const provider = react.createElement(Provider, { store: store }, RouterContext);
          const ReactApp = renderToString(provider);
          const RenderedApp = htmlData.replace('{{SSR}}', ReactApp);
          res.status(200).send(ReactApp);
        } else {
          error(); //Always enters this when trying to render images.
        }
      });
    }
  });
});

A: See the Express docs: http://expressjs.com/en/starter/static-files.html
You may be using the wrong path for your images. It would help to see your HTML, but if you are setting the src of your images like /src/img/my-image.jpg then that won't work, since the static middleware is relative to the path you give it. You can try app.use(express.static(path.join(__dirname, './src'))); and then use /img/my-image.jpg for your images, if you like.


text:
Q: How do I set up a pond for efficient drainage? I currently have two large ponds filled with water to depth 7 that I need to get drained.  Because I didn't think very hard about how liquid flow works, the out pipe on the one is one tile wide, controlled by a floodgate, and it's draining really slowly.  The other one doesn't have an out pipe yet, but I had pretty much the same plan.
I'm thinking there must be a more efficient way to do this.  Do I simply need a wider out-pipe?  If so, can I connect multiple floodgates to one lever?  (I'm favoring mechanical simplicity here.)  Or is there an even better way?  Assume that my pond isn't actually flooded, so a good pre-flooding setup will work too.
Here's a picture of the more interesting pond:

This one is directly below my trap-filled maze, hence all the ballista arrows, blood and corpses.  I flooded it for a long siege which just finished up.  The larger body of water to the north is the river, with its floodgate closed.  The out pipe goes off to the west and ends at a floodgate (open) and a fortification (flooded).  The tubes are weirdly shaped because that red ore is delicious hematite.  And yes, my pond of death is adjacent to my bedroom area.

A: A wider pipe will cause it to drain faster, as will an altitude drop as Martin Sojka suggests. Not sure which will be more effective; if you do both it should drain pretty fast. I know when I was building a waterfall in my dining room, it tended to back up sometimes when the drainage to the caverns was only 1 square.
You can connect any number of things to a single lever or pressure plate. There is no limit (well, no meaningful limit, probably if you try to connect more than 65k things it gets confused). So feel free to go wild with that.
Since you're fiddling with drainage systems, I'll give you another bit of advice for free: especially if you build a wide drainage pipe, put in some vertical bars blocking the outflow, with some convenient stairs up right in front of them. Otherwise, Urist McMason will decide that he just absolutely needs to use a rock left behind when you were digging out the sewers, and if there's any way he can find to get there, he'll go charging down to grab it and get washed away by the current. Give him something to hit before he gets washed entirely off. I had this happen to me with my waterfall as well; the poor guy got washed out the sewers, down the 6 z-level drop to the floor of the first cavern.

A: Drain the ponds to some place lower than their lowest point. The water pressure will make sure they'll empty into them almost instantly. If you're worried about the pressure overflowing and pushing the water back up, make a simple de-pressurizer somewhere on the pipe, like this:
                           ####################
                           ############         <- pressurized water in
depressurized water out <-             ########
                           ####################

(Version 0.31.25)


text:
Q: Passing file from web service to client in ASP.NET I need to pass a file that's obtained via a web service on to the end user. Right now, I'm doing this in two steps:

*

*Obtain file from a secure web service:
Dim client As New Net.WebClient
client.Headers.Add("Authorization", String.Format("Bearer {0}", access_token))
Dim data As Byte() = client.DownloadData(uri)

*Serve the file to the user via the http response.
This is taking a long time for the end user, as the user has to wait for the server to download the file from the service, and then for the client to download the file from the server.
Is it possible to instead stream the file directly from the web service to the user? If so, what's the best way to do it?

A: I think the best way to achieve this would be to progressively download the file and buffer it into the response so it progressively downloads to the client.  This way, the end user doesn't have to wait for the server to completely download the file and send it back.  It will just stream the file content as it downloads it from the other location.  As a bonus, you don't have to keep the entire file in memory or on disk!
Here's a code sample achieving this:
    protected void downloadButton_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "MyFile.exe"));
        Response.Buffer = true;
        Response.ContentType = "application/octet-stream";

        using (var downloadStream = new WebClient().OpenRead("http://otherlocation.com/MyFile.exe")))
        {
            var uploadStream = Response.OutputStream;
            var buffer = new byte[131072];
            int chunk;

            while ((chunk = downloadStream.Read(buffer, 0, buffer.Length)) > 0)
            {
                uploadStream.Write(buffer, 0, chunk);
                Response.Flush();
            }
        }

        Response.Flush();
        Response.End();
    }


text:
Q: Do common browsers update bookmarks when they receive 301?
301 redirects are permanent. They mean that the page has moved, and
  they request any search engine or user agent coming to the page to
  update the URL in their database. This is the most common type of
  redirect that people should use.

I migreated a certain part of my application from baseurl/app to app.mydomain.com. Eventually,
I would like to shut down baseurl/app. Hence, I was wondering if people who bookmarked mydomain.com/app will have their browser bookmark automatically updated.

A: I can say that most major browsers (IE, Firefox, Chrome, Safari, Opera) don't update their bookmarks themselves, so it might break bookmarks for some users when you stop the 301 redirect. You could check the server access log for these URL's to see if they are still commonly used. And inform users using the old URL's before shut down.
See also similar questions:

*

*Do browsers change URLs of saved bookmarks in response to 301 redirection?

*Client Web Browser Behavior When Handling 301 Redirect


text:
Q: Multiple TinyMCE on button click is initialized and appended but why only last one is writeable? I am using a button click to add TinyMCE dynamically. Everything is working except only one issue is that only the last one is writeable.
Below is my HTML
HTML

<button id='add_more_content_block' class='button'>Add more content</button>

and this is my Javascript to create and initialize TinyMCE wp.editor.initialize('editor_id');
Javascript
var counter = 1;
document.getElementById('add_more_content_block').addEventListener('click', function(e) {
    e.preventDefault();
    var editor_id = "editor_"+counter;

    // document.getElementById('wp-editor_0-editor-container').innerHTML += `<textarea name="_hus_landing_page_content[`+counter+`]" id="editor_`+counter+`" ></textarea>`
    document.getElementById('add_content_box').innerHTML += `<div class="wp-`+editor_id+`-editor-container">
        <textarea class="wp-editor-area" name="_hus_landing_page_content[]" id="`+editor_id+`" ></textarea>

`;

    wp.editor.initialize(editor_id,{
        mediaButtons: true,
        tinymce: true,
        quicktags: true
    });

    counter++;
});

I also have enqueued the scripts for editor.
PHP enqueue script
add_action( 'admin_enqueue_scripts', 'load_admin_scripts');
function load_admin_scripts() {
   wp_enqueue_editor();
}

I am not much familiar with WordPress TinyMCE API.

A: Ok, with many hours of debugging and I finally came to know why it was not working. So everything is supposed to work the way it should be but there was a minor mistake in my JavaScript.
Previous JavaScript
var counter = 1;
document.getElementById('add_more_content_block').addEventListener('click', function(e) {
    e.preventDefault();
    var editor_id = "editor_"+counter;

    document.getElementById('add_content_box').innerHTML += `<div class="wp-`+editor_id+`-editor-container">
        <textarea class="wp-editor-area" name="_hus_landing_page_content[]" id="`+editor_id+`" ></textarea>

`;

    wp.editor.initialize(editor_id,{
        mediaButtons: true,
        tinymce: true,
        quicktags: true
    });

    counter++;
});

The only problem with the above code innerHTML. Everytime you call innerHTML, it will reset all of your HTML back to the original condition. So to avoid this, we have to append. So my final solutions is this
Final Javascript
var counter = 1;
document.getElementById('add_more_content_block').addEventListener('click', function(e) {
    e.preventDefault();
    var editor_id = "editor_"+counter;

jQuery("#add_content_box").append('<textarea id="'+editor_id+'" name="content_block[]" class="form-control"></textarea>');

    wp.editor.initialize(editor_id,{
        mediaButtons: true,
        tinymce: true,
        quicktags: true
    });

    counter++;
});

Everything else will be the same.
I hope that will help someone in the future.


text:
Q: Can't make Apache Airflow installation to work I'm trying to run airflow standalone but im getting AirflowConfigException( airflow.exceptions.AirflowConfigException: Cannot use relative path: sqlite:///C:\Users\admin/airflow/airflow.db to connect to sqlite. Please use absolute path such as sqlite:////tmp/airflow.db
I've tried to use set AIRFLOW_HOME=~/airflow but it doesn't seem to work. Airflow is installed in a venv if that makes any difference.
I'm in Win11, python 3.10

A: Running Airflow on Windows is not yet supported unless you use something like WSL.  See here and here.


text:
Q: Remove all objects of a given type in R How can I use rm to remove all objects of a certain type in R?
I currently have a bunch of functions defined that I'd like to expunge.
I know ls has a pattern option, but this would only help if I was naming all the functions in a pattern (I'm not).

A: A variation on @Jilber's answer:
rm(list=names(Filter(is.function, mget(ls(all=T)))))

A: My solution is basically to use mget to get the class of everything in ls(), then subset ls() according to when class=="function":
rm(list=ls(all=TRUE)[sapply(mget(ls(all=TRUE)), class) == "function"])

@Jilber suggests a cleaner alternative:
rm(list=ls(all=TRUE)[sapply(mget(ls(all=TRUE)), is.function)])

These basic approaches can be expanded to accommodate more complex "genocide" (class-specific purging):
rm(list=ls(all=TRUE)[sapply(mget(ls(all=TRUE)), class) %in%
    c("function", "numeric")])
rm(list=ls(all=TRUE)[sapply(mget(ls(all=TRUE)),
                            function(x) is.function(x) | is.numeric(x))])

@Jilber's approach also has the advantage that it will catch multi-class objects (most notably, data.tables.
Suppose we wanted to remove all data.frames that are not (also) data.tables:
rm(list=ls(all=TRUE)[sapply(mget(ls(all=TRUE)),
                            function(x) is.data.frame(x) & !is.data.table(x))])

A: You may try ls.str where you can list objects of a certain mode (e.g. integer, list (data frame) or function), or lsf.str (returns functions only):
# some objects to 'look for'
int1 <- 1
char1 <- "a"
list1 <- data.frame(x1, x2)
fun1 <- function() x1 + x2

# ls()
# ls.str()
ls.str(mode = "function")
funs <- as.character(ls.str(mode = "function"))

lsf.str()
funs <- as.character(lsf.str())

# rm(funs)

A: There is an ls.str() function that accepts a mode argument. You can get all the functions in the global environment with:
ls.str( mode="function")  # or in a different environment if properly created

The exists function tests whether it can be found and can be limited to particular mode. This is a potentially destructive effect on a running session
rm( list = ls()[ sapply( ls(), exists, mode="function")] )
# test for errors and effectiveness
any( sapply( ls(), exists, mode="function"))
# [1] FALSE

If you were trying to remove only functions with particular patterns to their names you might select among the character vectors returned by ls() with grepl.

A: If you have Dirk's lsos function (also available in the stackoverflow package), then you could do this:
rm(list=rownames(subset(lsos(), Type == "POSIXct")))

This might be useful if the class doesn't have a builtin predicate for type checking (such as is.function)


text:
Q: IBM Worklight 6.0 - scriptError in dojo.js:21 I have created a simple application using the bundled Dojo v1.9 and upon running it device or emulator, I am getting the following error:

07-08 05:38:17.429: E/Web Console(530): Error: scriptError at file:///data/data/com.WorklightApp/files/www/default/dojo/dojo.js:21

These are the steps that I took:

*

*Create a Worklight project and application (with Dojo)

*Add a simple dojo tag on the main page

*Add the Android environment

*Build All and Deploy

*Run on device and/or emulator

The dojo components will not appear; instead I get the above mentioned error.
The application does however work correctly when previewed in Worklight Console.
Is there anything that I must do in Worklight v6.0 to make it work?

A: See if any of the following answers to questions about the same issue help you out:

*

*IBM Worklight 6.0 - Unable to run sample hybrid worklight app using dojo toolkit for android environment on avd?

*Worklight core-web-layer.js errors


text:
Q: Updates in Ubuntu 14.04 Currently i'm using Ubuntu 14.04 and it's very tempting that it shows updates every 2-3 days, so i have two solutions for now.

*

*Select Show updates after a long time(i.e-1-2 weeks) so that it shows updates after a regular and long time interval.

*Adjust the Settings so that it installes only the essential updates.

Currently i'm thinking about the 2nd option.
So I am thinking about how to configure my update settings so that it does not install unwanted updates.
It would be of great help if someone can tell me what are the important updates so that i can configure my settings.
Thanks.
Currently the options that i've selected are as follows.
Ubuntu Software

*

*Canonical-supported free and open-source software(main).

*Community-maintained free and open-source software(universe).

*Proprietary drivers for devices(restricted).

*Software restricted by copyright or legal issues(multiverse).
Updates

*

*Important security updates(trusty-security).

*Recommended updates(trusty-updates).

A: 1 .You can choose the type of updates from Software & Updates.

Adjust the settings to your needs!
2. Security is probably the most essential reason to always stay up to date.
Unwanted updates in your question I consider third-party updates being meant.

You can adjust this in the  Other software tab.

A: There are different dimensions to the usual APT sources.
Firstly, there's the repository:

*

*main

*universe

*restricted

*multiverse

The choices of respository don't affect the importance of updates you receive, it just affects which software is supported.  You should have all of these selected, unless you know you are not using any software from one of these.
If you disable any of these, it effectively turns off all update support from any already-installed software you may have from that repository.
Secondly, there's the classification of update:

*

*-security

*-updates

*-proposed

*-backports

"-security" should always be enabled, because it contains important security updates.
"-updates" is optional but recommended.  It contains updates that may fix bugs but are not necessary for security patches.  You could disable it if you wanted fewer updates, but it tends to receive fewer updates than -security anyway.
"-proposed" should usually be disabled.  It contains updates that have not been officially approved.
"-backports" is a special one.  If you enable it, you gain the option of installing newer versions of installed software, but only if you do it manually.  If you never manually choose a software version from backports, you won't get any updates from it and having "-backports" source won't affect you, but if you do, it'll stay updated.
This is all a rather long-winded way of saying there's no magic bullet to reducing the number of package updates you receive.  The one viable option might be to disable "-updates", but that doesn't save you much.


text:
Q: Custom Config Section in app.config in Windows Service I added custom config section in web.config MVC Web Project and it is working fine. I did the same in app.config under Windows Service Project and it is throwing error.
The type initializer for 'Quartz.Impl.StdSchedulerFactory' threw an exception

But on removing the custom config section, it is working fine without errors.
<configSections>
<section name="RegisterSchedule" type="Sample.Common.CustomConfig.RegisterScheduleConfig, Sample.Common.CustomConfig" />

  <RegisterSchedule>
    <Schedules>
      <Schedule Name="TestSchedule1" Value="test" IsEnabled="true" />
      <Schedule Name="TestSchedule2" Value="123" IsEnabled="true" />
    </Schedules>
 </RegisterSchedule>

A: It worked when i moved <configSections> to the top of the app.config next to configuration.


text:
Q: WPF - UI Not Updating When Item Added to Bound Collection I have a Generic List of objects that I've bound to a custom control.  Everything seems to work OK in the code-behind, but any changes I make to the collection don't seem to reflect in the UI (even though they're working find in all the code behind).
Here's the XAML for my UI:
<controls:ControllableListView x:Name="lvSummaryCaseEvents" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" Label="Case Events:" ItemsSource="{Binding CaseEvents}" AddButtonClicked="ControllableListView_AddButtonClicked">

And the code behind where I add the item into the collection:
_caseScreen.CaseEvents.Add(caseEvent);
//after the line above executes, lvSummaryCaseEvents (in the debugger) shows the correct number of items and the items' values are all correct.  No change to the UI whatsoever

The ItemSource property in my user control:
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(System.Collections.IList), typeof(ControllableListView));

public System.Collections.IList ItemsSource
{
    get
    {
        return this.GetValue(ItemsSourceProperty) as System.Collections.IList;
    }
    set
    {
        this.SetValue(ItemsSourceProperty, value);
    }
}

And finally, the XAML for a standard ListView that lives in my user control which is bound to the ItemsSource property listed above:
<ListView Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Name="lvListView" ItemsSource="{Binding ItemsSource}" View="{Binding View}" SelectionChanged="lvListView_SelectionChanged" />

Just to reiterate, everything works fine when I display the collection the first time around, but when I add an item to the collection, the UI does not reflect the changes made.
Thanks in advance,
Sonny

A: Change your collection to ObservableCollection<T>


text:
Q: Is it possible to launch a signed .ipa application on iOS Simulator without crashes
*

*Purpose:  Launch signed ios application Automation using Appium

*Lauch: Trying to launch the application via Appium inspector

*Application detail: ios Application, signed by a 3rd party developer. Only .ipa extions available

*Issue: App opens and crashes, continuously keeps crashing.

*Device options Different simulators - result is same and Real devices.

Logs from Simulator
error: Failed to start an Appium session, err was: Error: Instruments crashed on startup

info: [IOS_SYSLOG_ROW ] Apr 29 11:54:50 Muhammads-MacBook-Air profiled[1132]: (Error) MC: Failed to write /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles/Library/ConfigurationProfiles/ClientTruth.plist with error Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:50 Muhammads-MacBook-Air installd[1101]: 0x700000117000 -[MIBundle _validateWithError:]: 30: Failed to load Info.plist from bundle at path /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Applications/Photo Booth.app
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:50 Muhammads-MacBook-Air com.apple.CoreSimulator.SimDevice.E2D19473-66F0-4A32-9DD0-DCA4EF863154.launchd_sim[1091] (com.apple.iad.limitadtrackingd[1167]): Could not find and/or execute program specified by service: 2: No such file or directory: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/libexec/limitadtrackingd
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:50 Muhammads-MacBook-Air com.apple.CoreSimulator.SimDevice.E2D19473-66F0-4A32-9DD0-DCA4EF863154.launchd_sim[1091] (com.apple.iad.limitadtrackingd[1167]): Service setup event to handle failure and will not launch until it fires.
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:50 Muhammads-MacBook-Air dataaccessd[1165]: (Error) MC: MobileContainerManager gave us a path we weren't expecting; file a radar against them
    info: [IOS_SYSLOG_ROW ] Expected: /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
    info: [IOS_SYSLOG_ROW ] Actual: /Users/Salman/Library/Developer/CoreSimulator/Devices/E2D19473-66F0-4A32-9DD0-DCA4EF863154/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
    info: [IOS_SYSLOG_ROW ] Overriding MCM with the one true path
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:50 Muhammads-MacBook-Air dataaccessd[1165]: table drop: 101

    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:50 Muhammads-MacBook-Air installd[1101]: 0x700000117000 __69-[MIFileManager urlsForItemsInDirectoryAtURL:ignoringSymlinks:error:]_block_invoke: Ignoring symlink at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/CoreServices/CFNetworkAgent
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:51 Muhammads-MacBook-Air dataaccessd[1165]: table drop: 101
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:51 Muhammads-MacBook-Air dataaccessd[1165]: Bogus event on event stream listener.
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:51 Muhammads-MacBook-Air dataaccessd[1165]: 0x7f9f7a504f70|SubCal|Error|Error fetching subscribed holiday calendars. Giving up for now. Error Domain=CoreDAVErrorDomain Code=1 "(null)"
    UILabel:0x7fc65b5ab160' '.firstBaseline == SPUISearchTableHeaderView:0x7fc65b5a8580.top + 36>
    info: [IOS_SYSLOG_ROW ] Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
    info: [IOS_SYSLOG_ROW ] The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
    info: [IOS_SYSLOG_ROW ] Apr 29 11:54:54 Muhammads-MacBook-Air SpringBoard[1107]: Unable to simultaneously satisfy constraints.
    info: [IOS_SYSLOG_ROW ] Probably at least one of the constraints in the following list is one you don't want.
    info: [IOS_SYSLOG_ROW ] Try this:
    info: [IOS_SYSLOG_ROW ] (1) look at each constraint and try to figure out which you don't expect;
    info: [IOS_SYSLOG_ROW ] (2) find the code that added the unwanted constraint or constraints and fix it.
    info: [IOS_SYSLOG_ROW ] (
    info: [IOS_SYSLOG_ROW ] "<NSLayoutConstraint:0x7fc65b5af850
    info: Launching instruments

    info: [debug] Attempting to run app on iPhone 5s (9.3)
    info: [debug] Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /tmp/appium-instruments/instrumentscli0.trace -w "iPhone 5s (9.3)" /var/folders/ks/ybjl6ngd2056zt6c30y6v4sm0000gn/T/116329-663-1x53997/Payload/Discovery.app -e UIASCRIPT "/Users/Salman/Library/Application Support/appium/bootstrap/bootstrap-f062718992d59810.js" -e UIARESULTSPATH /tmp/appium-instruments
    info: [debug] And extra without-delay env: {}
    info: [debug] And launch timeouts (in ms): {"global":90000}

    info: [IOS_SYSLOG_ROW ] Apr 29 11:55:05 Muhammads-MacBook-Air CoreSimulatorBridge[1115]: Requesting installation of file:///var/folders/ks/ybjl6ngd2056zt6c30y6v4sm0000gn/T/116329-663-1x53997/Payload/Discovery.app/ with options: {
    info: [IOS_SYSLOG_ROW ] CFBundleIdentifier = "com.ctv.dailyplanet";
    info: [IOS_SYSLOG_ROW ] PackageType = Developer;
    info: [IOS_SYSLOG_ROW ] SimulatorRootPath = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk";
    info: [IOS_SYSLOG_ROW ] SimulatorUserPath = "/Users/Salman/Library/Developer/CoreSimulator/Devices/E2D19473-66F0-4A32-9DD0-DCA4EF863154/data";
    info: [IOS_SYSLOG_ROW ] }

    info: [debug] Cleaning app data files

    warn: Applications directory /Users/Salman/Library/Developer/CoreSimulator/Devices/E2D19473-66F0-4A32-9DD0-DCA4EF863154/data/Containers/Data/Application doesn't exist. Have you run this simulator before?
    warn: Applications directory /Users/Salman/Library/Developer/CoreSimulator/Devices/E2D19473-66F0-4A32-9DD0-DCA4EF863154/data/Containers/Bundle/Application doesn't exist. Have you run this simulator before?
    info: Couldn't find app directories to delete. Probably it's not installed
    info: [debug] Resetting Content and Settings for Simulator
    info: node-simctl: Executing: xcrun with args: simctl erase E2D19473-66F0-4A32-9DD0-DCA4EF863154 and timeout: 2000

    error: Failed to start an Appium session, err was: Error: Instruments crashed on startup

    info: [debug] Cleaning up appium session
    info: [debug] Error: Instruments crashed on startup
        at [object Object].Instruments.onInstrumentsExit (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-instruments/lib/instruments.js:440:31)
        at [object Object].<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-instruments/lib/instruments.js:353:12)
        at ChildProcess.emit (events.js:110:17)
        at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
    info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Instruments crashed on startup)","origValue":"Instruments crashed on startup"},"sessionId":null}
    info: <-- POST /wd/hub/session 500 64280.563 ms - 182

Logs from real device
error: Failed to start an Appium session, err was: Error: Instruments crashed on startup

info: [debug] Error: Instruments crashed on startup
    at [object Object].Instruments.onInstrumentsExit (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-instruments/lib/instruments.js:440:31)
    at [object Object].<anonymous> (/Applications/Appium.app/Contents/Resources/node_modules/appium/submodules/appium-instruments/lib/instruments.js:353:12)
    at ChildProcess.emit (events.js:110:17)
    at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Instruments crashed on startup)","origValue":"Instruments crashed on startup"},"sessionId":null}
info: <-- POST /wd/hub/session 500 32271.057 ms - 182

Objective:

*

*To automate the application.

*To launch either on simulator or on real device and inspect the
   application elements.

A: No.  Your ipa is a device application bundle, not suitable for the simulator.