text:
Q: Multiplying using Bitwise Operators I was wondering how I could go about multiplying a series of binary bits using bitwise operators. However, I'm interested in doing this to find the a decimal fraction value for the binary value. Here's an example of what I'm trying to do:
Given, say: 1010010,
I want to use each individual bit so that it will be computed as:
1*(2^-1) + 0*(2^-2) + 1*(2^-3) + 0*(2^-4).....
Though I'm interested in doing this in ARM assembly, having an example in C/C++ will still help as well.
I was thinking of performing a loop with a counter, where each time the loop iterates, a counter will increment, the value will be logically shifted left so that the first bit will be taken, and multiplied by 2^-counter.
However, I'm not entirely sure how I would go about just getting just the first bit/MSB to multiply, and I'm confused as to how I would multiply that value by base 2 to some negative power.
I know that logical shift lefts will multiply it with base two, but those usually have positive exponents. Ex. LSL r0, 2 means the value in r0 will be multiplied by 2^2 = 4.
Thanks in advance!

A: Multiplying two numbers using only bitwise operations (AND, OR, XOR, <<, >>) is perfectly possible, although probably not very efficient. You may want to read the relevant Wikipedia articles on Adder (electronics) and Binary multiplier.
A bottom-up approach for multiplication would be to create first a binary adder. For the lowest bit (bit 0) a half adder works fine. S means sum, C means carry.

For the rest of the bits you need a full adder for each bit. Cin means 'carry in', Cout means 'carry out':

The simplest logical circuit to sum several bits is called ripple-carry adder:

