analysis – C # How to validate the CSV headers compared to the expected list, without 2 sections like this one?

My application (legacy code) reads a CSV input file with an expected format w.r.t. Column names as follows.

1st column – should say "Marker"
2nd column – should say "Category"
3rd column … to … N columns – These are the actual data columns. Must have a number starting with 1 and increasing by 1 going to the right.

In other words, the 3rd column must have "1", the 4th column header must have "2".

Sample CSV file with 10 columns of data (total of 12 columns in the file):

Marker,Category,1,2,3,4,5,6,7,8,9,10
TODD,Sea,0.001062344,0.001931534,0.002334951,0.002738369,0.003141786,0.003545203,0.004788256,0.005917489,0.007025671,0.008078547
JAMIE,Fork,0.00133847,0.002433581,0.002941854,0.003450128,0.003958402,0.004466676,0.006032825,0.007455569,0.00885179,0.010178331
LENNY,PITCH,0.001686365,0.003066119,0.003706504,0.004346889,0.004987274,0.005627659,0.007600883,0.009393428,0.011152557,0.012823893

My code, who does this validation (and it works) is the following …

fileStream = new FileStream(delimitedFileName, FileMode.Open,
   FileAccess.Read, FileShare.Read);
csvStreamReader = new StreamReader(fileStream);
string headerLine = csvStreamReader.ReadLine();
var headers = headerLine.Split(delimiter, '\');

if (!string.Equals(headers(0), "Marker", StringComparison.InvariantCultureIgnoreCase) 
|| (!string.Equals(headers(1), "Category", StringComparison.InvariantCultureIgnoreCase)))
{
    throw new Exception("Invalid file format. Please use template (MarkerTemplate.csv).");
}

for (int i = 2; i < headers.Length; i++)
{
    if (!string.Equals(headers(i), (i-1).ToString(),
        StringComparison.InvariantCultureIgnoreCase))
    {
    throw new Exception("Invalid file format. Please use template (MarkerTemplate.csv).");
    }
}

I want to avoid doing it like that, in 2 steps.

Is there a way to do some sort of delegate or Action do the 2nd section, that is, validate that the names of the columns of data are correct, for a variable number of columns of data?

I want to avoid doing it in 2 separate sections as shown above and have duplicates throw new Exception code for essentially the same exception.

You also want the code to be more elegant 🙂

[Serious] What is expected to say in return?

So, a member of my family just came out of a psychiatric facility.
To tell the truth…
Someone who tells you that she is depressed and suicidal. What should we tell them? I find it hard to find words to say during these conversations and I am trying to find out what you are advising to do.

Mining theory – Can we measure Bitcoin's accumulated work in terms of entropy (in bits) directly rather than in expected number of hashes?

L & # 39; background

Bitcoin follows the chain job by counting the minimum expected number of hashes required to create a string of the same number of blocks and the same difficulty steps (1). Of course, the accumulated work measured in this way (for example, the expected number of hashes) increases with each new block added to the chain.

For a given target t, the minimum The expected number of hash tests needed to find a block that meets the proof of work criteria (hash less than or equal to t) is geometrically distributed (2) with the parameter p = t / 2^256.

We can calculate the entropy, w, of such a random variable geometrically distributed (3) by the equation w (p) = (- (1-p)log2 (1-p) – plog2 (p)) / p, and using p = t / 2^256 we can trivially rewrite this into a function of the target instead, w(t).

Using this method, we can calculate the minimum work (for example, entropy) w(t), in bits, necessary to describe the proof of work signal. The other components of the blockchain (such as the data contained in the blocks in addition to the proof of work signal) are not included in this analysis; that is why it is an estimate of the minimum coding.

Connect some numbers:

  • for the zero block (and any block with the lowest possible difficulty, from where p = 1 / 2^32), we have approximately 33.44 bits working by block.
  • for a newer block, let's say block #602784 we haveapproximately 76.97 bits working by block.

The question

Can we complete the above analysis for each difficulty period and add the entropies to get a lower limit on the bitcoin blockchain's minimum (bitcoin) complexity? Or is there a hypothesis (such as the possibility of summarizing entropy in this context?) Who is dangerous / wrong?

Attempted response and motivation

Performing such an analysis (4) seems to give a result, from block 602784, of about 36.9 million bits or 4.6 megabytes and growing.

However, one of the reasons why the method seems interesting is that, if it is reasonable, it seems that all the mathematical operations currently performed by the Bitcoin protocol with "time" (in the sense of the unix time stamp, such as the adjustments of the median advanced timestamps of n last block) could rather be performed in "bits". As such, could this be useful when / if the protocol is extended to work over large distances of space-time?

Again, there is probably something terribly wrong with this analysis, which is why the question is asked here.

The references

(1) Strongest vs. Longest Chain and Orphaned Blocks

(2) How is it that competing miners do not subvert the work of others?

(3) https://math.stackexchange.com/questions/490559/entropy-of-geometric-random-variable

(4) https://github.com/philbertw4/mathematicalbitcoin/blob/master/scala/SatsPerBit.sc

api – i get this error in this simple code, help me please json.decoder.JSONDecodeError: expected value: line 1 column 1 (character 0)

import requests,json
a=requests.get("http://saral.navgurukul.org/api/courses").json()
with open("params.json","w+") as b:
    json.dump(a,b)
    c=json.load(b)
    d=json.loads(c)
print(d)

I receive an error in this simple code some one please help
me guys

SharePoint library search does not work as expected

I have a simple document library that contains over 8,000 documents (invoices).
The user searches with partial characters of the invoice number.

Example: Find "111840-QAP0150969-69" by entering "QAP0150969-69"

but the SharePoint results are 0.

and the strange thing is, if I delete & # 39; – & # 39; from partial search criteria, it returns the exact invoice.

Could someone help me understand what's going on here?

Below is the log file query and I have no errors after this query.

eventSearchFlowDone: 0cbe723e-7916-4df0-a9af-e19566e0254c,
(path: "http: // xxxxxxxxxx / xx // new binding unit" OR
DocumentLink: "http: // xxxxxxxxxx / xx / New binding unit /" OR
ParentLink: "http: // xxxxxxx / xx / New binding unit /
AND) (QAP0150969-69)
-ContentClass = urn: content class: SPSPeople, Microsoft.SharePointSearchProviderFlow, 64, xxxxxx-APP22.

built – The lunch tool built by Android does not work as expected

I've cloned these rest.

git clone https://android.googlesource.com/platform/build
git clone https://android.googlesource.com/platform/build/soong
git clone https://android.googlesource.com/platform/build/blueprint

after the source my env exactly as shown in the Android build reference.
https://source.android.com/setup/build/building#initialize

I can not handle lunch well. lunch aosp_arm-eng Give me
build_build_var_cache:7: no such file or directory: build/soong/soong_ui.bash I created a copy of my build
in the root, but that did not help either. Subsequent order ./build/soong/soong_ui.bash
Give me go tool: no such tool "compile". However go tool compile works .

ripple – TfTypeError: expected property "0" of type Buffer, got Promise

the code is for a ripple address but I get this error (under the code)

const bip39 = require ("bip39");
const bip32 = require ("ripple-beep32");
const ripple = require (& # 39; ripple-keypairs & # 39;)

// var mnemonic = Shadow Join Tank prefers the surface around the tornado, the return of the enemy fish returns in parentheses & # 39;
// or generate:
mnemonic = bip39.generateMnemonic ()

console.log (& mnemonic: + mnemonic)
const seed = bip39.mnemonicToSeed (mnemonic) // add the second argument of the 25th encrypted word
console.log (& # 39; seed: & # 39; seed)
// const m = bip32.fromSeed (seed)
const m = bip32.fromSeedBuffer (seed)
console.log ("m:", m)
const keyPair = m.derivePath ("m / 44" / 144 "/ 0" / 0/0 "). keyPair.getKeyPairs ()
address const = ripple.deriveAddress (keyPair.publicKey)

console.log (& # 39; privateKey: & # 39; + keyPair.privateKey)
console.log (& # 39; publicKey: + keyPair.publicKey)
console.log (& # 39; address: + address)

This is the output when running the script.js node

C: JFF> node ps3.js –abort-on-uncaught-exception
mnemonic: ritual slam explain appearance man tail register future pink run drill insect
seed: promise {}

C: JFF node_modules typeforce index.js: 190
throws tfSubError (e, i)
^
TfTypeError: property "0" expected of type Buffer, got Promise
at captureStackTrace (C: JFF node_modules typeforce errors.js: 20:11)
at tfSubError (C: JFF node_modules typeforce errors.js: 99: 3)
at C: JFF node_modules typeforce index.js: 190: 17
at Array.every ()
to _tuple (C: JFF node_modules typeforce index.js: 186: 20)
at typeforce (C: JFF node_modules typeforce index.js: 233: 9)
on Function.HDNode.fromSeedBuffer (C: JFF node_modules ripple-beep32 lib hdnode.js: 32: 3)
to the object. (C: JFF ps3.js: 14: 17)
in Module._compile (internal / modules / cjs / loader.js: 956: 30)
on Object.Module._extensions..js (internal / modules / cjs / loader.js: 973: 10) {
message: expected property "0" of type Buffer, got Promise ",
__label: not defined,
__property: 0,
__type: (Function: _Buffer) {toJSON: (Function: linked)},
__value: Promise {},
__valueTypeName: Promise & # 39;
}

pr.probability – How to calculate an expected result?

I am not a mathematician, but a programmer who likes to solve mathematical puzzles, so forgive me if I do not use the correct terms.

Imagine that there are 100 lotteries with 100 tickets each. Lotteries have no connection with each other and all lotteries have exactly 1 prize. I buy 1 ticket from each lottery and I therefore have 100 tickets of 100 lotteries.

I know how to calculate the probability P (x) to obtain x price, with x ranging between 0 and 100. In total, all the probabilities added give 1.0

My question is: what is the expected number of prizes I will win? How do I calculate this correctly?

functions – the shortcode in the ID called post is not displayed as expected

Hello, I receive a message in the following theme:

$footer_post = get_post(pll_get_post(620));
echo $footer_post->post_content; // Load contents of the page

This shows the content of post (620) in the footer.

in the functions.php I've got:

function year_shortcode() {
$year = date('Y');
return $year;}
add_shortcode('YEAR', 'year_shortcode');

The problem is that when I write (YEAR) and try to use the short code in this specific post, the rendering will be similar to (YEAR) instead of 2019. Is that? bug or should I change my code? When I use the shortcode in a normal site, it is displayed correctly.

WordPress 5.2.4 last.

c ++ – Multi-threading slower than expected of a single-threaded loop

The following code is an experiment that I could play with the advantages of multi-threading in C ++. Given a number 10000000000 it calculates how many numbers are even, divisible by 5, divisible by 8, divisible by 10 between the range 1 at 10000000000.

First, it runs a single-threaded function followed by a multi-threaded function.

However, the problem with this is that the results I got were not as expected. This shows that multi-threading has no benefit. I do not even use mutex, just multiple threads.

Compiler / IDE used:

Microsoft Visual Studio 2019 Community Edition, C ++ 17, Version 64 Edition with Optimization / O2.

Code:

#include 
#include 
#include 
#include 
#include 

#define CALC_NUMBER 10000000000ull

struct Counters {
    unsigned long long int CountDivTen = 0;
    unsigned long long int CountDivEight = 0;
    unsigned long long int CountDivFive = 0;
    unsigned long long int CountEven = 0;
};

Counters DivCounter;

// For multi-threading
std::vector> parts = {
    {1, 2500000000}, {2500000001, 5000000000}, {5000000001, 7500000000},    
    {7500000001, 10000000000}
};

// Multi-threading counters.
std::vector MyCounters(4);


void SingleThreaded()
{
    std::chrono::high_resolution_clock::time_point StartTime = 
                         std::chrono::high_resolution_clock::now();

    for (unsigned long long x = 1; x <= CALC_NUMBER; ++x)
    {
        // Count the even number
        if ((x % 2) == 0)
            ++DivCounter.CountEven;

        // Count divisible by 5
        if ((x % 5) == 0)
            ++DivCounter.CountDivFive;

        // Count divisible by 8
        if ((x % 8) == 0)
            ++DivCounter.CountDivEight;

        // Count divisible by 10
        if ((x % 10) == 0)
            ++DivCounter.CountDivTen;
    }

    auto elapsed = std::chrono::high_resolution_clock::now() - StartTime;
    auto seconds = std::chrono::duration_cast(elapsed).count();
    std::cout << "Time in seconds: " << seconds << std::endl;
}

void MultiThread_Merge(int index)
{
    for (unsigned long long x = parts(index).first; x <= parts(index).second; ++x)
    {
        // Count the even number
        if ((x % 2) == 0)
            ++MyCounters(index).CountEven;

        // Count divisible by 5
        if ((x % 5) == 0)
            ++MyCounters(index).CountDivFive;

        // Count divisible by 8
        if ((x % 8) == 0)
            ++MyCounters(index).CountDivEight;

        // Count divisible by 10
        if ((x % 10) == 0)
            ++MyCounters(index).CountDivTen;
    }
}

void DoThreadUsingMerge()
{
    // Start timer
    std::chrono::high_resolution_clock::time_point StartTime = 
                     std::chrono::high_resolution_clock::now();

    // Create four Threads
    std::vector MyThreads(4);

    // Create Threads
    for (size_t i = 0; i < MyThreads.size(); ++i) {

        MyThreads(i) = std::thread(MultiThread_Merge, i);
    }

    // Wait for all threads to finish.
    for (size_t i = 0; i < MyThreads.size(); ++i) {

        MyThreads(i).join();
    }

    // When threads are done, add up numbers.
    for (auto i : MyCounters)
    {
        // Add all the numbers.
        DivCounter.CountEven += i.CountEven;
        DivCounter.CountDivFive += i.CountDivFive;
        DivCounter.CountDivEight += i.CountDivEight;
        DivCounter.CountDivTen += i.CountDivTen;
    }

    // Stop timer and get time.
    auto elapsed = std::chrono::high_resolution_clock::now() - StartTime;
    auto seconds = std::chrono::duration_cast(elapsed).count();
    std::cout << "Time in seconds: " << seconds << std::endl;
}

void DisplayCounters()
{
    std::cout << "Count divisible by 2: " << DivCounter.CountEven << std::endl;
    std::cout << "Count divisible by 5: " << DivCounter.CountDivFive << std::endl;
    std::cout << "Count divisible by 8: " << DivCounter.CountDivEight << std::endl;
    std::cout << "Count divisible by 10: " << DivCounter.CountDivTen << std::endl;
}


int main()
{
    std::cout << "Calculation number: " << CALC_NUMBER << std::endl;

    std::cout << "n============================================n";
    std::cout << "nSingle-Threaded ..n";

    SingleThreaded();

    DisplayCounters();

    // Reset for multi-thread
    DivCounter.CountEven = 0;
    DivCounter.CountDivFive = 0;
    DivCounter.CountDivEight = 0;
    DivCounter.CountDivTen = 0;

    std::cout << "n============================================n";
    std::cout << "nMulti-Threaded (Merge) ..n";

    DoThreadUsingMerge();
    DisplayCounters();

    system("pause");
}

The exits:

Here is the output on 4 processor cores, Windows 8.1 OS:

Calculation number: 10000000000

==========================================

Unifilar .. Time in seconds: 36
Account divisible by 2: 5000000000
Account divisible by 5: 2000000000
Account divisible by 8: 1250000000
Account divisible by 10: 1000000000

==========================================

Multi-Threaded (Merge) .. Time in seconds: 42
Account divisible by 2: 5000000000
Account divisible by 5: 2000000000
Account divisible by 8: 1250000000
Account divisible by 10: 1000000000
Press any key to continue. . .

Here is the output on the 6-core processor, Windows 10:

Calculation number: 10000000000

==========================================

Unifilar .. Time in seconds: 32
Account divisible by 2: 5000000000
Account divisible by 5: 2000000000
Account divisible by 8: 1250000000
Account divisible by 10: 1000000000

==========================================

Multi-Threaded (Merge) .. Time in seconds: 45
Account divisible by 2: 5000000000
Account divisible by 5: 2000000000
Account divisible by 8: 1250000000
Account divisible by 10: 1000000000
Press any key to continue. . .

Results:

The results show that, regardless of the number of times and regardless of the number of cores, the multithreaded code does not benefit from the threads.

What is the reason why this code does not behave as expected? Have I come across a code that does not benefit or can not benefit from multi-threading?