Processing large arrays that do not fit in RAM in Java

Question: I am developing a text analysis program that represents documents as arrays of "feature counts" (e.g., occurrences of a particular token) within some pre-defined feature space. These arrays are stored in an ArrayList after some processing.
I am testing the program on a 64 mb dataset, with 50,000 records. The program worked fine with small data sets, but now it consistently throws a "out of memory" Java heap exception when I start loading the arrays into an ArrayList object (using the .add(double[]) method). Depending on how much memory I allocate to the stack, I will get this exception at the 1000th to 3000th addition to the ArrayList, far short of my 50,000 entries. It became clear to me that I cannot store all this data in RAM and operate on it as usual.
However, I'm not sure what data structures are best suited to allow me to access and perform calculations on the entire dataset when only part of it can be loaded into RAM?
I was thinking that serializing the data to disk and storing the locations in a hashmap in RAM would be useful. However, I have also seen discussions on caching and buffered processing.
I'm 100% sure this is a common CS problem, so I'm sure there are several clever ways that this has been addressed. Any pointers would be appreciated :-)
Comment: Use a datadase which would either allow you to query a small subset or perform some other analysis (like running functions or joins) and which supports cursors (so it's not loading the entire set into memory) or some other memory/mapped cache
Comment: @MadProgrammer thanks...what about memory mapped IO files?
Comment: Not having used memory mapped files (directly) before, it's difficult to say.  My basic concern would be if the data would need to be `Serializable`
Comment: "I start loading the arrays into an ArrayList object"
Are you trying to get a List, or a List?
If latter, how are you going ot be saved by sparse arrays? You're not.
Comment: @alamar no, I meant List so the fewer elements I need to store, the better.
Comment: I can't imagine why you would see OutOfMemoryError when adding an array to list of arrays. How much arrays have you got there?
Comment: @alamar 50000 objects each holding a 151000 element array of doubles
Answer: You have plenty of choices:

Increase heap size (-Xmx) to several gigabytes.
Do not use boxing collections, use fastutil - that should decrease your memory use 4x. http://fastutil.di.unimi.it/
Process your data in batches or sequentially - do not keep whole dataset in memory simultaneously.
Use a proper database. There are even intraprocess databases like HSQL, your mileage may vary.
Process your data via map-reduce, perhaps something local like pig.
Comment: Thanks! I tried increasing heap size...not going to work. I am considering using sparse arrays to decrease storage and Ill look into fastutil. Three was my next choice. I like the idea of an intraprocess DB...will consider that too. MapReduce may be overkill, but its an option too.
Answer: How about using Apache Spark (Great for in-memory cluster computing) ?This would help scale your infrastructure as your data set gets Larger.
Comment: Hmmm...would this be overkill for a dataset that will likely never get to 10 TB?


Are these duplicates?

Question: Recently I have asked a question I wasn't able to find already asked: How to add behavior-based onclick to ajax-enabled Form API button?
Now, using comments by Beebee I found a working solution. Also, thanks to his comments, I get to know about older similar question: Listen to AJAX complete event from a behavior
Now, they are similar for sure. But are they duplicates? If so, which one should get closed? I dare to shamelessly say that it appears I've put a bit more effort in my question. And the answer to the older one simply does not work for me.
Comment: @Bala but MPD also provided different solution, and your acceptance proved I was wrong ;) Here we have quite opposite, for Paul Sheldrake listening for AJAX complete was a goal he put in his question. For me it was an answer. So in your case goals looked similar, solutions didn't, here goals are different, but solutions are similar.
Comment: +1 for having asked on meta about your how question.
Comment: I think users can ask same questions older than 6 month and no need to close.
Comment: @Bala Nope, there is no time limit. And I don't think there should be. Stack network is designed to be a knowledge repository. But I think these are different, even if similar. But Beebee called them dupes. I don't mind if they will get closed, if most of you thinks they are. I just want some opinions on this.
Comment: Molot FYI http://drupal.stackexchange.com/questions/88200/how-to-increase-the-speed-of-exposed-autocomplete-field-in-views-using-drupal-6 same condition here, but marked as duplicate by you and MPD disagreed. I think it depends on  person to person and expecting opinion may be looks broad.
Comment: @Mołot +1 this question shows your sinciarity to DA, great!!!
Answer: I would not say they are duplicates, since the other question doesn't even show any code. The other question is asking how to achieve something, while you are saying your code doesn't work and you want to know why, or how to fix it.
That is the important difference that cannot be forgetten. The questions are so different that the only thing they have in common is that they are about Drupal AJAX.
Comment: Thank you. It was thin line, especially since duplicates are no longer expected to be "exact" and this word got removed from close reason.
Comment: Still, _duplicates_ means more than "both the questions are about AJAX."
Comment: But I'm not arguing, I was just explaining the source of my doubts.
Comment: I understood; I just meant that removing that word doesn't mean that closing loosely related question is now acceptable.

Are these duplicates?


Fluorescent lights sometimes don't turn on

Question: I have two T12 double-ended G13 2-pin 4 foot fluorescent lights in my bathroom. They often (maybe 1/3 of the time) won't turn on, with a very slight glow in one corner, then usually turn on after an extended period of time. I replaced the bulbs with new ones and this still happens. From my googling I read this as a sign that my ballast is bad. Is that right?
My initial response was to replace the bulbs with LEDs, something like the Philips Instafit or Hyperikon "plug and play" models that work with a ballast, as that would be a very easy installation I could do myself. But if my ballast is bad, that won't help me, correct?
Installing a new ballast in 2019 doesn't seem to make sense. So am I right in thinking that my best path is to buy non-Instafit LED bulbs and bypass the ballast?
Thanks for any help!
Comment: Hello, and welcome to Home Improvement. Interesting question; keep 'em coming. And, you should probably [take our tour](//diy.stackexchange.com/tour) so you'll know how best to participate here.
Answer: Do not use plug-n-play LEDs - they depend on a functioning ballast and your ballast is suspect.
Because then, you'd be at a crossroads.  Return the plug-n-play and remove the ballast and get a direct-wire/ballast-bypass LED... Or replace the ballast and stay with PnP and support that ballast forever, even though LEDs don't actually need it.  Obviously the second one is pretty lame.
I honestly recommend a third choice, replace the ballast and keep that nice new tube you just got, that is probably 90 CRI and better light than you'll get anytime soon from LED.  Modern ballasts fix all the complaints about fluorescents.
Comment: *Incandescent* lights are being phased out. I would expect fluorescent to be with us for quite some time.
Comment: Thank you for confirming my guesses! My understanding is fluorescent tubes aren't even being manufactured anymore, so replacing the ballast doesn't make a great deal of sense.
Comment: @Georg -- fluorescent lights are still going strong; while they are a legacy technology, their lumens/watt is nowhere near as bad as incandescents, and they do offer some advantages over LED in terms of maturity and low cost
Comment: Ahh thanks, I was misinformed there.


How to use Google Translate HTML input elements

Question: Using the following code to try and translate input into HTML input fields and it doesn't seem to work:

<form>
   First Name: <input type="text" id="firstName" />
   Last Name: <input type="text" id="lastName" />
</form>

The content of the page is translated OK but not the values in the input fields.  Looked at this solution recommended but I'm unable to make it work.   How do I get values put into input fields to be translated?
Answer: Read through the Google Translate API here, but I'll also try and explain it a bit.
First of all the Google API requires a registered key with each query. Look on the API page to see how to aqcuire that key.
Next, if you look to the API page it will give you a default url to query like this:
https://www.googleapis.com/language/translate/v2?{paramaters}

An example to translate 'hello' from english to spanish would be:
https://www.googleapis.com/language/translate/v2?key={INSERT-YOUR-KEY}&source=en&target=es&q=hello

to pass on the input from a form, you will need to use PHP to plug your information into your google translate query string.
Hope this helps!
Comment: @Cameronn, Unfortunately this won't work for me as I'm unable to pay for the service.  Thanks for the tip though.
Answer: I made something like this. It works form me. I haven't use any API.
create input like this scheme:
<value for="1" style="display:none">Asia,Southern Asia</value>
<input contenteditable="true" name="1" type="text" placeholder="Asia,Southern Asia" value="Asia,Southern Asia">

translate your page with Google translate plug. Then, call this function
function translateInput(){
    for(i=0; i<$('input').length; i++){
            $('input').eq(i).val($('value').eq(i).text());
    }
}

Answer: Let Me give You one more simple solution
html

$(document).ready(function(){

function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'ar', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}

$('#confirmTraslate').click(function(){

   $('.translated-element').each(function(){
      id=$(this).data('label-for');
      $('#'+id).val( $(this).text() );
   });

});

});

                              Address
                              <input class="form-control" id="consignee_address_line1" name="consignee_address_line1" value="القطيف - حي الشاطي
شارع ابي ذر الغفاريالقطيفSaudi Arabia" type="text">
                              القطيف - حي الشاطي
شارع ابي ذر الغفاريالقطيفSaudi Arabia


What are the requirements for unlocking Epona?