Ripple-carry adder is basically a series of full adders, the carry is propagated to the full adder computing the next more significant bit. Other more efficient methods do exist, but due to reasons of simplicity, I skip them. So now we have a binary adder.
The binary multiplier is a more difficult case. But as I see this more as a proof of concept than a practical way to multiply two numbers, let's take a simpler detour.
Let's assume we want to compute the product of a and b, a = 100, b = 5. a and b are both 16-bit unsigned integers (can be fixed-point too). We can create an array of summands in which we write the value of a (100) b (5) times, or vice versa. As the highest unsigned value that is representable in 16 bits is 2^16-1 (65535), we want to create an array of 65535 unsigned integers, filled with zeros. Then we need to set some 5 values of the array to 100, using only bitwise operations.
We can do this: first we fill an array (let's call it a_array) with the value of a (100). Then we want to zero some values in a_array based on the value of b, so that b values of a_array stay unmodified, the rest values of a_array are zeroed. For that we use a binary mask and AND bitwise operation.
So we loop through the bits of b. For each bit of b we create a binary mask based on the value of that bit in b. Creating such binary mask requires only bit shifts (<<, >>), bitwise AND and bitwise OR.

0 -> 0b0000 0000 0000 0000
1 -> 0b1111 1111 1111 1111

So, now we have a binary mask. But how we use it? Well, the bit 0 of b corresponds to numerical value of 0 or 1. The bit 1 of b corresponds to numerical value 0 or 2. The bit 2 of b corresponds to numerical value of 0 or 4. So bit n of b corresponds to the numerical value of 0 or 2^n. So, as we loop through the bits of b and create a binary mask for each bit, we AND 2^n values of a_array with the corresponding binary mask. The corresponding value in a_array either gets zeroed or stays unmodified. In C code I use a for loop for ANDing through the a_array, together with incrementing and decrementing counters. Increment and decrement are not a bitwise operations. But the for loop is not necessary, it's used only for readability (from human point of view). Actually, I first wrote in x86-64 assembly a 4-bit * 4-bit = 4-bit multiplier to try this concept, using only and, or, xor, shl (bit shift left), and shr (bit shift right) and call. call is function or procedure call, that is, not a bitwise operation, but you can inline all those functions or procedures and thus compute the product using only AND, OR, XOR, << and >>. So instead of a for loop, for each bit of b, you can AND n (n = 1, 2, 4, 8 ...) corresponding values of a_array using the bitwise mask based on the corrsponding bit of b. For a 16-bit * 16-bit = 16-bit multiplication that requires 65535 AND commands (without a loop). Computers have no problem with such an input, but humans tend to have problems reading such code. For that reason a for loop is used.
Now we have a_array filled with b values of a, the rest are zeroes. The rest is simple: we just add all the values of a_array using out bitwise adder (it's the function my_add in the below C code).
Here's the code for 16-bit * 16-bit = 16-bit unsigned integer multiplication. Please note that the function memset16 assumes a little-endian architecture. Converting memset16 to a big-endian architecture should be trivial. The code works for fixed-point multiplication too, you only need to add a bit shift in the end. Converting to different variable sizes as well as implementing overflow detection should be trivial too. Tasks are left for the reader. Compiles with GCC, tested in x86-64 Linux.
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#define NUMBER_OF_BITS 16
#define MAX_VALUE 65535

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;

typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;

typedef struct result_struct{
    u16 result;
    u16 carry;
} result_struct;

u16 extend_lowest_bit(u16 a)
{
    /* extends lowest bit (bit 0) to all bits. */
    u16 a_extended;
    a = (a & 1);
    a_extended = a | (a << 1) | (a << 2) | (a << 3) | (a << 4);
    a_extended = a_extended | (a << 5) | (a << 6) | (a << 7) | (a << 8);
    a_extended = a_extended | (a << 9) | (a << 10) | (a << 11) | (a << 12);
    a_extended = a_extended | (a << 13) | (a << 14) | (a << 15);
    return a_extended;
}

result_struct my_add(u16 a, u16 b)
{
    /* computes (a + b). */
    result_struct add_results;

    u16 a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15;
    u16 b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15;
    u16 carry, result = 0;
    /* prepare for bitwise addition by separating
     * each bit of summands a and b using bitwise AND. */
    a0 = a & 1;
    a1 = a & (1 << 1);
    a2 = a & (1 << 2);
    a3 = a & (1 << 3);
    a4 = a & (1 << 4);
    a5 = a & (1 << 5);
    a6 = a & (1 << 6);
    a7 = a & (1 << 7);
    a8 = a & (1 << 8);
    a9 = a & (1 << 9);
    a10 = a & (1 << 10);
    a11 = a & (1 << 11);
    a12 = a & (1 << 12);
    a13 = a & (1 << 13);
    a14 = a & (1 << 14);
    a15 = a & (1 << 15);

    b0 = b & 1;
    b1 = b & (1 << 1);
    b2 = b & (1 << 2);
    b3 = b & (1 << 3);
    b4 = b & (1 << 4);
    b5 = b & (1 << 5);
    b6 = b & (1 << 6);
    b7 = b & (1 << 7);
    b8 = b & (1 << 8);
    b9 = b & (1 << 9);
    b10 = b & (1 << 10);
    b11 = b & (1 << 11);
    b12 = b & (1 << 12);
    b13 = b & (1 << 13);
    b14 = b & (1 << 14);
    b15 = b & (1 << 15);

    add_results.result = a0 ^ b0;
    /* result: 0000 0000 0000 000x */
    carry = (a0 & b0) << 1;
    add_results.result = add_results.result | (a1 ^ b1 ^ carry);
    /* result: 0000 0000 0000 00xx */
    carry = ((carry & (a1 ^ b1)) | (a1 & b1)) << 1;
    add_results.result = add_results.result | (a2 ^ b2 ^ carry);
    /* result: 0000 0000 0000 0xxx */
    carry = ((carry & (a2 ^ b2)) | (a2 & b2)) << 1;
    add_results.result = add_results.result | (a3 ^ b3 ^ carry);
    /* result: 0000 0000 0000 xxxx */
    carry = ((carry & (a3 ^ b3)) | (a3 & b3)) << 1;
    add_results.result = add_results.result | (a4 ^ b4 ^ carry);
    /* result: 0000 0000 000x xxxx */
    carry = ((carry & (a4 ^ b4)) | (a4 & b4)) << 1;
    add_results.result = add_results.result | (a5 ^ b5 ^ carry);
    /* result: 0000 0000 00xx xxxx */
    carry = ((carry & (a5 ^ b5)) | (a5 & b5)) << 1;
    add_results.result = add_results.result | (a6 ^ b6 ^ carry);
    /* result: 0000 0000 0xxx xxxx */
    carry = ((carry & (a6 ^ b6)) | (a6 & b6)) << 1;
    add_results.result = add_results.result | (a7 ^ b7 ^ carry);
    /* result: 0000 0000 xxxx xxxx */
    carry = ((carry & (a7 ^ b7)) | (a7 & b7)) << 1;
    add_results.result = add_results.result | (a8 ^ b8 ^ carry);
    /* result: 0000 000x xxxx xxxx */
    carry = ((carry & (a8 ^ b8)) | (a8 & b8)) << 1;
    add_results.result = add_results.result | (a9 ^ b9 ^ carry);
    /* result: 0000 00xx xxxx xxxx */
    carry = ((carry & (a9 ^ b9)) | (a9 & b9)) << 1;
    add_results.result = add_results.result | (a10 ^ b10 ^ carry);
    /* result: 0000 0xxx xxxx xxxx */
    carry = ((carry & (a10 ^ b10)) | (a10 & b10)) << 1;
    add_results.result = add_results.result | (a11 ^ b11 ^ carry);
    /* result: 0000 xxxx xxxx xxxx */
    carry = ((carry & (a11 ^ b11)) | (a11 & b11)) << 1;
    add_results.result = add_results.result | (a12 ^ b12 ^ carry);
    /* result: 000x xxxx xxxx xxxx */
    carry = ((carry & (a12 ^ b12)) | (a12 & b12)) << 1;
    add_results.result = add_results.result | (a13 ^ b13 ^ carry);
    /* result: 00xx xxxx xxxx xxxx */
    carry = ((carry & (a13 ^ b13)) | (a13 & b13)) << 1;
    add_results.result = add_results.result | (a14 ^ b14 ^ carry);
    /* result: 0xxx xxxx xxxx xxxx */
    carry = ((carry & (a14 ^ b14)) | (a14 & b14)) << 1;
    add_results.result = add_results.result | (a15 ^ b15 ^ carry);
    /* result: xxxx xxxx xxxx xxxx */
    add_results.carry = ((carry & (a15 ^ b15)) | (a15 & b15)) << 1;
    return add_results;
}

result_struct add_array(void* array, s32 size)
{
    /* adds together all u16 values of the array. */
    result_struct add_results;
    u16* i;
    u16* top_address;

    add_results.result = 0;
    add_results.carry = 0;

    for (i = array; i < ((u16*)array + size); i++)
    {
        add_results = my_add(add_results.result, *i);
    }
    return add_results;
}

void memset16(void* dest, u16 value, s32 size)
{
    /* does a 16-bit memset. size is the number of u16's (words). */
    u8* i;

    for (i = (u8*)dest; i < ((u8*)dest+(2*size)); i+=2)
    {
        memset(i, (int)(value & 0xff), 1);
        memset(i+1, (int)(value >> 8), 1);
    }
}

result_struct my_mul(u16 a, u16 b)
{
    /* computes (a * b) */
    u16 bitmask, a_array[MAX_VALUE];
    u32 block_length;
    s16 bit_i;
    s32 count, size;
    u16* i;
    void* p_a_array;
    p_a_array = a_array;

    result_struct mul_results;
    mul_results.result = 0;

    size = MAX_VALUE;
    memset16(p_a_array, a, size);   // can be replaced with AND.

    /* mask the summands. can be unrolled to
     * use only bitwise operations. */
    i = p_a_array;

    for (bit_i = 0, block_length = 1; bit_i < NUMBER_OF_BITS; bit_i++)
    {
        bitmask = extend_lowest_bit(b >> bit_i);

        for (count = block_length; count > 0; count--)
        {
            *i = (*i & bitmask);
            i++;
        }
        block_length <<= 1;
    }
    /* the array of summands is now masked. */

    /* add the values of the array together. */
    mul_results = add_array(p_a_array, MAX_VALUE);
    return mul_results;
}

int main(void)
{
    int a, b;
    result_struct multiply_results;

    printf("Enter the 1st unsigned 16-bit integer.\n");
    scanf("%d", &a);
    printf("Enter the 2nd unsigned 16-bit integer.\n");
    scanf("%d", &b);
    multiply_results = my_mul((u16)a, (u16)b);
    printf("%d * %d = %d\n", a, b, multiply_results.result);
    return 0;
}

A: Multiplication using only bitwise arithmetic is masochism, as is addition. The hardware you would be attempting to replace is nontrivial. (Note: the other answers here use native addition; such is not a bitwise implementation.)
If you have an integer type twice as wide as your operands, then just perform regular multiplication and use a right shift to align the radix point to the correct bit. If you multiply two 8-bit fractions in the range [0, 1), then the result should be shifted right by 8 bits to take the radix point from the 216's place back to the 28's place.
Given the prevalence of long long, this technique portably handles multiplication of 32-bit fractions.
const uint64_t fix_factor
    = static_cast< uint64_t >( std::numeric_limits< uint32_t >::max() ) + 1;

uint32_t a = (7./13) * fix_factor;
uint32_t b = (13./14) * fix_factor;
uint32_t prod = static_cast< uint64_t >( a ) * b / fix_factor;

(Live demos with x86-64 assembly and sensible output.)
If you have access to assembly, there should be no need for any tricks no matter what, since most CPUs offer a multiply-high instruction. (This is used to implement long long multiplication, but with assembly you can be sure the unnecessary low-order result bits are not computed.)

A: As an exercise, perhaps this may help:
#include <iostream>
using namespace std;

int main()
{
  unsigned bits = 0x52; // 01010010
  int n = 7; // position of the radix point E.g. 0.1010010
  double result = 0;
  for( int i=0 ; i<n ; ++i )
  {
    result += (bits>>i) & 1;
    result *= 0.5;
  }
  cout << result << endl; // 0.640625
  return 0;
}

One way to think of this is to take
1*(2^-1) + 0*(2^-2) + 1*(2^-3) + 0*(2^-4) + ...

and rewrite it as
(1+(0+(1+(0+(0+(1+0/2)/2)/2)/2)/2)/2)/2

As you can see the original binary number 1010010 shows up directly in this evaluation.

A: it sounds like you are on the right track...just do it.
if I have these binary numbers I am multiplying
  abcd
* 1011
=======

where a, b, c, d are just bits, one or zero which dont matter just yet as you will see why
1011 as you know is 1*(2^0)+1(2^1)+0*(2^2)+1(2^3).
exactly like grade school math, but simpler since we only care about 1 and 0 and not 9 to 0..
     abcd
   * 1011
   =======
     abcd  (abcd * 1 * 2^0)
    0000   (abcd * 1 * 2^1)
   abcd    (abcd * 0 * 2^2)
+ abcd     (abcd * 1 * 2^3)
==========

and if the light bulb didnt go off yet then
     abcd
   * 1011
   =======
     abcd  (abcd << 0)
    00000  (abcd << 1)
   abcd00  (0 << 2)
+ abcd000  (abcd << 3)
==========

Then you add up those values.
unsigned long long mymult ( unsigned int a, unsigned int b )
{
    unsigned long long ra;
    unsigned int rb;
    ra=0;
    for(rb=0;rb<32;rb++)
    {
        if(b&(1<<rb)) ra+=(unsigned long long a)<<rb;
    }
}

Which should be pretty easy to implement in assembly.  Using a simple calculator (well using one that does hex) you can very quickly see that 0xFF * 0xFF = 0xFE01, and if you keep trying things you should realize that it can take up to twice as many bits as the width of the operand to hold the result.  If you multiply two 8 bit numbers, to handle all the possible combinations you need a 16 bit results.  Now too many processors that have a multiply dont actually do it that way making the processors multiply somewhat useless IMO.  So you can choose to do a simple 32 bit = 32bit * 32 bit, or you can try something like above and do a 64 bit = 32 bit * 32bit (assuming the compiler interprets the lengths of long and int as I assume them to be).  You might want to start with 32 bit = 32 bit * 32 bit and go from there.  it gets pretty tricky beyond that, another topic. (which can also be easily modeled in a C example, fairly trivial but not as trivial as this below).
unsigned int mymult ( unsigned int a, unsigned int b )
{
    unsigned int ra;
    unsigned int rb;
    ra=0;
    for(rb=0;rb<32;rb++)
    {
        if(b&(1<<rb)) ra+=a<<rb;
    }
}

Negative powers?  well if 2^4 means shift left 4 then 2^(-4) would mean shift right 4 yes?  that covers negative powers.
Just like floating point you need to arbitrarily choose where your decimal point is and normalize to it.  So if you want 4 bits of fraction and 28 bits of whole number then if you want to multiply 5 * 7 you need to adjust those numbers to 5<<4 and 7<<4 normalizing them to your decimal location.  0b1010000 and 0b1110000  multiplying gives the result 0b1000110000.  35 (0x23) with no fraction.  the first bit to the right of your imaginary decimal point is 2^-1 or 1/2, the next bit over is 2^-2 or 1/4th and so on.
This is how floating point works but it does it basically in a scientific notation style with most of the meat of the number to the right of the decimal place.  Just like scientific notation math from middle or high school you have to follow those rules for preparing your numbers before and after the simple math operation.  exponents have to match before you can add for example, multiplication they dont but you add the exponents as well as multiply the number portion...

A: Multiplication with bitwise operations is perfectly doable and it can be parallelized for efficiency; See how to perform addition of three bit vectors efficiently.
int sum_three(int a, int b, int c)
{
   int sum=a^b^c,c2;
   c=((c&a)|(a&b)|(c&b))<<1;
   while (c) {
     c2=(c&sum)<<1;
     sum^=c;
    c=c2;
   }
   return sum;
}

Now that we have a loop that can add three vectors to one, we can either recursively split the standard multiplication matrix, or to implement the CSA tree already mentioned in my earlier answer.
     abcdefg
   * hijklmn
   ---------
     abcdefg * n <-- bitwise AND, sum these three vectors with the given
    abcdefg  * m <-- bitwise AND  algorithm to produce vector NMLNMLNMLNML
   abcdefg   * l <-- bitwise AND
      ...

   The first three rows will produce a 9-element vector  0000LMNLMNLMN = a1
   The next three rows will produce a vector             0IJKIJKIJK000 = b1
   And finally h*abcdefgh needs to be added:             HHHHHHH000000 = c1

Fortunately these partial sums can be added with a single additional call to sum_three(a1,b1,c1);
The bit-serial multiplier, or CSA multiplier in iterative form can be expressed as:
 acc_0 = 0;
 cry_0 = 0;
 loop (max 2n) times:
   add_n = vectorY.bit0 AND (vectorX << n);
   vectorY >>= 1;
   cry_i+1 = (cry_i & add_i) | (add_i & acc_i) | (acc_i & cry_i);
   acc_i+1 = acc_i ^ cry_i ^ add_i;

One can break the loop when both cry_i+1 == 0 and vectorY == 0.


text:
Q: Accessing lineage of a NiFi flow file I'm developing some kind of error handling for flow files for NiFi, e.g. a database sub-system refuses to write the data from a flow file, because the data is not as expected, because the source system of this data is missing some master data.
So this error handling writes the data into a MongoDB with more information what went wrong.
One of those 'more information' is some kind of stacktrace for this flow file, meaning the data lineage. For this purpose I wrote an InvokeScriptedProcessor with a Groovy script to achieve this.
Here is the important part of the script:
ArrayList getStacktrace(flowfileUuid){
    def lineage = this.provenanceRepository.createLineageQuery(flowfileUuid)
    def lineageData = this.provenanceRepository.getLineageData(lineage.id)

    if (lineageData.results == null || lineageData.results.nodes.size() == 0){
        println "cannot find stacktrace for ${flowfileUuid}."
        return []
    }
    def eventIds = lineageData.results.nodes.findAll {n -> n.type == 'EVENT'}.collect {n -> n.id }.sort()
    def provenanceEvents = []
    for (eventId in eventIds){
        provenanceEvents << this.provenanceRepository.getProvenanceEvent(eventId).provenanceEvent.componentName
    }
    this.provenanceRepository.deleteLineageQuery(lineage.id)
    return provenanceEvents
}

For createLineageQuery I'm POSTING to the nifi-api with /nifi-api/provenance/lineage adding the uuid of the flow file in the body. The result is, among others, the ID of the query. I'm using this ID to getLineageData; there is also a property finished and I'm waiting until the query is finished.
With this lineage data I getProvenanceEvent data and write the name of the component (processor) into an array.
After that I deleteLineageQuery as stated in the documentation.
So this would be my stack trace.
The problem now is, the the lineage data is empty when the flow file first hits this InvokeScriptedProcessor. I tried a lot of things, like waiting and stuff. Doesn't help.
Now the odd thing is, that the lineage data is not empty, when I replay the flow file for this processor.
So the behavior is not deterministic as I'm expecting it.
Sometimes the lineage data is not empty when I'm processing the flow file for the first time.
I also tried the thing with Fiddler, there it worked all the time.
Is there a problem with my approach?
I'm currently using NiFi 1.6.0.
EDIT:
I'll take the answer of Bryan as solution.
I'll investigate that as soon as I've got the time, but sounds correct. Nevertheless, I tried my solution with NiFi 1.8.0 and it works as intended. So currently I'm fine with the way I implemented it in the first step, but I'll improve my solution with Bryan's suggestion.

A: I'm not totally sure what the problem is, but in general provenance data is not really meant to be accessed from a processor, which is why there is no API provided by the session or context that lets you retrieve provenance events, only creating events is allowed.
In order to run a provenance query the events need to be indexed, and there is no guarantees about when the indexing will take place related to when the flow file is being processed. So it is possible the events are not visible yet.
A ReportingTask is the intended way to access provenance events and can be used to push them out of NiFi to some external system for longer term storage.

redpajama_set_name: RedPajamaStackExchange


text:
Q: External Control of File Name or Path Veracode scanning issue I have an application in asp.net, which uses the Veracode scan for detecting any security flaws in the application. When scanning for one of my functions shows the following error "External Control of File Name or Path". Anyone know how to fix this error?
sample code:
if (!Directory.Exists(fullPath))
            Directory.CreateDirectory(fullPath);

I have tried validating the fullPath parameter for invalid characters, referred below url. But the issue still persists. Can anyone please help me in fixing this issue? Thanks.
http://www.howtoasp.net/asp-net-security-tutorials/how-to-control-path-composition-to-protect-asp-net-web-application-from-directory-traversal-vulnerability-in-c/

A: It is mainly because of the filepath,filestream or stream writer. Make sure that you validate the path with your input. Veracode thinks that a hacker can add a path say windows/importantfile and would try to get access to that folder.
If you are not validating your path with input this flaw may come up with veracode.
Please see the link for more information.
Veracode directory traversal Issue c#


text:
Q: Clojure CSV Parsing Commas in Quotes I have a CSV file as follow (EDITED: note the space after the first comma)
0, "a,a,a,a"
1, "b,b,b,b"
2, "c,c,c,c"

and I am hoping to parse each row as a vector of 2 strings, i.e.
[0 "a,a,a,a"]
[1 "b,b,b,b"]
[2 "c,c,c,c"]

in such way that the commas within quotes are preserved.
However, both data.csv and clojure-csv provide vectors of 5 strings:
[0 "a a a a"]
[1 "b b b b"]
[2 "c c c c"]

I've tried different values of parser options (:quote-char ") but had still no luck.
Here's my code:
(with-open [in-file (io/reader "myData.csv")]
  (doall
    (map println
     (take 10 (parse-csv in-file)))))

A: There is clojure.data.csv:
(:require [clojure.data.csv :as csv])
(csv/read-csv (slurp "myData.csv"))

It will generate output:
(["0" "a,a,a,a"] ["1" "b,b,b,b"] ["2" "c,c,c,c"])


text:
Q: Random Forest: Predictors have more than 53 categories? What is the solution when we want to apply the Random Forest function in R to a predictor with more than 53 categories?
> RandomForestPrediction=function(alpha){
+   d = sort(sample(nrow(MPS), nrow(MPS)*alpha))
+   train<-MPS[d,]
+   test<-MPS[-d,]
+   myNtree=1000
+   myMtry=5
+   myImportance=TRUE
+   mod2 = randomForest(factor(m.Decision)~.,data=train,tree=myNtree,mtry=myMtry,importance=myImportance)
+   fitted=predict(mod2,test,type="response")
+   return(table(fitted,test$m.Decision))
+ }
> RandomForestPrediction(0.7)
Error in randomForest.default(m, y, ...) :
Can not handle categorical predictors with more than 53 categories.

A: In this youtube video, Jeremy Howard explains his technique to deal with this problem in r, he separates the variables in two sets according the number of observations for each level :

*

*Set 1 : levels for $N_{obs}>100$ or ( $25<N_{obs}<100$ + predictive value)

*Set 2 : all the rest.

I should mention that I'm new to Random Forest and the luck has just made that I looked at this video two days ago. And even if this technique makes sense to me (separate in two sets with different importance) I can't explain the choice of these thresholds (which are obviously a bit arbitrary and dataset dependent), and at what point one can consider that a level has a honorable predictive value.


text:
Q: what's the principle of xamarin.ios remote simulator? xamarin.ios has a powerfull feature: mirror the ios simulator to windows.
I'd like to know how xamarin implements it.
when the mirrored simulator is showing in WIN, I can't find any Simulator.app process running in the MAC, so how does xamarin run it ? is there any public API for controlling the ios simulator ?

A:
when the mirrored simulator is showing in WIN, I can't find any
  Simulator.app process running in the MAC, so how does xamarin run it ?

The simulator is still running in the mac. The process is com.apple.CoreSimlutor.CoreSimlutorService, I find some related processes about simulator when run the simulator on Windows.
And I think the mirrored simulator is showing in WIN is using the technology like a remote desktop. Like VNC. (Just my own thinking, not the official answer)
Here is the picture:


text:
Q: Oracle Deadlock issue in Container Managed Persistence (EJB2.1) This is my first post & have visited occasionally for any kind of Java related issues.  This is a very useful site and the seniors members are so kind to help others.
Environment: Oracle, Jboss, EJB 2, hibernate, MDB, MQ, CMP
We are facing a deadlock issue randomly once/twice a day in our application, so I had turned on the hibernate trace.  Please is the high level code
@Stateless
public class SaveData() {

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
methodA(){

    Method B();
    em.persist(obj1);

    Method C();
    Method D();

    em.flush();
}

methodB(){

}

methodC(){

  em.persist(obj2);
}

methodD(){
  em.persist(obj3);
}

} // Bean end
Since this problem is happening only in production & no where else and I couldn't recreate it.  So I am going to add the TransactionAttributeType.REQUIRES_NEW to keep it in the same transaction, now following are my questions:

*

*Is the beginning of the transaction is MethodB() & ending is MethodD() or Will there be any inner new transaction?.

*How do I check the transaction id or log message for start & end of the transaction to make sure everything is happening in one transaction?.
Thanks for your help.

A: *

*Is the beginning of the transaction is MethodB() & ending is MethodD() or Will there be any inner new transaction?. No. Transaction is started from A & also ends there, as it calls other methods internally. Also you haven't specified any transaction attribute explicitly, so the default will be Required. Therefore, the same transaction will propagate through other methods.

*How do I check the transaction id or log message for start & end of the transaction to make sure everything is happening in one transaction?. In case of CMT not sure how to verify that, but if you want to monitor & manage it explicitly, you can have BMT. Then you will be able to start & end transaction manually.


text:
Q: To use MPI_type_contiguous and MPI_Type_CREATE_Subarray in FORTRAN 90 structure Hi
  I am trying to use fortran structure like this
type some
   u                ! actual code will have 17 such scalars
end type some
TYPE(some),ALLOCATABLE,DIMENSION(:) :: metvars,newmetvars

Now the aim of my test program is to send 10 numbers from one processor to another but the starting point of these 10 numbers would be my choice (example if i have an vector of say 20 numbers not necesary i will take the first 10 numbers to the next processor but lets say my choice is from 5 to 15). So first u use mpi_type_contiguous like this
 CALL MPI_TYPE_CONTIGUOUS(10,MPI_REAL,MPI_METVARS,ierr) ! declaring a derived datatype of the object to make it in to contiguous memory
 CALL MPI_TYPE_COMMIT(MPI_METVARS,ierr)

I do the send rec and was able to get the first 10 numbers to the other processor (I am testing it for 2 processors)
 if(rank.EQ.0)then
     do k= 2,nz-1
     metvars(k)%u = k
     un(k)=k
     enddo
 endif

I am sending this
now
for the second part i used mpi_TYPE_CREATE_SUBARRAY so
then
   array_size = (/20/)
   array_subsize =(/10/)
   array_start = (/5/)

   CALL MPI_TYPE_CREATE_SUBARRAY(1,array_size,array_subsize,array_start,MPI_ORDER_FORTRAN,MPI_METVARS,newtype,ierr)
   CALL MPI_TYPE_COMMIT(newtype,ierr)

   array_size = (/20/)
   array_subsize =(/10/)
   array_start = (/0/)

   CALL MPI_TYPE_CREATE_SUBARRAY(1,array_size,array_subsize,array_start,MPI_ORDER_FORTRAN,MPI_METVARS,newtype2,ierr)
   CALL MPI_TYPE_COMMIT(newtype2,ierr)

  if(rank .EQ. 0)then
     CALL MPI_SEND(metvars,1,newtype,1,19,MPI_COMM_WORLD,ierr)
  endif

  if(rank .eq. 1)then
     CALL MPI_RECV(newmetvars,1,newtype2,0,19,MPI_COMM_WORLD,MPI_STATUS_IGNORE,ierr)
  endif

I don't understand how to do this.
I get an error saying
[flatm1001:14066] *** An error occurred in MPI_Recv
[flatm1001:14066] *** on communicator MPI_COMM_WORLD
[flatm1001:14066] *** MPI_ERR_TRUNCATE: message truncated
[flatm1001:14066] *** MPI_ERRORS_ARE_FATAL (your MPI job will now abort)

I use openmpi in my local machine. I was able to make use of the subarray command without the mpi_type_contiguous part. However if i combine both because in this case I need to do that since i have a structure with fortran in the real code. I dunno if there is a better way to do it either. Any sort of help and suggestios are appreciated.
Thanks in advance

A: I assume your custom type contains 1 real, as it's not specified.  You first construct a contigious type of 10 of these variables, i.e. MPI_METVARS represents 10 contiguous reals.  Now, I don't know if this is really the problem, as the code you posted might be incomplete, but the way it looks now is that you construct a subarray of 10 MPI_METVARS types, meaning you have in effect 100 contiguous reals in newtype and newtype2.
The 'correct' way to handle the structure is to create a type for it with MPI_TYPE_CREATE_STRUCT, which should be your MPI_METVARS type.
So, pls provide the correct code for your custom type and check the size of the newtype type.


text:
Q: How to stream live, auto-updating charts of my ML model to my website? So I'm trying to create a website which displays live and automatically updating graphs using my deep learning model.
I'm trying to establish a workflow as follows:
-use api to get daily new stock data
-have my model automatically train on new data (in cloud)
-update graph on website with new data
There's a website called finbrain.tech and I am trying to implement something like this.
For reference, I am building my website with NextJs, and I am using Python for the deep learning side of things.
Can someone please point me in the right direction to go about establishing such a workflow??
Thanks!

A: Here's one idea for a workflow: Your application can schedule a task to call the API daily (perhaps with https://apscheduler.readthedocs.io/en/3.x/) and upload the data to the ML platform. Then, take the output and save it in cloud storage or a cloud database, and your website can read it from there to produce the graph.


text:
Q: Formula to move/shift items in a 2d-table, so that they are in same rows of the matching 1d-table items? I have a table Google Sheet with more than 100 rows and columns. Each column is alphabetically sorted, The key table/column contains all the unique items in the table (also sorted alphabetically). Each item in the table has a unique URL attached to it (col1 item A has a different URL from col2 item A).
Note: key table/column items have no URLs attached
I need to move these items to the matching key table item rows, while keeping their columns are unchanged. Is there a way to do this using a single Gsheet formula (or 2, a easier way). The changes don't need to be done on the table itself.
current and required table formats

Current Table

    Key
    col 1
    col 2
    col 3
    col 4
    col N

      A

    A
    A
    B
    A
    C

      B

    B
    D
    E
    D
    E

      C

    C
    E
    G
    G
    F

      D

    D
    G

    H

      E

    F

      F

      G

      H

Required Table

    Key
    col 1
    col 2
    col 3
    col 4
    col N

      A

    A
    A

    A

      B

    B

    B

      C

    C

    C

      D

    D
    D

    D

      E

    E
    E

    E

      F

    F

    F

      G

    G
    G
    G

      H

    H

A: According your snippet you can use following formula:
=ArrayFormula(IF(COUNTIF(B$2:B$9,$A13:$A20),$A13:$A20,""))

A: Here you go:
=ARRAYFORMULA(
  IFNA(
    VLOOKUP(
      (ROW(H3:H10) - ROW(H3)) * COLUMNS(B3:F10) + (COLUMN(I3:M3) - COLUMN(I3)),
      {
        FLATTEN(
          IF(
            B3:F10 = "",
              "",
                (
                    VLOOKUP(
                      B3:F10,
                      {A3:A10, ROW(A3:A10)},
                      2,
                      0
                    )
                  - ROW(A3)
                )
              * COLUMNS(B3:F10)
              + COLUMN(B3:F10)
              - COLUMN(B3)
          )
        ),
        FLATTEN(B3:F10)
      },
      2,
      0
    )
  )
)


text:
Q: webclient upload file methods It seems that webclient supports PUT and POST uploading. Is there any difference?

A: Yes, one sends a PUT to the server, one sends a POST.  In theory, PUT means "enclosed entity [should] be stored under the supplied Request-URI", and POST means "the entity enclosed in the request [i]s a new subordinate of the resource identified by the Request-URI"
But in practice, it's up to the server what to do.


text:
Q: Prestashop Los estados no se cambian automáticamente soy nuevo por aquí y en PS también. Estoy empezando a trabajar con este CMS así que espero podamos aprender todos aquí.
He abierto este mismo post en los foros de oficiales de Prestashop (español e ingles). Pero después de 2 semanas, no tengo respuesta. Espero aquí alguien me ayude.
Resulta que el error es simplemente es que a la hora de hacer un pedido y elegir el pago por transferencia bancaria el estado que se cambiaba automáticamente, ha dejado de hacerlo, tanto en el panel de administración (back-office) con en la cuenta del usuario (front-office).
En el back-end se ve tal que asi:
https://www.prestashop.com/forums/uploads/monthly_2022_04/image.png.7ebfb5225c08947ad63f3591997cd27a.png
Y así en mi perfil desde la tienda (Front office):
https://www.prestashop.com/forums/uploads/monthly_2022_04/image.png.acad4b687f896d78bcade65d06bc7838.png
Que ocurre:
Resulta que al hacer esto, debería mandar dos correos, uno para la confirmación de compra (ese se envía sin problemas) y el otro con los datos del banco para la transferencia ( no se envía, solo se envía al cambiar el estado manualmente).
Los correos funcionan bien, tengo un servidor SMTP y las plantillas con los datos bancarios, aparecen sin problema (cuando se envía manual), y en el panel de "Estados" de los pedidos, esta puesto para que envié el correo cuando se elija esta opción.
Para mas pruebas instale PS ultima versión (1.7.8.5) y usando la web DEMO si funciona y hace los cambios automáticos y te manda los dos correos sin problemas.
Entonces (revelaciones):
Buscando y rebuscando, me doy cuenta que los productos que compro con esta opción de pago (banco) cuando las busco en las bases de datos (PHPAdmin), compruebo que tienen el ID de current_state 0 y debería estar en 10 (que es el estado de "en espera de pago por transferencia"),
Entonces empiezo a pensar que el problema es posiblemente un modulo o algún hook (paymentReturn) que este mal, pero desactive todos los módulos no oficiales y sigue sin funcionar.
Como ya se que me diréis que tengo que actualizar, ya lo he hecho con el modulo " 1 click Upgrade". Y Con PS en la ultima versión y todos los módulos actualizados, tampoco funciona.
Base de datos PHPAdmin
https://www.prestashop.com/forums/topic/1062841-ayuda-los-estados-no-se-cambian-autom%C3%A1ticamente/?tab=comments#comment-3389012
He visto que muchos directamente o creáis un modulo modificado o directamente modificáis el código php de algunas partes, entre ellas esta: Mail.php (nada) modules/ps_wirepayment/controller/front/validation.php (creo que es ahi, pero...) o buscando en los php de Orders...no consigo entender donde se le asigna el valor 0 en lugar de 10 y mandar el email.
Respuestas de preguntas:
PS-versión : 1.7.6.8 (mi Backup) 1.7.8.5 (la ultima, actualizada)
PHP versión: 7.2.4


text:
Q: Populate stacklayout from async task table I'm getting data from api via async task:
public async Task<PostModel.Post[]> GetPostsAsync()
    {
        var client = new HttpClient();
        var uri = new Uri("link here");
        var response = await client.GetAsync(uri);
        if (response.IsSuccessStatusCode)
        {
            var jsonString = await response.Content.ReadAsStringAsync();
            var rootObject = JsonConvert.DeserializeObject<PostModel.Post[]>(jsonString);
            return rootObject;
        }
        else
            return null;
    }

Also I've created a simple vertical view:
<ContentPage.Content>
    <ListView x:Name="MainView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout Orientation="Vertical" HorizontalOptions="Fill" VerticalOptions="Fill" BackgroundColor="WhiteSmoke">
                        <Frame OutlineColor="Black">
                            <Label x:Name="Title" Text="{Binding Name}"/>
                            <Image x:Name="Image" Source="{Binding path}" />
                        </Frame>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage.Content>

Wrote a custom cell for displaying data:
 public CustomCell()
    {
        //instantiate items in views
        var Image = new Image();
        var NameLabel = new Label();
        var horizontalLayout = new StackLayout() { BackgroundColor = Color.WhiteSmoke };

        //set bindings
        NameLabel.SetBinding(Label.TextProperty, new Binding("Name"));
        Image.SetBinding(Image.SourceProperty, new Binding("path"));
        Image.HorizontalOptions = LayoutOptions.Center;
        Image.HeightRequest = 600;
        Image.WidthRequest = 600;
        NameLabel.FontSize = 24;

        //add views to the view hierarchy
        horizontalLayout.Children.Add(NameLabel);
        horizontalLayout.Children.Add(Image);

        //add to parent view
        View = horizontalLayout;
    }

Now I'd like to populate layout from the async task dynamically. For example if task gets 6 items - create 6 cells with data from each of the async task items. Any suggestions how can i do it? I'm completely green in xamarin.forms and just started trying it.

A: in OnAppearing, just set the source for your ListView
MainView.ItemSource = await GetPostsAsync();


text:
Q: Session: an attempt was made to request new permissions for a session that has a pending request I want to publish story via Android app and I use a code below.
    private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
    private static final String PENDING_PUBLISH_KEY = "pendingPublishReauthorization";
    private boolean pendingPublishReauthorization = false;
    private UiLifecycleHelper uiHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        uiHelper = new UiLifecycleHelper(XXActivity.this, callback);
        uiHelper.onCreate(savedInstanceState);
        setContentView(R.layout.layoutAct);
            ...
            ...
            ...
        publishAddCardStory();
            ...
    }

    @Override
    public void onResume() {
        super.onResume();
        Session session = Session.getActiveSession();
        if (session != null && (session.isOpened() || session.isClosed())) {
            onSessionStateChange(session, session.getState(), null);
        }
        uiHelper.onResume();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        uiHelper.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
    }

    @Override
    public void onPause() {
        super.onPause();
        uiHelper.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        uiHelper.onDestroy();
    }

     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
         outState.putBoolean(PENDING_PUBLISH_KEY, pendingPublishReauthorization);
         uiHelper.onSaveInstanceState(outState);
     }

    private void publishAddCardStory() {
        Session session = initFacebookSession(PopupAddCardSuccessActivity.this);
        session = Session.getActiveSession();
        if (session != null){

            // Check for publish permissions
            List<String> permissions = session.getPermissions();
            if (!isSubsetOf(PERMISSIONS, permissions)) {
                pendingPublishReauthorization = true;
                Session.NewPermissionsRequest newPermissionsRequest = new Session
                        .NewPermissionsRequest(this, PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
                return;
            }

            Bundle params = new Bundle();
            ...
            params.putString("message", msg);
            params.putString("description", desc);
            params.putString("link", LINK);
                    ...

            Request.Callback callback= new Request.Callback() {
                public void onCompleted(Response response) {
                    JSONObject graphResponse = response
                                               .getGraphObject()
                                               .getInnerJSONObject();
                    String postId = null;
                    try {
                        postId = graphResponse.getString("id");
                    } catch (JSONException e) {
                        Log.i("FB-Response",
                            "JSON error "+ e.getMessage());
                    }
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Toast.makeText(XXActivity.this
                             .getApplicationContext(),
                             getString(R.string.fb_post_fail),
                             Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(XXActivity.this
                                 .getApplicationContext(),
                                 getString(R.string.fb_post_success),
                                 Toast.LENGTH_LONG).show();
                    }
                }
            };

            Request request = new Request(session, "me/feed", params,
                                  HttpMethod.POST, callback);

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
        }

    }

    private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
        for (String string : subset) {
            if (!superset.contains(string)) {
                return false;
            }
        }
        return true;
    }

    private void onSessionStateChange(Session session, SessionState state, Exception exception) {
        if (state.isOpened()) {
            //shareButton.setVisibility(View.VISIBLE);
        } else if (state.isClosed()) {
            //shareButton.setVisibility(View.INVISIBLE);
        }
    }

    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    private static Session initFacebookSession(Context context) {
        Session session = Session.getActiveSession();
        if (session != null)
            return session;

        if (session == null)
            session = new Session(context);
        return session;
    }

