text:
Q: Web audio oscillator is clicking in Firefox only I'm trying to create a simple metronome using the web audio oscillator, so that no external audio files are needed. I'm creating the sound of the metronome by ramping the volume of the oscillator up and down very quickly (since you can't use start() and stop() more than once), and then repeating that function at a set interval. It ends up sounding like a nice little wood block.
The code below works/sounds great in Chrome, Safari and Opera. But in Firefox, there's a nasty intermittent "click" when the volume ramps up. I've tried changing the attack/release times to get rid of the click, but they have to be really, really long before it consistently disappears. So long, in fact, that the oscillator just sounds like a sustained note.
var audio = new (window.AudioContext || window.webkitAudioContext)();
var tick = audio.createOscillator();
var tickVol = audio.createGain();

tick.type = 'sine';
tick.frequency.value = 1000;
tickVol.gain.value = 0; //setting the volume to 0 before I connect everything
tick.connect(tickVol);
tickVol.connect(audio.destination);
tick.start(0);

var metronome = {
    start: function repeat() {
        now = audio.currentTime;

        //Make sure volume is 0 and that no events are changing it
        tickVol.gain.cancelScheduledValues(now);
        tickVol.gain.setValueAtTime(0, now);

        //Play the osc with a super fast attack and release so it sounds like a click
        tickVol.gain.linearRampToValueAtTime(1, now + .001);
        tickVol.gain.linearRampToValueAtTime(0, now + .001 + .01);

        //Repeat this function every half second
        click = setTimeout(repeat, 500);
    },
    stop: function() {
        if(typeof click !== 'undefined') {
            clearTimeout(click);
            tickVol.gain.value = 0;
        }
    }
}

$("#start").click(function(){
  metronome.start();
});

$("#stop").click(function(){
  metronome.stop();
});

Codepen
Is there any way to get FF to sound like the other 3 browsers?

A: I was getting the exact same problem in latest Opera and found the problem to be the individual sounds 'decimal time length'.
I wrote a morse code translator, and like yours, it's just a series of simple short sounds/beeps created via createOscillator.
With morse code you have a speed count (words per minute) based on a 5 letter long word like codex or paris.
To get 20 or 30 paris' per minute to finish exactly on the minute, I had to use a sound time length of, for example, 0.61. In Opera, this caused the 'end of sound click'. On changing this to 0.6 and the click disappeared across all browsers - except Firefox.
I've tried freq = 0 and gain = 0 between sounds but still get the click at the end in FF and I don't know enough about Web Audio to try anything else.
On another note, I noticed you're using a loop and timeout to get to the next tick. Have you tried an 'Oscillator onended function' instead? I've used it with a simple counter increment and variable length blank sound/note. Go to the very end of my JS if you want to have a look.
**UPDATE - I've been fiddling about with setValueAtTime() and linearRampToValueAtTime() and appeared to have cracked the click problem. Scroll to bottom of script to see example. **

(function(){

/* Morse Code Generator & Translator - Kurt Grigg 2003 (Updated for sound and CSS3) */

var d = document;
d.write('
'
+'
Morse Code Generator Translator
'
+'<textarea id="txt_in" class="Mtxtarea"></textarea>'
+'
Input
'
+'<textarea id="txt_out" class="Mtxtarea" style="top: 131px;"></textarea>'
+'
Output
'
+'
'
+'<input type="button" class="Mbuttons" id="how" value="!">'
+'<input type="button" class="Mbuttons" id="tra" value="translate">'
+'<input type="button" class="Mbuttons" id="ply" value="play">'
+'<input type="button" class="Mbuttons" id="pau" value="pause">'
+'<input type="button" class="Mbuttons" id="res" value="reset">
'
+'<select id="select" class="Mselect">'
+'<option value=0.07 selected="selected">15 wpm</option>'
+'<option value=0.05>20 wpm</option>'
+'<option value=0.03>30 wpm</option>'
+'</select>'
+'
volume <input id="volume" type="range" min="0" max="1" step="0.01" value="0.05"/>
'
+'
'
+'separator <input type="checkbox" id="slash" class="Mchckbox">'
+'
'
+'
'
+'Input morse
'
+'

Enter morse into input box using full stop (period) and minus sign (hyphen)
'
+'
Morse letters must be separated by 1 space
'
+'
Morse words must be separated by 3 or more spaces
'
+'
You can use / to separate morse words. There must be at least 1 space before and after each separator used
'
+'
'
+'Input text
'
+'

Enter text into input box
'
+'
Characters that cannot be translated will be ignored
'
+'
If morse and text is entered, the converter will assume morse mode

'
+'<input type="button" value="close" id="clo" class="Mbuttons">'
+'

A MSG
<input type="button" value="close" id="cls" class="Mbuttons">

');

var ftmp = d.getElementById('mdl');
var del;

d.getElementById('tra').addEventListener("click", function(){convertToAndFromMorse(txtIn.value);},false);
d.getElementById('ply').addEventListener("click", function(){CancelIfPlaying();},false);
d.getElementById('pau').addEventListener("click", function(){stp();},false);
d.getElementById('res').addEventListener("click", function(){Rst();txtIn.value = '';txtOt.value = '';},false);

d.getElementById('how').addEventListener("click", function(){msgSelect();},false);
d.getElementById('clo').addEventListener("click", function(){fadeOut();},false);

d.getElementById('cls').addEventListener("click", function(){fadeOut();},false);
d.getElementById('bdy').addEventListener("click", function(){errorSelect();},false);

var wpm = d.getElementById('select');
wpm.addEventListener("click", function(){wpMin()},false);

var inc = 0;
var playing = false;
var txtIn = d.getElementById('txt_in');
var txtOt = d.getElementById('txt_out');
var paused = false;
var allowed = ['-','.',' '];
var aud;
var tmp = (window.AudioContext || window.webkitAudioContext)?true:false;
if (tmp) {
    aud = new (window.AudioContext || window.webkitAudioContext)();
}
var incr = 0;
var speed = parseFloat(wpm.options[wpm.selectedIndex].value);
var char = [];
var alphabet = [["A",".-"],["B","-..."],["C","-.-."],["D","-.."],["E","."],["F","..-."],["G","--."],["H","...."],["I",".."],["J",".---"],
    ["K","-.-"],["L",".-.."],["M","--"],["N","-."],["O","---"],["P",".--."],["Q","--.-"],["R",".-."],["S","..."],["T","-"],["U","..-"],
    ["V","...-"],["W",".--"],["X","-..-"],["Y","-.--"],["Z","--.."],["1",".----"],["2","..---"],["3","...--"],["4","....-"],["5","....."],
    ["6","-...."],["7","--..."],["8","---.."],["9","----."],["0","-----"],[".",".-.-.-"],[",","--..--"],["?","..--.."],["'",".----."],["!","-.-.--"],
    ["/","-..-."],[":","---..."],[";","-.-.-."],["=","-...-"],["-","-....-"],["_","..--.-"],["\"",".-..-."],["@",".--.-."],["(","-.--.-"],[" ",""]];

function errorSelect() {
    txtIn.focus();
}

function modalSwap(msg) {
    d.getElementById('modalMsg').innerHTML = msg;
}

function msgSelect() {
    ftmp = d.getElementById('about');
    fadeIn();
}

function fadeIn() {
    ftmp.removeEventListener("transitionend", freset);
    ftmp.style.display = "block";
    del = setTimeout(doFadeIn,100);
}

function doFadeIn() {
    clearTimeout(del);
    ftmp.style.transition = "opacity 0.5s linear";
    ftmp.style.opacity = "1";
}

function fadeOut() {
    ftmp.style.transition = "opacity 0.8s linear";
    ftmp.style.opacity = "0";
    ftmp.addEventListener("transitionend",freset , false);
}

function freset() {
    ftmp.style.display = "none";
    ftmp.style.transition = "";
    ftmp = d.getElementById('mdl');
}

function stp() {
    paused = true;
}

function wpMin() {
    speed = parseFloat(wpm.options[wpm.selectedIndex].value);
}

function Rst(){
    char = [];
    inc = 0;
    playing = false;
    paused = false;
}

function CancelIfPlaying(){
    if (window.AudioContext || window.webkitAudioContext) {paused = false;
        if (!playing) {
            IsReadyToHear();
        }
        else {
            return false;
        }
    }
    else {
        modalSwap("
Your browser doesn't support Web Audio API
");
        fadeIn();
        return false;
    }
}

function IsReadyToHear(x){
    if (txtIn.value == "" || /^\s+$/.test(txtIn.value)) {
        modalSwap('
Nothing to play, enter morse or text first
');
        fadeIn();
        txtIn.value = '';
        return false;
    }
    else if (char.length < 1 && (x != "" || !/^\s+$/.test(txtIn.value)) && txtIn.value.length > 0) {
        modalSwap('
Click Translate button first . . .
');
        fadeIn();
        return false;
    }
    else{
        playMorse();
    }
}

function convertToAndFromMorse(x){
    var swap = [];
    var outPut = "";
    x = x.toUpperCase();

    /* Is input empty or all whitespace? */
    if (x == '' || /^\s+$/.test(x)) {
        modalSwap("
Nothing to translate, enter morse or text
");
        fadeIn();
        txtIn.value = '';
        return false;
    }

    /* Remove front & end whitespace */
    x = x.replace(/\s+$|^\s*/gi, '');
    txtIn.value = x;
    txtOt.value = "";

    var isMorse = (/(\.|\-)\.|(\.|\-)\-/i.test(x));// Good enough.

    if (!isMorse){
        for (var i = 0; i < alphabet.length; i++){
            swap[i] = [];
            for (var j = 0; j < 2; j++){
                swap[i][j] = alphabet[i][j].replace(/\-/gi, '\\-');
            }
        }
    }

    var swtch1 = (isMorse) ? allowed : swap;
    var tst = new RegExp( '[^' + swtch1.join('') + ']', 'g' );
    var swtch2 = (isMorse)?' ':'';
    x = x.replace( tst, swtch2);  //remove unwanted chars.
    x = x.split(swtch2);

    if (isMorse) {
        var tidy = [];
        for (var i = 0; i < x.length; i++){
            if ((x[i] != '') || x[i+1] == '' && x[i+2] != '') {
                tidy.push(x[i]);
            }
        }
    }

    var swtch3 = (isMorse) ? tidy : x;

    for (var j = 0; j < swtch3.length; j++) {
        for (var i = 0; i < alphabet.length; i++){
            if (isMorse) {
                if (tidy[j] == alphabet[i][1]) {
                    outPut += alphabet[i][0];
                }
            }
            else {
                if (x[j] == alphabet[i][0]) {
                    outPut += alphabet[i][1] + ((j < x.length-1)?"  ":"");
                }
            }
        }
    }

    if (!isMorse) {
        var wordDivide = (d.getElementById('slash').checked)?"  /  ":"     ";
        outPut = outPut.replace(/\s{3,}/gi, wordDivide);
    }

    if (outPut.length < 1) {
        alert('Enter valid text or morse...');
        txtIn.value = '';
    }
    else {
        txtOt.value = outPut;
    }

    var justMorse = (!isMorse) ? outPut : tidy;

    FormatForSound(justMorse);
}

function FormatForSound(s){
    var n = [];
    var b = '';
    if (typeof s == 'object') {
        for (var i = 0; i < s.length; ++i) {
            var f = (i == s.length-1)?'':'  ';
            var t = b += (s[i] + f);
        }
    }
    var c = (typeof s == 'object')? t : s;
    c = c.replace(/\//gi, '');
    c = c.replace(/\s{1,3}/gi, '4');
    c = c.replace(/\./gi, '03');
    c = c.replace(/\-/gi, '13');
    c = c.split('');
    for (var i = 0; i < c.length; i++) {
        n.push(c[i]);
    }
    char = n;
}

function vlm() {
    return document.getElementById('volume').value;
}

function playMorse() {

    if (paused){
        playing = false;
        return false;
    }

    playing = true;
    if (incr >= char.length) {
        incr = 0;
        playing = false;
        paused = false;
        return false;
    }

    var c = char[incr];
    var freq = 550;
    var volume = (c < 2) ? vlm() : 0 ;
    var flen = (c == 0 || c == 3) ? speed : speed * 3;

    var osc = aud.createOscillator();
    osc.type = 'sine';
    osc.frequency.value = freq;

    var oscGain = aud.createGain();
    oscGain.gain.value = volume;
    osc.connect(oscGain);
    oscGain.connect(aud.destination);

    var now = aud.currentTime;

    osc.start(now);

        /*
        Sharp volume fade to stop harsh clicks if wave is stopped
        at a point other than the (natural zero crossing point)
        */
        oscGain.gain.setValueAtTime(volume, now + (flen*0.8));
        oscGain.gain.linearRampToValueAtTime(0.0, now + (flen*0.9999));

    osc.stop(now + flen);

    osc.onended = function() {
        incr++;
        playMorse();
    }
}
})();
body {
    text-align: center;
}

.Mcontainer {
display: inline-block;
position: relative;
width: 382px;
height: 302px;
border: 1px solid #000;
border-radius: 6px;
text-align: center;
font: bold 11px sans-serif;
background-color: rgb(203,243,65);
box-shadow: 0px 4px 2px rgba(0,0,0,0.3);
}
.Mtitle {
-webkit-user-select: none;
-moz-user-select: none;
display: inline-block;
position: absolute;
width: 380px;
height: 20px;
margin: auto;
left: 0; right: 0;
font-size: 16px;
line-height: 20px;
color:  #666;
}
.Mtxtareatitle {
-webkit-user-select: none;
-moz-user-select: none;
display: block;
position: absolute;
top: 60px;
left: -36px;
height: 22px;
width: 106px;
font-size: 18px;
line-height: 22px;
text-align: center;
color: #555;
transform: rotate(-90deg);
}
.Mtxtarea {
display: block;
position: absolute;
top: 18px;
margin: auto;
left: 0; right: 0;
height: 98px;
width: 344px;
border: 0.5px solid #000;
border-radius: 6px;
padding-top: 6px;
padding-left: 24px;
resize: none;
background-color: #fffff0;
font: bold 10px courier;
color: #555;
text-transform: uppercase;
overflow: auto;
outline: 0;    box-shadow: inset 0px 2px 5px rgba(0,0,0,0.5);
}
.Minfo {
display: none;
position: absolute;
top: -6px; left:-6px;
padding: 6px;
height: auto;
width:  370px;
text-align: left;
border: 0.5px solid #000;
border-radius: 6px;
box-shadow: 0px 4px 2px rgba(0,0,0,0.3);
background-color: rgb(203,243,65);
font: 11px sans-serif;
color: #555;
opacity: 0;
}
.Mbuttonwrap {
display: block;
position: absolute;
top: 245px;
margin: auto;
left: 0; right: 0;
height: 26px;
width: 100%;
}
.Mbuttons {
display: inline-block;
width: 69px;
height: 22px;
border: none;
margin: 0px 3.1px 0px 3.1px;
background-color: transparent;
font: bold 11px sans-serif;
color: #555;
border-radius: 20px;
cursor: pointer;
box-shadow: 0px 2px 2px rgba(0,0,0,0.5);
outline: 0;
}
.Mbuttons:hover {
background-color:  rgb(213,253,75);
}
.Mbuttons:active {
position: relative;
top: 1px;
box-shadow: 0px 1px 2px rgba(0,0,0,0.8);
}
.Mchckboxwrap {
display: block;
position: absolute;
top: 274px;
left: 289px;
width: 87px;
height: 21px;
line-height: 22px;
border: 0.5px solid #000;
color: #555;
background: #fff;
-webkit-user-select: none;
-moz-user-select: none;
}
.Mselect {
display: block;
position: absolute;
top: 274px;
left: 6px;
width: 88px;
height: 22px;
border: 0.5px solid #000;
padding-left: 5%;
background: #fff;
font: bold 11px sans-serif;
color: #555;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: 0;
}
::selection {
color: #fff;
background: #555;
}
.Mchckbox {
margin-top: 1px;
vertical-align: middle;
cursor: pointer;
outline: 0;
}
.modal {
display: none;
position: absolute;
margin: auto;
top: 0;right: 0;bottom: 0;left: 0;
background: rgba(0,0,0,0.5);
-webkit-user-select: none;
-moz-user-select: none;
opacity: 0;
text-align: center;
}
.modal > div {
display: inline-block;
position: relative;
width: 250px;
height: 70px;
margin: 10% auto;
padding: 10px;
border: 0.5px solid #000;
border-radius:6px;
background-color: rgb(203,243,65);
font: bold 11px sans-serif;
color: #555;
box-shadow: 4px 4px 2px rgba(0,0,0,0.3);
text-align: center;
}
.sliderWrap {
display: block;
position: absolute;
top: 274px;
margin:auto;padding: 0;
left: 0; right: 0;
width: 184px;
height: 21px;
border: 0.5px solid #000;
background: #fff;
font: bold 11px sans-serif;
color: #555;
line-height: 21px;
text-align: center;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
outline: 0;
}
input[type=range] {
-webkit-appearance: none;
width: 50%;
margin: 0;padding: 0;
vertical-align: middle;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 4px;
cursor: pointer;
background: #666;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 1px 1px 0.5px rgba(0, 0, 0, 0.5);
border: none;
height: 10px;
width: 20px;
border-radius: 5px;
background: #ffffff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -3px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: #666;
}
input[type=range]::-moz-range-track {
width: 100%;
height: 4px;
cursor: pointer;
background: #666;
}
input[type=range]::-moz-range-thumb {
box-shadow: 1px 1px 0.5px rgba(0, 0, 0, 0.5);
height: 10px;
width: 20px;
border: none;
border-radius: 5px;
background: #ffffff;
cursor: pointer;
}
input[type=range]::-ms-thumb {
height: 10px;
width: 20px;
border: none;
border-radius: 5px;
background: #ffffff;
box-shadow: 1px 1px 0.5px rgba(0, 0, 0, 0.5);
cursor: pointer;
}
input[type=range]::-ms-track {
width: 100%;
height: 4px;
cursor: pointer;
background: transparent;
border: 5px solid transparent;
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #666;
}
input[type=range]::-ms-fill-upper {
background: #666;
}
::-ms-tooltip {
display: none;
}
select::-ms-expand {
display: none;
}

A: It would be best to get Firefox to fix the issue (if indeed it is a Firefox bug with automations).  Having said that, you could probably make all the browsers be consistent by using an AudioBufferSource node that has a precomputed click waveform that you want.  Just generate a sine wave, ramp it up and down as you want (manually) and play that back at regular intervals.
Not great, but it should be cross-platform.

A: AFAIK this issue is not specific to Firefox, although looking at your code, I'm unsure why it doesn't happen in other browsers.
The problem is that the moment you schedule a *rampToValueAtTime to an audible source when that source is not currently interpolating between two ramp points, the "clicking" sound occurrs, possibly due to how the underlying implementation will immediately start taking the new ramp point into consideration, even if it's scheduled to happen the future.
The clicking sound will also be heard if you schedule a new ramp point between two points between which interpolation is occurring.
What I came up with as a workaround solution is either using an alternative approach to gradually changing AudioParam values, setTargetAtTime, or setting the value property of the AudioParam to the first ramp point value. Not setValueAtTime, but assigning to the value property itself, before anything audible happens on the given branch.

setTargetAtTime
You'll be needing neither cancelScheduledValues nor setValueAtTime, just two calls to setTargetAtTime, which is just a setValueAtTime with an exponential interpolation with a specified length.
var metronome = {
    start: function repeat() {
        now = audio.currentTime;

        //Play the osc with a super fast attack and release so it sounds like a click
        tickVol.gain.setTargetAtTime(1, now, 0.01);
        tickVol.gain.setTargetAtTime(0, now + 0.01, 0.01);

        //Repeat this function every half second
        click = setTimeout(repeat, 500);
    }
}

Live demo on JSFiddle


text:
Q: Como validar telefone com sms React-Native No app em que estou trabalhando após fazer o login por facebook o usuário precisa preencher os dados dele, incluindo o telefone, mas preciso confirmar o telefone do usuário por sms antes de permitir ele salvar os dados
A autenticacao seria na mesma forma do accountkit porém o usuário já está logado
Existe algum modo de fazer isso?

A: Você deve utilizar serviços como por exemplo https://www.twilio.com/sms. No caso, você gera um código, envia por SMS para o número e o usuário deve confirmar.

redpajama_set_name: RedPajamaStackExchange


text:
Q: ImageMagick : Extractng images from PSD I'm trying to extract images from my PSD using this command :
 convert my_file.psd extracted/image-%d.png

The problem is some pictures are perfectly extracted, but about 60% are not. Here is a sample of what I get : http://dl.dropbox.com/u/78906691/image-93.png
Please help me.

A: I fixed it by removing the first layers. It seems like it was linked with transparency, so launched the command twice: once with the original, and once with another file in which I had removed the pictures I already got.


text:
Q: error in the execution of treetagger command tag-eng i 'm trying to do an application in java that use the treetagger.
so tapped this on eclipse
String commande="cmd /c  C:\Program Files (x86)\tree-tagger-windows-3.2\TreeTagger\bin\\tag-english"+" "+path;

 Process p=Runtime.getRuntime().exec(commande);

But it dosesn't work.
I have not much idea about the TreeTagger and to test if I install TreeTagger under windows I typed these commands on the command prompt cd C: \ Program Files (x86) \ tree-tagger-windows-3.2 \ TreeTagger \ bin and then
tag-English nom_de_fichier_à_tagger but the cmd displays this error message 'perl' is not recognized as an internal or external command, executable program or batch file.
the TreeTagger I install is a zip file I extracted to a folder and I put it in C: \ Program Files (x86) is what I did exactly
if I made a mistake during installation can you help me because I too searched the web and I understood nothing.

A: It sounds like you need to install a perl on windows.  I suggest that you use Strawberry Perl.
I have no experience with TreeTagger, but doing a little googling points to this reference: TreeTagger - a language independent part-of-speech tagger.  Scrolling down there is a Windows version in zip form, that contains an INSTALL.txt which states:
Installation
------------

1. Install a Perl interpreter (if you have not already installed one).
   You can download a Perl interpreter for Windows for free at
   http://www.activestate.com/activeperl/

2. Move the TreeTagger directory to the root directory of drive C:.

3. Download the PC parameter files for the languages you need, decompress
   them (e.g. using Winzip or 7zip) and move them to the subdirectory lib.
   Rename the parameter files to <language>.par
   Example: Rename french-par-linux-3.1.bin to french.par

   The UTF8 versions of the parameter files are not supported yet, but
   see below some hints on how to build tagging scripts for the UTF8
   parameter files.

4. Add the path C:\TreeTagger\bin to the PATH environment variable.

5. Open a shell and type the command
   set PATH=C:\TreeTagger\bin;%PATH%

6. Change to the directory C:\TreeTagger

7. Now you can test the tagger, e.g. by analyzing this file with the command
   tag-english INSTALL.txt

Obviously you must've skipped step 1. :) You could use ActiveState as they suggest, but these days Strawberry perl is a much better option in my opinion.


text:
Q: I want to run ping-pub/explorer and type yarn && yarn serve an error like this, how to solve it? root@vultr:~/explorer# yarn && yarn serve
yarn install v1.22.19
[1/5] Resolving packages...
[2/5] Fetching packages...
error @intlify/vue-i18n-loader@2.1.2: The engine "node" is incompatible with this module. Expected version ">= 12". Got "10.19.0"
error Found incompatible module.


text:
Q: Image to vector of points I'm trying to calculate the covariance of a multichannel image patch (using cv::calcCovarMatrix), so I can in turn calculate the Mahalonobis distance of a pixel from that patch and I'm really struggling to find the right options to reshape the matrix into the right format.
For example if my matrix has 3 rows, 4 columns, and 2 channels:
// Channel 1:
1 2 3 4
5 6 7 8
9 0 1 2

// Channel 2:
99 98 97 96
95 94 93 92
91 90 89 88

What I believe I need is to reshape the image into a shape with 3x4=12 rows and 2 columns (or its transpose):
// Desired result:
1  2  3  4  5  6  7  8  9  0  1  2
99 98 97 96 95 94 93 92 91 90 89 88

*

*Is this the correct format for cv::calcCovarMatrix?

*What parameters do I need for .reshape() to achieve this?

An example in code:
#include <opencv2/opencv.hpp>
int main(int argc, char* argv[])
{
    // Construct channel 1
    cv::Mat_<float> channel1 = (cv::Mat_<float>(3, 4) << 1.0, 2.0, 3.0, 4.0,
                                                         5.0, 6.0, 7.0, 8.0,
                                                         9.0, 0.0, 1.0, 2.0);
    std::cout << "Channel 1: " << std::endl;
    std::cout << channel1 << std::endl;

    // Construct channel 2
    cv::Mat_<float> channel2 = (cv::Mat_<float>(3, 4) << 99.0, 98.0, 97.0, 96.0,
                                                         95.0, 94.0, 93.0, 92.0,
                                                         91.0, 90.0, 89.0, 88.0);
    std::cout << "Channel 2: " << std::endl;
    std::cout << channel2 << std::endl;

    // Merge together
    std::vector<cv::Mat> stack;
    cv::Mat merged;
    stack.push_back(channel1);
    stack.push_back(channel2);
    cv::merge(stack, merged);
    std::cout << "Merged:" <<std::endl;
    std::cout << merged << std::endl;

    // Reshape
    cv::Mat reshaped = merged.reshape(0,1).reshape(1); // <----Need help with this line
    std::cout << "Reshaped:" <<std::endl;
    std::cout << reshaped << std::endl;

    return 0;
}

A: Not tested, but looking at the docs and the calcCovarMatrix() implementation, you should do something like
cv::Mat reshaped = merged.reshape(1,1);

or
cv::Mat reshaped = merged.reshape(1,3*4);

It seems that calcCovarMatrix() can process both column matrices and row-matrices.
You can take a look at the code in opencv/modules/core/src/matmul.cpp, line 2097


text:
Q: How do I store the output of a repeat loop in a dataframe My basic idea is to compute the Means of chunks (column-wise) of a large matrix and store these Means as rows of a data frame. Note, the chunks have different sizes (number of rows) and these are stored in a vector vec1. Below is my code:
df <- setNames(data.frame(matrix(nrow = 4000, ncol = 3)),
                             c("Age","Weight", "height"))
#
i <- 1
j <- vec1[1] - 1
k <- 0
repeat {
    elements <- as.vector(apply(mydata[i : (j + 1), 3:5], 2, mean))
    df <- rbind(df, elements)
    k <- k + 1
    i = i + vec1[k]
    j = j + vec1[k + 1]
    if (j + 1 >= l){
        break
    }
}

N.B.: When I perform the computations manually without looping it works. But the result of the loop yields a 4000 * 3 matrix filled with NA apart from the first row.
vec1 is a vector with 4000 entries, and whose first 500 elements - head(vec1, 500) -are below:
c(15L, 45L, 111L, 32L, 25L, 13L, 144L, 31L, 150L, 124L, 22L,
94L, 60L, 156L, 4L, 30L, 12L, 12L, 16L, 23L, 242L, 58L, 65L,
17L, 63L, 193L, 148L, 162L, 79L, 6L, 22L, 30L, 188L, 44L, 7L,
130L, 49L, 10L, 87L, 11L, 6L, 113L, 113L, 100L, 42L, 5L, 64L,
127L, 73L, 36L, 13L, 120L, 44L, 34L, 153L, 10L, 35L, 205L, 31L,
102L, 181L, 26L, 105L, 75L, 42L, 122L, 42L, 221L, 216L, 120L,
50L, 171L, 56L, 1L, 89L, 11L, 103L, 167L, 96L, 31L, 67L, 182L,
114L, 45L, 4L, 118L, 19L, 243L, 241L, 48L, 36L, 64L, 94L, 63L,
16L, 8L, 213L, 26L, 127L, 139L, 71L, 91L, 133L, 23L, 88L, 31L,
28L, 70L, 112L, 6L, 25L, 82L, 17L, 24L, 196L, 39L, 78L, 23L,
73L, 110L, 64L, 87L, 84L, 11L, 101L, 19L, 6L, 25L, 39L, 59L,
68L, 31L, 183L, 52L, 142L, 63L, 41L, 214L, 19L, 120L, 85L, 104L,
3L, 8L, 38L, 11L, 12L, 21L, 12L, 53L, 37L, 85L, 106L, 12L, 31L,
106L, 75L, 10L, 121L, 60L, 137L, 96L, 177L, 102L, 97L, 145L,
52L, 11L, 112L, 73L, 67L, 8L, 235L, 203L, 182L, 168L, 101L, 144L,
238L, 73L, 38L, 85L, 56L, 14L, 162L, 131L, 14L, 154L, 28L, 30L,
75L, 88L, 268L, 169L, 255L, 127L, 111L, 63L, 42L, 156L, 12L,
22L, 71L, 140L, 110L, 33L, 99L, 79L, 47L, 7L, 131L, 69L, 10L,
61L, 2L, 57L, 96L, 111L, 41L, 250L, 77L, 22L, 198L, 187L, 15L,
108L, 130L, 76L, 190L, 249L, 68L, 117L, 79L, 2L, 13L, 108L, 9L,
39L, 42L, 43L, 149L, 62L, 47L, 66L, 85L, 197L, 109L, 21L, 263L,
54L, 13L, 61L, 72L, 73L, 80L, 46L, 7L, 110L, 128L, 236L, 27L,
240L, 61L, 23L, 82L, 157L, 92L, 95L, 6L, 137L, 237L, 2L, 20L,
45L, 48L, 200L, 20L, 127L, 21L, 64L, 49L, 38L, 108L, 11L, 16L,
108L, 18L, 62L, 15L, 61L, 81L, 28L, 20L, 33L, 50L, 222L, 267L,
29L, 3L, 44L, 46L, 3L, 212L, 53L, 67L, 131L, 43L, 3L, 123L, 134L,
106L, 91L, 194L, 2L, 97L, 43L, 39L, 65L, 96L, 233L, 36L, 81L,
6L, 57L, 29L, 10L, 17L, 10L, 92L, 28L, 168L, 78L, 52L, 227L,
86L, 134L, 58L, 65L, 175L, 20L, 113L, 33L, 143L, 11L, 87L, 101L,
19L, 106L, 63L, 68L, 38L, 263L, 140L, 45L, 169L, 268L, 182L,
114L, 88L, 39L, 6L, 53L, 244L, 84L, 99L, 46L, 53L, 1L, 111L,
88L, 115L, 93L, 35L, 124L, 145L, 262L, 47L, 10L, 84L, 20L, 159L,
207L, 102L, 48L, 79L, 28L, 51L, 77L, 3L, 58L, 20L, 81L, 54L,
46L, 29L, 12L, 74L, 28L, 4L, 18L, 18L, 38L, 29L, 157L, 108L,
94L, 56L, 23L, 92L, 60L, 86L, 39L, 59L, 85L, 14L, 53L, 23L, 88L,
130L, 8L, 149L, 65L, 71L, 88L, 31L, 67L, 83L, 106L, 44L, 35L,
23L, 76L, 90L, 271L, 12L, 167L, 30L, 87L, 3L, 7L, 15L, 159L,
199L, 7L, 35L, 193L, 207L, 6L, 98L, 61L, 81L, 95L, 66L, 2L, 65L,
242L, 221L, 51L, 6L, 5L, 265L, 119L, 126L, 7L, 159L, 74L, 63L,
188L, 15L, 42L, 26L, 41L, 116L, 50L, 62L, 121L, 67L, 1L, 10L,
192L, 59L, 42L, 84L, 187L, 26L, 32L, 35L, 60L, 117L, 227L, 20L,
20L, 125L, 191L, 24L, 270L, 13L, 14L, 59L, 214L, 96L, 100L, 15L,
22L, 100L, 49L, 146L, 137L, 257L, 93L, 91L, 23L, 234L, 108L,
52L, 7L, 124L, 48L, 2L, 42L, 82L, 99L, 85L, 11L, 141L, 185L,
30L, 1L, 269L, 83L, 25L, 187L, 122L, 222L, 11L, 201L, 95L, 40L,
146L, 75L, 218L, 3L, 39L, 76L, 205L, 21L, 23L, 36L, 43L, 105L,
89L, 10L, 155L, 32L, 144L, 160L, 181L, 144L, 139L, 5L, 2L, 26L,
48L, 55L, 177L, 178L, 108L, 221L, 149L, 32L, 77L, 29L, 160L,
115L, 23L, 193L, 113L, 1L, 154L, 87L, 239L, 221L, 36L, 100L,
34L, 42L, 77L, 62L, 20L, 73L, 81L, 17L, 21L, 33L, 3L, 33L, 84L,
92L, 31L, 9L, 65L, 187L, 62L, 87L, 48L, 218L, 6L, 41L, 90L, 102L,
67L, 27L, 1L, 270L, 159L, 46L, 31L, 50L, 19L, 2L, 30L, 35L, 211L,
103L, 12L, 99L, 75L, 37L, 99L, 83L, 49L, 38L, 125L, 53L, 29L,
11L, 23L, 50L, 41L, 114L, 72L, 44L, 32L, 105L, 25L, 67L, 203L,
24L, 82L, 167L, 205L, 28L, 89L, 75L, 52L, 36L, 29L, 16L, 137L,
95L, 230L, 43L, 4L, 194L, 12L, 21L, 25L, 6L, 176L, 48L, 6L, 142L,
24L, 15L, 101L, 160L, 43L, 9L, 125L, 122L, 53L, 55L, 226L, 241L,
259L, 150L, 142L, 47L, 89L, 13L, 2L, 173L, 147L, 5L, 15L, 159L,
7L, 27L, 117L, 97L, 38L, 71L, 7L, 35L, 91L, 172L, 149L, 103L,
51L, 117L, 67L, 142L, 63L, 53L, 87L, 105L, 2L, 1L, 17L, 30L,
114L, 55L, 202L, 34L, 70L, 50L, 37L, 167L, 45L, 7L, 102L, 238L,
176L, 27L, 7L, 86L, 43L, 269L, 88L, 1L, 18L, 41L, 14L, 71L, 88L,
144L, 44L, 19L, 189L, 258L, 76L, 13L, 44L, 20L, 152L, 133L, 86L,
32L, 1L, 56L, 140L, 65L, 74L, 131L, 155L, 40L, 40L, 112L, 186L,
178L, 249L, 42L, 184L, 43L, 5L, 13L, 90L, 111L, 173L, 220L, 71L,
223L, 5L, 178L, 42L, 126L, 56L, 6L, 15L, 249L, 254L, 148L, 60L,
133L, 218L, 111L, 29L, 77L, 16L, 71L, 128L, 100L, 4L, 13L, 72L,
21L, 133L, 130L, 51L, 62L, 14L, 189L, 99L, 32L, 211L, 5L, 15L,
35L, 72L, 153L, 59L, 85L, 165L, 18L, 51L, 21L, 123L, 15L, 93L,
53L, 2L, 210L, 126L, 196L, 62L, 156L, 57L, 179L, 79L, 27L, 22L,
52L, 167L, 33L, 150L, 72L, 30L, 3L, 65L, 36L, 89L, 54L, 18L,
55L, 137L, 119L, 258L, 33L, 21L, 32L, 116L, 12L, 176L, 91L, 168L,
74L, 6L, 4L, 138L, 149L, 39L, 47L, 49L, 81L, 35L, 61L, 4L, 58L,
31L, 172L, 30L, 27L, 184L, 41L, 51L, 24L, 115L, 81L, 71L, 61L,
154L, 206L, 182L, 149L, 42L, 49L, 6L, 104L, 2L, 217L, 27L, 148L,
37L, 159L, 182L, 139L, 49L, 30L, 41L, 20L, 2L, 15L, 35L, 157L,
86L, 261L, 161L, 145L, 105L, 87L, 220L, 12L, 99L, 233L, 190L,
59L, 95L, 151L, 38L, 46L, 32L, 56L, 48L, 71L, 22L, 44L, 143L,
34L, 34L, 7L, 20L, 87L, 106L, 114L, 26L, 7L, 110L, 93L, 113L,
83L, 76L, 43L, 22L, 2L, 101L, 22L, 65L, 17L, 112L, 116L, 138L,
122L, 68L, 5L, 247L, 155L, 149L, 4L, 49L, 130L, 46L, 13L, 223L,
74L, 15L, 175L, 24L, 2L, 96L, 114L, 125L, 56L, 27L, 67L, 30L,
206L, 38L, 42L, 9L, 118L, 24L, 11L, 156L, 109L, 154L, 40L, 175L,
107L, 193L, 30L, 75L, 72L, 44L, 232L, 37L, 130L, 47L, 81L, 18L,
120L, 126L, 93L, 51L, 138L, 6L, 47L, 76L, 65L, 91L, 14L, 92L,
45L, 73L, 107L, 42L, 87L, 158L, 124L, 14L, 151L, 11L, 148L, 122L,
36L, 169L, 149L, 41L, 152L, 116L, 122L, 39L, 196L, 124L, 142L,
12L, 21L, 107L, 4L, 236L, 18L, 193L, 225L, 31L, 147L, 151L, 14L,
63L, 12L, 79L, 55L, 198L, 7L, 84L, 101L, 22L, 194L, 150L, 5L,
20L, 153L, 45L, 231L, 33L, 44L, 174L, 171L, 74L, 9L, 114L, 97L,
107L, 7L, 87L, 113L, 49L, 14L, 32L, 1L, 43L, 131L, 43L, 22L,
32L, 36L, 201L, 206L, 18L, 170L, 79L, 55L, 218L, 198L, 10L, 51L,
35L, 144L, 163L, 255L, 23L, 180L, 20L, 40L, 89L, 107L, 82L, 67L,
115L, 255L, 14L, 155L, 9L, 53L, 55L, 16L, 38L, 16L, 26L, 155L,
4L, 154L, 147L, 223L, 57L, 75L, 54L, 50L, 104L, 79L, 145L, 71L,
39L, 110L, 20L, 23L, 10L, 110L, 67L, 171L, 16L, 5L, 28L, 163L,
204L, 250L, 144L, 101L, 18L, 36L, 139L, 10L, 102L, 57L, 125L,
66L, 33L, 20L, 188L, 15L, 41L, 20L, 112L, 109L, 64L, 28L, 10L,
149L, 196L, 108L, 26L, 173L, 1L, 58L, 185L, 35L, 44L, 37L, 106L,
45L, 58L, 162L, 34L, 151L, 122L, 48L, 8L, 9L, 33L, 4L, 21L, 105L,
36L, 32L, 133L, 55L, 87L, 18L, 18L, 6L, 46L, 79L, 113L, 17L,
70L, 138L, 22L, 42L, 104L, 43L, 9L, 24L, 94L, 142L, 31L, 241L,
23L, 2L, 86L, 62L, 36L, 80L, 2L, 76L, 89L, 160L, 13L, 12L, 4L,
57L, 25L, 85L, 22L, 88L, 170L, 120L, 218L, 14L, 75L, 12L, 9L,
198L, 225L, 139L, 75L, 1L, 6L, 35L, 23L, 67L, 19L, 157L, 68L,
69L, 9L, 6L, 57L, 18L, 169L, 255L, 3L, 20L, 8L, 54L, 94L, 154L,
34L, 151L, 52L, 68L, 85L, 107L, 9L, 232L, 165L, 50L, 153L, 14L,
200L, 78L, 94L, 140L, 222L, 143L, 56L, 37L, 101L, 83L, 48L, 53L,
38L, 155L, 8L, 132L, 148L, 39L, 53L, 151L, 3L, 5L, 59L, 3L, 56L,
100L, 37L, 65L, 192L, 30L, 212L, 70L, 149L, 10L, 43L, 92L, 28L,
97L, 20L, 105L, 133L, 134L, 4L, 65L, 83L, 16L, 158L, 168L, 119L,
47L, 55L, 51L, 38L, 80L, 16L, 124L, 105L, 68L, 178L, 23L, 15L,
177L, 146L, 71L, 7L, 2L, 36L, 7L, 3L, 89L, 54L, 42L, 67L, 133L,
64L, 44L, 39L, 119L, 64L, 15L, 44L, 73L, 41L, 49L, 92L, 8L, 110L,
167L, 59L, 224L, 102L, 23L, 6L, 69L, 126L, 97L, 240L, 21L, 32L,
52L, 59L, 34L, 17L, 12L, 270L, 60L, 119L, 103L, 92L, 218L, 62L,
127L, 15L, 65L, 64L, 63L, 17L, 135L, 67L, 49L, 149L, 24L, 24L,
24L, 54L, 27L, 167L, 7L, 8L, 53L, 72L, 85L, 47L, 92L, 36L, 158L,
113L, 26L, 126L, 3L, 127L, 19L, 27L, 98L, 34L, 82L, 217L, 44L,
105L, 104L, 65L, 35L, 63L, 82L, 41L, 167L, 12L, 136L, 52L, 205L,
18L, 96L, 136L, 74L, 163L, 52L, 194L, 32L, 74L, 217L, 11L, 54L,
228L, 33L, 22L, 51L, 42L, 52L, 8L, 235L, 250L, 38L, 130L, 126L,
57L, 18L, 53L, 108L, 126L, 54L, 128L, 17L, 230L, 40L, 49L, 31L,
38L, 42L, 18L, 14L, 203L, 114L, 73L, 226L, 4L, 4L, 271L, 48L,
86L, 221L, 18L, 55L, 176L, 119L, 255L, 18L, 124L, 63L, 58L, 77L,
159L, 118L, 116L, 71L, 123L, 22L, 38L, 61L, 114L, 114L, 1L, 104L,
115L, 9L, 192L, 4L, 199L, 118L, 199L, 4L, 13L, 114L, 175L, 11L,
39L, 189L, 30L, 113L, 112L, 13L, 102L, 11L, 26L, 130L, 2L, 47L,
90L, 77L, 184L, 76L, 15L, 116L, 166L, 20L, 21L, 3L, 136L, 108L,
106L, 87L, 60L, 78L, 106L, 18L, 45L, 85L, 41L, 11L, 85L, 46L,
33L, 244L, 26L, 35L, 14L, 8L, 45L, 98L, 7L, 203L, 9L, 118L, 70L,
85L, 178L, 23L, 8L, 29L, 221L, 171L, 67L, 106L, 118L, 95L, 216L,
32L, 177L, 72L, 16L, 21L, 161L, 49L, 52L, 80L, 174L, 5L, 70L,
41L, 43L, 13L, 238L, 5L, 70L, 128L, 152L, 53L, 128L, 18L, 19L,
107L, 70L, 94L, 119L, 63L, 2L, 7L, 2L, 208L, 128L, 37L, 73L,
8L, 166L, 243L, 216L, 137L, 115L, 178L, 32L, 31L, 49L, 13L, 4L,
217L, 4L, 40L, 48L, 24L, 127L, 25L, 46L, 238L, 107L, 28L, 76L,
54L, 97L, 104L, 9L, 142L, 4L, 32L, 21L, 46L, 36L, 11L, 75L, 175L,
46L, 109L, 25L, 106L, 115L, 78L, 69L, 152L, 2L, 51L, 10L, 63L,
142L, 66L, 168L, 78L, 11L, 147L, 271L, 90L, 88L, 10L, 143L, 71L,
202L, 259L, 133L, 23L, 71L, 238L, 37L, 38L, 24L, 64L, 133L, 8L,
194L, 24L, 92L, 25L, 230L, 195L, 34L, 162L, 18L, 69L, 75L, 18L,
20L, 34L, 99L, 24L, 152L, 83L, 24L, 4L, 41L, 103L, 77L, 86L,
23L, 46L, 53L, 63L, 98L, 54L, 17L, 122L, 9L, 25L, 237L, 71L,
82L, 42L, 259L, 37L, 35L, 21L, 77L, 2L, 5L, 2L, 41L, 46L, 26L,
100L, 265L, 224L, 45L, 68L, 263L, 136L, 243L, 109L, 122L, 25L,
186L, 1L, 7L, 135L, 116L, 18L, 32L, 94L, 192L, 29L, 184L, 174L,
41L, 71L, 14L, 125L, 61L, 70L, 178L, 90L, 7L, 14L, 194L, 167L,
5L, 2L, 21L, 100L, 60L, 230L, 66L, 10L, 162L, 39L, 99L, 91L,
65L, 22L, 162L, 139L, 43L, 230L, 59L, 61L, 168L, 14L, 23L, 73L,
35L, 141L, 73L, 71L, 44L, 59L, 131L, 127L, 68L, 122L, 164L, 2L,
17L, 111L, 4L, 34L, 147L, 33L, 11L, 33L, 54L, 48L, 235L, 136L,
27L, 57L, 8L, 86L, 63L, 86L, 24L, 212L, 92L, 131L, 113L, 47L,
132L, 5L, 175L, 12L, 51L, 81L, 29L, 232L, 126L, 20L, 157L, 158L,
17L, 16L, 62L, 25L, 74L, 58L, 25L, 35L, 85L, 61L, 112L, 241L,
135L, 183L, 77L, 41L, 12L, 101L, 12L, 25L, 113L, 38L, 28L, 95L,
232L, 6L, 98L, 67L, 13L, 46L, 9L, 107L, 88L, 164L, 79L, 18L,
13L, 200L, 20L, 152L, 107L, 40L, 31L, 146L, 121L, 75L, 6L, 237L,
153L, 150L, 161L, 198L, 174L, 167L, 15L, 154L, 160L, 171L, 169L,
23L, 22L, 187L, 226L, 40L, 213L, 87L, 269L, 136L, 153L, 103L,
141L, 21L, 79L, 22L, 144L, 119L, 1L, 11L, 13L, 7L, 128L, 43L,
77L, 50L, 142L, 79L, 5L, 182L, 19L, 39L, 5L, 63L, 228L, 13L,
5L, 49L, 58L, 14L, 145L, 129L, 102L, 211L, 152L, 43L, 269L, 67L,
36L, 10L, 103L, 98L, 83L, 13L, 25L, 155L, 11L, 33L, 127L, 79L,
46L, 64L, 40L, 88L, 23L, 52L, 204L, 125L, 39L, 10L, 184L, 38L,
113L, 123L, 68L, 69L, 126L, 7L, 36L, 43L, 3L, 243L, 82L, 50L,
109L, 122L, 44L, 40L, 41L, 140L, 134L, 168L, 122L, 16L, 2L, 61L,
37L, 73L, 163L, 70L, 18L, 9L, 205L, 12L, 89L, 1L, 17L, 119L,
17L, 54L, 31L, 13L, 185L, 157L, 113L, 53L, 156L, 157L, 72L, 61L,
29L, 52L, 69L, 23L, 261L, 51L, 118L, 48L, 98L, 49L, 250L, 29L,
222L, 55L, 14L, 130L, 72L, 27L, 23L, 45L, 27L, 5L, 62L, 46L,
208L, 183L, 32L, 37L, 168L, 39L, 47L, 3L, 88L, 74L, 40L, 254L,
5L, 28L, 165L, 109L, 181L, 209L, 142L, 107L, 21L, 14L, 42L, 58L,
198L, 30L, 91L, 175L, 108L, 18L, 60L, 86L, 6L, 82L, 26L, 8L,
85L, 202L, 261L, 113L, 142L, 19L, 67L, 96L, 116L, 262L, 60L,
55L, 47L, 56L, 33L, 39L, 196L, 77L, 10L, 86L, 142L, 11L, 49L,
7L, 56L, 38L, 26L, 180L, 74L, 60L, 236L, 7L, 37L, 81L, 119L,
26L, 7L, 103L, 38L, 6L, 184L, 153L, 90L, 42L, 22L, 140L, 57L,
50L, 97L, 14L, 42L, 3L, 14L, 16L, 66L, 56L, 89L, 21L, 58L, 7L,
101L, 16L, 125L, 224L, 64L, 110L, 20L, 5L, 67L, 57L, 161L, 271L,
13L, 18L, 51L, 119L, 42L, 122L, 51L, 116L, 41L, 2L, 89L, 229L,
2L, 45L, 22L, 180L, 3L, 127L, 195L, 8L, 230L, 203L, 72L, 203L,
61L, 7L, 61L, 253L, 37L, 46L, 59L, 161L, 110L, 5L, 223L, 195L,
45L, 1L, 48L, 163L, 3L, 56L, 76L, 77L, 107L, 183L, 7L, 30L, 145L,
4L, 26L, 174L, 76L, 83L, 73L, 172L, 226L, 2L, 18L, 1L, 8L, 90L,
36L, 8L, 44L, 36L, 90L, 64L, 89L, 127L, 24L, 67L, 7L, 263L, 71L,
178L, 21L, 21L, 28L, 236L, 116L, 46L, 82L, 79L, 17L, 18L, 131L,
49L, 90L, 65L, 168L, 93L, 2L, 267L, 59L, 35L, 126L, 35L, 185L,
6L, 45L, 31L, 42L, 71L, 67L, 85L, 11L, 9L, 30L, 22L, 24L, 123L,
119L, 14L, 98L, 31L, 101L, 137L, 81L, 47L, 79L, 4L, 167L, 78L,
11L, 30L, 9L, 115L, 32L, 12L, 80L, 33L, 68L, 36L, 130L, 31L,
7L, 169L, 54L, 9L, 155L, 61L, 250L, 89L, 149L, 2L, 101L, 66L,
166L, 41L, 4L, 62L, 9L, 160L, 189L, 144L, 101L, 190L, 129L, 11L,
124L, 22L, 13L, 151L, 1L, 58L, 173L, 195L, 47L, 3L, 3L, 24L,
26L, 27L, 177L, 43L, 29L, 27L, 7L, 3L, 154L, 100L, 125L, 91L,
212L, 224L, 77L, 53L, 135L, 2L, 11L, 65L, 60L, 115L, 78L, 55L,
66L, 31L, 88L, 72L, 87L, 181L, 198L, 75L, 239L, 111L, 10L, 128L,
103L, 68L, 27L, 127L, 4L, 24L, 102L, 3L, 19L, 103L, 268L, 5L,
153L, 216L, 9L, 56L, 154L, 3L, 13L, 128L, 252L, 17L, 10L, 78L,
65L, 245L, 53L, 166L, 11L, 28L, 43L, 85L, 11L, 179L, 200L, 127L,
235L, 61L, 7L, 4L, 35L, 28L, 85L, 118L, 69L, 92L, 158L, 40L,
91L, 104L, 165L, 135L, 30L, 230L, 121L, 204L, 44L, 106L, 5L,
51L, 19L, 145L, 34L, 184L, 16L, 217L, 62L, 67L, 44L, 16L, 5L,
39L, 13L, 16L, 95L, 158L, 43L, 93L, 37L, 47L, 33L, 18L, 178L,
13L, 65L, 123L, 54L, 165L, 265L, 9L, 118L, 93L, 10L, 3L, 114L,
13L, 8L, 48L, 103L, 160L, 92L, 135L, 50L, 7L, 38L, 16L, 64L,
85L, 215L, 13L, 251L, 41L, 10L, 67L, 13L, 56L, 202L, 72L, 156L,
249L, 56L, 38L, 27L, 15L, 177L, 39L, 36L, 62L, 53L, 86L, 62L,
126L, 177L, 46L, 30L, 81L, 6L, 74L, 37L, 65L, 54L, 67L, 123L,
66L, 144L, 90L, 48L, 173L, 47L, 49L, 108L, 22L, 103L, 22L, 144L,
23L, 233L, 78L, 181L, 136L, 27L, 3L, 135L, 46L, 34L, 30L, 42L,
6L, 53L, 49L, 180L, 247L, 106L, 22L, 124L, 9L, 161L, 43L, 82L,
112L, 225L, 153L, 124L, 53L, 90L, 64L, 86L, 35L, 121L, 118L,
129L, 39L, 3L, 16L, 24L, 224L, 128L, 145L, 108L, 124L, 32L, 9L,
7L, 22L, 16L, 207L, 51L, 27L, 22L, 6L, 132L, 154L, 26L, 223L,
145L, 105L, 78L, 44L, 171L, 29L, 53L, 229L, 89L, 47L, 41L, 81L,
62L, 169L, 102L, 241L, 35L, 6L, 174L, 51L, 181L, 83L, 52L, 92L,
31L, 110L, 148L, 52L, 7L, 73L, 136L, 25L, 29L, 42L, 84L, 190L,
49L, 139L, 62L, 7L, 86L, 13L, 182L, 203L, 68L, 127L, 13L, 27L,
244L, 69L, 65L, 92L, 14L, 257L, 7L, 49L, 20L, 44L, 17L, 13L,
73L, 20L, 43L, 33L, 242L, 4L, 66L, 70L, 99L, 193L, 12L, 179L,
63L, 14L, 53L, 49L, 105L, 59L, 113L, 79L, 124L, 35L, 9L, 7L,
44L, 6L, 21L, 8L, 114L, 36L, 90L, 121L, 113L, 96L, 26L, 253L,
14L, 53L, 10L, 25L, 18L, 18L, 10L, 87L, 4L, 159L, 179L, 17L,
9L, 222L, 68L, 268L, 120L, 197L, 21L, 67L, 59L, 250L, 221L, 233L,
41L, 114L, 20L, 136L, 136L, 94L, 19L, 29L, 11L, 81L, 179L, 154L,
20L, 29L, 148L, 249L, 34L, 246L, 212L, 46L, 4L, 33L, 118L, 47L,
246L, 116L, 42L, 91L, 60L, 49L, 186L, 37L, 85L, 8L, 26L, 5L,
30L, 44L, 22L, 28L, 48L, 144L, 200L, 33L, 29L, 77L, 15L, 120L,
33L, 27L, 53L, 126L, 183L, 79L, 62L, 102L, 61L, 112L, 56L, 77L,
201L, 74L, 7L, 99L, 120L, 110L, 148L, 35L, 48L, 18L, 4L, 16L,
84L, 53L, 39L, 20L, 36L, 159L, 30L, 3L, 46L, 247L, 31L, 127L,
61L, 127L, 238L, 109L, 154L, 178L, 78L, 31L, 5L, 77L, 69L, 3L,
49L, 165L, 91L, 29L, 72L, 24L, 30L, 105L, 55L, 225L, 28L, 36L,
13L, 18L, 106L, 56L, 143L, 105L, 55L, 33L, 4L, 100L, 215L, 59L,
169L, 103L, 70L, 76L, 189L, 42L, 94L, 101L, 41L, 83L, 52L, 231L,
120L, 111L, 37L, 198L, 69L, 57L, 51L, 13L, 14L, 55L, 24L, 74L,
136L, 1L, 218L, 110L, 125L, 26L, 106L, 203L, 46L, 57L, 16L, 90L,
186L, 209L, 64L, 254L, 1L, 103L, 175L, 3L, 5L, 41L, 51L, 232L,
89L, 73L, 67L, 260L, 85L, 189L, 249L, 166L, 72L, 250L, 56L, 2L,
66L, 232L, 33L, 259L, 12L, 47L, 7L, 106L, 193L, 63L, 132L, 3L,
21L, 76L, 195L, 15L, 43L, 171L, 29L, 108L, 84L, 199L, 189L, 98L,
43L, 83L, 28L, 67L, 47L, 195L, 62L, 57L, 53L, 163L, 48L, 65L,
188L, 3L, 52L, 257L, 62L, 62L, 114L, 38L, 128L, 26L, 205L, 100L,
75L, 104L, 56L, 146L, 105L, 35L, 26L, 18L, 46L, 25L, 96L, 61L,
1L, 91L, 13L, 169L, 35L, 54L, 77L, 35L, 9L, 213L, 124L, 22L,
29L, 52L, 203L, 98L, 61L, 8L, 33L, 14L, 11L, 13L, 48L, 105L,
76L, 22L, 136L, 123L, 18L, 39L, 39L, 9L, 212L, 11L, 37L, 9L,
59L, 254L, 18L, 85L, 38L, 180L, 159L, 94L, 42L, 15L, 230L, 38L,
35L, 19L, 98L, 185L, 10L, 24L, 103L, 67L, 8L, 63L, 200L, 135L,
34L, 39L, 19L, 62L, 175L, 13L, 9L, 1L, 37L, 116L, 41L, 42L, 105L,
54L, 17L, 90L, 47L, 38L, 34L, 23L, 105L, 23L, 57L, 115L, 107L,
58L, 50L, 121L, 123L, 23L, 99L, 31L, 148L, 9L, 106L, 4L, 76L,
55L, 102L, 66L, 135L, 43L, 73L, 7L, 255L, 15L, 24L, 229L, 115L,
55L, 52L, 18L, 22L, 39L, 181L, 1L, 135L, 45L, 103L, 24L, 180L,
118L, 228L, 219L, 116L, 90L, 154L, 35L, 73L, 65L, 48L, 58L, 35L,
26L, 166L, 66L, 128L, 15L, 28L, 109L, 154L, 3L, 24L, 52L, 89L,
50L, 53L, 69L, 17L, 15L, 124L, 50L, 134L, 267L, 11L, 194L, 6L,
143L, 40L, 35L, 223L, 12L, 27L, 45L, 181L, 60L, 37L, 19L, 6L,
24L, 57L, 75L, 12L, 93L, 38L, 27L, 140L, 32L, 57L, 115L, 82L,
262L, 5L, 185L, 223L, 10L, 72L, 7L, 110L, 12L, 81L, 61L, 29L,
91L, 12L, 85L, 62L, 34L, 73L, 27L, 16L, 85L, 216L, 228L, 157L,
66L, 73L, 38L, 88L, 26L, 83L, 184L, 10L, 108L, 43L, 11L, 3L,
47L, 61L, 139L, 10L, 8L, 69L, 11L, 63L, 224L, 82L, 5L, 22L, 3L,
51L, 39L, 5L, 232L, 150L, 93L, 89L, 174L, 5L, 85L, 159L, 49L,
150L, 187L, 101L, 29L, 20L, 48L, 4L, 142L, 44L, 57L, 105L, 79L,
51L, 91L, 89L, 115L, 14L, 67L, 2L, 165L, 114L, 2L, 17L, 67L,
38L, 108L, 23L, 103L, 223L, 1L, 34L, 21L, 41L, 73L, 186L, 55L,
14L, 61L, 81L, 75L, 15L, 95L, 85L, 145L, 222L, 139L, 231L, 162L,
79L, 67L, 80L, 75L, 17L, 27L, 48L, 38L, 27L, 71L, 100L, 51L,
132L, 2L, 183L, 110L, 23L, 37L, 103L, 30L, 43L, 138L, 1L, 13L,
83L, 180L, 27L, 21L, 236L, 78L, 118L, 93L, 95L, 83L, 28L, 15L,
236L, 41L, 51L, 11L, 181L, 91L, 4L, 40L, 86L, 165L, 24L, 115L,
252L, 28L, 35L, 13L, 15L, 7L, 9L, 27L, 33L, 9L, 40L, 5L, 105L,
28L, 5L, 16L, 117L, 153L, 27L, 141L, 52L, 168L, 10L, 84L, 17L,
47L, 56L, 233L, 140L, 69L, 221L, 19L, 8L, 71L, 37L, 123L, 137L,
10L, 55L, 146L, 14L, 41L, 69L, 142L, 89L, 4L, 37L, 170L, 37L,
35L, 182L, 70L, 24L, 158L, 83L, 25L, 38L, 116L, 132L, 209L, 69L,
221L, 41L, 114L, 28L, 20L, 42L, 132L, 83L, 168L, 87L, 64L, 249L,
155L, 66L, 113L, 44L, 35L, 100L, 133L, 31L, 126L, 10L, 184L,
53L, 64L, 57L, 22L, 2L, 30L, 25L, 39L, 151L, 164L, 42L, 72L,
2L, 38L, 29L, 8L, 22L, 9L, 91L, 58L, 58L, 78L, 82L, 117L, 104L,
29L, 80L, 70L, 137L, 137L, 115L, 10L, 87L, 66L, 1L, 11L, 21L,
118L, 262L, 70L, 5L, 153L, 118L, 35L, 249L, 68L, 38L, 79L, 30L,
39L, 39L, 158L, 17L, 145L, 5L, 8L, 47L, 177L, 77L, 203L, 94L,
107L, 96L, 68L, 7L, 12L, 24L, 18L, 146L, 13L, 164L, 54L, 73L,
143L, 96L, 22L, 5L, 100L, 71L, 65L, 1L, 16L, 22L, 13L, 39L, 101L,
39L, 75L, 148L, 45L, 257L, 67L, 18L, 50L, 62L, 29L, 222L, 96L,
7L, 7L, 130L, 108L, 44L, 48L, 109L, 67L, 112L, 100L, 169L, 260L,
130L, 169L, 79L, 111L, 121L, 15L, 21L, 240L, 220L, 56L, 8L, 18L,
4L, 37L, 98L, 46L, 247L, 66L, 69L, 19L, 66L, 112L, 42L, 103L,
122L, 155L, 36L, 4L, 60L, 39L, 25L, 2L, 182L, 105L, 157L, 5L,
70L, 16L, 55L, 52L, 39L, 156L, 14L, 118L, 88L, 91L, 132L, 52L,
18L, 38L, 31L, 35L, 75L, 186L, 45L, 110L, 232L, 52L, 135L, 33L,
11L, 29L, 129L, 147L, 20L, 20L, 59L, 46L, 6L, 53L, 251L, 120L,
192L, 41L, 87L, 38L, 134L, 5L, 120L, 130L, 71L, 121L, 84L, 183L,
166L, 20L, 8L, 20L, 74L, 201L, 35L, 176L, 189L, 17L, 231L, 48L,
38L, 3L, 142L, 53L, 199L, 135L, 6L, 38L, 256L, 76L, 6L, 56L,
154L, 25L, 76L, 69L, 149L, 107L, 113L, 246L, 61L, 23L, 6L, 76L,
3L, 68L, 70L, 89L, 130L, 226L, 31L, 157L, 24L, 80L, 170L, 169L,
64L, 12L, 110L, 47L, 141L, 159L, 22L, 53L, 167L, 61L, 81L, 98L,
172L, 261L, 99L, 9L, 13L, 132L, 103L, 16L, 97L, 186L, 35L, 128L,
73L, 136L, 62L, 187L, 30L, 31L, 26L, 115L, 76L, 260L, 54L, 11L,
169L, 227L, 43L, 6L, 23L, 212L, 23L, 68L, 119L, 181L, 34L, 137L,
144L, 48L, 101L, 25L, 10L, 92L, 5L, 92L, 132L, 206L, 44L, 113L,
9L, 25L, 249L, 69L, 250L, 67L, 35L, 6L, 60L, 251L, 6L, 32L, 94L,
13L, 224L, 21L, 43L, 81L, 9L, 9L, 95L, 11L, 7L, 26L, 172L, 46L,
17L, 3L, 2L, 39L, 26L, 7L, 18L, 57L, 88L, 16L, 47L, 136L, 135L,
73L, 26L, 60L, 56L, 77L, 158L, 23L, 1L, 139L, 234L, 76L, 99L,
28L, 22L, 83L, 114L, 6L, 122L, 7L, 36L, 59L, 4L, 33L, 79L, 25L,
26L, 8L, 28L, 19L, 33L, 2L, 23L, 44L, 158L, 56L, 14L, 8L, 56L,
16L, 36L, 90L, 18L, 22L, 7L, 74L, 70L, 2L, 51L, 13L, 130L, 25L,
17L, 23L, 48L, 37L, 60L, 17L, 58L, 15L, 41L, 261L, 245L, 35L,
17L, 41L, 234L, 13L, 11L, 192L, 3L, 5L, 29L, 14L, 34L, 4L, 110L,
63L, 47L, 157L, 9L, 116L, 120L, 29L, 126L, 26L, 106L, 219L, 209L,
93L, 255L, 137L, 88L, 96L, 87L, 229L, 23L, 128L, 101L, 62L, 2L,
193L, 58L, 1L, 8L, 146L, 44L, 12L, 27L, 99L, 270L, 54L, 41L,
161L, 231L, 53L, 126L, 139L, 77L, 55L, 32L, 6L, 159L, 131L, 54L,
266L, 87L, 13L, 205L, 154L, 3L, 82L, 35L, 11L, 2L, 56L, 84L,
110L, 116L, 28L, 30L, 60L, 74L, 12L, 147L, 31L, 206L, 31L, 56L,
209L, 115L, 149L, 33L, 198L, 205L, 71L, 28L, 40L, 201L, 32L,
3L, 40L, 75L, 91L, 32L, 9L, 4L, 192L, 11L, 41L, 30L, 46L, 57L,
44L, 243L, 67L, 118L, 108L, 181L, 83L, 45L, 93L, 13L, 2L, 104L,
163L, 92L, 8L, 17L, 14L, 150L, 5L, 60L, 123L, 100L, 105L, 110L,
225L, 249L, 207L, 100L, 188L, 138L, 6L, 176L, 68L, 91L, 8L, 20L,
18L, 21L, 79L, 20L, 4L, 99L, 136L, 28L, 156L, 7L, 36L, 226L,
33L, 42L, 1L, 28L, 227L, 11L, 9L, 157L, 206L, 34L, 17L, 61L,
113L, 112L, 158L, 24L, 18L, 36L, 75L, 40L, 18L, 183L, 3L, 37L,
92L, 69L, 13L, 213L, 48L, 163L, 188L, 251L, 59L, 75L, 1L, 12L,
46L, 232L, 13L, 74L, 32L, 149L, 219L, 22L, 59L, 109L, 264L, 25L,
141L, 5L, 67L, 41L, 5L, 71L, 19L, 63L, 114L, 28L, 76L, 80L, 86L,
71L, 18L, 166L, 40L, 57L, 185L, 88L, 115L)

A: The problem is that you initially created 4000 * 3 data.frame filled in with NA. Please see the corrected code. I did not put your actual data vec1 (too long) and simulated vec1 with sampling from exponential distribution. Additionally I used colMeans as more effective than apply. See the code below:
# vec1, mydata, l - simulation
set.seed(123)
vec1 <- (sample(1:271, 4000, replace = TRUE, prob = dexp(1:271, rate = .01)))
mydata <- matrix(1:(300 * 300), nrow = 300)
l <- 300

# data given by OP
df <- data.frame(Age  = 1, Weight  = 1, height = 1 )
df <- df[-1, ]
i <- 1
j <- vec1[1] - 1
k <- 0

repeat{
  elements <- as.vector(colMeans(mydata[i:(j + 1), 3:5]))
  df <- rbind(df, elements)
  k <- k + 1
  i = i + vec1[k]
  j = j + vec1[k + 1]
  if (j + 1 >= l){
    break
  }
}
df <- setNames(df, c("Age","Weight", "height"))
df

Output:
    Age Weight height
1 608.0  908.0 1208.0
2 638.0  938.0 1238.0
3 716.0 1016.0 1316.0
4 787.5 1087.5 1387.5
5 816.0 1116.0 1416.0
6 835.0 1135.0 1435.0


text:
Q: Solving normal equation system in C++ I would like to solve the system of linear equations:
 Ax = b

A is a n x m matrix (not square), b and x are both n x 1 vectors. Where A and b are known, n is from the order of 50-100  and m is about 2 (in other words, A could be maximum [100x2]).
I know the solution of x: $x = \inv(A^T A) A^T b$
I found few ways to solve it: uBLAS (Boost), Lapack, Eigen and etc. but i dont know how fast are the CPU computation time of 'x' using those packages. I also don't know if this numerically a fast why to solve 'x'
What is for my important is that the CPU computation time would be short as possible and good documentation since i am newbie.
After solving the normal equation Ax = b i would like to improve my approximation using regressive and maybe later applying Kalman Filter.
My question is which C++ library is the robuster and faster for the needs i describe above?

A: uBlas is not optimized unless you use it with optimized BLAS bindings.
The following are optimized for multi-threading and SIMD:

*

*Intel MKL. FORTRAN library with C interface. Not free but very good.

*Eigen. True C++ library. Free and open source. Easy to use and good.

*Atlas. FORTRAN and C. Free and open source. Not Windows friendly, but otherwise good.

Btw, I don't know exactly what are you doing, but as a rule normal equations are not a proper way to do linear regression. Unless your matrix is well conditioned, QR or SVD should be preferred.

A: This is a least squares solution, because you have more unknowns than equations.  If m is indeed equal to 2, that tells me that a simple linear least squares will be sufficient for you.  The formulas can be written out in closed form.  You don't need a library.
If m is in single digits, I'd still say that you can easily solve this using A(transpose)*A*X = A(transpose)*b.  A simple LU decomposition to solve for the coefficients would be sufficient.  It should be a much more straightforward problem than you're making it out to be.

A: If liscencing is not a problem, you might try the gnu scientific library
http://www.gnu.org/software/gsl/
It comes with a blas library that you can swap for an optimised library if you need to later (for example the intel, ATLAS, or ACML (AMD chip) library.

A: If you have access to MATLAB, I would recommend using its C libraries.

A: If you really need to specialize, you can approximate matrix inversion (to arbitrary precision) using the Skilling method.  It uses order (N^2) operations only (rather than the order N^3 of usual matrix inversion - LU decomposition etc).
Its described in the thesis of Gibbs linked to here (around page 27):
http://www.inference.phy.cam.ac.uk/mng10/GP/thesis.ps.gz


text:
Q: Is the FileOptions.DeleteOnClose Windows specific? I'm trying to create a temporary file using a FileStream along with FileOptions.DeleteOnClose. I'm seeing the expected behaviour when the stream is being closed, however if an exception is thrown then the file is not being deleted. I can't use using because the closing of the stream is being handled by a FileStreamResult. I know on Windows it is being handled by the winapi flag FILE_FLAG_DELETE_ON_CLOSE, but I don't know if/how this works for other platforms on .NET Core applications.
I've tried wrapping a try-catch around this to manually dispose the stream in erroneous situations, which does work but SHOULD BE unnecessary since the file would get removed anyways as soon as all handles are released.
            const FileOptions fileOptions =
                FileOptions.Asynchronous |
                FileOptions.DeleteOnClose |
                FileOptions.Encrypted |
                FileOptions.SequentialScan;

            var fileStream = new FileStream(
                Path.GetRandomFileName(),
                FileMode.Create,
                FileAccess.ReadWrite,
                FileShare.None,
                4096,
                fileOptions);

I expected the file to be deleted when all handles are released if FileOptions.DeleteOnClose is cross-platform, but the file is still present.

A: Reading the source code of src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs, it seems FileOptions.DeleteOnClose is honoured and emulated on *nix platforms at time of disposal:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// ...

// If DeleteOnClose was requested when constructed, delete the file now.
// (Unix doesn't directly support DeleteOnClose, so we mimic it here.)
if (_path != null && (_options & FileOptions.DeleteOnClose) != 0)
{
    // Since we still have the file open, this will end up deleting
    // it (assuming we're the only link to it) once it's closed, but the
    // name will be removed immediately.
    Interop.Sys.Unlink(_path); // ignore errors; it's valid that the path may no longer exist
}

The above snippet is from lines 261-269 of src/libraries/System.Private.CoreLib/src/System/IO/FileStream.Unix.cs and part of FileStream.Dispose implementation.
I created a Gist with the following test code:
using System.IO;

var fileName = Path.GetRandomFileName();
Console.WriteLine($"File name: {fileName}");
Console.WriteLine($"Exists? {File.Exists(fileName)}");
using (var fs = File.Create(fileName, 4096, FileOptions.DeleteOnClose))
    Console.WriteLine($"Exists? {File.Exists(fileName)}");
Console.WriteLine($"Exists? {File.Exists(fileName)}");

and then tested on Linux with .NET Core SDK 3.1 using Docker as follows:
> docker run --rm -it mcr.microsoft.com/dotnet/core/sdk:3.1
> root@86a890d817b7:/# dotnet tool install dotnet-script --version 0.53.0 --tool-path /usr/bin
You can invoke the tool using the following command: dotnet-script
Tool 'dotnet-script' (version '0.53.0') was successfully installed.
> root@86a890d817b7:/# dotnet script https://gist.github.com/atifaziz/2a0291a076c77e197d849eab7c049b1b/raw/9b5a08c0ffd45e09eac19325445b9fbdf799e10c/test.csx
File name: hrylnqis.nxv
Exists? False
Exists? True
Exists? False

The output seems to confirm FileOptions.DeleteOnClose is working as expected and so, no,  it's not Windows-specific per your question.
Bear in mind, though, since DeleteOnClose is emulated for (some definition of) Unix, it doesn't have the same strong guarantees as on Windows. For example, if the process crashes or exits brutally via Environment.Exit then the file will be deleted on Windows but not on a Unix-based system.

A: My current 'fix' is a wrapper for the FileStream that immediately calls File.Delete() on it, as this works for UNIX systems (you can still work with the file as long as there's handles on the file), and catching the IO exception that occurs on Windows.
Obviously not my preferred solution so I'll keep the question open for a while and see if anyone takes interest.


text:
Q: loop though a array then if and then output result? i have a little problem, in the code below (C#) it loops thought the arrays, it then check if the user_id has a user_post greater than 50, it then write the user_id, the expected outcome is
12
13

but the actual output is
12
12
12

whats wrong with the code? I tried a standard for loop but could not get it right?
int[] user_id = new int[64];
int[] group_id = new int[64];
int[] user_post = new int[64];

//user 55
user_id[0] = 10;
group_id[0] = 8;
user_post[0] = 4;

//user56
user_id[1] = 11;
group_id[1] = 2;
user_post[1] = 15;

//user57
user_id[2] = 12;
group_id[2] = 2;
user_post[2] = 55;

//user58
user_id[3] = 13;
group_id[3] = 2;
user_post[3] = 56;

foreach (int i in group_id)
{
    if (group_id[i] == 2)
        if (user_post[i] > 50)
            Console.WriteLine(Convert.ToString(user_id[i]));
}

Console.WriteLine("Press any key too continue...");
Console.ReadLine();
// continue...

A: Because you have an if statement that only checks for 2
 if (group_id[i] == 2)

where as "i"  is not a counter instead the element from the foreach loop.
and items at 2 & 3rd position have 2 group id so it alway ends like this:
if (group_id[8] == 2) //false
if (group_id[2] == 2) //true
if (group_id[2] == 2) //true

Instead of that vague code you should have your loop as this:
for(int i = 0 ; i< 64 ; i++)
{
    if (group_id[i] == 2)
    {
        if (user_post[i] > 50)
        Console.WriteLine(Convert.ToString(user_id[i]));
    }

}

A: foreach (int i in group_id)

is wrong, you must use:
for(int i = 0; i < group_id.Length; i++)

because with the former you're using the values in group_id as indexes of your arrays.
BTW, I'd suggest you to create a class e.g. Info like:
class Info
{
   public int GroupId {get; set;};
   public int UserId {get; set;};
   public int PostId {get; set;}
}

this would allow you to create one array only (i.e. Info[]) and avoid possible errors due to different lenghts of the 3 arrays...

A: You're looping around the wrong array with the for each statement. You should loop using the regular for statement instead like this:
    for (int i = 0;i < user_post.Length; i++)
    {
        if (user_post[i] > 50 && group_id[i] == 2)
        {
          Console.WriteLine(Convert.ToString(user_id[i]));
        }
    }

A: in your foreach statement, i takes on the values stored in your group_id array - 8, 2, 2, 2
In your if and output statements, your are using this value as an index into the arrays
So, your if statements end up doing this:
if(group_id[8])...
if(group_id[2])...
if(group_id[2])...
if(group_id[2])...

You are only examining elements 8 and 2 in your arrays.
Use a for loop to iterate through the array indexes

A: The for syntax is as follows:
for (int i = 0; // incremental variable
     i < 100;   // determining a limit
     ++i)       // increment the variable

While foreach works like this:
foreach (var element        // the element itself, not an index
         in
         elementCollection) // iterating through the collection


text:
Q: How to create overlapping header/content like Facebook's What is the correct way to create a solid color header that the content can partially overlap with CSS?
Facebook has the exact look that I am going for (notice the picture overlapping the blue header):
alt text http://www.thewizkids.net/facebookExample.png
Here are my ideas, but I don't know if they pose problems:

*

*Put the picture/overlapping content in the header section and absolute position so that it will break out of the div.

*Code the content beneath the header, but relatively position to push it upward - therefore overlapping the header.
Will either of these work, or is there a better option?

A: I suggest that you use Firebug to look at their html / css markup.

A: Just use a cleverly placed background image. Then make sure your tab-bottoms sit flush "on top" of the bottom of your background-image.

A: Like Jonathan Suggested, use a background image. But I'd like to add that you should make sure you know the difference between margin and padding, which is extremely important for Facebook's theme.


text:
Q: Is it possible to have 2 different font size within a PBI card visual I managed to work out concatenate two measures within one power bi card visual, but is it possible to make the font smaller just for the value in the bracket in the formula?
If yes, how?

A: There is no direct option for that but always there is workaround. The solution is-

Show your first line in 1 card visual

Show your second line in another card visual

Now place a rectangle shape around

Now select all 3 visual and group them

This way you can format your values in different card as per your requirement. Here below is a sample output-


text:
Q: What is the distribution of the number of inversions in a riffle shuffle with fixed cut? Fix $a,b \ge 1$. Starting with a deck of $a+b$ distinct cards in order, consider cutting the deck into the first $a$ cards (collectively $A$) and the last $b$ cards (collectively $B$), and then riffling the two decks together (ie, merging them while preserving the order of each deck). There are ${a+b \choose a,b}$ possible outcomes. Each outcome has a number of inversions. When selecting an outcome uniformly at random, what is the distribution of the number of inversions?
Here are a couple equivalent formulations of this:

*

*Form a grid graph with $a$ vertical steps and $b$ horizontal steps, with all edges having unit length and oriented down or right. The riffles are naturally in bijection with the paths from the top left to the bottom right: whenever the $i$-th step goes down, the $i$-th card in the riffle comes from $A$, and whenever the $i$-th step goes right, the $i$-th card comes from $B$. The number of inversions appears as the area below this path. So this question is, equivalently, what is the distribution of the area below a uniformly random path in the grid?

*Select, uniformly at random, non-negative integers $\lambda_0,\ldots,\lambda_b$ subject to $\lambda_0+\cdots+\lambda_b = a$, and output $\sum_{i=0}^b i\cdot \lambda_i$. This is distributed the same as above: each choice of $\lambda_0,\ldots,\lambda_b$ corresponds bijectively to a choice of path in the grid interpretation where $\lambda_i$ counts the number of vertical steps following the $i$-th horizontal step. The sum counts, row-by-row, the area below the path. One can of course swap the roles of $a$ and $b$ as well.

*Form the polynomial $$\sum_{d=0}^{ab} c_{a,b,d}\cdot q^d = \binom{a+b}{a}_q$$ in the indeterminate $q$. (See Gaussian binomial coefficient.) Sample the value $d$ with probability $c_{a,b,d}/\binom{a+b}{a}$. (This is a probability distribution.)
In any case, let's call the random variable $V_{a,b}$. It is, of course, integer-valued. Every integer in $[0,ab]$ is a possible outcome. By the 180° rotational symmetry of the grid, the distribution is symmetric about $ab/2$. In particular the mean is $ab/2$. I've computed the variance as $\frac{1}{12}ab(a+b+1)$. That's essentially the limit of what I can prove though. Empirically, the distribution is unimodal, and no outcome is particularly likely (maximum probability of any one outcome bounded by $O(1/{\sqrt{ab(a+b)}})$). In general, it seems to loosely resemble a normal distribution with the same first two moments, even when $a$ and/or $b$ is small. I'd like to understand to what extent that is true.
In case it helps, here are two more tidbits:

*

*$V_{a,b}$ satisfies a recurrence in the sense that the distribution of $V_{a,b}$ coincides with the distribution where, with probability $\frac{a}{a+b}$, one samples $V_{a-1,b}$, while with probability $\frac{b}{a+b}$, one samples $V_{a,b-1}$ and adds $a$.

*It seems nicer to work with a related quantity, $\delta_{a,b} = ab - 2V_{a,b}$. In the deck-shuffling formulation, it counts $-1$ for each inversion, and $+1$ for each non-inversion. In the grid formulation, it counts the area above the path minus the area below the path. Similarly there is an interpretation in the integer-partition formulation. $\delta_{a,b}$ is integer-valued, and every integer in $[-ab,ab]$ with the same parity as $ab$ is a possible outcome. It has a similar recurrence to $V_{a,b}$ in that $\delta_{a,b}$ coincides with the distribution where, with probability $\frac{a}{a+b}$, one samples $b+\delta_{a-1,b}$, and with probability $\frac{b}{a+b}$ one samples $-a+\delta_{a,b-1}$. $\delta_{a,b}$ is symmetrically distributed about 0 (so all odd-order moments are zero), and its variance is $\frac{1}{3}ab(a+b+1)$. Its fourth moment is $$\frac{1}{15}ab(a+b+1)\cdot[5(a^2b+b^2a) - 2(a^2+b^2) + 3ab - 2(a+b)].$$ I computed the second and fourth moments using the recurrence for $\delta_{a,b}$.


text:
Q: How to cancel all pending $resource requests using promis on $state change I am trying to stop all the pending requests when a state change occurs.The below code works fine with $http but not with $resource.
                 var cancel=$q.defer();
    $http.get('api/cafservicestatus',{timeout:cancel.promise,cancel:cancel}).then(onsuccess,onerror);

    function onsuccess(result) {
        console.log(result)
    }

    function onerror(error) {
        console.log(error)
    }

    function stopHttp() {
        $http.pendingRequests.forEach(function(request) {
            if (request.cancel) {
                request.cancel.resolve();
            }
        });
    }

But this code doesn't work with $resource
 Here is a sample code for $resource
             $resource(resourceUrl, {}, {
        'query': { method: 'GET', isArray: true,timeout:$q.defer().promise,cancel:$q.defer()},
        'get': {
            method: 'GET',
            transformResponse: function (data) {
                if (data) {
                    data = angular.fromJson(data);
                }
                return data;
            }
        },
        'update': { method:'PUT' }
    });

How can I stop all requests using $resource

A: I have figured out this one.You must add a cancellable:true to your request and cancel the request in your controller using $cancelRequest()method of $resource.
for example, In your case
$resource(resourceUrl, {}, {
    'query': { method: 'GET', isArray: true,cancellable:true},
    'get': {
        method: 'GET',
        transformResponse: function (data) {
            if (data) {
                data = angular.fromJson(data);
            }
            return data;
        }
    },
    'update': { method:'PUT' }
});

and inside your controller
 var aborted= YourService.query();

//and later on state change

  $scope.$on('$stateChangeSuccess',function(event){
     aborted.$cancelRequest();
      }
      );


text:
Q: check if resource exist in Azure errorvariable does not work Following SO answer provided me with a solution that I've been using for some time. But now for some reason if I execute the following code The errorvariable has no effect :(
I've tested the following code without resource group name which gives me output of all the recovery service vaults in my subscription and with the resourcegroupname paramerer which gives me no output at all.
How come this code that seems to be obvious does not work for this situation ?
Can anyone see what I am missing, don't see here?
Get-AzRecoveryServicesVault -ResourceGroupName xxxxxxxxxx -ErrorVariable notPresent -ErrorAction SilentlyContinue
if($notpresent){
Write-Host -ForegroundColor "There is no backup vault available"
}
else
{
write-host -ForegroundColor Yellow "there is more than one backup vault available"
}

A: This command Get-AzRecoveryServicesVault -ResourceGroupName xxxxxxxxxx will return nothing instead of error message when there is no result, so your script will not work.

So your script could be like below.
$vault = Get-AzRecoveryServicesVault -ResourceGroupName <ResourceGroupName>

if($vault){

Write-Host "there is more than one backup vault available"
}
else
{
Write-Host "There is no backup vault available"
}


text:
Q: How to change docker default ip binding? When Docker starts, it creates a virtual interface docker0 and binds it to private subnet 172.17.42.1/16. How to change this default to another ip block e.g. 192.168.42.1/24?

A: It does not always assign 172.17.42.1/16, normally it chooses from a private range defined by RFC 1918 that are not in use on the host machine.
For changing it to a desired value you can use the following option:
--bip=CIDR — supply a specific IP address and netmask for the docker0 like "--bip=192.168.42.1/8"

More information can be seen for this on Advanced Networking with Docker.


text: Q: Mouse scroll dropdown list of ComboBox in Excel 2016 64-bit I have a ComboBox dropdown list that has 150+ lines. I was wondering if there's a way to control the scrolling with the mouse wheel over the lines so you don't need to use the bar on the right.


text:
Q: Can't get the NumberPickers from TimePicker - Android version 7.0 (API 24) I have an Android.Widget.NumberPicker in my app and I'm using a FindAllChildernByType method to get the NumberPickers inside.
It seems that the NumberPicker is different on Android version 7.0 (API 24). There is no NumberPickers, only TexViews, so when running on this OS, the app crashes.
Is it a known issue? Thus anyone came up with a nice solution for this?


text:
Q: Работа с асинхронными запросами. JAVA Значит, поставили задачу, нужно написать небольшое приложение под Android. Авторизация и получение какой-либо информации из базы Mysql с одного из серверов.
Есть класс User, который будет получать информацию из базы.
public User(Context context){

    Thread t = new Thread(){
            @Override
            public void run() {
                super.run();
                Log.e("result", "Получаем данные");
                Thread.sleep(5000);
            }
        };
        t.start();
        t.join();

        Log.e("result", "Данные получены");
    }

Класс User Вызываю из MainActivity, при этом главный поток зависает и ждет выполнения нового потока, из-за t.join().
Вопрос: Как делать запросы чтобы не останавливать главный поток? И после получения данных, в MainActivity, была возможность работать с классом User. пример:
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

            User user = new User(this);
            Log.e("result", user.getFullName());
    }

A: Синхронно никак не получится. Надо использовать колбэки. Вообще получение асинхронно данных из сети делается всякими либами. Есть стандартные решения типа AsyncTask (устарел), Loaders (сложная и непонятная х*рь); сторонние решения Okhttp (для вообще сетевых запросов), Retrofit (надстройка над OkHttp для REST).
Для работы с разными потоками можно ещё RxJava использовать.
А так да - в основном потоке запрос делать нельзя, тормозить основной поток нельзя (будет ANR через 5с).
Лично я советую Okhttp + Retrofit + RxJava - кратко и красиво и понятно выйдет в коде.


text:
Q: Error-cannot find module 'config-chain' After running the command
    mean init myapp
I  ran the command
    mean package mypack
I get the error - cannot find module 'config-chain'

A: After the execution of the command 'mean init appname'
Try executing the following:
1.To see whether the protocol has been https or http, run the command
'npm config ls -l'
2.If you find registry="https://registry.npmjs.org/" then run...
npm config set registry="http://registry.npmjs.org/"
3.finally
npm config set strict-ssl false
again start with npm install.
For me the problem was solved.


text:
Q: How to get post url from instagram using Selenium as everytime I do it, it dynamically changes everytime i scroll down? I am trying to scrape Instagram Post on an Account but whenever I tell it to scroll down, the previous links disappears and new ones show up but never all in same position and now it's always capturing just 29 out of 1100 posts.
 while(count<10):
        for i in range(1,2):
            #.execute_script("window.scrollTo(0, document.body.scrollHeight);")
            self.browser.execute_script('window.scrollTo(0,document.body.scrollHeight)')
            print('.', end="",flush=True)
            time.sleep(2)

        elements = self.browser.find_elements_by_xpath("//div[@class='v1Nh3 kIKUG  _bz0w']")
        hrefElements = self.browser.find_elements_by_xpath("//div[@class='v1Nh3 kIKUG  _bz0w']/a")

        elements_link = [x.get_attribute("href") for x in hrefElements]

        i = 1
        unique = 1
        text_file = open("Passed.txt", "r")
        lines = text_file.readlines()
        text_file.close()

        for elements in elements_link:
            print(str(i)+'.',end ="",flush=True)
            found = self.found(elements,lines)

            if found==True:
                pass
            else:
                with open('Passed.txt','a') as f:
                    f.write(elements+'\n')
                unique+=1
            i+=1
        count+=1

        print('-----------------------------------------------')
        print('No. of unique Posts Captured : '+ str(unique))
        print('-----------------------------------------------')

This is my code for loading the posts and capturing the links from the posts and saving it into another file so I won't have to rerun it everytime.
the found function
`   def found(self,key,lines):
    for i in lines:
        if i == key + '\n':
            return True
        else:
            return False

`
I am trying to capture 1100 posts
here's what happens everytime it scrolls down

then scrolling down this changes to

A: You should first find the links and then scroll the page down in order to save the links, scroll the page and get the links that show up scrolling the page. In this way you will save also the links that disappear scrolling the page. Here an example:
wait = WebDriverWait(self.browser, 10)
links = []
number_of_posts = 1100

while True:
   hrefElements = wait.until(ec.visibility_of_all_elements_located((By.XPATH, "//div[@class='v1Nh3 kIKUG  _bz0w']/a")))

   elements_link = [x.get_attribute("href") for x in hrefElements]
   for link in elements_link:
       if link not in links:
           links.append(link)

   self.browser.execute_script('window.scrollTo(0,document.body.scrollHeight)')
   self.browser.implicitly_wait(5)

  if len(links) >= number_of_posts:
      break

links = links[:number_of_posts]
with open('Passed.txt','a') as f:
    for link in links:
        f.write(elements+'\n')


text:
Q: Linq, OData and WCF : "the method join is not supported" I'm trying to recover and display data from multiple table. o i've done a mutliple join like that :
var prod = from product in context.PRODUCT
    join islocated in context.ISAUDITEDIN on product.PRODUCT_ID equals islocated.PRODUCT_ID
    join location in context.LOCATION on islocated.LOCATION_ID equals location.LOCATION_ID
    orderby location.LOCATION_ID
    group new
    {
       Location_ID = location.LOCATION_ID,
       Product_ID = product.PRODUCT_ID
    } by location.LOCATION_ID into locat
    select new {
       Location_ID = locat.Key,
       Product = locat
    };

where context is the OData that result to a call from a web service. That link is working : when I do a simple select, I'm able to recover the data.
Then, I want to display the data that are in the result. So i've created a Dictionnary :
Dictionary<string,List<ProductModel>> dict = new Dictionary<string,List<ProductModel>>();
foreach (var locat in prod) {
    List<ProdctModel> products = new List<ProductModel>();
    foreach (var p in locat.Product)
    {
        products.Add(new ProductModel(p.Location_ID, p.Product_ID));
    }
    dict.Add(locat.Location_ID.ToString(), products);
}

Where ProductModel is a simple class like that:
public class ProdctModel
{
    public int locationID{get; set;}
    public int productID{get; set;}
    public ProdctModel(int location_ID, int product_ID)
    {
        this.locationID = location_ID;
        this.productID = product_ID;
    }
}

But when i'm running that, i've got the following :
"the method join is not supported"
Ligne 131 :            Dictionary<string,List<ProdctModel>> dict = new Dictionary<string,List<ProdctModel>>();
Ligne 132 :            foreach (var locat in prod) {

How to solve that ? I've seen a couple of things by using method .Expand() instead of join but I dunno how to use it : could you help me ?
Thanks!

A: I never used the odata with linq, but im assuming you can't join different remote resources. Try to get the objects to memory first, and then do the join:
var products = context.PRODUCT.ToList();
var islocateds = context.ISAUDITEDIN.ToList();
var locations = context.LOCATION.ToList();

var prod = from product in products
                       join islocated in islocateds on product.PRODUCT_ID equals islocated.PRODUCT_ID
                       join location in locations on islocated.LOCATION_ID equals location.LOCATION_ID
                       orderby location.LOCATION_ID
                       group new
                       {
                           Location_ID = location.LOCATION_ID,
                           Product_ID = product.PRODUCT_ID
                       } by location.LOCATION_ID into locat
                       select new {
                           Location_ID = locat.Key,
                           Product = locat
                       };

Remember that this will download all 3 tables.
EDIT
Also, the reason you are getting the exception when creating dictionary, is that the "prod" varialble is an IEnumerable- it executes the request only when you do "foreach" or something similiar.


text:
Q: Find the boundaries of Signature How do I find the boundaries of this inverted binary image?

A: Because there are gaps in the signature, using standard bounding box algorithms will fail to fully encapsulate the entire signature because when you detect bounding boxes, the gaps in the strokes will be interpreted as individual regions, and so individual bounding boxes will be detected there.  One work around is to simply find all of those pixels that are non-zero, and find the minimum and maximum row and column locations.  You can use find to help you do that.  These minimum and maximum values will correspond to the top left and bottom right corners of the overall bounding box that encapsulates this signature.
Before I show any code, I'm directly reading your image that you have uploaded, but it is a RGB image.  As such, I'm going to convert this to grayscale with rgb2gray, then threshold the image with im2bw.  There's also an unnecessary white border around the signature image so I'm going to clear this up with imclearborder.
Without further ado, here's the code:
%// Read in image and convert to binary
%// Also clear the borders
im = imread('http://oi59.tinypic.com/5fk9y0.jpg');
im_bw = imclearborder(im2bw(rgb2gray(im)));

%// Find those non-zero pixel locations
[rows, cols] = find(im_bw);
min_row = min(rows);
max_row = max(rows);
min_col = min(cols);
max_col = max(cols);

%// Now extract the bounding box
bb = im_bw(min_row:max_row, min_col:max_col);

%// Show the image
imshow(bb);

When you do this, bb should contain the image where the signature is bounded so that it fits within the image exactly.  This is what I get when you display bb:

Have fun!

A: Just in case Matlab isn't a firm requirement, or if you wish to check your Matlab results easily, or anyone else is looking who can't afford Matlab, there is the incredibly powerful ImageMagick that runs on all platforms, with command line and bindings for Perl, Python, .NET, Ruby and others.
I increased the borders around your image to make a proper test, and ran the following command:
convert out.png -format "%@" info:
362x135+49+26

which tells me that the bounding box you seek is 362 pixels wide and 135 pixels tall and its top-left corner is offset 49 pixels right and 26 pixels down from the top-left of the background - all in one simple command.
Just for fun, I can then draw that box in in red with the following command:
convert out.png -stroke red -strokewidth 1 -fill none -draw "rectangle 49,26 410,160" box.png

so it looks like this:


text:
Q: InfluxDB data -- where does the data go if you forget to assign disk partition to the service? Context:

*

*Working on a Debian 10 server

*Recently collected data in InfluxDB on this server; forgot to mount the service to disk partition

*A day after data collection started, the server crashed because /var directory was at a use% of 100%; I'm assuming all the InfluxDB went into this directory and in turn, the directory filled up and the server crashed, as a result

*To prevent this from happening in the future......assigned the service to a disk partition, as I should have to begin with

Current Issue:

*

*Using the "df-h" output.....cannot seem to knock the "/var" directory use% below 99%

Attempted Resolutions:

*

*Rotated and deleted logs from the server

*Deleted logs without rotating as a pre-requisite

*Emptied the biggest sub-directories within the /var directory
Questions:

*

*None of the contents I have been able to find -- "hidden" or otherwise -- or delete from the /var directory have had any InfluxDB-related data.....where could I find data collected pre-mounting-service-to-disk? Thinking deleting this data will aid in dropping the /var disk utilization below 99%.

Any insight into the above scenario or questions would be much appropriate. Please let me know if there any questions pertaining to the question or scenario.


text:
Q: Direct convert returns InvalidCastException I have a method with generics return type that works with my SQLite database:
    public static T SelectScalar<T>(string sql)
    {
        // some code...
        var result = command.ExecuteScalar();
        connection.Close();
        return (T)result;
    }

While calling it like this: SqliteReader.SelectScalar<int>(mysql); the InvalidCastException raised on return line. What's wrong with it? I'm quite new with generics, please tell, what's wrong? TIA.
EDIT
Screenshot with result content:

A: apparently the type BigInt cannot simply be casted to an int. According to this post it seems to be a

IIRC you are getting a SqInt32 struct which is castable to Int32

In your case probably a SqInt64 struct. You need to convert it
return (T)Convert.ChangeType(result, typeof(T));

I also would suggest to restrict the generic parameter at least down to structs:
public static T SelectScalar<T>(string sql) where T: struct

A: ExecuteScalar() returns an object, in this case a boxed long.
If you cast an object to an int, it tries to unbox .. an actual int. Casting a long to an int would be a conversion instead.
A cast that would work for these specific lines (but .. wouldn't help you) is
return (T)(long)result;

Potential duplicate: https://stackoverflow.com/a/3541712/59492


text:
Q: Rewriting ArrayList XML serialisation with jackson-dataformat-xml If I use jackson-dataformat-xml to serialise an ArrayList of JsonNode it produces the following:
<ArrayList><item>...</item><item>...</item></ArrayList>

I'd like to have it read:
<events><event>...</event><event>...</event></events>

I've tried using a custom serialiser and does give me the <event/> tags I want but it also still wraps everything in an <ArrayList><item></item></ArrayList>
public class ArrayListSerializer extends JsonSerializer<ArrayList<JsonNode>> {

    @Override
    public void serialize(ArrayList<JsonNode> value, JsonGenerator gen,
            SerializerProvider serializers)
            throws IOException, JsonProcessingException {
        gen.writeStartObject();

        for (JsonNode node : value) {
            gen.writeObjectField("event", node);
        }

        gen.writeEndObject();
    }

    @Override
    public Class<ArrayList<JsonNode>> handledType() {
        @SuppressWarnings("unchecked")
        Class<ArrayList<JsonNode>> typeClass = (Class<ArrayList<JsonNode>>)(Class<?>)List.class;
        return typeClass;
    }
}

Any suggestions? Thanks.

A: You can also consider defining the XML element names using annotations. Here is an example:
public class JacksonXmlArray {
    static class Document {
        @JsonProperty
        @JacksonXmlElementWrapper(localName = "events")
        @JacksonXmlProperty(localName = "event")
        List<String> events = Arrays.asList("a", "b");
    }
    public static void main(String[] args) throws JsonProcessingException {
        final XmlMapper xmlMapper = new XmlMapper();
        System.out.println(xmlMapper.writeValueAsString(new Document()));
    }
}

Output:
<Document xmlns=""><events><event>a</event><event>b</event></events></Document>


text:
Q: How do you protect Web Services when using it as JSON via Jquery? I currently use asmx for Json transactions using Jquery.
How do I protect it from being accessed across other websites and make it exclusive only through my domain?

A: Ensure the requestor has:

*

*HTTP_REFERER set to your site; and

*a valid cookie for your site.

This will prevent the behaviour that is most akin to hotlinking. However if a site uses an HTTP library to use your Web service and it's public there's not a lot you can do beyond IP throttling and similar techniques.


text:
Q: Delphi: How do i know what my property editor is editing? i have a property editor (descendant of TPropertyEditor) that is used to edit a property.
When it comes time to edit my property, how do i know what property of what object i'm editing? If i'm going to edit a property, i have to know what property i'm editing.
i've been pulling my hair out, sifting through the Delphi help, the online help, and the TPropertyEditor and descendant source code, and i can't find the answer.
i expected something like:
TPropertyEditor = class(...)
public
    procedure Initialize(TheObject: TObject; ThePropertyName: string);
end;

As far as i can tell, my property editor is created, and i will be told to "Edit", and i just have to divine what property they wanted me to edit.

From the help:

Editing the property as a whole
You can optionally provide a dialog
  box in which the user can visually
  edit a property. The most common use
  of property editors is for properties
  that are themselves classes. An
  example is the Font property, for
  which the user can open a font dialog
  box to choose all the attributes of
  the font at once.
To provide a
  whole-property editor dialog box,
  override the property-editor class's
  Edit method.
Edit methods use the same
  Get and Set methods used in writing
  GetValue and SetValue methods. In
  fact, an Edit method calls both a Get
  method and a Set method. Because the
  editor is type-specific, there is
  usually no need to convert the
  property values to strings. The editor
  generally deals with the value "as
  retrieved."
When the user clicks the '...' button
  next to the property or double-clicks
  the value column, the Object Inspector
  calls the property editor's Edit
  method.
Within your implementation of
  the Edit method, follow these steps:

*

*Construct the editor you are using
  for the property.

*Read the current
  value and assign it to the property
  using a Get method.

*When the user
  selects a new value, assign that value
  to the property using a Set method.

*Destroy the editor.

Answer
It's tucked away, and not documented, but i found out how. The property i'm editing that i edit:
TheCurrentValue := TMyPropertyThing(Pointer(GetOrdValue));

Now that i have the value, i can edit it. If i want to replace the property with some other object:
SetOrdValue(Longint(TheNewValue));

The full code:
Create a property editor that descends from TClassProperty:
TMyPropertyEditor = class(TClassProperty)
public
   procedure Edit; override;
   function GetAttributes: TPropertyAttributes; override;
end;

First is the housekeeping, telling Delphi's object inspector that my property editor will display a dialog box, this will make a "..." appear next to the property:
function TMyPropertyEditor.GetAttributes: TPropertyAttributes;
begin
   //We show a dialog, make Object Inspector show "..."
   Result := [paDialog];
end;

Next is the actual work. When the user clicks the "..." button, the object inspector calls my Edit method. The trick that i was missing is that i call my GetOrdValue method. Even though my property isn't an ordinal, you still use it, and just cast the resulting thing to an object:
procedure TMyPropertyEditor.Edit;
var
   OldThing: TMyPersistentThing;
   NewThing: TMyPersistentThing;
begin
   //Call the property's getter, and return the "object" i'm editing:
   OldThing:= TMyPersistentThing(Pointer(GetOrdValue));

   //now that i have the thing i'm editing, do stuff to "edit" it
   DoSomeEditing(OldThing);

   //i don't have to, but if i want to replace the property with a new object
   //i can call the setter:
   NewThing := SomeVariant(OldThing);
   SetOrdValue(Longint(NewThing));
end;

A: If I understand your question right, you're wondering how you're supposed to actually find the value you need to be editing, especially if the object in question contains more than one of them.  The answer is that the IDE sets that up for you and the property editor comes "preloaded" by the time Edit is called.  TPropertyEditor comes with a bunch of GetValue methods that your Edit function can use to retrieve the value.  Or if it's not one of those types, (if it's an object descended from TPersistent, for example,) then you can call GetOrdValue and cast the result to a TPersistent.
Also, you might want to check out TJvPersistentPropertyEditor in the JvDsgnEditors unit of the JVCL to use as a base class.  It provides some of the functionality for you.
BTW if you really need it, you can use the GetName method, which will give you the name of the property, but you usually shouldn't have to.  And be careful if you're inheriting from something other than TPropertyEditor itself, as GetName is virtual and can be overridden.

A: A property editor keeps the information about which objects and properties it's editing in the private FPropList variable. The IDE fills that in by calling your editor's SetPropEntry method. You're then generally supposed to call the various methods of TPropertyEditor to find out the properties' values.
It's not really supposed to matter which property you were asked to edit. Your property editor edits properties of a particular type. For in-place editing, your editor provides an implementation of SetValue that translates the string from the Object Inspector into a value of the proper type for the property, and then you call the appropriate Set function, such as SetOrdValue or SetIntfValue. For whole-property editing, the IDE won't call SetValue. Instead, it will call Edit, and you're expected to call GetOrdValue or GetIntfValue (for example) yourself, since your editor already knows what type of property it's designed to edit.
Remember that property editors, in general, can edit multiple properties simultaneously. The name of the property will be the same for all of them, but the type of component they belong to may vary, and thus so may their getters and setters. Call your property editor's GetName method to find out the name. To get the objects, call GetComponent for each index from 0 to PropCount - 1. (Be careful; there's no range checking in those Get functions.) You can also check whether a specific object is in the list by calling HasInstance. The GetPropInfo method will tell you the PPropInfo pointer for the first property, but I don't think that will necessarily be equal to the pointers of all the other properties. Aside from that, you don't get direct access to the PPropInfo data, but again, it really shouldn't matter. If you think you need that for your editor, you're probably doing something wrong; post a new question with more specific information about your underlying task.

A: Property editors only care about (and are registered for) the type of the property, not the specific property itself.


text:
Q: Unable to access static methods from singleton of static class I've a class that has a singleton and a method as below:
public class ProductManager
    {
       private static ProductManager _Value = null;
        public static ProductManager Value
        {
            get { if (_Value == null) _Value = new ProductManager(); return _Value; }
        }

public static void SaveProduct(string productname)
        {
        }
}

I've another class in another assembly (SecondAssembly), that wraps around that class, like this :
public class BaseManager
    {

        public static FirstAssembly.ProductManager ProductManager
        {
            get
            {
                return FirstAssembly.ProductManager.Value;
            }
        }
}

In the same assembly (SecondAssembly), i want to access SaveProduct method of ProductManager class through this property of BaseManager. But i am unable to do so, it won't just show up :
BaseManager.ProductManager.SaveProduct("abc"); // Can't access it..

Please exaplain to me, why i cant do so ?

A: You are trying to access static method via instance. It's a nonsense. You don't need an instance in this case. You can call just ProductManager.SaveProduct(...)
EDIT:
If you want to wrap ProductManager by BaseManager you can either make SaveProduct instance method instead of static or wrap SaveProduct in your BaseManager:
public class BaseManager
{
    ...
    public static SaveProduct(...)
    {
        ProductManager.SaveProduct(...);
    }
}

In my opinion it's better to make SaveProduct non-static since ProductManager is anyway singleton

A: static method is accessible from anywhere.
ProductManager.SaveProduct()

SEE HERE


text:
Q: How to use useContext to change the background when using Chakra UI? I am using useContext from React to create a hook to control my background color but when I add Chakra UI it no longer works and only changes the background for a portion of the screen. Is there anyway I can use Chakra to change the background color or should I be tweaking useContext?
import React, { useState, useEffect, useContext, createContext } from "react";
import { useTile } from "./TileContext";

const StudioContext = createContext({});
    <StudioContext.Provider
      value={{
        studioState,
        setStudioState,
        currentRoomIndex,
        setCurrentRoomIndex,
        updateItemLocation,
        updateShadow,
        updateRoomTitle,
        updateRoomBackground,
        addRoom,
        currentItemIndex,
        setCurrentItemIndex,
        updateItem,
        addItem,
        unsavedChanges,
        setUnsavedChanges,
        removeItem,
        currentItemAspectRatio,
        updateCustomIcon,
        verificationItems,
        centerRoom,
        updateRoomSetting,
        addTextItem,
        updateTextItem,
        roomCenter,
        updateRoom,
        centerRoomOnItem,
        addLinkItem,
        addItems,
        removeRoom,
        theme,
        setTheme
      }}
    >
      {children}
    </StudioContext.Provider>


text:
Q: R tabulizer package list of matrices dimensions vary for same format PDF tables I'm using Tabulizer 0.2.2 extract_tables on the following pdf in R on Mac.
sales <- "http://www.greenwichct.org/upload/medialibrary/5cd/Residential-Sales-by-Address-10-10-to-10-15.pdf"
test <- extract_tables(sales,pages=c(1:10),method="decide")
I believe the tables on each page are the same, but resulting list of matrices for the first ten pages for example gives matrices with 3 different dimensions. Columns are sometimes concatenated, for example in test[[3]] with columns 1 and 2.
I have tried setting the area, specifying methods. I have looked around for how to specify the column parameter, but cannot find anything specific. Even went through with extract_area(), but same result. Same problems using Tabula app also.
Any thoughts appreciated.