Question: According to multiple sources online (including video evidence), you can get Epona in Breath of the Wild by using the Link Amiibo from Super Smash Bros.
Before knowing this, I had already used that Amiibo and it just gave me a few random resources. When I found out about Epona later, I assumed it probably didn't work for me because I did it too early (it was at the very beginning of the game, maybe even before getting to the first tower - the game probably wouldn't want me to have a horse at that point).
However, when I tried it again the next day (having made quite a bit of progress and owning three horses), the same thing happened again. Just random stuff, no Epona.
Are there any specific requirements for this to work, or did I somehow break my save file by using the Link Amiibo too early?
I'm playing the Wii U version if that makes any difference.
Comment: @Ise Is "Plains of Epona" an area in the game? If so, I haven't heard of it yet, and can't seem to find any info about it.
Comment: Well, I didn't tried it yet, but some websites say that you need to 'be in the Plains of Epona to have any chance of success. Otherwise, you'll just get a chest with, admittedly, some cool items, such as Twilight Link's tunic.'
Can you try that ?
(I'll buy that amiibo instantly if that work !)
Answer: According to this article you should have gotten it on your first use of the amiibo. And if you did not put Epona into a stable you may not get her to summon again. It does not seem that there are any requirements for getting her to summon other than using the amiibo and it being the first time doing so, there are no indicators that using it at a specific point in the game changes how this works.

If the player has the Smash Bros. Series Link Amiibo, you can use the
  Amiibo Rune to tap Link onto the NFC reader. While most other Amiibo
  will summon a supply drop of items - the first time the Smash. Bros
  Series Link is used, Epona will be summoned instead.

So my guess is, based off their explanation, is that you potentially summoned her and didn't notice and it may be stuck where you can't summon her again. Or you summoned her in the Plateau and you did not get to put her in a stable, thus she disappears.

However, if you wish to keep and ride Epona - you must register the
  horse at a stable as soon as possible. If you summon Epona in a place
  where you cannot get to a Stable, like on the Great Plateau, you will
  be unable to summon Epona again, as using the Smash. Bros Series Link
  Amiibo on other days will only summon standard supply drop items.

However; there is another article that mentions a fountain that may be of help to you.

The downside, of course, is that if Epona dies -- that's it. You
  cannot respawn Epona by tapping the amiibo again after she dies, and
  you will only be able to get her by restarting your game or by finding
  the Horse God's Great Fairy Fountain.

So perhaps there is a chance you can get Epona back, based off of what that article says:

Unlocking this Great Fairy will allow you to bring any horse back to
  life -- provided that it was registered, and that you have the means
  to pay for it. Even legendary or rare horses can be brought back to
  life at this fountain -- including Epona (provided you already
  summoned her with an amiibo).

But since it doesn't seem like you registered her if she did spawn by chance, it may not work either. The only solution remaining after that, as far as I can tell, is restarting, which I can't imagine you want to do.
Comment: @Andii It seems like you can try again and again to re use the amiibo and you might be lucky enough to get her a second time. People speak about trying 50 times and getting her :) http://press-start.com.au/guides/2017/03/06/can-get-epona-zelda-breath-wild-second-time/
Comment: Yes, but as I said, there was an item drop, no horse to be seen. I can imagine the game thinking I've already spawned her though, maybe it only remembers that the amiibo was used before and won't give me another chance. I really should have looked up what it's supposed to do before...
Comment: [Apparently I'm not the only one with this problem.](https://en-americas-support.nintendo.com/app/social/questions/detail/qid/48903/) I'll probably just keep playing for now and hope it's eventually patched.
Comment: Thank you for the detailed answer. I'm fairly certain Epona did not spawn, since in the videos I saw she was the only spawn that happened, while I got some items and a chest. I'll wait to see if I can get any more info, but yeah, restarting would suck.
Comment: Were you in the plateau when you used it?
Comment: That could be part of the issue, since it may have seen you were in a place where you could not register her which may have bugged it out, and now that it's been used it probably won't show again.
Comment: Where did you use the amiibo the first time? Was it in a place where a horse is not supposed to be (e.g. a tower)?
Comment: @Ise Wow, that's great news, thanks! Haven't had any luck so far, but I'll keep trying. :)
Comment: Quick update: I finally managed to unlock Epona. It turned out to be surprisingly easy if done in a certain way. I posted my solution [as an answer to another question](http://gaming.stackexchange.com/questions/302360/what-to-do-if-i-did-not-register-epona-from-the-super-smash-brothers-link-amiibo/302582#302582) (because it fit that one better than mine).
Comment: you will need the right amino to get epona.DO NOT SUMON HER ON THE GREAT PLETU.other wise you will never get her agen.once you have epona,bord her at a stable.
Answer: It's very easy to miss on Epona if you use the Link Amiibo the first time in a place where horses cannot spawn. That may happen inside caverns, sanctuaries, ruins, on the volcano, or inside a village or a relay.
If you want to be sure, try a place where you see wild horses.
Note that you can only get Epone on the very first time you use the Amiibo in a given game. Trying again the next day, or after quitting and re-entering the game, or after using a different Amiibo, doesn't work.
The good news is that you don't have to restart the game from scratch if you miss Epona, provided that you act right away and load a previous save. Then you'll have another shot.
Answer: You're probably not using the right Amiibo.
I got Epona the first time I used the Super Smash Bros. Link Amiibo, that looks like Link with a Hylian shield in this battle pose. There is a chance you get treasure instead, but I think it's a 90% chance to get Epona.
Probably bad luck, or wrong Amiibo


Linking PGI OpenACC Runtime Library directly with gcc

Question: I am insterested in using PGI OpenACC runtime API directly from code compiled by GCC.
I've noticed that the PGI OpenACC installation provides two openacc.h headers. One for PGI (located in  include/openacc.h) and another that seems to be compatible with GCC (etc/include_acc/openacc.h). It is safe to use the second header with GCC?
So far I've been able to compile & run a small test:
#include <openacc.h>
#include <cuda_runtime_api.h>
#include <stdio.h>

int main()
{
   acc_init( acc_device_nvidia );

   int ndev = acc_get_num_devices( acc_device_nvidia );

   printf("Num OpenACC devices: %d\n", ndev);

   cudaGetDeviceCount(&ndev);

   printf("Num CUDA devices: %d\n", ndev);

   return 0;
}

Using PGI:
pgcc -acc -ta=tesla,cuda8.0 -Mcuda ./test.c -o oacc_test.pgi
Using GCC + PGI OpenACC:
gcc -isystem /usr/local/cuda-8.0/include -isystem /usr/local/pgi/linux86-64/17.4/etc/include_acc -o oacc_test.both test.c -L/usr/local/cuda-8.0/lib64 -Wl,-rpath,/usr/local/cuda-8.0/lib64 -lcudart -lcuda -L/usr/local/pgi/linux86-64/17.4/lib   -Wl,-rpath,/usr/local/pgi/linux86-64/17.4/lib   -laccapi -laccg -laccnc -laccn -laccg2 -ldl -lpgc -lm
Using GCC + GCC OpenACC: (for comparison)
gcc -fopenacc -isystem /usr/local/cuda-8.0/include                                       -o oacc_test.gnu  test.c -L/usr/local/cuda-8.0/lib64 -Wl,-rpath,/usr/local/cuda-8.0/lib64 -lcudart -lcuda
And execute:
$ ./oacc_test.pgi
Num OpenACC devices: 4
Num CUDA devices: 4
$ ./oacc_test.both
Num OpenACC devices: 4
Num CUDA devices: 4
$ ./oacc_test.gnu

libgomp: device type nvidia not supported

More info:
$ ldd oacc_test.pgi
    linux-vdso.so.1 (0x00007ffd843f8000)
    libaccapi.so => /usr/local/pgi/linux86-64/17.4/lib/libaccapi.so (0x00007fa5a2b9f000)
    libaccg.so => /usr/local/pgi/linux86-64/17.4/lib/libaccg.so (0x00007fa5a2981000)
    libaccnc.so => /usr/local/pgi/linux86-64/17.4/lib/libaccnc.so (0x00007fa5a2777000)
    libaccn.so => /usr/local/pgi/linux86-64/17.4/lib/libaccn.so (0x00007fa5a2552000)
    libaccg2.so => /usr/local/pgi/linux86-64/17.4/lib/libaccg2.so (0x00007fa5a233c000)
    libcudapgi.so => /usr/local/pgi/linux86-64/17.4/lib/libcudapgi.so (0x00007fa5a213b000)
    libcudart.so.8.0 => /usr/local/cuda/lib64/libcudart.so.8.0 (0x00007fa5a1ed5000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa5a1b49000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa5a1945000)
    libcudadevice.so => /usr/local/pgi/linux86-64/17.4/lib/libcudadevice.so (0x00007fa5a1731000)
    libpgmp.so => /usr/local/pgi/linux86-64/17.4/lib/libpgmp.so (0x00007fa5a14af000)
    libnuma.so => /usr/local/pgi/linux86-64/17.4/lib/libnuma.so (0x00007fa5a12ae000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa5a1091000)
    libpgc.so => /usr/local/pgi/linux86-64/17.4/lib/libpgc.so (0x00007fa5a0dae000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa5a0aaa000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa5a070b000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa5a04f2000)
    /lib64/ld-linux-x86-64.so.2 (0x000055767be3b000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa5a02ea000)

$ ldd oacc_test.both
    linux-vdso.so.1 (0x00007ffe55753000)
    libcudart.so.8.0 => /usr/local/cuda/lib64/libcudart.so.8.0 (0x00007f7ddfe3c000)
    libcuda.so.1 => /usr/lib/x86_64-linux-gnu/libcuda.so.1 (0x00007f7ddf3d8000)
    libaccapi.so => /usr/local/pgi/linux86-64/17.4/lib/libaccapi.so (0x00007f7ddf1b8000)
    libaccg.so => /usr/local/pgi/linux86-64/17.4/lib/libaccg.so (0x00007f7ddef9a000)
    libaccnc.so => /usr/local/pgi/linux86-64/17.4/lib/libaccnc.so (0x00007f7dded90000)
    libaccn.so => /usr/local/pgi/linux86-64/17.4/lib/libaccn.so (0x00007f7ddeb69000)
    libaccg2.so => /usr/local/pgi/linux86-64/17.4/lib/libaccg2.so (0x00007f7dde955000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7dde751000)
    libpgc.so => /usr/local/pgi/linux86-64/17.4/lib/libpgc.so (0x00007f7dde46e000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7dde16a000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7ddddcb000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7dddbac000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7ddd9a4000)
    libnvidia-fatbinaryloader.so.378.13 => /usr/lib/x86_64-linux-gnu/libnvidia-fatbinaryloader.so.378.13 (0x00007f7ddd753000)
    /lib64/ld-linux-x86-64.so.2 (0x00005593f06f5000)

$ ldd oacc_test.gnu
    linux-vdso.so.1 (0x00007ffd967d7000)
    libcudart.so.8.0 => /usr/local/cuda/lib64/libcudart.so.8.0 (0x00007f9002679000)
    libcuda.so.1 => /usr/lib/x86_64-linux-gnu/libcuda.so.1 (0x00007f9001c15000)
    libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f90019e8000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f90017cb000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f900142c000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9001226000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f900101e000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9000d1a000)
    libnvidia-fatbinaryloader.so.378.13 => /usr/lib/x86_64-linux-gnu/libnvidia-fatbinaryloader.so.378.13 (0x00007f9000ac9000)
    /lib64/ld-linux-x86-64.so.2 (0x0000563eee684000)

Is is safe to use the PGI OpenACC Runtime API that way?
Also threre is any difference between the CUDA runtime provided by Nvidia (usually in /usr/local/cuda) and the one provided by PGI (in my case in /usr/local/pgi/linux86-64/2017/cuda)?
I've noticed that pgcc uses the CUDA 7.5 from it's own install path but when -ta=cuda8.0 is provided it uses the one in /usr/local/cuda. Any special reason?
Answer: PGI compiled objects are interoperable with GNU and it's fine to mix in PGI OpenACC compiled code with GNU compiled objects.  Though, the OpenACC runtimes libraries aren't compatible so I'd recommend not mixing the OpenACC code.  Note that GNU support for OpenACC has gotten a lot better in their 7.0 release, so while I work for PGI, I'd encourage you to try both compilers.  The one caveat is the they (GNU) don't support the "kernels" construct, so you'll want to stick to using "parallel" regions.
As for the CUDA libraries, PGI ships all the libraries that we need to compile your OpenACC code.  Though, there's no difference in the CUDA libraries themselves.  We didn't want users to have to co-install the CUDA SDK and it allows us to add convenience flags such as "-Mcudalib[=cublas|cufft|curand|cusolver|cusparse]" since we know where these libraries are located as well as include our own Fortran interface modules to these libraries.
Unless you have the flag "CUDAROOT=" set on your compilation line, "-ta=tesla:cuda8.0" should be using the PGI supplied CUDA 8.0 directory located in "$PGI/linux86-64/2017/cuda/8.0".  Are you sure it's using the /usr/local/cuda install?  You can double check by adding the verbose flag (-v) to see what the compiler driver is executing or "-dryrun" to see the commands without having the driver execute them.
Another possibility is that you're using "-L" or "-Wl" flags to point to the CUDA install (like you do with GNU) in which case the linker will pick-up the CUDA libraries from these directories.  Though since they're the same libraries as we ship, it shouldn't be a problem.
Comment: Thank you!, I will check gcc 7.0. The thing about the CUDA 8.0 directory... It was my fault because `LD_LIBRARY_PATH` was set to `:/usr/local/cuda/lib64`


Type of drywall

Question: Can someone help me figure out type of drywall I need to buy to cover wooden beams in picture?
1st picture gives you view from the far.
In 2nd picture, I have  zoomed in the area inside red rectangle in 1st picture.
In 2nd picture,
C is wood.
B is thick drywall but I am not sure about what A is. Is it part of drywall ? I have never seen anything like this. I need to buy similar piece of drywall and cover that wooden beams.

3rd picture shows cross section view of all layers.
4th and 5th picture shows how piece of layer A look like.
Comment: Measure the overall thickness and that is your guide to what drywall you are going to buy. Thats all.
Comment: A in the picture is jointing compound, who ever did this used the jointing compound to fill in the gaps between the corner bead to give a nice square edge. You will find more jointing compound used in DIY projects than professionals use as professional drywall contractors have a lot more experience in getting tight corners and don't like wasting material. If you are doing this yourself consider using a corner bead tool to get a nice tight corner and you will use less jointing compound.
Comment: When you say you intend to "cover that wooden beam", do you mean to say that you mean to drywall over the entire beam span, on the bottom, shown as "C"?
Comment: Noybman - I tried finding drywall with similar thickness but I couldn't find. Thats why I want to know if A and B are part of one thing or applied separetly.                                 Jimmy - yes, I want to cover entire beam span with drywall. Infact that is how it was before I had to open it (to dry ) because of water damage from upstairs.
Comment: why don't you slide a boxcutter blade between A and B to determine if they are separate layers
Comment: Jsotola, I added few more pictures. As you suggested I sliced out layer of A with utility knief. Looks like it is either very thin drywall or thick layer of drywall mud. But I want someone to confirm it.
Comment: Wow, someone went to town with mud it seems. As @CarlErnest suggests, find something you can get your hands on (e.g., 1/4" material of anything, including drywall), and then add the 1/2" 3/8" etc. You'll have to mud the seams as done in the picture but should never need that much
Answer: You can wrap the beam with a number of different sheet materials. You're not limited to drywall - but that will work too. The key is to select a material closest to the existing wall board thickness. You are trying to match that thickness.The finish mud and tape will stick to plywood (for example) as well as paper covered gypsum sheets. Drywall is commonly used because it is inexpensive, not because it has any desirable structural characteristics.
Comment: Drywall does sometimes contribute desirable characteristics, it can provide fire rated protection where required (e.g. 5/8" Type-X gives 1 hr. fire rating). Also, it's a good insulator, good sound blocker, it's nice and flat and easy to paint, it is easily repairable, ect...

Type of drywall


Animating multiple views causes animations to freeze

Question: I have a simple animation that makes a view go from one side of the screen to the other and its defined in the anim folder as left_to_right.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="true">

    <translate
        android:fromXDelta="-300%" android:toXDelta="360%"
        android:fromYDelta="0%" android:toYDelta="0%"
        android:duration="3200"/>

</set>

What I want is to have multiple views sliding across the screen at the same time but different speeds, so I have 2 more xmls called left_to_right_fast.xml and left_to_right_slow.xml which are the exact same except for a different duration.
So in my view class I have these methods to create a image of a stripe and animate it, and when the animation is done, I remove it and make another:
    private fun doAStripe() {
        if (!isRunning) return

        val stripe = makeStripe()

        stripeHolder.addView(stripe)

        stripe.animation.onAnimationEnd {
            (stripe.parent as ViewGroup).removeView(stripe)

            doAStripe()
        }

        stripe.animate()
    }

    private fun makeStripe(): AppCompatImageView {
        val imageView = AppCompatImageView(context)

        imageView.layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)

        imageView.setImageResource(listOf(R.drawable.cp_stripe_blue, R.drawable.cp_stripe_gray, R.drawable.cp_stripe_red).random())

        imageView.clearAnimation()

        imageView.animation = AnimationUtils.loadAnimation(context, listOf(R.anim.left_to_right, R.anim.left_to_right_fast, R.anim.left_to_right_slow).random())

        imageView.x = width / 2f
        imageView.y = (0..(stripeHolder.height)).random().toFloat()

        return imageView
    }

So when I just call doAStripe() it works as expected, a stripe slides across the screen, and repeats.
But I want to be able to have multiple stripes going at the same time, so I try calling doAStripe() three times in a row, but when I do that - the stripes all seem to animate across the screen the first time but when the reappear they don't move, sit still for a couple seconds then disappears and new stripes appear to replace them.
So it seems like the animation is happening since the onAnimationEnd is getting called... but its not actually happening. Anyone know the reason for this?
Also my onAnimationEnd is just this convenience extension:
fun Animation.onAnimationEnd(callback: () -> Unit) {
    setAnimationListener(object : Animation.AnimationListener {
        override fun onAnimationRepeat(p0: Animation?) {
        }

        override fun onAnimationEnd(p0: Animation?) {
            callback()
        }

        override fun onAnimationStart(p0: Animation?) {
        }
    })
}

Update: Here is a git repo with a demo project showing the bug
you'll notice if you make onCreate only call doAStripe() once it works great, but call it more than once - and it works well for a couple stripes then starts freezing the animations.
Comment: A sample on Github would be great so we can test your real code...
Comment: what exactly you want to do is that

having three view with animation that go left and right

with different speed ? right ? but you want it to get repeat ? or you also want ? a pause between animation ?
Comment: @ArbazPirwani I want three views going at the same time, and each of them repeating with no pause in-between.
Comment: @Skizo-ozᴉʞS unfortunatley the real code is in a giant private repo for my work and I'm not allowed to make it public. Perhaps ill make a demo app shortly and give a link to that.
Comment: @Skizo-ozᴉʞS Just made a git repo which has an example of the bug, updated the question
Comment: Why are you calling `doAStripe()` twice?
Comment: Also you are not using isRunning, I mean you are not setting to true or false never
Comment: I'm calling it twice because I want more than 1 stripe going at a time. and yes isRunning is not used in the example app, it was used in the app I copied this code from but wasn't relevant to the question.
Answer: You do a little hack to do the two animations run at the same time, but well I followed your repository and I tested and yes, it looks laggy, the thing is, if you control the Animation inside a Handler Android will treat the threading for you, and there is one problem with your implementation, all of those animation were on the MainThread and this causes laggy.
So I ended up doing this :
private fun doAStripe() {
    val stripe = makeStripe()
    stripeHolder.addView(stripe)
    stripe.postDelayed({
        (stripe.parent as ViewGroup).removeView(stripe)
        doAStripe()
    }, stripe.animation.duration)
    stripe.animate().withLayer()
}

It looks smoothie, but not much fast, maybe you can control it with the anim files.
I also added withLayer()

it enables hardware animations for all views you subsequently add to the animation.

Also added imageView.invalidate() in your makeStripe() method, to invalidate the ImageView. For more information you can read this When it's necessary to execute invalidate on a view
This is a simple demo how it looks :
https://vimeo.com/334493212
This is not the best option, but, well, the problem it self is not correctly stated at all, so, if I have more time I'll go deeper to check it out, but from now, the problem of "freeze" is gone.


How do I match elements with any data attribute in jQuery?

Question: I want to select all elements with any data attribute in jQuery. Is this possible? I know how to use wildcards in attribute values in the selector, but I can't find a way to use wildcards in the attribute name.
I can't use .data() for this because it also matches other objects like the window. I only want to select elements with a data attribute in the HTML.
Comment: Note however that psudoclasses are not recommended due to the fact that if you combine it with any other selector, the selector can no longer be handled by `document.querySelectorAll`. I'd suggest using the same solution, but with .filter() instead.
Answer: Try this
var $result = $('*').filter(function(){
    return !$.isEmptyObject($(this).data());
});

or if you're just talking about the attribute:
var $result = $('*').filter(function(){

    var ret = false;

    $.each(this.attributes, function() {

        if(/^data-/.test(this.nodeName)){
           ret = true;
           return false; //to break the loop
        }
    });

    return ret;
});

Perhaps not the most efficent way, but hey
http://jsfiddle.net/M5bAY/
Comment: This will also catch elements that have data but no data attributes, fyi. may or may not be a problem for the OP
Comment: @KevinB I'm aware of that. I wasn't sure if that's what OP wanted. But I'll update with an attribute-only solution as well.


SQL Server PIVOT on multiple columns is losing data

Question: I've spent way too much time on this issue, and I'm not getting to the finish line. Please read this through before you run to a conclusion that this is a duplicate of all the other pivot with multiple columns on SO.
We have properties and units, with a table which keeps track of when something changed in the unit. We cannot change the structure of the table, as this is a vendor application.
Objective: Pull out the begin and end date for when a unit had an unavailable code of "model".
Issue: I need to filter out the dates where it was available in the middle, though that seems to omit one row of data each time (for unit 105).
what I've tried: PIVOT, CROSS APPLY in conjunction with LEAD/LAG
Here's a link to a SQLFiddle: http://sqlfiddle.com/#!6/29592/2/0
The rest of the question has the tsql from the SQLfiddle including the results which I got. The desired result is at the end.
Create table and insert sample data
DROP TABLE IF EXISTS testModelUnit;
CREATE TABLE testModelUnit(
    propertykey         INT             NOT NULL
    ,unitNumber         VARCHAR(10)     NOT NULL
    ,rowStartDate       DATETIME        NOT NULL
    ,rowEndDate         DATETIME        NOT NULL
    ,unavailableCode    varchar(10)     NULL
    ,CONSTRAINT pk_testModelUnit PRIMARY KEY (propertykey, unitNumber, rowStartDate )
)
GO

INSERT INTO testModelUnit VALUES

(33,'105',  '2010-11-11 00:00:00.000','2016-11-11 00:00:00.000','MODEL')
,(33,'105', '2016-11-11 00:00:00.000','2016-12-14 07:51:03.307','MODEL')
,(33,'105', '2016-12-14 07:51:03.307','2017-01-01 00:00:00.000',NULL)
,(33,'105', '2017-01-01 00:00:00.00','2017-03-21 12:21:13.703','MODEL')
,(33,'105', '2017-03-21 12:21:13.703','2017-04-21 12:21:13.703','MODEL')
,(33,'105', '2017-04-21 12:21:13.703','9999-12-31 00:00:00.000','MODEL')
,(33,'2606','2017-04-21 12:21:23.207','9999-12-31 00:00:00.000','MODEL')
,(33,'2606','2017-04-19 10:30:09.227','2017-04-21 12:21:23.207','MODEL')
,(33,'2703','2016-12-14 07:51:03.307','2017-04-19 10:29:47.970','MODEL')
,(33,'2703','2011-11-11 00:00:00.000','2016-12-14 07:51:03.307','MODEL')

GO

That gives you all the data which you need in order to test it, as unit 105 was available for a short period of time at the end of 2016.
Attempt 1 - use LEAD/LAG to determine if a date is the first in a series - then use multiple PIVOT statements
SELECT
    propertykey
    ,unitNumber
    ,firstDate
    ,lastDate
FROM (
    SELECT
        propertykey
        ,unitNumber
        ,rowStartDate
        ,rowEndDate
        ,CASE
            WHEN propertykey = LAG(propertykey,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate)
                AND unitNumber = LAG(unitNumber,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate)
                AND LAG(rowEndDate,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate) = rowStartDate THEN NULL
            ELSE 'firstDate'
        END ISFIRST
        ,CASE
            WHEN propertykey = LEAD(propertykey,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate)
                AND unitNumber = LEAD(unitNumber,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate)
                AND LEAD(rowStartDate,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate) = rowEndDate THEN NULL
            ELSE 'lastDate'
        END ISLAST
    FROM testModelUnit
    WHERE UnavailableCode = 'model'
) SRC
PIVOT (
    MAX(rowStartDate)
    FOR isfirst in ([firstDate])
) as pivotFirst
PIVOT (
    MAX(rowEndDate)
    FOR islast in ([lastDate])
) as pivotLast

Results were:
propertykey  unitNumber  firstDate                  lastDate
33           105         NULL                       9999-12-31 00:00:00.000
33           105         2010-11-11 00:00:00.000    NULL
33           105         2017-01-01 00:00:00.000    NULL
33           2606        NULL                       9999-12-31 00:00:00.000
33           2606        2017-04-19 10:30:09.227    NULL
33           2703        NULL                       2017-04-19 10:29:47.970
33           2703        2011-11-11 00:00:00.000    NULL

Issue is twofold: firstly, I have the NULLs in different rows, and secondly, I am missing an end date for unit 105 (by reversing the order of the two pivot statements, I reversed the issue, and I was then missing on start date)
Second attempt: use the LAG/LEAD as before, though this time use CROSS APPLY to get the first/last values into one column and then pivot the result
SELECT
    propertykey
    ,unitNumber
    ,firstDate
    ,lastDate
FROM(
    SELECT
        propertykey
        ,unitNumber
        ,ca.col
        ,ca.value
    FROM
    (
        SELECT
            propertykey
            ,unitNumber
            ,rowStartDate
            ,rowEndDate
            ,CASE
                WHEN propertykey = LAG(propertykey,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate)
                    AND unitNumber = LAG(unitNumber,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate)
                    AND LAG(rowEndDate,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate) = rowStartDate THEN NULL
                ELSE 'firstDate'
            END ISFIRST
            ,CASE
                WHEN propertykey = LEAD(propertykey,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate)
                    AND unitNumber = LEAD(unitNumber,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate)
                    AND LEAD(rowStartDate,1,NULL) OVER (PARTITION BY propertykey,unitNumber ORDER BY rowStartDate) = rowEndDate THEN NULL
                ELSE 'lastDate'
            END ISLAST
        FROM testModelUnit
        WHERE UnavailableCode = 'model'
    ) sub
    OUTER APPLY (
        SELECT ISFIRST, rowStartDate
        UNION ALL
        SELECT ISLAST, rowEndDate
    ) CA (col, value)
    WHERE col IS NOT NULL
)src
PIVOT
(
    max(value)
    for col in ([firstDate],[lastDate])
) AS pivoted

Result:
propertykey  unitNumber firstDate                 lastDate
33           105        2017-01-01 00:00:00.000   9999-12-31 00:00:00.000
33           2606       2017-04-19 10:30:09.227   9999-12-31 00:00:00.000
33           2703       2011-11-11 00:00:00.000   2017-04-19 10:29:47.970

Issue: I got rid of the NULL rows, though I am still missing one record of data for 105
Desired result:
propertykey      unitNumber firstDate                 lastDate
    33           105        2010-11-11 00:00:00.000   2016-12-14 07:51:03.307
    33           105        2017-01-01 00:00:00.000   9999-12-31 00:00:00.000
    33           2606       2017-04-19 10:30:09.227   9999-12-31 00:00:00.000
    33           2703       2011-11-11 00:00:00.000   2017-04-19 10:29:47.970

Answer: Are you looking query like below?
Select PropertyKey, UnitNumber, Min(RowStartDate) as FirstDate, Max(rowEndDate) as LastDate from (
    Select *, Bucket = Row_number() over(partition by propertykey, unitnumber order by rowStartDate) -
            Row_number() over(partition by propertykey, unitnumber, unavailablecode order by rowStartDate)
    from testModelUnit
) a
Where a.unavailableCode is not null
group by propertykey, unitNumber, Bucket

Output as below:
+-------------+------------+-------------------------+-------------------------+
| PropertyKey | UnitNumber |        FirstDate        |        LastDate         |
+-------------+------------+-------------------------+-------------------------+
|          33 |        105 | 2010-11-11 00:00:00.000 | 2016-12-14 07:51:03.307 |
|          33 |        105 | 2017-01-01 00:00:00.000 | 9999-12-31 00:00:00.000 |
|          33 |       2606 | 2017-04-19 10:30:09.227 | 9999-12-31 00:00:00.000 |
|          33 |       2703 | 2011-11-11 00:00:00.000 | 2017-04-19 10:29:47.970 |
+-------------+------------+-------------------------+-------------------------+

Demo
Comment: That is brilliant! Avoiding all of the lag/lead stuff. Less = More. Thanks!


Emacs launched from favorites doesn't read .bashrc

Question: If I open emacs from the command line, it loads my .bashrc and correctly sets my paths.
M-: (getenv "PATH")

Returns my actual $PATH variable.
If I open emacs from the command line, pin the icon to favorites, close emacs, then open emacs from the favorites panel, it does not load .bashrc and does not correctly set my paths.
M-: (getenv "PATH")

Produces very different results that look like system defaults.  This is emacs 27.1 and Ubuntu 18.04.
Questions:

What is happening?
How can I fix it?
What bashrc is being read if not mine?
Comment: Also noting, this caused me tremendous frustration while thinking I had my $GOPATH variable set incorrectly.  It was set correctly, and emacs found it in the shell, but emacs.d/init.el did not find it.
Comment: What do you mean by "emacs found it in the shell"? My guess is that the emacs started by the `.desktop` file you pinned to favourites is not started from bash and thus `.bashrc` is not sourced.
Comment: If I M-x shell, and echo $PATH, it is right.  But if I M-x getenv it is not right.
Comment: My guess remains the same. If you M-x shell, it starts bash, which in turn sources `.bashrc` (just tested it in Kubuntu 18.04). `getenv` doesn't start a bash, so `.bashrc` is not sourced and thus the environment variables exported in `.bashrc` aren't visible.
Comment: Thanks, @danzel.  In previous ubuntus, this is the way I would pin things to the launcher, and they would retain the start environment they had when I launched them, as far as I can tell.  Is there a new process for adding things to the launcher without breaking them now?  Did I do something wrong?
Comment: Possibly related: [Difference between launching an application from a keyboard shortcut vs the terminal?](https://askubuntu.com/questions/150361/difference-between-launching-an-application-from-a-keyboard-shortcut-vs-the-term)
Answer: I had the same problem with Ubuntu 19.04, and the solution I found is based on this answer:

Move PATH-related stuff from my ~/.bashrc to ~/.profile (which apparently is the proper place for it)
Logout and login again

Then my Emacs (launched from both from the Favorites bar and a bash console) had the proper PATH values.


What's the meaning of `-uc -us` options in `debuild -uc -us`?

Question: Everybody on the Internet tells to build packages with debuild -uc -us, this answer for example, but I totally can't find what do these options mean, even the built-in help (debuild --help) doesn't tell anything about -uc and -us.
So what do these options mean?
Answer: Commands' built in 'help' is usually insufficient for this kind of thing.
If you had read the debuild manpage you'd find those are dpkg-buildpackage flags which are passed from debuild to dpkg-buildpackage and then would have been able to use dpkg-buildpackage's manpage to find the answer.
From the Xenial man page for dpkg-buildpackage:
   -us    Do not sign the source package.

   -uc    Do not sign the .changes file.

Comment: > "those are dpkg-buildpackage flags which are passed from debuild to dpkg-buildpackage" — this was nowhere near obvious, although I tried reading man page as well. Thank you for the answer!
Comment: @SargeBorsch Read the "Examples" section of the manpage, it says it right here: "dpkg-buildpackage(1) options may be given on the command line."  And provides examples with `-uc -us`.


Why is it printing the location of a1 and not printing what a1 actually is

Question: Why is it printing the location of a1 and not printing what a1 actually is?
Comment: Please post text, not images.
Comment: Alright I will keep it in mind for next time
Comment: Your image is difficult to read.  I can't copy your text in the image into my IDE.  Sorry, no further help from me.
Answer: Because box is array. C++ doesn't know how to print arrays, so it converts the array into a pointer and prints that.
If you want to print an array, then write a loop.
Comment: Thank you, John. So just make a loop for board?
Comment: Well, I'm not sure. It looks to me like you are trying to print a `box`, so you need to make a loop for `box` not `board`. But I'm not sure what you are really trying to do, all I can say is why your code printed an address. What did you want your code to print?
Comment: `board[0][0]` is a `box*` pointer, and `box` is itself a `char[4][6]` array. So, you need 2 more loops, 1 for each dimensions of the `box`.
Answer: Your printing the starting location of board[][] by using a pointer of type *[][].
Display the values of of your character array a1[][] using two loops:
for(int i=0; i<4; i++)
{ for(int j=0; j<6; j++)
     cout<< a1[i][j];
}


My awk script not using all lines of input

Question: FYI: $NEWFILE is newfile.vcf
awk 'BEGIN {FS="[\t]+"}; NR <= 2 || $6 >= 100 {print $0 > "newfile.vcf"}'
$NEWFILE

So this is my awk code.  I have a list of data, and column 6 must be greater than or equal to 100.  I also want to ignore the first 2 lines.
The data is delimited by tabs, but is ended with a new line.  My code only does one line of the data, which happens to have column 6 be greater than 100. (It does, however, ignore the first 2 lines), then stops.  The rest of the lines do not show up in newfile.vcf  I'm guessing because of the new line.  Anyway how can I fix this?
INPUT:
                                                     NAME1    NAME2    NAME3
#CHROM   POS    ID    ALT    REF   QUAL   FILTER    953_102   953_103    953_104
Chr1    1058     .     TAA    TAAA    999   StandBias
Chr1    1071     .     TAA    TAAA    118   StandBias
Chr1    1084     .     TAA    TAAA    27.5  StandBias
Chr1    1089     .     TAA    TAAA    999   StandBias

Desired Ouput:
                                                     NAME1    NAME2    NAME3
#CHROM   POS    ID    ALT    REF   QUAL   FILTER    953_102   953_103    953_104
Chr1    1058     .     TAA    TAAA    999   StandBias
Chr1    1071     .     TAA    TAAA    118   StandBias
Chr1    1089     .     TAA    TAAA    999   StandBias

Current Ouput:
                                                     NAME1    NAME2    NAME3
#CHROM   POS    ID    ALT    REF   QUAL   FILTER    953_102   953_103    953_104
Chr1    1058     .     TAA    TAAA    999   StandBias

Program (Although the stuff until the awk is kind of irrelevant to the question.  Everything before the awk works as intended.)
#! /bin/bash
#removing the extra stuff at the top of datafile.
NEWFILE=newfile.vcf
LINESINLEGEND=`wc legend.txt | awk {'print $1'}`
LINESINLEGEND=$((LINESINLEGEND-1))
NEWLEGEND=`tail -n$LINESINLEGEND $2`

if [ $# -eq 0 ]
then
    echo "usage: filename.vcf <optional>legend.txt"
fi

if [ $# -eq 2 ]
then
    printf "$NEWLEGEND" > temp
    CUTME=`cut -f 5 temp | cut -d " " -f 4 temp | tr -s '\n' '\t'`
    rm temp
    printf "" > $NEWFILE
    printf "\t" >> $NEWFILE
    printf "\t" >> $NEWFILE
    printf "\t" >> $NEWFILE
    printf "\t" >> $NEWFILE
    printf "\t" >> $NEWFILE
    printf "\t" >> $NEWFILE
    printf "\t" >> $NEWFILE
    printf "\t" >> $NEWFILE
    printf "\t" >> $NEWFILE
    printf "$CUTME\n" >> $NEWFILE

    grep -v "^\#\#" $1 >> $NEWFILE
    awk 'NR==1 || $6 >= 100' newfile.vcf > newfile.vcf
    #suggested code makes nothing appear in newfile.vcf
fi

Comment: I wonder how that command even works! Please post some sample lines from your input and your expected output.
Comment: Added input and output
Comment: using awk 'NR==1 || $6 >= 100' newfile.vcf > newfile.vcf prints nothing now.
Answer: This command should do it:
awk 'NR==1 || $6 >= 100' input.file > newfile.vcf

NR==1 matches the first line of input. $6 >= 100 matches those lines where QUAL is greater or equal than 100. The default action in awk is to print the whole while of input to output. That's why you can omit the {print $0}.
You don't need to specify TAB as the delimiter since it is one of the default delimiters.
Comment: Your code worked, I just created a temp and used it as input.  Thank you.
Comment: Hi, thanks for your suggestion, however my program hangs after using that command.
Answer: I think this should do the trick:
 awk -F"\t" '{if ( $6 > 100 || NR<=2) print $0}' input.vcf > newfile.vcf

Of course, with awk there are more than a few ways to skin the cat. Other than the $6 token being written as 6$, your script really should have worked. If this script I just wrote does the same thing, then perhaps not all of your lines on your input file are tab delimited.
Comment: Sorry I rewrote the command by hand, it was $6 on my machine.  I tried your code, and my newfile.vcf is blank. But maybe you're right about not all the lines being tab delimited, it's hard to tell there is so much data.
Comment: On the Command line try `awk -F"\t" '$6!="" || NR<=3' yourinput.file | wc -l` That will count how many records are returned by awk that don't have a NULL $6 token or are in the first two records (suggesting the line is not tab delimited). Compare that to `wc -l yourinputfile.txt` If the two don't match, then you have a problem.
Comment: You won't need to pass `-F"\t"`. It is a delimiter by default
Comment: @anton5999 You are telling `your program hangs`. Please show your program.
Comment: Hi JNevill, The two commands are different.  The first one yields 85 while the 2nd one yields 147.  Also hek2gml I will post the program right now, just need to explain what it does.
Comment: but @hek2mgl, I meant your code causes my program to hang.  Even if I just put your code in the terminal it would hang.


C# Best Practise: Code within the form or create a class and call its methods?

Question: Is it better to create a class then call the class methods from the form using controls as parameters or put all the methods within the form?
Comment: ...depends on the code.  the form can handle much of the trivial stuff and events related to user interaction.  Managing the resulting *data* should usually be left to a class; that doesnt have to require passing controls to the class though
Answer: of course it is better to create a class : it's separation of concern (view / model).


Infinite non-periodic binary fraction

Question: I have an infinite non-periodic binary fraction. For example:
$frac_1=0.101111011100110010001001010010000001001...$
Is it always true that $1-frac_1$ = non-periodic binary fraction?
Comment: By non-periodic, I suppose you mean not "ultimately periodic". The answer is quite obviously yes. Notice that $1-frac_1$ has the same binary expansion where you switch $0$ and $1$.
Answer: Well, yes. This is actually quite obvious.
If a fraction repeats (is periodic) then it is a fraction. If it's not, then it's not a fraction (that is, it's irrational).
Clearly, a number $q$ is a fraction if and only if $1-q$ is. Hence, if the digits of some number $q$ do not repeat, neither will the digits of $1-q$.
In fact, as pointed out in the comments, it's even easier to see it when you realize $1-q$ (if it's binary) is just $q$ with the digits flipped (changing $0$s into $1$s and vice versa). So, if $q$ doesn't repeat, neither will $1-q$.

Infinite non-periodic binary fraction


How can I launch using LiveServer / npm run dev/start over my local network?

Question: Is there a way to view my project (npm run dev/liveServer) across my home internet network so that hypothetically my iPad, phone or iMac could also view the project live as its being worked on (all connected to my wireless network) without deploying?
Answer: I believe for LiveServer the setting you are looking to put in your settings.json file is the following:
"liveServer.settings.useLocalIp": true

This will make the live server hosted on your local IP address instead of the loopback/localhost address.
As for your React app, if you're using create-react-app, then you can use the HOST and PORT environment variables. You can get your machine's local IP address using ipconfig on Windows, and on UNIX, use one of the methods described in https://superuser.com/q/347408/1749748 such as ifconfig -a. If you're not using create-react-app, then use the host and port fields of the devServer field of your Webpack config as described here.


Getting error in mixins when I try to login as a user

Question: I created an order page where customer can view all the orders that he have done in past but as I want the customer to login and view the orders So I created a loginrequiredmixin
mixins.py
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator

from carts.models import Cart
from .models import Order

class LoginRequiredMixin(object):
    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        return super(LoginRequiredMixin, self).dispatch(request,*args, **kwargs)

class CartOrderMixin(object):
    def get_order(self, *args, **kwargs):
        cart = self.get_cart()
        if cart is None:
            return None
        new_order_id = self.request.session.get("order_id")
        if new_order_id is None:
            new_order = Order.objects.create(cart=cart)
            self.request.session["order_id"] = new_order.id
        else:
            new_order = Order.objects.get(id=new_order_id)
        return new_order

    def get_cart(self, *args, **kwargs):
        cart_id = self.request.session.get("cart_id")
        if cart_id == None:
            return None
        cart = Cart.objects.get(id=cart_id)
        if cart.items.count() <= 0:
            return None
        return cart

views.py
from django.shortcuts import render
from django.views.generic.edit import CreateView, FormView
from  django.views.generic.list import ListView
# Create your views here.
from .mixins import CartOrderMixin, LoginRequiredMixin
from .models import UserCheckout, Order

class OrderList(LoginRequiredMixin, ListView):
    queryset = Order.objects.all()

    def get_queryset(self):
        user_check_id = self.request.user.id
        user_checkout = UserCheckout.objects.get(id=user_check_id)
        return super(OrderList, self).get_queryset().filter(user=user_checkout)

models.py
from decimal import Decimal
from django.conf import settings
from django.db import models
from django.db.models.signals import pre_save

# Create your models here.
from carts.models import Cart

class UserCheckout(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, null=True, blank=True) #not required
    email = models.EmailField(unique=True) #--> required

    def __unicode__(self): #def __str__(self):
        return self.email

ORDER_STATUS_CHOICES = (
        ('created', 'Created'),
        ('completed', 'Completed')
    )

class Order(models.Model):
    status = models.CharField(max_length=120, choices=ORDER_STATUS_CHOICES, default ='created')
    cart = models.ForeignKey(Cart)
    user = models.ForeignKey(UserCheckout, null=True)
    #shipping_address = models.ForeignKey
    #final_total_price = models.DecimalField(default=)
    order_total = models.DecimalField(max_digits=50, decimal_places=2,)
    #orderid
    def __unicode__(self):
        return str(self.cart.id)

    def mark_completed(self):
        self.status = "completed"
        self.save()

def order_pre_save(sender, instance, *args, **kwargs):
    cart_total = instance.cart.total
    order_total = Decimal(cart_total)
    instance.order_total = order_total

pre_save.connect(order_pre_save, sender=Order)

Error
DoesNotExist at /orders/
UserCheckout matching query does not exist.
Request Method: GET
Request URL:    http://127.0.0.1:8000/orders/
Django Version: 1.8.4
Exception Type: DoesNotExist
Exception Value:
UserCheckout matching query does not exist.
Exception Location: /Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7/site-packages/django/db/models/query.py in get, line 334
Python Executable:  /Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/bin/python
Python Version: 2.7.10
Python Path:
['/Users/apulgupta/Documents/ecommerce-2-before-guest-save/Try-Django-1.8/src',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python27.zip',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7/plat-darwin',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7/plat-mac',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7/lib-tk',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7/lib-old',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/Users/apulgupta/Desktop/ecommerce-2/Try-Django-1.8/lib/python2.7/site-packages']
Server time:    Wed, 15 Mar 2017 17:42:22 +0000

As soon as I get the login page and I try to login I get the above stated error
Answer: That's because UserCheckout.objects.get(id=user_check_id) fails.
You should catch any potential fails like this:
try:
    user_checkout = UserCheckout.objects.get(id=user_check_id)
except UserCheckout.DoesNotExist as e:
    # do something if UserCheckout obj with user_check_id does not exist
else:
    # user_checkout succeeded. Procceed

or you can throw a 404 page if object does not exist
from django.shortcuts improt get_object_or_404

def get_queryset(self):
    user_check_id = self.request.user.id
    user_checkout = get_object_or_404(UserCheckout, id=user_check_id)
    return super(OrderList, self).get_queryset().filter(user=user_checkout)

Comment: You can use `UserCheckout.objects.get_or_create` if you want the user to always have an associated `UserCheckout` object
Comment: also when doing a get_or_create request I get a type error stating           int() argument must be a string or a number, not 'UserCheckout'
Comment: @ApulGupta of course it throws 404 page. You handle it this way. Have you consider using the 1st option (the `try` `except` option) if that's not what you want?
Comment: @nik_m I really don't know how but I somehow got logged in as a user on orders page
Comment: i found the problem
Comment: The problem is that when i print(user_check_id) I get 1 which means I am logged in with my first user further when I print self.request.user I got the username through which I logged in further when I print (UserCheckout.objects.all()) I go all the emails . Which brings me to the problem that I am trying to compare username with email which is throwing me error so now I need to find out way to compare either username only or email only
Comment: Edit your question then and ask **this** specifically!
Answer: I would rather say that this was more of a logical error my bad :|
In the above code I was trying to compare two quantities i.e. username id  and email address id  of user which led to that error. So I decided to make things simpler by using username and email address as a whole and then comparing it which worked for me
Edited
views.py
from django.shortcuts import render
from django.views.generic.edit import CreateView, FormView
from  django.views.generic.list import ListView
# Create your views here.
from .mixins import CartOrderMixin, LoginRequiredMixin
from .models import UserCheckout, Order

class OrderList(LoginRequiredMixin, ListView):
    queryset = Order.objects.all()

    def get_queryset(self):
        user_check_id = self.request.user.email
        template_name = 'orders/order_list.html'
        print user_check_id
        user_checkout = UserCheckout.objects.get(email=user_check_id)
        print user_checkout
        return super(OrderList, self).get_queryset().filter(user=user_checkout)


How to specify what an application is allowed to access and what not?

Question: Using Ubuntu 22.04: I have downloaded several applications such as Firefox, LibreOffice, Thunderbird, Gimp, Zoom, Teams, Visual Studio Code, FileZilla FTP, HTOP, and a few others.   Some as native using sudo apt install and some as snap install.
Is there a way of specifying what each of of these applications is allowed and not allowed to access, such as microphone, camera, home directory, internet access etc.?
For example, if I wanted to block zoom being able to access any of my ~/home/username/Documents files, but allow zoom to access my microphone & camera.  On the other hand, allow firefox to access only ~/Desktop for downloads but no other directories and no camera/microphone.
Another example, to forbid LibreOffice being able to access ~/Pictures
Would the solution differ it these were native apt installs or snaps?
Say Visual Studio Code is available both in apt install and in snap install, which would be safer to run in terms of ensuring my privacy that Microsoft doesn't collect any data in secret, as most big tech companies do.
Thank you!!
Comment: What made you so paranoid?  Your solution is very simple: disconnect from the internet and nobody can send anything to any company.  All data sent to companies currently is opt-in on Ubuntu. You need to consent to it. If Microsoft uses opt-out you opt-out. It is that simple. If you want to trace outgoing traffic: your router has an extensive log and will proof 100% any phone-home action from software.
Comment: This question seems far too broad to be answered in the AskUbuntu format, even before getting to the tinfoil-hat nonsense. If you discover proof, code or other *real* evidence that an application is stealing your data, please file a bug report with sufficient detail for a engineer on the Ubuntu Security Team to reproduce the issue in their test environment.
Comment: Thank you for the comments.  Not being paranoid, but I suspect the big companies are always on the hunt for our data and habits.
Answer: Most of these application have options, to restrict them from accessing certain  facilities of your device
For example in Firefox you could select:
Settings > Privacy & Security > Permissions

And customise your permissions,
If you can't find an option in an application you can change the permissions and ownership of a particular folder/file
For example if you want to restrict access to /home/username/Documents run the command:
Warning: Executing this command will restrict all applications from accessing the particular folder, only root can access it
sudo chown root /home/username/Documents
sudo chmod a= /home/username/Documents
sudo chmod u+rwx /home/username/Documents


How to light the pilot for an old Gas Heater

Question: We have moved in to a new home (new for us!) and we noticed that there was no heat coming from the base board. I tried to read the instructions on the Gas Heater in the basement and it talks about the need to light the pilot. I've posted pictures of the instructions and the Heater below. I looked up this video to figure out how to light it. The instructions in the video are very similar to that of the instructions posted on the Heater.
But I'm not sure where the pilot is on the system, the knob to turn it off (I can turn it off the switch at the circuit break however). Can you guys help me locate it on the image below and any instructions that can help us? Thanks.
Comment: That lower panel on the front of the boiler unit slides upwards and lifts away to expose the pilot light assembly. I recommend using one of the those long, bendable neck butane candle lighters. I had one of these units in my last place. I googled: peerless boiler lighting instructions  - This was on the results: https://www.youtube.com/watch?v=LwiTEou08FY
Answer: Call the gas company.
If they aren't also the power company and there isn't a power crisis like a wind storm, then they'll often send someone out to light it for you for free.
The gas company's perspective is they would much rather make a service call than have you attempt to light it and fail (e.g. Due to an obsolete or defective valve) and blow your house up.  That also lets them put eyes on your setup, do a safety check, and give you advice if you need it.  If they have conservation incentive programs that your unit qualifies for, they can have that conversation with you too.


Cannot get jQuery and RadioButtonList to Work

Question: I'm pulling my hair out trying to get a jQuery script working that will pick up the selected value in a RadioButtonList. I've done the usual thing when I can't get a script to run - cut and paste somebody else's into a blank page, get it working and then copy into the required page.
I have tried three different scripts, however, that take different approaches to defining the selected value but I can't get any of them to work, even though comments on some of the  webpages I got them from seem to suggest that they are working for other people.
This script throws an unrecognised expression error:
//In head with prior reference to local copy of jquery-1.4.1.js

//In body
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
    <asp:ListItem>1</asp:ListItem>
    <asp:ListItem>2</asp:ListItem>
   <asp:ListItem>3</asp:ListItem>
</asp:RadioButtonList>
 <input id="btnSubmit" type="button" value="Submit" />

In the following code, the alert box justs gives 'undefined' (Note I've tried it with both the remote reference and reference to local copy of jquery-1.4.1.js )

  <title></title>

  <form id="form1" runat="server">

    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
        <asp:ListItem Text="Yes" Value="1"></asp:ListItem>
        <asp:ListItem Text="No" Value="2"></asp:ListItem>
    </asp:RadioButtonList>

   <input type="button" id="btnTest" value="Uncheck" />
  </form>

I've also tried the following in a basic HTML page (i.e. not asp.net) and it does nothing
//In head
$("input[@name='option_layout']").change(
function()
{
    if ($("input[@name='option_layout']:checked").val())
        $(".group").toggleClass("group_vert");
    else
        $(".group").toggleClass("group_vert");
    $(this).blur();
}
);

//In body
<input type="radio" name="option_layout" value="0" checked="checked" />
<input type="radio" name="option_layout" value="1" />

I've tried modifying .change to .click as I know that there is a bug in IE with .change, even though I had tested with no success in both IE and Fiefox. I also tried wrapping the code inside a   $(document).ready(function() block but no difference. I've also tried adding an alert box into the first line of the function but it again throws an unrecognised expression error.
Anyone any idea what is going wrong here?
Answer: The @ was deprecated/removed from attribute selectors in jQuery 1.3, so your first attept should look like this:
$(document).ready(function() {
  $("#btnSubmit").click(function() {
    alert($("#RadioButtonList1 input[checked]").val());
  });
});

Or a bit more simplified using the :checked selector:
$(function() {
  $("#btnSubmit").click(function() {
    alert($("#RadioButtonList1 :checked").val());
  });
});

Also, here's what I think you're after in the third attempt, just as a starting point :)
Comment: @mharran - You should comment if you're having issues...your question didn't involve a master page, I would have pointed out how to make this work if you asked :)
Comment: Sorry, Nick, I didn't realise that a master page could be causing problems as it's working fine with the rest of my jQuery code.

Also, I've found since that the solution I've just given doesn't work when I transfer the jQuery code into an external file - I'm still learning this stuff but I suspect that <%= ... %> doesn't work from an external file.

For the moment, I'm using $("#MainContent_RadioButtonList1 ")... which is the name that the control gets in the output HTML. Any easy way around that?
Answer: Thanks, Nick, your answer got me there ... eventually :)
Your first code
alert($("#RadioButtonList1 input[checked]").val());

wouldn't work at all, giving me 'undefined' in the alert box.
Your second code
alert($("#RadioButtonList1 :checked").val());

worked in a basic asp.net page but wouldn't work in a Master/Child page which is what I am using here. I changed it to
alert($("#<%=RadioButtonList1.ClientID %>").find("input[checked]").val());

and it works fine.


c++ when to use the new keyword when creating a class object

Question: I'm learning C++ and I am trying to understand when to assign a pointer to a base class to an object created using the new keyword as opposed to creating an object normally and setting a pointer equal to the address of the object?
Effectively is there any difference in the methods implemented below.
#include<iostream>
using namespace std;

class Base
{
public:
    virtual void show() { cout<<" In Base \n"; }
};

class Derived: public Base
{
public:
    void show() { cout<<"In Derived \n"; }
};

int main(void)
{

    Base *bp = new Derived();
    bp->show();

    Derived d1;
    Base *bp = &d1;
    bp->show();

    return 0;
}

Comment: As for your title: Almost never.
Comment: Possible duplicate of [When should I use the new keyword in C++?](https://stackoverflow.com/questions/655065/when-should-i-use-the-new-keyword-in-c)
Comment: @RHertel Too bad that's an old question. It's in need a more modern answer. A quick search shows that the terms `make_unique` and `make_shared` don't show up at all. As TheDude commented, a modern answer should say "Almost Never".
Comment: related: https://stackoverflow.com/q/6500313/
Comment: `Effectively is there any difference in the methods implemented below` The only difference is that the first one uses heap while the second one uses stack. Allocating on stack is faster because it doesn't require `new` call which has some overhead (by the way, you didn't `delete` in first example, hence memory leak). On the other hand lifetime of things on stack is restricted - they only live until the containing scope (i.e. the function) exits.
Comment: @FrançoisAndrieux Good point. I retracted my close vote.
Comment: @RHertel Though the answers are unfortunately out of date, it seems to me like the questions are still duplicates. I feel the best course of action would be to close this question as a duplicate and write a better answer for the other question.
Answer: The formula is pretty simple:
1) If you use new, you are allocating memory (on the heap) for the newly created object. Your variable (pointer) points to that memory region. You should delete the created object (through its pointer) at some point yourself.
Referring to your example:
Base *bp = new Derived();
bp->show();
delete bp;
bp = NULL; // this is good practice, NULLing the pointer after deleting
           // the referenced memory

2) If you just have a (non pointer) local variable, then the memory is automatically allocated for it on the function's stack. Memory is automatically freed when the execution point leaves that function. If you just have a pointer to a local variable, you don't need to free (delete) the memory.
Derived d1;
Base *bp = &d1;
bp->show();
// no need to free

However, it's better to do just this:
Derived d1;
d1.show();

Simpler.
Comment: You forgot to say _"almost never use new directly"_ use a smart pointer instead.
Comment: @Richard Not to mention that the shown example code is prone to memory leaks if `bp->show();` throws an exception.
Answer: The only difference - in your code at least - is in how lifetime is managed,
The first object is dynamically allocated (created when the programmer chooses, at run time) and will continue to exist until a corresponding delete expression.   Since there is no delete expression, the object will never be released (although modern operating systems will typically reclaim memory as the program exits, that is not strictly required).    If you were to add a statement that does delete bp, it will have undefined behaviour, since Base does not have a virtual destructor.
The second case is a variable of automatic storage duration, so ceases to exist when the enclosing block ends.   It will cease to exist as main() returns.
In your code as shown, there will be no visible difference in output.   That does not mean the two cases work the same way.
Answer: The difference is in how your memory is being allocated. If you use your first definition, you are using memory from the heap, which is essentially boundless (within system constraints obviously), if you allocate the object the second way you are using the stack which has a finite set of memory allocated to it for a given process running it. An example where this could become an issue is when you are creating a ton of objects on your stack (E.g., for a video game) and that stack becomes full, then you will get a stack over flow error returned. This has happened to me once, and then you must leverage the power and knowledge of the heap.


PHP extensions installed through apt are not working

Question: When I try to install PHP curl extension through apt, I get a message saying I already have the newest version installed.
However, it doesn't get loaded into PHP. What are possible reasons for this?
I'm using PHP 7 with nginx on Xenial.
Answer: I just tried this:
user@mybox:~$ lxc launch ubuntu:16.04 test
mybox:~$ lxc exec test /bin/bash
root@test:~# apt install php7.0-fpm php7.0-curl
root@test:~# php7.0 -i | grep -i curl
/etc/php/7.0/cli/conf.d/20-curl.ini,
curl
cURL support => enabled
cURL Information => 7.47.0

make sure there is a symlink from /etc/php/7.0/*/conf.d/20-curl.ini to /etc/php/7.0/mods-available/curl.ini


How do I make text slide to the right upon page load?

Question: I'm not fluent in javascript and I'm trying to edit this example at w3schools to make a simple headline within a div slide to the right smoothly (from out of view) upon page load. I just KNOW it has something to do with the code that is already here, but I'm having two problems.

When I turn the box they are moving into a text headline and change the "div" selector into '.headline' (or whatever I've named it), clicking the button won't move it.
If I figure that out, I still don't know how to make it work without the button.
Answer: Right now that code is invoked with a click handler, just remove the wrapper for that and execute it on page load:
$(document).ready(function() {
    $(".header").animate({ //be sure to change the class of your element to "header"
        left:'250px',
        opacity:'0.5',
        height:'150px',
        width:'150px'
    });
});

Demo: http://jsfiddle.net/tymeJV/ZWtQw/1/
Answer: if you want to make it when body loads just try these
100% working
The html content and coding are as follows:
<!DOCTYPE html>

 in the body tag  i have added onload event which tells that when body is fully loaded then do this function which has a name of function1 or you can name something else but remember in script tag the name after var should be same as the name in onload event

Comment: You could elaborate on how / why they work the way they do, possibly a jsfiddle.


Should I sand Kliz High-Build primer before painting?

Question: I am painting medium oak-stained wood closet doors white.  I bought Kliz High-Build primer because I wanted to cover the stain color well.  I sanded the stained door and now I am done with a coat of this primer, and I think I will do a second coat of primer before applying regular satin white paint.
Should I lightly sand before the second coat to get a smoother finish?  After?  Hand-sand or use my orbital sander?
Comment: When using a high build primer I usually do not sand because I would be removing the thick coating I just paid for on really tough jobs I have put down up to 3 coats to cover without sanding.
Answer: I do not think you will have good results if you try to sand this primer, it will leave visible surface defects and clog up your paper. If you let it cure for a month or so it would be sandable with very fine sandpaper.
I know "the ship already sailed" because you already started, but this is not really the best primer for your application. The high-solids content of this stuff is basically for resurfacing problem surfaces, although it does have good stain blocking properties (see technical data sheet). You should use the very best applicators and very careful application technique to get the smoothest prime coat that you can, because your prime coat imperfections will affect the smoothness of your finish coat; it's just the nature of the primer you chose. Do not apply a second coat unless you need to, to cover imperfections of your first coat.
Although there are many ways to skin this cat, next time for cabinets or other fine woodwork consider a shellac based primer if you need stain blocking properties. It goes on thin and smooth when applied correctly and allows for a beautifully smooth mirror-like finish coat. Good luck.
Comment: Good to know.  The primer looks pretty good dry, but we shall see how the finished doors look after they are hung!


What does upside down "v" ($\wedge$) mean in this equation?

Question: I have a simple question, but it is hard to google it. I have this equation here:
$$y(t, x) = \sum_{i=1}^{d}(|x_i| \wedge t)^{2}
$$
Here $x$ is a size $d$ signal and $t$ is just a scalar. I am not sure how to read that equation in english... I understand everything except for how they use the $\wedge$ here...
If context helps, this is part of a cost function, based on a threshold $t$ that is selected, for your vector $x$.
Comment: It probably means the minimum of $|x_i|$ and $t$.
Comment: Yes, I mean $(|x_i|\wedge t)\equiv\min(|x_i|,t)$.
Comment: @user1551 Are you sure about that? If it helps, "t" is supposed to signify a threshold value, and $x(i)$ is just some sample from a d-length vector.
Comment: Of course I am *not* sure, because I don't see why one would want to take the minimum of a spatial quantity ($|x_i|$) and a temporal quantity ($t$). Yet the wedge symbol usually has three meanings: logical conjunction, some sort of "wedge product" and the minimum function. As both $|x_i|$ and $t$ are scalars, we can rule out the first two possibilities. So the minimum function is the most plausible explanation I can think of.
Comment: @user1551 I didnt mean for my comment to come off as rude, far from it. I only meant to ask for further insight. The $t$ btw is not a temporal quantity, it is just a threshold. (I edited the question). Based on what you are saying, this means "take the sum of squares of whatever is minimum between x(i) and t" correct?
Comment: Interpreting the symbol as "minimum" would seem to be consistent with interpreting $t$ as a threshhold. Although there are other possibilities. It could mean, "zero, unless $|x_i|\ge t$, in which case, $|x_i|$." But surely the equation didn't drop into your lap from the sky. Surely there is some context to help you work it out.
Comment: @GerryMyerson Yes, it would seem to mean minimum after all.
Answer: $|x_i|\wedge t$ probably means $\min(|x_i|,t)$.
There are three usual meanings of the wedge ($\wedge$) symbol: logical conjunction, some sort of "wedge product" and the minimum function. As both $|x_i|$ and $t$ are scalars, we can rule out the first two possibilities. So the minimum function is the most plausible interpretation I can think of. But certainly, you should look at the context of your equation to make sure that this is a correct interpretation.


ma.Nested probably does not work sqlalchemy and marshmallow

Question: I have one to many relationships between tables in a database and I want to get the data using an API.
I think that ma.Nested does not work because I don't get all the fields
can anyone help me?
I get only this :
[
  {
    "IsRef": false,
    "commands": [
      "299d7f0b-721c-484b-9448-072716a5fd70",
      "382c5d9f-99a1-4aa2-ac30-96084e202fad",
      "299d7f0b-721c-484b-9448-072716a5fd75",
      "382c5d9f-99a1-4aa2-ac30-96084e202fak"
    ],
    "filename": "uiyg",
    "version": 8
  }
]
this is the database model :
class File(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    filename = db.Column(db.String(255), unique=True)
    version = db.Column(db.Integer, unique=True)
    IsRef = db.Column(db.Boolean)
    commands = db.relationship('Command', backref='log', lazy='joined')

    def __init__(self, filename, version, IsRef):
        self.filename = filename
        self.version = version
        self.IsRef = IsRef

class Command(db.Model):
    id_command = db.Column(db.String(255), primary_key=True, autoincrement=False)
    name = db.Column(db.String(255))
    log_id = db.Column(db.Integer, db.ForeignKey('file.id'))
    status = db.Column(db.Boolean)
    events = db.relationship('Event', backref='com', lazy='joined')

    def __init__(self, id_command, name, log_id, status):
        self.id_command = id_command
        self.name = name
        self.log = log_id
        self.status = status

class Event(db.Model):
    id_event = db.Column(db.Integer, primary_key=True)
    event_name = db.Column(db.String(255))
    seq_number = db.Column(db.Integer)
    com_id = db.Column(db.Integer, db.ForeignKey('command.id_command'))

    def __init__(self, event_name, seq_number, com_id):
        self.event_name = event_name
        self.seq_number = seq_number
        self.com = com_id

this is the schema :

class EventSchema(ma.ModelSchema):
    class Meta:
        model = Event
        fields = ('event_name', 'seq_number')

class CommandSchema(ma.ModelSchema):
    class Meta:
        model = Command
        events = ma.Nested(EventSchema)
        fields = ('id_command', 'name', 'status', 'events')

class LogSchema(ma.ModelSchema):
    class Meta:
        model = File
        commands = ma.Nested(CommandSchema)
        fields = ('filename', 'version', 'IsRef', 'commands')

Log_schema = LogSchema(many=True)

this is the API :
@app.route("/getall/<version>", methods=["GET"])
def get_all(version):
    alle = File.query.filter_by(version=version)
    return Log_schema.jsonify(alle)

Comment: I use sql-alchemy for just simple queries. wen it become complex, i resort to raw sql. Though I always ensure that all parameters are well escaped to avoid sql injection attack
Answer: this question is solved. I've changed 'lazy ='joined'' to 'lazy='dynamic'' and I've put ma.Nested out of the Meta class


How do I affect a player that is 20 blocks away from me if I am looking in their direction?

Question: In Minecraft, I want to give a player a potion effect if I (a player with the correct score for it) am looking in that target player's direction (N, NE, E, SE, etc. using 45 degree angle increments) and they are within 20 blocks.
How do I do this with command blocks?
Comment: Please _Reform Your Question_: I can't exactly tell whether you're trying to _Inform Us About How You Did It_ or if you're _Asking How To Do It_. Perhaps insert some **line-spaces** and contain the NWSE-Directions in a **Code-Box**,
'> (stuff)'. However, I'll get to writing an answer - check in soon.
Comment: @ghostwalker13 It's pretty clear that the OP is asking how to do it.
Comment: I think you need to use partial NBT tags to detect the direction the player is facing. I'm not sure if you can make a selector to affect players inside the 45° pie slice though.
Comment: You can only check for *exact* values a player is facing, which would make it pretty much impossible to achieve your goal.
Answer: Beforehand Note: There are some misconceptions, this covers the original post's question of 'How to apply potion effects in a certain area', for why the post remains in this way. I have gone a bit into how to manipulate Scoreboards as well - if you're into this stuff, read on!
Let's say you wanted to give ol' Ghosty over here an Effect

Well, you'd get to doing that by either acquiring yourself a Suitable Command Line (Press / ) or for the ambitious, a Command Block. Got what you need? Great!
You'll want to use the /effect command to apply either a Potion(Status) Effect or a Beacon Effect to a player.
(To see a full list of Effects, see here)
For my example, I'll use the Nightvision Effect (from potions).
To target a player, group of players, or entity(ies) - you designate either the @p , @a , @r or @e Selector (Because, if you were to apply a potion effect on everything, your game would probably crash, 'fatally'!) .
All meaning 'Closest Player', 'All Players', 'Random Player' and 'All Entities' respectively.
If you wanted, you could instead input the Player's Name, so... /effect Ghosty blah blah , etc
As Night Vision uses the Effect-ID of 16, I'd input the command into the terminal / block...

/effect @p 16 …

The elipsis after the 16 represents the duration of time you require your designated player to have the effect for. So, let's say One Minute, being 60 Seconds.

/effect @p 16 60

Right, that's the basics. But what about in a certain range? Wel-hehe, easy!
Applying Effects in a Radius
By the sound of radius, you're probably thinking, "Gosh... this is hard - I'm probably going to be handling radians and that fancy trigonometry stuff...".
Short answer, nope! It's easy: you just have to use the Extended Selector Attribute (It's what I call it) .
All you have to add to your current command, is this...

/effect @p[r=~] 16 60

See that ~ is how many blocks the radius of your area is. Radius , not Diameter.
And it's good to know that: the radius also draws a slight circle around you or the designated coordinate(s), and all blocks touched by the 'invisible-line' or within the circle are marked as within the area .
So you could apply Effects to other unexpected things, keep that in mind!
What's the Final Result?
With all this knowledge and a few close-ups of my 'adorable face', we now know how to apply Effects from Beacons or Potions, in a set area. Heck, individual players even (refer to line 11) .
Our result?

/effect @p[r=5] 16 60

5 is the placeholder number, however, if you want to do it standing behind them - it's perfect. (They won't be able to get away in time before you enter the command - sure, apply a Levitation Effect if you want to, Levitation-Effect-ID: 25)
Let's take a look at a couple reference images just to be sure.

The command being entered, and eventually activated by a fellow villager.

3rd person perspective without Night Vision.

3rd person perspective with Night Vision.
It's really, not that hard.
Now, according to the Question-Asker's Specifications (This answer is for everyone and is for generality, meaning for everyone), for certain parts such 'looking in certain directions' - I can not devise a solution for, sorry.
But I can however, lead you in the direction of what to do with Scoreboards.
Scoreboards and Relations to /effect
For this, you certainly will need command blocks - as it is the only way forward without bundling up the command into a single-line jumbled-mess or minifying it.
Place a CMD-Block and type in the command:

/testfor @a[r=5,team=Neutral]

The above is assuming that you already have a viable scoreboard system in place, marking 'Neutral' (placeholder name) and 'People' (another placeholder).
If you do not  know how to use scoreboards: do a quick internet search, you'll get the hang of it, or maybe test it yourself in your Minecraft World with /scoreboard teams add(/remove) blah and so on - anyway, you can change the placeholder names to your own. Then either set the Command Block Type to Repeat (and assign the Conditional Part as Unconditional) or attach it to a really fast clock. Example, picture from an earlier post.

Note that the comparator in the super-fast-clock, if you are deciding to build it, has to be set to Subtract-Mode.
Set down a comparator next to your last CMD-Block that you used (the one that you used recently there-of) without changing it to Subtract-Mode.
This should be hooked up to a command block running the /effect command; which you most likely already know, looking at the above three sections about it. :)
So the result dictates that when a Player within the Neutral Team steps within the radius of the command block, the comparator will activate in turn triggering the second command block. Cool. So, if you were to place it underneath a structure and link it to a certain effect, you could possibly create a haunted house or a future-tech-y house and such with shining lights that set fire to your retinas... so and so.
What's the Final-Final Result?
Well, you now know how to manipulate Scoreboard Technology (or should do, if this confuses you - give it another skim over) and using it to apply Effects to players. If you were to do mobs, it'd be a whole new level; psst... @e[type=mobHere] id time , have fun!
I hope this has helped you fellow Minecraftians and or Intermediate Command/Redstone-ers.
Comment: This ignores the OP's question about which way a player is facing. I assume from the way the question is worded that the OP already knows how to use /effect and /scoreboard
Comment: also the OP wants a radius around the player, not around a command block setup
Comment: @XeroOI
The original question, before being edited, asked _broadly_ about how to apply potion effects in a certain area and which way they were facing. Therefor I went over the 'basics'; and regarding which way the player is facing, I may have an idea now. If I decide to branch out from it, I'll edit my post.
Comment: I didn't see that the original post was edited. Nevermind then
Answer: Maybe you can use an entity to teleport towards that direction for 20 blocks and executing the effect command.

Find out the players orientation.
Summon an armor stand.
teleport the armor stand 1 block towards that direction.
execute the armor stand to give effect to nearby players.
repeat step 3-4 for 20 times.(maybe you can copy the chain of command block for 20 times... to do this in 1 game tick)


Get real GPS coordinates out of known edges values on python

Question: I'm trying to find a way to convert pixels into a real coordinates. I have an image with known (GPS) edges values.

Top left = 43.51281, -70.46223

Top right = 43.51279, -70.46213

Bottom left = 43.51272, -70.46226

Bottom right = 43.51270, -70.46215

Image with known edges values

I have another script that prints the coordinates in pixels of an image. Is there any way that the value of each corner is declared, and that it prints the real coordinates of where I clicked?
For example: The next image shape is [460, 573] and when I click somewhere on it, the pixels of that click are shown, I want it to be real coordinates.
Example
Comment: Please provide enough code so others can better understand or reproduce the problem.
Answer: An option is to use OpenCV's getPerspectiveTransform() function, see this for an intuitive explanation of how the function maps real world coordinates to coordinates on another image (which in your case would be mapping the GPS values to the pixel values within the image):
https://towardsdatascience.com/how-to-track-football-players-using-yolo-sort-and-opencv-6c58f71120b8
And these for an example of the function being used:
Python Open CV perspectiveTransform()
https://www.geeksforgeeks.org/perspective-transformation-python-opencv/
Comment: an affine transformation would be good enough
Comment: I read and researched perspective transformation with opencv. I was already using that, but with the part of the gps coordinates I still don't understand it. I saw examples that use image recognition to do it but never declare every corner with a known gps value. I am newbie to python by the way.


Database access in c++

Question: When I compile this program,
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <afxdb.h>
#define _AFXDLL

int main(int argc, char *argv[])
{
    CString sDsn;
    CDatabase db;

    sDsn = "ODBC; DRIVER={MICROSOFT ACCESS DRIVER (*.mdb)}; DSN = ''; DBQ = D:\DATABASE\bible.mdb";
    db.Open(NULL, false, false, sDsn);

    try
    {
        CRecordset rs(&db);
        CString strOut;
        CString strOut2;
        CString strOut3;

        CString SqlString = "SELECT nom_prophete FROM L_PROPHETE";

        rs.Open(CRecordset::snapshot, SqlString, CRecordset::appendOnly);

        rs.GetFieldValue((short)0, strOut);
        AfxMessageBox(strOut);

        // --- petite transformation en string
        // --- pour l'affichage sur la console

        CT2CA pszConvertedAnsiString(strOut);

        std::string strStd(pszConvertedAnsiString);

        std::cout << "--" << strStd.c_str() << std::endl;

        rs.MoveNext();

        // --- petite transformation en string
        // --- pour l'affichage sur la console

        CT2CA pszConvertedAnsiString2(strOut2);

        std::string strStd2(pszConvertedAnsiString2);

        std::cout << "--" << strStd2.c_str() << std::endl;

        rs.MoveNext();

        rs.GetFieldValue((short)0, strOut3);
        AfxMessageBox(strOut3);

        // -- petite transformation en string
        // -- pour l'affichage sur la console

        CT2CA pszConvertedAnsiString3(strOut3);

        std::string strStd3(pszConvertedAnsiString3);

        std::cout << "--" << strStd3.c_str() << std::endl;

        rs.Close();
    }
    catch (CDBException *p)
    {
        AfxMessageBox(p->m_strError);
    }
    return 0;
}

it shows this error,
Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]    c:\program files (x86)\microsoft visual studio 12.0\vc\atlmfc\include\afx.h 24  1   MA_BIBLE
*/
Answer: Go to Project Settings -> Configuration Properties -> General and make sure that you set "Using MFC in a Shared DLL" for both debug and release versions.
Also if you include windows.h somewhere - remove that line since MFC projects should include only afxwin.h

Database access in c++


Swift Compiler Error RealmSwift, Xcode 8.2

Question: I'm seeing an "Argument labels '(iCloudToken:)' do not match any available overloads" in Sync.swift.
/// Initialize new credentials using an iCloud account token.
public static func iCloud(token: Token) -> SyncCredentials {
    return SyncCredentials(RLMSyncCredentials(iCloudToken: token))
}

Is there a fix for this error?
Answer: We renamed that method from iCloud to cloudKit in the latest version of the API. We realized that our authentication mechanism is a wholly CloudKit-based implementation, so referring to it as iCloud was incorrect.
public static func cloudKit(token: Token) -> SyncCredentials {
    return SyncCredentials(RLMSyncCredentials(cloudKitToken: token))
}

The documentation will be updated soon to reflect this. Sorry for the confusion!


Kinvey Swift 3 KCSCustomEndpoints

Question: I converted my project to swift 3 and am having issue with the kinvey conversion. I had this before but it now gives me this error: "Cannot convert value of type '(AnyObject!, NSError!) -> Void' to expected argument type 'KCSCustomEndpointBlock!'". How could I fix this issue?
<code>KCSCustomEndpoints.callEndpoint("endpointName", params: params, completionBlock: {
            (results: AnyObject!, error: NSError!) -> Void in
            if results != nil {
            }
        })
</code>
Comment: Check how `KCSCustomEndpointBlock` was defined, especially the types like results, maybe it's `Any` type
Answer: Mitch94,
This has been escalated to the engineering team for adding Swift 3 example of invoking custom endpoint to the Kinvey documentation.
I will get back to you once I have more information on it.
Thanks,
Pranav
Kinvey Support
Comment: Thank you Pranav. Could you please let me know when your engineering team adds the swift 3 example of invoking customer endpoints?

Kinvey Swift 3 KCSCustomEndpoints