Sometime I got these 2 error....

java.lang.UnsupportedOperationException: Session: an attempt was made
  to request new permissions for a session that has a pending request.

or sometime...

java.lang.UnsupportedOperationException: Session: an attempt was made
  to request new permissions for a session that is not currently open.

Any suggestion would be appreciate.

A: First of all, your initFacebookSession method is useless since you call Session.getActiveSession() right below it, so you can delete this method.
Next, you should handle SessionState changes in onSessionStateChange method. While you don't and only place where you call publishAddCardStory method is in onCreate, I assume the reason you get that errors is this:

*

*you call publish method in onCreate

*in publish method you call requestNewPermissions over Session, therefore your activity would be destroyed and facebook activity with dialog that requests allowing new permissions from user appears and Session get into pending state

*user would allow (or not) new permissions via dialog

*your activity is created again, therefore you call newPermissionsRequest over Session again while Session is still in pending state while onSessionStateChange was not called yet

Try to look to Facebook Dev Tutorials: https://developers.facebook.com/docs/android/scrumptious/
how to handle SessionState changes. Facebook SDK also provides some sample applications that may be helpful as well. Good luck! :)


text:
Q: How to call a php site transmitting values via POST? Let´s say I have an index.php:
<?php
    $currentUser = "Paedow";
?>

And I have an user.php:
<?php
    printf($_POST["currentUser"]);
?>

How can I submit the variable $currentUser to the user.php while calling it?
I tried this code, but this only submits the data without calling/viewing the page:
function PostToHost($host, $path, $referer, $data_to_send) {
  $fp = fsockopen($host, 80);
  fputs($fp, "POST $path HTTP/1.1\r\n");
  fputs($fp, "Host: $host\r\n");
  fputs($fp, "Referer: $referer\r\n");
  fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
  fputs($fp, "Content-length: ". strlen($data_to_send) ."\r\n");
  fputs($fp, "Connection: close\r\n\r\n");
  fputs($fp, $data_to_send);
  while(!feof($fp)) {
      $res .= fgets($fp, 128);
  }
  fclose($fp);

  return $res;
}

A: Option 1
Use client-side javascript that will post your data, return the output so you can do with it what you want. See jQuery.post
Option 2
Use server-side (like something that you use already) but instead of this use cURL to post your values. See cURL

A: The contents of $data_to_send would need to look like this:
currentUser=Paedow

That's what form-urlencoded data looks like.
However, can I suggest a different tack: it may be easier for you to use cURL to do a HTTP POST instead like so:
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_URL, $endpoint);
$response = curl_exec($curl);
curl_close($curl);
print_r($response);

(Keep in mind, I haven't tested that and just typed it in off the top of my head.)

A: It seems it isn´t possible as I like; so I´m using Cookies.
Another option would be to use a Session.


text:
Q: Rotation matrices and $SO(3)$ Let $R$ denote the set of matrices that rotate $\mathbb R^3$ around an axis. For the $x,y,z$ axes the matrices are given here.
Let $SO(3)$ denote the set of orthogonal $3\times 3$ matrices with determinant $1$.
It is clear to me that $R \subseteq SO(3)$.
How can I show that $SO(3) \subseteq R$?

A: Let $A\in SO(3)$, and we show that $1$ is an eigenvalue of $A$. The characteristic polynomial is of degree $=3$, and so there are two possible cases:
a) All eigenvalues are real. Since $A$ preserves lengths, all eigenvalues are $\pm1$, and since $\det A=1$, the product of all three eigenvalues is $1$, hence $1$ has to be an eigenvalue.
b) $A$ has one real eigenvalue and two non-real eigenvalues, which are conjugate to one another, and so their product is positive. Hence the real eigenvalue has to be positive as well, and (again) as $A$ preserves lengths, the real eigenvalue must be $1$.
Having verified that $1$ is an eigenvalue, let $v\in\mathbb{R}^3$ such that $Av=v$, and let $U$ denote the orthogonal complement of $v$. Then $U$ is of dimension $2$, it is clearly invariant under $A$, and the restriction $A|_U$ is orthogonal with positive determinant.
If you believe that any matrix in $SO(2)$ represents a rotation (and this is not hard to see), you're done.

A: Essentially, you need to prove that every orientation-preserving orthonormal matrix is a rotation. First of all, it's obvious that the matrices preserve lengths and angles. You can also show there is always an eigenvalue equal to $1$ (obvious in 3D, because eigenvalues of orthonormal matrices are in complex conjugate pairs). The associated eigenvector is the axis. You can then show that when you go into a coordinate frame with the axis aligned along $z$, there is only one remaining degree of freedom (the matrix in this frame looks like a rotation matrix around $z$).
Or you could use (derive) the Rodriguez formula which is a direct bijection between rotations and axis-angle representation. Essentially, an orthogonal matrix $R$ is a rotation by an angle
$${\rm Tr\,}(R)=1+2\cos\theta$$
and
$$R-R^T=2\sin\theta\begin{bmatrix}0&a_z & -a_y \\ -a_z & 0 & a_x \\ a_y & -a_x & 0 \end{bmatrix}$$
You can do this for any matrix... but you can show, that for orthogonal matrices, if you do this transformation and then go back with Rodriguez formula, you get the original matrix (therefore the mapping is bijective).


text:
Q: How to use .NET TextBoxRenderer with TextBoxState.Hot to draw a hot text box? i am trying to use TextBoxRenderer to render a "hot" text box:
TextBoxRenderer.DrawTextBox(e.Graphics, rectangle, TextBoxState.Hot);

except that it doesn't work, it doesn't render the text box as hot.

*

*TextBoxState.Selected doesn't render as selected

*TextBoxState.Hot doesn't render as hot

How do i make TextBoxRenderer.DrawTextBox(..., Hot) render as Hot?
Related but different question:
How do i make TextBoxRenderer.DrawTextBox(..., Selected) render as Selected?

A: It seems that TextBoxRenderer uses EP_BACKGROUNDWITHBORDER, whereas EP_EDITBORDER_NOSCROLL is typically used by TextBox controls[1].
if (VisualStyleRenderer.IsSupported)
{
  // Use the text control's focus rectangle.
  // EP_EDITBORDER_NOSCROLL, EPSN_FOCUSED
  VisualStyleElement element = VisualStyleElement.CreateElement("EDIT", 6, 3);
  if (VisualStyleRenderer.IsElementDefined(element))
  {
    VisualStyleRenderer renderer = new VisualStyleRenderer(element);
    renderer.DrawBackground(e.Graphics, ClientRectangle);
  }
}

(It's tempting to try to get the element from VisualStyleElement but there's no nested class for EP_EDITBORDER_NOSCROLL. So numeric constants 6 and 3 it is.)


text:
Q: Creating nested folders in R I have done what I need separately in different functions but need help to combine them. I have a list of bank names (10 different banks) in a columns of a data frame. For each bank, I want R to:

*

*Create a folder and name the folder using the BankName - I use split() and Map() to do so,

*Create three different Level folders inside each bank folder (namely: "_Lev1","_Lev2","_Lev3") - I use for loop as attached below to do so,

*Create four different Grade folders inside each Level folder (namely: "_G1","_G2","_G3","_G4") - I also use for loop as attached below to do so,

In the current situation, I am able to do all of the three requests separately but not nested, what I need help with is how to combine the above functions to create the nested folders? The results should include, for example,: BankName1 includes three Level folders, the three Level folders should include the Grade folders.
Banks_name = paste0('BankName_', 1:10)
Banks_ID = paste0('ID_', 1:10)
df = data.frame(Banks_name, Banks_ID)

# I use split() and Map() to do task#1:
list_Banks = split(df1, df1$BankName)
Map(write.xlsx, list_Banks, paste0(names(list_Banks), 'Bank_.xlsx'))

# I use for() to do task#2:
Levels <- c("_G1","_G2","_G3")
for (j in seq_along(Levels)){
  folder<-dir.create(paste0("~/Library/CloudStorage/Dropbox/Levels",Levels[j]))}

# I also use for() to do task#3:
Grades <- c("_G1","_G2","_G3")
for (j in seq_along(Grades)){
  folder<-dir.create(paste0("~/Library/CloudStorage/Dropbox/Grades",Grades[j]))}

Thanks in advance.

A: Using file.path() is safer than simple pasting as it is idependent of OS.
There's a typo in your definition of Levels, I think.
Levels <- c("_L1","_L2","_L3")

# Edit as required for your purposes
rootFolder <- "."
for (b in Banks_name) {
  dir.create(file.path(rootFolder, b))
  for (l in Levels) {
    dir.create(file.path(rootFolder, b, l))
    for (g in Grades) {
      dir.create(file.path(rootFolder, b, l, g))
    }
  }
}

A: I would split the task into two parts:

*

*Generate the full path names

*Create the folders

If we had to create folders recursively I would probably approach this differently (as shown in Limey's answer) but the dir.create function allows us to create nested directories in one go, so we can pass it a path and it creates the full hierarchy; e.g. dir.create("does/not/exist", recursive = TRUE) creates the folders does, does/not and does/not/exist all at once.
To solve (1), expand.grid provides a very elegant tool. Unfortunately the result type is a bit unwieldy to work with. We can avoid it here by judicious use of the rep function:
bank_names = paste0('BankName_', 1 : 10)
levels = paste0('_Lev', 1 : 3)
grades = paste0('_G', 1 : 4)

full_paths = file.path(
  banks,
  rep(levels, each = length(banks)),
  rep(grades, each = length(banks) * length(levels))
)

And now you can loop over full_paths once, and call dir.create on each item.

A: Since the combinations are known in advance and are the same for all the banks you can create all of these from the start and then you can loop over just one object.
Banks_name = paste0('BankName_', 1:10)
Banks_ID = paste0('ID_', 1:10)
df1 = data.frame(Banks_name, Banks_ID)

tmp=expand.grid(
  df1$Banks_name,
  c("_Lev1","_Lev2","_Lev3"),
  c("_G1","_G2","_G3")
)

for (i in seq_along(row.names(tmp))) {
  paste0(unlist(tmp[i,]),collapse="/")
}

and put in the write commands.


text:
Q: Mock an Interface with Mockito return a NullPointerException I m trying create unit tests for one project.I m facing a problem because when I try control the result of an interface(mock). When the code get the Interface variable that return a NullPointerException.
Firstly I tried @Override the method in my test class (ClassA), but it don't work. After that I tried mock the interface object and control the comportment with Mockito.When().tehnReturn();
I will put here my code, I read some solutions but none works.
My Interface:
    @FunctionalInterface
    public interface Interface {
        UpdateXResponse process(UpdateXRequest request) throws Exception;
    }

The class I want to test:
    @Service(ClassA.class)
    public class ClassA extends VService implements UpdateX {

        @Reference
        @Inject
        private Interface interface;

        @Inject
        public ClassA(...) {...}

        @Override
        public UpdateXResponse process(UpdateXRequest request) throws Exception {
            UpdateXResponse response = initResponse(context, request, new UpdateXResponse());
            UpdateXInput input = request.getInput();
            UpdateXOutput output = new UpdateXOutput();
            response.setOutput(output);

            try {
                firstMethodCall(...);

            } catch (Exception t) {
                throwCorrectException(t, logger);
            }
            return response;
        }

        private void firstMethodCall(...) throws Exception {
            TypeF typeF = callInterfaceMethod(...);
            ...
        }

        /**
         * Orchestrates Interface service
         */
        protected TypeF callInterfaceMethod(...) {
            ...
            request.setInput(input);
            request.setHeader(header);

            InterfaceResponse response = interface.process(request); // LINE ERROR - In this step interface is NULL when the test get this

            return response;
        }
    }

And finally my class test:
    @RunWith(PowerMockRunner.class)
    @PrepareForTest(value = {ClassA.class,Interface.class} )
    public class WithPowerMockUnitTest{

        @InjectMocks
        private ClassA classA;

        private Interface interface;

        @Before
        public void setUp() throws Exception {
            InterfaceRequest InterfaceRequest = createInterfaceRequest();
            InterfaceResponse serviceUnavailableResponse = createInterfaceResponse();

            Interface = Mockito.mock(Interface.class);
            when(Interface.process(Mockito.any(InterfaceRequest.class))).thenReturn(serviceUnavailableResponse);
        }

        @Test
        public void testh() throws SOAException {
            InterfaceResponse res = interface.process(Mockito.any(InterfaceRequest.class)); // There all run ok. The interface is not null and return what i expected.
            System.out.println("RES "+res);
        }
        @Test
        public void test() {
            assertNotNull(classA);  // not null
            assertNotNull(interface); // not null
        }

        @Test
        public void newTest() throws Exception {

            InterfaceRequest InterfaceRequest = createInterfaceRequest();
            InterfaceResponse serviceUnavailableResponse = createInterfaceResponse();

            UpdateXResponse response = ClassA.process(updateXRequest()); // PROBLEM!! When that get the LINE ERROR the interface is null! WHY?
        }
    }

I put some comments in the lines where the problem exists for me.

    public interface A{
        Response process(Request r) throws Exception;
    }

    public class B{

    private Class_That_Override_Interface_method  ctoim;

        public Response function(){
          X res = method_B();
        }
        protected X method_B(){
          response res = ctoim.process(request); // That ctoim is always NULL when the test get that line/call
        }

    }

Thanks

A: You're missing the @Mock annotation on your Interface variable.
Therefore the mock is not injected into your classA and the newTest() fails. (In this case remove Interface = Mockito.mock(Interface.class); from the setUp method).
Alternativly remove the @InjectMocks annotation and create your class under test manually passing your mock into the constructor.

For this specific case (assuming its a different case from the last question)
there doesn't seem to be a need to involve PowerMockito. So unless you left out some relevant parts you might as well just use the MockitoJUnitRunner.

Ps.:
Also remeber what I said last time about compilable examples?

*

*interface is a keyword and can't be used for variables.

*You should also aim to write variables identical all the times (not Interface and interface / classA and ClassA)

And in case you haven't read it yet check out the help section about minmal reproducible examples.

Edit:
I fogot to mention that the line interface.process(Mockito.any(InterfaceRequest.class)); in testh() is actually invalid syntax. You should use ArgumentMatchers only for parameters of mocked methods.
Also consider adding the MockitoAnnotations.initMocks(this); to your setUp method, when using the PowerMockRunner.


text:
Q: Headphones not detected with Alienware 17R3 I am new to Linux, not by choice but I had a couple of stroke a few years ago and have had to relearn everything.
I have an Alienware 17 R3 with Sound Blaster Recon 3Di sound card. I get no sound via the headphones (but the computer "recognizes" when the plug gets plugged in/out), but the behavior of the sound only comes out of the internal speakers, regardless headphones are plugged in or not. I have the same problem with any version of Linux (Mint 18.1, 18.2 and 18.3) and now the currently Ubuntu-Mate 18.04 LTS. I have read previous specific others having the same problem, but they are on the 16.04 instance of previous similar Linux distributions. Where can I find the same problem/resolution with this version on 18.04 LTS? (Detail system info follows!)
Thanks for your help and pointing me in the right direction!

System:  Host: Ubuntu-Mate18 Kernel: 4.15.0-20-generic x86_64 bits: 64
         gcc: 7.3.0

Desktop: MATE 1.20.1 (Gtk 3.22.30-1ubuntu1) info: mate-panel dm: lightdm
         Distro: Ubuntu 18.04 LTS

Machine: Device: laptop System: Alienware product: Alienware 17 R3
         v:1.3.10 serial: N/A
   Mobo: Alienware model: 0GH72M v: A00 serial: N/A UEFI [Legacy]:
         Alienware v: 1.3.10 date: 12/12/2016 Chassis: type: 10

    CPU: Quad core Intel Core i7-6700HQ (-MT-MCP-) arch: Skylake-S rev.3
         cache: 6144 KB flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 ssse3
         vmx) bmips: 20736 clock speeds: min/max: 800/3500 MHz 1: 3214 MHz
         2: 3302 MHz 3: 3206 MHz 4: 3188 MHz 5: 3174 MHz 6: 3297 MHz 7:
         3221 MHz 8: 3224 MHz

Graphics:  Card-1: Intel HD Graphics 530 bus-ID: 00:02.0 chip-ID:
           8086:191b
           Card-2: NVIDIA GM204M [GeForce GTX 970M] bus-ID: 01:00.0 chip-
           ID: 10de:13d8
           Display Server: x11 (X.Org 1.19.6 ) drivers: modesetting,nvidia
           (unloaded: fbdev,vesa,nouveau)
           Resolution: 1920x1080@60.02hz
           OpenGL: renderer: GeForce GTX 970M/PCIe/SSE2 version: 4.6.0
           NVIDIA 390.48 Direct Render: Yes

Audio:     Card Intel Sunrise Point-H HD Audio driver: snd_hda_intel bus-
           ID: 00:1f.3 chip-ID: 8086:a170

Sound:     Advanced Linux Sound Architecture v: k4.15.0-20-generic


text:
Q: Routes navigation is not working in NodeJs I am using router in my NodeJs app.When I am trying to navigate it is unable to navigate to the given page.
Register.js is placed in routes folder and server.js is placed in parent directory.
Here is my code:
Server.js
const express = require('express');

const app = express();

app.set('view engine','ejs');
app.use(require('./routes/register'));

const port = process.env.PORT || 3000;

app.listen(port, (req,res) => {
  console.log("Server is running at:", +port);
});

Register.js
const express = require('express');
const router = express.Router();
const bodyParser = require('body-parser');

var app = express();

router.use(bodyParser.json);
router.use(bodyParser.urlencoded({extended:true}));

router.get('/users', (req,res) => {

  console.log('Hello there');

});

module.exports = router;

Now when I run this code and go to localhost:3000/users nothing happens and not even error shows in console.
Please let me know what I am doing wrong in above code.

A: Use router.use(bodyParser.json()); in register.js.

A: You have used body-parser at wrong place. Also you should initiate those with express instances always.
Also check your file name you have imported. Reigster -> register
Updated code:
Server.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();

app.set('view engine','ejs');
app.use(require('./Register'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
const port = process.env.PORT || 3000;

app.listen(port, (req,res) => {
    console.log("Server is running at:", +port);
});

Register.js
const express = require('express');
const router = express.Router();
const bodyParser = require('body-parser');

router.get('/users', (req,res) => {

    console.log('Hello there');
    res.sendStatus(200)
});

module.exports = router;


text:
Q: Переадресация после отправки формы Есть некая форма, в ней поля. Не моя, я пишу под нее userJS.
Я её заполнил и отправил.
Как сделать после отправки переход на другую страницу?
Пробовал вот так:
$('div form').submit(function(){
    location.href = 'qwerty.ru';
});

$('div form').submit(function(){
    this.submit();
    location.href = 'qwerty.ru';
});

A: В том виде как вы пытаетесь - никак. Но зачем вам вообще форма? Собрали данные и отправили POST, а по callback делать переход:
$('div form').submit(function(event) {
    event.preventDefault(); // отменяем отправку формы

    // собираем данные
    // отправляем
    $.ajax({/* ... */}).done(function(result) {
        // переход
        window.location.href = "http://test.com";
    });
});


text:
Q: java.lang.NoClassDefFoundError: org.apache.http.Consts I am converting my project in  Studio from eclipse.I am sending image in multi part to sever using httpmime 4.5.1 jar file. This is my code.it gives me NoClassDefFoundError: org.apache.http.Consts error.
Please help me.
This is my code.
new AsyncTask<String, Integer, Void>() {

                @Override
                protected void onPreExecute() {

                   // setting progress bar to zero
                    progressBar.setProgress(0);

                    super.onPreExecute();

                }

                @Override
                protected void onProgressUpdate(Integer... progress) {
                    // Making progress bar visible

                    // updating progress bar value
                    progressBar.setProgress(progress[0]);

                    txtPercentage.setText(progress[0] + "%");

                }

                @SuppressWarnings("deprecation")
                @Override
                protected Void doInBackground(String... params) {

                    for (i = 0; i < allPath.length; i++) {

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                // TODO Auto-generated method stub
                                txtCount.setText((i + 1) + "/"
                                        + allPath.length);

                            }
                        });

                        allPath[i] = selected.get(i).sdcardPath;

                        String responseString = null;

                        HttpClient httpclient = new DefaultHttpClient();
                        HttpPost httppost = new HttpPost(
                                Config.FILE_UPLOAD_URL);

                        try {

                            AndroidMultiPartEntity entity = new AndroidMultiPartEntity(
                                    new ProgressListener() {

                                        @Override
                                        public void transferred(long num) {
                                            publishProgress((int) ((num / (float) totalSize) * 100));
                                        }
                                    });

                            File sourceFile = new File(
                                    compressImage(allPath[i]));

                            // Adding file data to http body
                            entity.addPart("tag", new StringBody(
                                    "productAdd"));

                            // Adding file data to http body
                            entity.addPart("image",
                                    new FileBody(sourceFile));

                            entity.addPart(
                                    "seller_id",
                                    new StringBody(
                                            CommonUtilities
                                                    .getSellerId(getApplicationContext())));
                            entity.addPart(
                                    "shop_id",
                                    new StringBody(
                                            CommonUtilities
                                                    .getCurentShopId(
                                                            getApplicationContext())
                                                    .toString()));
                            entity.addPart(
                                    "product_pId",
                                    new StringBody(
                                            CommonUtilities
                                                    .getMaxProductId(
                                                            getApplicationContext())
                                                    .toString()));

                            entity.addPart("cat_id", new StringBody(cat_id));

                            entity.addPart("product_image", new StringBody(
                                    allPath[i]));

                            totalSize = entity.getContentLength();

                            httppost.setEntity(entity);

                            // Making server call
                            HttpResponse response = httpclient
                                    .execute(httppost);

                            HttpEntity r_entity = response.getEntity();

                            int statusCode = response.getStatusLine()
                                    .getStatusCode();

                            if (statusCode == 200) {
                                // Server response
                                responseString = EntityUtils
                                        .toString(r_entity);
                            } else {
                                responseString = "Error occurred! Http Status Code: "
                                        + statusCode;
                                flagForError = true;

                            }

                        } catch (ClientProtocolException e) {
                            responseString = e.toString();
                            flagForError = true;

                        } catch (IOException e) {
                            responseString = e.toString();

                            flagForError = true;
                        }

                        if (flagForError == false) {

                            updateAfterResponse(responseString);

                        } else {

                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    // TODO Auto-generated method stub

                                    uploadDialog.cancel();
                                    dialogForError();
                                }
                            });

                            task.cancel(true);
                            break;

                        }
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                progressBar.setProgress(0);
                            }
                        });

                        if (i == allPath.length - 1) {

                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    // TODO Auto-generated method stub
                                    txtCount.setText("Done");
                                }
                            });

                        }
                        // return responseString;
                    }
                    return null;

                }

                @Override
                protected void onPostExecute(Void result) {

                    // showing the server response in an alert
                    // dialog

                    super.onPostExecute(result);

                    // if (i == (allPath.length - 1)) {

                    if (uploadDialog.isShowing()) {

                        uploadDialog.dismiss();
                    }

                }

            }.execute();

and it is giving me error
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime: Process: com.elsner.orderlite, PID: 10320
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime: java.lang.RuntimeException: An error occured while executing doInBackground()
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at android.os.AsyncTask$3.done(AsyncTask.java:300)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     a`enter code here`t java.util.concurrent.FutureTask.run(FutureTask.java:242)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:841)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:  Caused by: java.lang.NoClassDefFoundError: org.apache.http.Consts
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at org.apache.http.entity.mime.content.StringBody.<init>(StringBody.java:147)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at com.elsner.sellerproduct.CustomGalleryActivity$2$1.doInBackground(CustomGalleryActivity.java:311)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at com.elsner.sellerproduct.CustomGalleryActivity$2$1.doInBackground(CustomGalleryActivity.java:221)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-10 17:35:58.710 10320-10340/? E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:841)

A: in bundle.gradle use
compile('org.apache.httpcomponents:httpmime:4.3.6') {
    exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'

A:
To do multipart POST calls, you need to get three additional Apache
  open source projects: Apache Commons IO, Mime4j, and HttpMime. You can
  download these projects from the following web sites: Commons IO:
  http://commons.apache.org/io/ Mime4j: http://james.apache.org/mime4j/
  HttpMime: http://hc.apache.org/downloads.cgi (inside of HttpClient)

A: If you are using sdk version 23, you have to add to your gradle:
android {
    compileSdkVersion 23
    ...
useLibrary 'org.apache.http.legacy'
    ...
}


text:
Q: F# applying universally typed mapping I'm struggling with finding out why this code below doesn't work.
Let's say I defined a function Map (like List.Map) for universal type.
type Uni = Iu of int
            | Flu of float
            | Su of string
            | Bu of bool
            | Lu of Uni List
            | Fu of (Uni -> Uni)

let uMap : Uni -> Uni -> Uni =
    fun (Fu f) (Lu xs) -> Lu (List.map f xs)

That works fine, now I'm trying to call that function but my code doesn't seem to match with the function signature.
uMap (Fu(fun (Iu(x)) -> Iu(x) + Iu(1))) (Lu([Iu(2); Iu(3); Iu(4)]))

The error is to be from the function applied for mapping (the first argument), more specifically, from the Iu(1) within (Fu(fun (Iu(x)) -> Iu(x) + Iu(1)))

error FS0584: Successive patterns should be separated by spaces or
  tupled

How should I use this function? I can't seem to find any problem with it.

A: I think you actually wanted
uMap (Fu(fun (Iu(x)) -> Iu(x + 1))) (Lu([Iu(2); Iu(3); Iu(4)]));;

A few of your brackets were in the wrong place and I think you used Iu(x) an Iu(1) in places where you meant x and 1 respectively.


text:
Q: How does bounty awarded by community to an answer with 1 upvote? This answer to Android "No content provider found for permission revoke" has one upvote and has 25 bounty awarded by community. What I know is that, community awards bounty only if the answer has 2 or more vote ups, but in this case the vote ups are only 1. How come in this case the bounty is awarded?

A: The first count of daily votes in the answer's timeline is from a few months after the bounty was awarded, and before the first edit.  At that time the question had one upvote, but there's no public data about prior votes.
To get the bounty the answer must have had a second upvote at the time.
 Because there were no earlier edits, users who upvoted wouldn't have been able to remove those votes.  However, when votes are invalidated or users are deleted, those votes vanish without a trace.  If you've ever lost rep to a "user was removed" event, you know that you don't get told which specific posts were affected.  Unless you happen to notice (for example, you have a Good Answer on something that's now +24/-0), you can't find out.  Even moderators don't have that information.
The most likely explanation is that there was a second vote at the time the bounty ended, and sometime in the next few months that vote was invalidated or the voting user was deleted.


text:
Q: Rendering data, fetched from an API in react-native I am using React-Native and am having issues just getting data to render from an API, into the render function. I'm running node JS and express on one end to pull some data from a SQL database. This returns JSON that looks like this:
{"routines":[{"routine_id":1,"name":"Morning Routine","start_time":"2020-03-09T14:24:38.000Z","end_time":"2020-03-09T15:24:44.000Z","is_approved":0}]}

I want to loop through the routines key and print out each routine as components in React. I don't really care about what type of component that gets used, I just want to get the data. I've tried a few methods:
Method 1: Using componentDidMount with fetch:
 constructor() {
    super();
    this.state = { routines: {} }
}

componentDidMount() {
    fetch('http://localhost:3000/routines')
    .then((response) => response.json())
    .then((responseJson) => {
        return responseJson;
    })
    .then( routines  => {
        this.setState({routines: routines});

    })
    .catch( error => {
        console.error(error);
    });
}

render() {
    console.log(this.state)

render of this.state logs an empty object, despite the then(routines portion of the code returning the correct data.
Method 2: Putting everything in componentDidMount
  async componentDidMount() {
    const response = await fetch("http://localhost:3000/routines")
    const json = await response.json()
    console.log('json');
    console.log(json);
    const routines = json.routines
    this.setState({routines})
}

Again, logging the state in render produces nothing while logging the json that gets returned from componentDidMount does return valid data.
Inside the render method i've also tried:
const { routines } = this.state;

And routines comes up as undefined.
Method 3: Directly calling a function to set the state.
constructor() {
        super();
        this.state = { routines: this.fetchData() }
    }

This ends up returning some weird data:
{"routines": {"_40": 0, "_55": null, "_65": 0, "_72": null}}

I'm assuming it's because react native does not want me to do this.
I just want a simple way to fetch data from an API and display that data in render. I've gone through about four tutorials and all of them end up with undefined or objects set as the default value in the constructor in the render method. Am I going crazy? It feels like this is somehow impossible..?

A: You do everything right, just use state in render and you will see updates.
constructor() {
    super();
    this.state = { routines: [] }
}

render() {
    const { routines } = this.state

    return (
        <View>
            {routines.map(item => <Text>{item.name}</Text>)}
        </View>
    )
}

A: Since fetch is an async task the data this.setState({routines}) get's set after render() is executed. You can execute this.forceUpdate() after setting this.setState({routines}). This will re-execute render() when the data is set.
See: https://reactjs.org/docs/react-component.html#forceupdate
However, debugging mode can also be the culprit.

A: its may be because fetch call is async ,and your render method may try to use it before its loaded by the api call,
so your componentDidMount should be like
 componentDidMount() {
 this.setState({routines:null})
//fire an api call
fetch('http://localhost:3000/routines')
.then((response) => response.json())
.then((responseJson) => {

    return responseJson;
})
.then( routines  => {
    this.setState({routines: routines});

})
.catch( error => {
    console.error(error);
});

}
now inside your render function you should first confirm that routines is not null and have some valid values like
render(){
 if(this.state.routines !==null){
   //your code to render component
 }else{
   //your loading or error message
  }
}


text:
Q: Decrypting bytes encrypted by .NET's RijndaelManaged using Java I am trying to decrypt something, which was encrypted using RijndaelManaged of .NET/C#, using Java to decrypt.
The C# program is not mine; I cannot change it to be more interoperable. But I know how it is encrypting:
byte[] bytes = new UnicodeEncoding().GetBytes(password); // edit: built-in is 8chars
FileStream fileStream = new FileStream(outputFile, FileMode.Create);
RijndaelManaged rijndaelManaged = new RijndaelManaged();
CryptoStream cryptoStream = new CryptoStream((Stream) fileStream,
    rijndaelManaged.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);

I do not know how to decrypt this on the Java end. The closest thing to useful I have found is this blog post, but it is light on actual details and I could not implement a decrypter.
Edit: I'm an idiot and now have it working.
UnicodeEncoding is UTF-16LE, while I was using UTF-8. Switching to the proper encoding when plugging the password in has fixed the program.
I also needed to get BouncyCastle and do Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
finaledit: Here's the code to decrypt a default RijndaelManaged stream from .NET in Java, assuming it was created using a raw password as the key:
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
String password = "kallisti"; // only 8, 12, or 16 chars will work as a key
byte[] key = password.getBytes(Charset.forName("UTF-16LE"));
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"),
    new IvParameterSpec(key));
return cipher; // then use CipherInputStream(InputStream, Cipher)

And remember: if you control the C# end, don't use an underived password as your key!

A: It's possible using the standard AES decryption. Rijndel is just a superset of AES which is more lax with particular options. See Rijndael support in Java for more details.
From the answer given in the linked question:
byte[] sessionKey = null; //Where you get this from is beyond the scope of this post
byte[] iv = null ; //Ditto
byte[] plaintext = null; //Whatever you want to encrypt/decrypt
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
//You can use ENCRYPT_MODE or DECRYPT_MODE
cipher.calling init(Cipher.DECRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv));
byte[] ciphertext = cipher.doFinal(plaintext);


text:
Q: How to go through a column of arrays and flag each row based on is it contains an item in a list? I have an array with two columns. The first contains a name and the second contains an arraylist of items with each name being different and each arraylist within the rows containing different values that have been aggregated together. I then have a list of items. I want to flag the rows in which the array contains a value that is also in the list with a yes or a no if nothing matches. This is the code I have thus far:
 df1 = df.withColumn("ITEM_FLG",
              f.when(f.array_intersect(f.col("ITEM_DESCR_SET"), item_list), f.lit("Y"))
              .otherwise("N")
             )

'ITEM_FLG" is the column I want to create with the values, 'ITEM_DESCR_SET' is the column that contains the array lists, and 'item_list' contains the list of items I am checking for. When I run the code, however, I get 'TypeError: Invalid argument, not a string or column' which is because of the item_list I believe.
need this for pyspark ideally or pandas if necessary. thank you!

A: We can use arrays_overlap() to check if any of the items from the item_list is in your array column. But, we'd need to convert the item_list list to a pyspark array field.
Here's a simple example.
data_sdf = spark.sparkContext.parallelize(data_ls).toDF(['names_array'])

# +------------------+
# |       names_array|
# +------------------+
# |   [foo, bar, baz]|
# |[karen, sam, john]|
# +------------------+

# root
#  |-- names_array: array (nullable = true)
#  |    |-- element: string (containsNull = true)

name_list = ['bar', 'carter', 'samantha']

# convert the list to a pyspark ArrayType()
name_psarray = func.array(*[func.lit(k) for k in name_list])
# Column<'array(bar, carter, samantha)'>

data_sdf. \
    withColumn('name_flag',
               func.when(func.arrays_overlap('names_array', name_psarray), func.lit('Y')).
               otherwise(func.lit('N'))
               ). \
    show(truncate=False)

# +------------------+---------+
# |names_array       |name_flag|
# +------------------+---------+
# |[foo, bar, baz]   |Y        |
# |[karen, sam, john]|N        |
# +------------------+---------+


text:
Q: Created an unsigned int based on 8 hexadecimal bytes I am trying to print out an unsigned int as a hex, but not simply using %08X. I need to print the hex of the MSB and the LSB for each byte with the MSB first. I have gotten that:
unsigned int num = 1234567890;
char *p = (char*)#
for (int i = 0; i < 4; i++) {
    printf("%X%X", (*(p+i) & 0xF0) >> 4, *(p+i) & 0x0F);
}
// prints: D2029649

However I am having trouble going back to an unsigned int from a string containing D2029649:
short dehex(char hexLetter) {
  if(hexLetter > 47 && hexLetter < 58) hexLetter -= 48;
  if(hexLetter > 64) hexLetter -= 55;
  return hexLetter;
}

unsigned int o = 0;
char *in = "D2029649";
int len = strlen(in);
for(int i = 0; i < len; i++) {
    if(i % 2 == 0) {
        o |= ((unsigned char)dehex(in[i]) << 4) + dehex(in[i+1]);
        o <<= 8;
    }
}

Needless to say, this doesn't work at all. The two lines of code manipulating o are the result of my attempts to undo what the original encoding does and some research I did on how to turn bytes back into an int.
Perhaps my trouble comes with a complete misunderstanding of what I am actually doing when I am generating the hex.
Does anyone have any tips to get me going in the right direction to take the hex back to the original unsigned int?

A: The purpose of your exercise appears to be converting the integer to a string, based on its memory layout, and then converting it back.
Otherwise, you wouldn't fiddle around with trying to figure out whether you're on a byte boundary or not and then doing bit-shift "gymnastics". Rather, you'd just just left shift the value by four and add the next digit in, something like:
#include <stdio.h>
#include <string.h>

short dehex (char hexLetter) {
    if ((hexLetter >= '0') && (hexLetter <= '9'))
        return hexLetter - '0';
    return hexLetter - 'A' + 10;
}

int main (void) {
    unsigned int o = 0;
    char *in = "D2029649";
    int len = strlen (in);
    for (int i = 0; i < len; i++)
            o  = (o << 4) + dehex (in[i]);
    printf ("%X\n", o);
    return 0;
}

You'll notice I've changed the dehex function slightly since I'm not a big fan of magic numbers where character constants are much more readable (it's still not portable to all implementations, such as EBCDIC, but there's precious few of those around nowadays).
This program will output the unsigned integer value from that string in uppercase hex for checking: D2029649.
However, the value 1234567890 decimal is, in hex, 499602D2, with the order of the bytes reversed from what you have in your string. That's because you're on what's known as a little-endian architecture.
So you have two problems.
The first is that you're processing the bytes in the wrong order for getting back your original number.
You need to start at the end of the string and work backwards, something like:
for (int i = len - 2; i >= 0; i -= 2) ...

The second is that you're doing the add/shift operations in the wrong order.
Because your original code shifted after the add, it was getting to D2029649 and then shifting that left by eight bits resulting in 02964900 - the D2 shifts off the left into oblivion and a zero byte is shifted in at the right. You need to shift then add:
o <<= 8;
o |= ((unsigned char)dehex(in[i]) << 4) + dehex(in[i+1]);

Finally, though not necessary, you can simplify your code quite a bit if you just use unsigned char for returning the converted nybble. The code I would write would be along the following lines:
#include <stdio.h>
#include <string.h>

unsigned char dehex (char hexLetter) {
    if ((hexLetter >= '0') && (hexLetter <= '9'))
        return hexLetter - '0';
    return hexLetter - 'A' + 10;
}

int main (void) {
    unsigned int num = 1234567890;
    char *p = (char*) #
    for (int i = 0; i < 4; i++)
        printf("%X%X", (*(p+i) & 0xF0) >> 4, *(p+i) & 0x0F);
    putchar ('\n');

    unsigned int o = 0;
    char *in = "D2029649";
    int len = strlen (in);
    for (int i = len - 2; i >= 0; i -= 2) {
        o <<= 8;
        o |= (dehex (in[i]) << 4) + dehex (in[i+1]);
    }
    printf ("%X, or %u\n", o, o);
    return 0;
}

Note that that makes a lot more sense in terms of doing it a byte at a time rather than a nybble at a time. With nybble-based code, you would have to do array indexes in the order 6, 7, 4, 5, 2, 3, 0, 1 rather than a nice little 0..7 loop.
The output of this program is:
D2029649
499602D2, or 1234567890

showing that you're getting back your original number.


text:
Q: Comparing 2 custom objects - C# I need to write a generic method in the base class that would accept 2 objects as parameters and compares them for equality.
Ex:
public abstract class BaseData
{

  public bool AreEqual(object O1, object O2)
  {
    //Need to implement this
  }
}

public class DataTypeOne : BaseData
{
  public string Name;
  public string Address;
}

public class DataTypeTwo : BaseData
{
  public int CustId;
  public string CustName;
}

The AreEqual() method would accept 2 instances of DataTypeOne or 2 instances of DataTypeTwo.
My guess is I need to use Reflection? I can use LINQ if it can be more readable/concise.
EDIT:
The reason I would like to implement this method in the base class is because of project restrictions. There are a large number of devs working on the derived classes. By implementing this in the base class, I am trying to have 1 less thing for them to worry about.

A: Here's what I came up with using reflection.  Hope it helps.
public bool AreEqual(object obj)
    {
        bool returnVal = true;

        if (this.GetType() == obj.GetType())
        {
            FieldInfo[] fields = this.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

            foreach (FieldInfo field in fields)
            {
                if(field.GetValue(this) != field.GetValue(obj))
                {
                    returnVal = false;
                    break;
                }
            }
        }
        else
            returnVal = false;

        return returnVal;
    }

A: Don't do it. Inheritance is the way to go and each class, should override the Equal and GetHashCode where needed.
Maybe you'll get some work done out of those developers now but I'll come back to bite you in the ass in the future when the product needs to be maintained.
Seriously, just try to find another way to help.

A: (Assuming that what you want is to compare all the fields of the two objects for equality.)
Usually, you wouldn't bother using reflection for this, you'd just compare each field yourself.  The IEquatable<T> interface exists for this purpose, and you also might want to override Object.Equals() on the types in question.  For example:
public class DataTypeTwo : BaseData, IEquatable<DataTypeTwo>
{
    public int CustId;
    public string CustName;

    public override int GetHashCode()
    {
        return CustId ^ CustName.GetHashCode(); // or whatever
    }

    public override bool Equals(object other)
    {
        return this.Equals(other as DataTypeTwo);
    }

    public bool Equals(DataTypeTwo other)
    {
        return (other != null &&
                other.CustId == this.CustId &&
                other.CustName == this.CustName);
    }
}

Also, consider whether or not your type makes sense as a struct instead.  Value types automatically compare equality by doing a field-by-field comparison.
Note that by overriding Equals, you basically achieve what (it seems to me) you're trying to achieve with your "master equals method" scheme.  That is, people using DataTypeTwo will be able to naturally test for equality without having to know anything special about your API -- they'll just use Equals like they would with other things.
EDIT:  Thanks to Jared for reminding me about GetHashCode.  You'll also want to override it to maintain normal-looking behavior in hashtables by making sure that any two objects which are "equal" also return the same hash code.

A: I would probably do something like this:
public abstract class BaseData : IEquatable<BaseData>
{
    public abstract bool Equals(BaseData other);
}

public class DataTypeOne : BaseData
{
    public string Name;
    public string Address;

    public override bool Equals(BaseData other)
    {
        var o = other as DataTypeOne;
        if(o == null)
            return false;
        return Name.Equals(o.Name) && Address.Equals(o.Address);
    }
}

public class DataTypeTwo : BaseData
{
    public int CustId;
    public string CustName;

    public override bool Equals(BaseData other)
    {
        var o = other as DataTypeTwo;
        if (o == null)
            return false;
        return CustId == o.CustId && CustName.Equals(o.CustName);
    }
}

A: Yes, you will have to use reflection, because the base class knows nothing about derived classes. But why do you want to implement that function in the base class? Why not in the derived classes?
Further there is a standard way to do this by overriding Object.GetHashCode() and Object.Equals().

A: public void CompareTwoObjects()
{
    try {
        byte[] btArray = ObjectToByteArray(object1);   //object1 is you custom object1
        byte[] btArray2 = ObjectToByteArray(object2); //object2 is you custom object2
        bool result = ByteArrayCompare(btArray, btArray2);
    } catch (Exception ex) {
        throw ex;
    }
}

public byte[] ObjectToByteArray(object _Object)
{
    try {
        // create new memory stream
        System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream();

        // create new BinaryFormatter
        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _BinaryFormatter
            = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

        // Serializes an object, or graph of connected objects, to the given stream.
        _BinaryFormatter.Serialize(_MemoryStream, _Object);

        // convert stream to byte array and return
        return _MemoryStream.ToArray();
    } catch (Exception _Exception) {
        // Error
        Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
    }

    // Error occured, return null
    return null;
}

public bool ByteArrayCompare(byte[] a1, byte[] a2)
{
    if (a1.Length != a2.Length)
        return false;

    for (int i = 0; i < a1.Length; i++)
        if (a1[i] != a2[i])
            return false;

    return true;
}