C-like arrays in perl

Question: I want to create and manipulate large arrays of (4 byte) integers in-memory. By large, I mean on the order of hundreds of million.  Each cell in the array will act as a counter for a position on a chromosome.  All I need is for it to fit in memory, and have fast (O(1)) access to elements.  The thing I'm counting is not a sparse feature, so I can't use a sparse array.
I can't do this with a regular perl list, because perl (at least on my machine) uses 64 bytes per element, so the genomes of most of the organisms I work with are just too big.  I've tried storing the data on-disk via SQLite and hash tying, and though they work, are very slow, especially on ordinary drives. (It works reasonably ok when I run on 4-drive raid 0's).
I thought I could use PDL arrays, b/c PDL stores its arrays just as C does, using only 4 bytes per element.  However, I found that update speed to be excruciatingly slow compared to perl lists:
use PDL;
use Benchmark qw/cmpthese/;

my $N = 1_000_000;
my @perl = (0 .. $N - 1);
my $pdl = zeroes $N;

cmpthese(-1,{
    perl => sub{
        $perl[int(rand($N))]++;
    },
    pdl => sub{
        # note that I'm not even incrementing here just setting to 1
        $pdl->set(int(rand($N)), 1);
    }
});

Returns:
          Rate  pdl perl
pdl   481208/s   -- -87%
perl 3640889/s 657%   --

Does anyone know how to increase pdl set() performance, or know of a different module that can accomplish this?
Comment: have you looked at the bioinformatics perl modules?
Answer: I cannot tell what sort of performance you will get, but I recommend using the vec function, documented here, to split a string into bit fields. I have experimented and found that my Perl will tolerate a string up to 500_000_000 characters long. which corresponds to 125,000,000 32-bit values.
my $data = "\0" x 500_000_000;
vec($data, 0, 32)++;            # Increment data[0]
vec($data, 100_000_000, 32)++;  # Increment data[100_000_000]

If this isn't enough there may be something in the build of Perl that controls the limit. Alternatively if you think you can get smaller fields - say 16-bit counts - vec will accept field widths of any power of 2 up to 32.
Edit: I believe the string size limit is related to the 2GB maximum private working set on 32-bit Windows processes. If you are running Linux or have a 64-bit perl you may be luckier than me.

I have added to your benchmark program like this
my $vec = "\0" x ($N * 4);

cmpthese(-3,{
    perl => sub{
        $perl[int(rand($N))]++;
    },
    pdl => sub{
        # note that I'm not even incrementing here just setting to 1
        $pdl->set(int(rand($N)), 1);
    },
    vec => sub {
        vec($vec, int(rand($N)), 32)++;
    },
});

giving these results
          Rate  pdl  vec perl
pdl   472429/s   -- -76% -85%
vec  1993101/s 322%   -- -37%
perl 3157570/s 568%  58%   --

so using vec is two-thirds the speed of a native array. Presumably that's acceptable.
Answer: The PDL command you want is indadd. (Thanks to Chris Marshall, PDL Pumpking, for pointing that out to me elsewhere.)
PDL is designed for what I call "vectorized" operations. Compared with C operations, Perl operations are quite slow, so you want to keep the number of PDL method invocations to a minimum, and have each invocation do a lot of work. For example, this benchmark lets you specify the number of updates to perform in a single go (as a command-line parameter). The perl side has to loop, but the PDL side only performs five or so function calls:
use PDL;
use Benchmark qw/cmpthese/;

my $updates_per_round = shift || 1;

my $N = 1_000_000;
my @perl = (0 .. $N - 1);
my $pdl = zeroes $N;

cmpthese(-1,{
    perl => sub{
        $perl[int(rand($N))]++ for (1..$updates_per_round);
    },
    pdl => sub{
        my $to_update = long(random($updates_per_round) * $N);
        indadd(1,$to_update,$pdl);
    }
});

When I run this with an argument of 1, I get even worse performance than when using set, which is what I expected:
$ perl script.pl 1
          Rate   pdl  perl
pdl    21354/s    --  -98%
perl 1061925/s 4873%    --

That's a lot of ground to make up! But hold in there. If we do 100 iterations per round, we get an improvement:
$ perl script.pl 100
        Rate  pdl perl
pdl  16906/s   -- -18%
perl 20577/s  22%   --

And with 10,000 updates per round, PDL outperforms Perl by a factor of four:
$ perl script.pl 10000
      Rate perl  pdl
perl 221/s   -- -75%
pdl  881/s 298%   --

PDL continues to perform roughly 4x faster than plain Perl for even larger values.
Note that PDL's performance can degrade for more complex operations. This is because PDL will allocate and tear down large but temporary workspaces for intermediate operations. In that case, you may want to consider using Inline::Pdlpp. However, that's not a beginner's tool, so don't jump there until you've determined it's really the best thing for you.
Another alternative to all of this is to use Inline::C like so:
use PDL;
use Benchmark qw/cmpthese/;

my $updates_per_round = shift || 1;

my $N = 1_000_000;
my @perl = (0 .. $N - 1);
my $pdl = zeroes $N;
my $inline = pack "d*", @perl;
my $max_PDL_per_round = 5_000;

use Inline 'C';

cmpthese(-1,{
    perl => sub{
        $perl[int(rand($N))]++ for (1..$updates_per_round);
    },
    pdl => sub{
        my $to_update = long(random($updates_per_round) * $N);
        indadd(1,$to_update,$pdl);
    },
    inline => sub{
        do_inline($inline, $updates_per_round, $N);
    },
});

__END__

__C__

void do_inline(char * packed_data, int N_updates, int N_data) {
    double * actual_data = (double *) packed_data;
    int i;
    for (i = 0; i < N_updates; i++) {
        int index = rand() % N_data;
        actual_data[index]++;
    }
}

For me, the Inline function consistently beats both Perl and PDL. For largish values of $updates_per_round, say 1,000, I get Inline::C's version roughly 5x faster than pure Perl and between 1.2x and 2x faster than PDL. Even when $updates_per_round is just 1, where Perl beats PDL handily, the Inline code is 2.5x faster than the Perl code.
If this is all you need to accomplish, I recommend using Inline::C.
But if you need to perform many manipulations to your data, you're best sticking with PDL for its power, flexibility, and performance.  See below for how you can use vec() with PDL data.
Answer: PDL::set() and PDL::get() are intended more as a learning aid than anything else.  They constitute the pessimal way to access PDL variables.  You would be far better off using some of the built-in bulk access routines.  The PDL constructor itself accepts Perl lists:
$pdl = pdl(@list)

and is reasonably fast.   You can also load your data directly from an ASCII file using PDL::rcols, or from a binary file using one of many IO routines.  If you have the data as a packed string in machine order, you can even gain access to the PDL memory directly:
$pdl = PDL->new_from_specification(long,$elements);
$dr = $pdl->get_dataref;
$$dr = get_my_packed_string();
$pdl->upd_data;

Also note that you can "have your cake and eat it too" by using PDL objects to hold your arrays of integers, PDL computations (such as indadd) for large-scale manipulation of the data, but also use vec() directly on the PDL data as a string which you can get via the get_dataref method:
vec($$dr,int(rand($N)),32);

You'll will need to bswap4 the data if you are on a little-endian system:
$pdl->bswap4;
$dr = $pdl->get_dataref;
vec($$dr,int(rand($N)),32)++;
$pdl->upd_data;
$pdl->bswap4;

Et, voila!
Answer: PDL wins when the operations can be threaded, apparently its not optimized for random access and assignment. Perhaps someone with more PDL knowledge could help.
Comment: It is not the random access but the start-up time to initialize the PDL data structures.  Depending on the calculation involved, PDL requires from 100-1000 elements to be processed before breaking even in performance with native perl operations.  With its support for implicit looping, one line of PDL code can replace multiple, nested scalar or list loops in plain perl.
Comment: You would be the best one to know, thanks for the comment. Certainly there are better answers posted to this question now than mine. :-)
Answer: Packed::Array on CPAN might help.

Packed::Array provides a packed signed integer array class. Arrays built using Packed::Array can only hold signed integers that match your platform-native integers, but take only as much memory as is actually needed to hold those integers. So, for 32-bit systems, rather than taking about 20 bytes per array entry, they take only 4.
Comment: Yes I have looked at this module, as well as `Tie::Array::Pack`, `Tie::Array::Packed`, `Tie::VecArray` and `Tie::Array::PackedC`. Unfortunately the Perl `tie` API is very slow and the fastest (`Tie::Array::Packed`) is still ten times slower than native arrays.
Answer: since were using Integers, which should be ok for use
with chromosomes try this
use PDL;
use Benchmark qw/cmpthese/;

my $N =  1_000_000;
my @perl;
@perl = (0 .. $N - 1);
my $pdl;
$pdl = (zeroes($N));

cmpthese(-1,{
perl => sub{
    $perl[int(rand($N))]++;
},
pdl2 => sub{
    # note that I'm not even incrementing here just setting to 1
    $pdl->set(int(rand($N)), 1);
    $pdl2 = pack "w*", $pdl;
}
});

and the out put I got from this was ...
           Rate  pdl2  perl
pdl2   46993/s    --  -97%
perl 1641607/s 3393%    --

which shows a big performance difference
from when I first tried this code with out
adding in my 2 cents I got
          Rate  pdl perl
pdl   201972/s   -- -86%
perl 1472123/s 629%   --

Answer: My above answer may be worthless ...
this might help tho ..
 use PDL;
$x = sequence(45000,45000);

now that wont work unless you have 16 gb of ram and use
$PDL::BIGPDL=1;

C-like arrays in perl


Pytest not able to find shared object .so

Question: I'm using ghostscript as a dependency in my docker container. For that, I've installed both the library and C deps:
FROM python:3.9.5-slim-buster

...
RUN apt-get install -y ... ghostscript python3-tk` # and requirements.txt with ghostscript.

REPL in the container works as expected:
>>> from ctypes.util import find_library
>>> find_library("gs")
'libgs.so.9'
>>> import tkinter
>>>

and the file does exist in the container: /usr/lib/x86_64-linux-gnu/libgs.so.9
However, when running plain pytest it is not found:
os.environ["LD_LIBRARY_PATH"] += os.pathsep + "/usr/lib/x86_64-linux-gnu/"

import tkinter
from ctypes.util import find_library

assert find_library("gs") is not None

and fails.
I have no idea of what I'm missing here, can't seem to find relevant issues with pytest and shared objects. I reinstalled all libs and deleted .pytest_cache just in case with no luck. Is there at least a workaround to load the shared object directly just for pytest?
Answer: It seems like this was caused by the pyfakefs extension, which creates a fake filesystem, so an issue has been raised there
Comment: Could you please link to the issue.
Comment: https://github.com/pytest-dev/pyfakefs/discussions/796


Power Source of outside outlets

Question: I have two outside outlets that don't work.  One on the front other on the back.  Nothing is labeled for them in the breaker box, I don't know what to turn off to replace them.  How do I find the power source?  The house is 8 years old and they haven't worked for about 3 years.
Answer: One possibility to consider is that it is the outlets themselves that have failed and that there is still live mains wiring in the electrical box behind the outlet. One scheme would be to attempt to see if a non-contact electrical tester probe can detect the live wire in the box. If so you can use a process of elimination to see which circuit breaker removes the live connection from the electrical box. You may need to do this process separately for each of the outlets as they may very well be on separate circuits.
The outlets may have failed for any number of reasons. The first likely candidate is that they were connected to the wiring using the back stab holes on the outlet. These are a known failure point and in your case the temperature cycling that occurs over time may have contributed to the back stab failure. When you replace such outlets it is highly recommended to not use the back stab style of connection and instead connect the wires using the screw terminals on side.
Another failure possibility could be similar to something I personally experienced. In my case an exterior outlet quit working and there was no detectable live wire in the electrical box. Obviously the process of elimination as described above did not work to determine the circuit breaker. It was not until months later that I discovered that the outlet was wired into the load side of a GFCI type outlet located in an obscure part of my garage. That GFCI had tripped for some unknown reason and resetting it restored operation to my external outlet!!
Answer: Cheaper than usual GFCI (bargain-builder-brand) failed in 5 years rather than the usual 10-or-so. If the outlets are not themselves GFCIs, look for a non-working GFCI outlet or tripped blank-face GFCI somewhere in the house, and try resetting it. If they are (or one of them is) GFCI's expect live wires on the backside and either shut off the main or handle with appropriate care until you can find the breaker.

Power Source of outside outlets


Open Source Development

Question: I am a Fedora12(GNOME) user. I recently started development in Linux. Most of the Linux system applications/utilities are written in c/c++. The problem i am facing is that how to integrate a downloaded source code with some IDE(e.g, Anjuta etc).
In simple words i want to know that, what is the best way to start development on some existing source code using an IDE.
Lets take the example of GRUB2(v1.97.1). I downloaded the source code and now i want to study/customize/enhance/add new things to this code, so i want all the source files should be visible in a structural/hierarchical way for the ease of development?
Answer: It depends on what IDE you are using. I think the simplest one to configure is Eclipse (the newest version has a pretty decent C++ plugin), despite many of its problems. Just create a new project. You should create a C++ Makefile project, because it uses an existing Makefile, while the in standard C++ project, Eclipse will manage its own Makefile. Set the project base directory to the base directory of your program, and tell it not to create any new files.
Another option is KDevelop. I don't know much about it, but it natively supports Automake and CMake, and many other tools that are used in development under Linux. It also has a lot of bugs.
If you are a hard enough geek, and have the patience to configure it, gvim can be made a usable IDE, too. I think there are several plugins for this purpose, though I only used it for basic text editing.
Comment: @petersohn: what about Anjuta?
Answer:
so i want all the source files should be visible in a structural/hierarchical way for the ease of development?

Create a project and import all the files. Bind a keyboard shortcut to build using the makefile. Using the makefile for compilation is probably the best because there is a lot of logic that goes into the build process for nontrivial applications like grub that most likely will not map 1:1 with any IDE.
Answer: I guess you should look for autotools and a text editor. Looking for an IDE is wasting your time.

Open Source Development


If the vectors (2, 3, 4) and (10, y, z) are perpendicular, how must $y$ and $z$ be related?

Question: I'm trying to solve this question by using the dot product property for vectors that are perpendicular where if you multiply the vectors, they should equal $0$. I've tried the following:

$ 20 + 3y + 4z = 0$
$3y + 4z = -20$

I'm unsure how to find a $y$ or $z$ value that makes $(10, y, z)$ perpendicular to $(2, 3, 4)$ from here.
Comment: You're pretty much done.  *Any* $y, z$ that satisfy the relation you found will work.  Do you see why?  (And I have no idea why this question was downvoted.)
Comment: It seems youi have used dot product properly, and indeed you have found a relation between $y$ and $z$, that is a plane.
Answer: You're basically done. For any pair $(y, z)$ that satisfies the linear relation $3y + 4z = -20$, the vector $(10, y, z)$ is perpendicular to $(2, 3, 4)$. For example $(y, z) = (-4, -2)$ works and you can check that $(10, -4, -2)$ works. Here's a picture of the linear relation:

I've indicated some points with integer coordinates, but any points on the line work. And each one corresponds to a vector perpendicular to $(2, 3, 4)$.
There's a whole line's worth of solutions because in $3$-dimensional space, there's a whole $2$-d plane's worth of vectors perpendicular to a give one. Once we restrict our attention to only those vectors in the plane for which the first coordinate $x=10$, then we get the $1$-d line of solutions. In general$^\dagger$ each equation cuts the dimension of the space of solutions down by $1$. Here we have $2$ equations in a $3$-d space and $3-2=1$.

$^\dagger\!$ Lines, planes, and other subspaces can be parallel or otherwise not intersect in this generic fashion, but these are interesting edge cases. This discussion of dimension is only meant to inspire intuition about dimensions, and it is exactly what happens in all but those edge cases.
Comment: I don't understand why the textbook is saying that the answer is $y=-4/3$ and $z=-20/3$, I don't understand how these are the answers when they don't work when I plug them into this equation $3y+4z=−20$
Comment: Congratulations! You've found a mistake in your textbook! With $y=-\tfrac43$ the vector $\bigl(10, -\tfrac43, \color{red}{-4}\bigr)$ works. Or with $z=-\tfrac{20}{3}$ the vector $\bigl(10, \color{red}{\tfrac{20}{9}}, -\tfrac{20}{3}\bigr)$ works. Either of $y$ or $z$ determines the other, and it turns out that pair doesn't work.


How frequently can I expect to cook "special" meals?

Question: Rupees are kinda hard to come by in this game surprisingly, but apples aren't.  So I've been taking up all my excess apples and cooking them together to sell back (from 3RPA to 10RPA cooked). There was one time while cooking Simmered Fruit (5 apples), the music played back was slightly different and I managed to cook a "special" Simmered Fruit.
It's "special" in that it looks exactly the same as the regular Simmered Fruit dish and has no distinctive look or description (and costs the same) but it heals 8 hearts rather than the usual 5.

How often can I expect this to happen?
Comment: Aww man, I lost the save getting that screenshot when I took out the sd card. I'm gonna keep cooking to see if I can get it again. Edit: got it again after the 7th attempt straight. So at least it doesn't seem to happen at a fixed rate.
Comment: Hmmm, after another pass at cooking more meals, I got it again on the second meal after the previous attempt.  This might be testable. :)
Answer: It seems to be pretty random, from what I've been able to find. From this page:

Recipes may acquire random bonuses, such as being boosted from low to mid or have extra hearts. The jingle heard is altered when the results are randomly improved.

This site also says that it is random and that it will apply one of a few different effects to your dish.

On top of these buffs, when cooking you may also hear a special sound. When this happens you will receive an extra bonus at random. These are:

Extra yellow heart
Three extra hearts
Buff increase by a further 5 minutes
Buff increased by +1
Stamina increases

However, this article also says that there is a way to guarantee this boost.

You can actually guarantee these bonuses by using particular items or cooking during a certain time.
Cooking during a Blood Moon, when the moon is red and enemies respawn, will give you a random bonus. As will using a star fragment or dragon body part in your recipe.

Thus, it's not yet known the exact chance to have this bonus happen to you, but you're able to force it to happen by cooking under certain conditions or using certain ingredients.
Comment: I can definitely confirm the blood moon part. Otherwise, it's obviously random, I think having the rate handy would be very useful.
Comment: @JeffMercado agreed. However, from all the stuff I've seen, everyone is just chalking this occurrence up to "random chance," and no one has concrete numbers, at least not yet. If I find any more information, I'll update this answer, though!
Comment: I've noticed that the chances of getting special food seems to be increased if you use several similar but different ingredients in one dish. For example, if you can combine the iron mushroom, armoranth, and armored carp with two other ingredients, the chances of getting a special iron dish is increased (not guaranteed though). This is completely anecdotal, though, so it might not actually be true.
Comment: To add some more detail: "during a Blood Moon" starts at 11:30 PM (when the blood moon sound effects and ambient effects start) and ends at 12:00 (when the cut scene triggers). I found that in that time I can cook about 1.5 inventory pages of food (around 30 items).


why null instead of empty arrayCollection?

Question: I have two entities with a oneToMany relationship:
Post entity:
...
oneToMany:
  images:
    mappedBy: post
    targetEntity: Shop\Bundle\ManagementBundle\Entity\Image

Image entity:
...
    manyToOne:
        post:
            targetEntity: Shop\Bundle\ManagementBundle\Entity\Post
            inversedBy: images
            joinColumn:
                onDelete: cascade

when I do $entity->getImages(), I receive null. Even if in database there are many images linked to a post.
I really did all my best to figure out what might cause such issue. Your usual help is much appreciated.
PS:
Given an integer $id, I fetch a Post entity in controller using:
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ShopManagementBundle:Post')->find($id);

I successfully get all the attributes of Post entity except from images. When I do $entity= new Post, getImages gives an empty arrayCollection!!.
solution:
Get child entities returns null instead of arrayCollection object
Answer: There is nothing about join columns in configuration. Try to add this info.
manyToOne:
    post:
        targetEntity: Shop\Bundle\ManagementBundle\Entity\Post
        inversedBy: images
        ...
        joinColumns:
            post_id:
                referencedColumnName: id
        ...
        cascade: { }

Comment: Thank you for your feedback. I already have the joinColumn config. About the cascade, I already tried it to no avail. :(
Comment: Sir, thank you for your time, I posted the solution I hope it helps


What NEC code limits circuit breaker selection?

Question: I'm looking for a citation of the section of code that states more or less "You may only use breakers in a breaker panel that said panel lists as approved for use therein.".
What is the section number and actual verbiage as of the 2014 NEC?
Comment: I'm not asking for restrictions based on amperage, wire size, etc.   What rule makes it irrelevant if "a breaker fits"; Requiring instead that its suitable compatibility be explicitly listed by the manufacturer.
Comment: Is this a hypothetical or do you have a specific breaker which you would like to install in a certain panel, but that breaker is not listed for that panel?
Comment: What do you mean by "fits"?
Answer:
110.2 Approval. The conductors and equipment required or permitted by this Code shall be acceptable only if approved.
110.3(B) Installation and Use. Listed or labeled equipment shall be installed and used in accordance with any instructions included in the listing or labeling.

Sometimes it's the basic stuff that's easiest to overlook.
Comment: @ThreePhaseEel that's a tough one because the OEM presumably isn't thrilled that a competitor makes breakers for their panel.  I would rely on the principle of antecedance: your 1980s panel does not list *any* AFCI breakers, and so does that mean you can't put an AFCI in an 80s panel? No, since the breaker is obviously newer, the breaker being listed for the panel will suffice.  AKA the listings don't need to be *mutual*.
Comment: I don't think this cite answers the question re: UL classified breakers, though


Adding canvas inside another canvas: obj.setCoords is not a function( fabric js)

Question: Started using fabric.js and trying to add a canvas inside another canvas, so that the top canvas stays constant and I'll add objects to inner canvas.
Here is the snippet of adding a canvas to another canvas.
canvas  = new fabric.Canvas('artcanvas');
innerCanvas = new fabric.Canvas("innerCanvas");
canvas.add(innerCanvas);

and my html looks like this
<canvas id="artcanvas" width="500" height="500"></canvas>
<canvas id="innerCanvas" width="200" height="200" ></canvas>

Once adding these successfully, what I am going to do is , add the coordinates to the inner canvas, so that it looks like one on another to the end user.
However, ran into the below error for the tried code
    Uncaught TypeError: obj.setCoords is not a function
    at klass._onObjectAdded (fabric.js:6894)
    at klass.add (fabric.js:231)
    at main.js:60
    at fabric.js:19435
    at HTMLImageElement.fabric.util.loadImage.img.onload (fabric.js:754)
_onObjectAdded @ fabric.js:6894
add @ fabric.js:231
(anonymous) @ main.js:60
(anonymous) @ fabric.js:19435
fabric.util.loadImage.img.onload @ fabric.js:754

Looking at the error message, just went to the line of error and here is what I found in chrome console

Can someone point the mistake in my codes ?
Comment: Are you sure that fabric allows nested canvas? You can also use CSS positioning if the goal is to overlay canvas over each other.
Comment: What does `console.log(t)` says?
Comment: @PraveenKumar t is minified version. It is obj in extracted version. Updated the screenshot
Comment: DId you try my answer? should really be what you are looking for
Answer: After going through no.of discussions and internet solutions, for time being I am using Fabric Rectangle as a clipper and setting it's boundaries so user can be able to drop/play with in that particular clipper.
Dotted red(image below) is my clipper and now I can bound the dropping and below is the code to add an image with a clipper.
function addImageToCanvas(imgSrc) {
    fabric.Object.prototype.transparentCorners = false;
    fabric.Image.fromURL(imgSrc, function(myImg) {
        var img1 = myImg.set({
            left: 20,
            top: 20,
            width: 460,
            height: 460
        });
        img1.selectable = false;
        canvas.add(img1);

        var clipRectangle = new fabric.Rect({
            originX: 'left',
            originY: 'top',
            left: 150,
            top: 150,
            width: 200,
            height: 200,
            fill: 'transparent',
            /* use transparent for no fill */
            strokeDashArray: [10, 10],
            stroke: 'red',
            selectable: false
        });

        clipRectangle.set({
            clipFor: 'layer'
        });
        canvas.add(clipRectangle);

    });
}

Now while appending any image/layer to the canvas, I bind that image/layer/text to the clipper I created.
function addLayerToCanvas(laImg) {

    var height = $(laImg).height();
    var width = $(laImg).width();
    var clickedImage = new Image();
    clickedImage.onload = function(img) {

        var pug = new fabric.Image(clickedImage, {

            width: width,
            height: height,
            left: 150,
            top: 150,
            clipName: 'layer',
            clipTo: function(ctx) {
                return _.bind(clipByName, pug)(ctx)
            }
        });
        canvas.add(pug);
    };
    clickedImage.src = $(laImg).attr("src");

}

And the looks like, after restriction of bounds,
Here is the fiddle I have created with some static image url.
https://jsfiddle.net/sureshatta/yxuoav39/
So I am staying with this solution for now and I really feel like this is hacky and dirty. Looking for some other clean solutions.
Comment: wow, Suresh, this is a great example!  Thank you for your efforts
Answer: As far as I know you can't add a canvas to another canvas - you're getting that error as it tries to call setCoords() on the object you've added, but in this case it's another canvas and fabric.Canvas doesn't contain that method (see docs). I think a better approach would be to have two canvases and position them relatively using CSS - see this simple fiddle
HTML

    <canvas id="artcanvas"  width="500" height="500"></canvas>

    <canvas id="innerCanvas" width="200" height="200" ></canvas>

CSS
.parent {
  position: relative;
  background: black;
}

.artcanvas {
  position: absolute;
  left: 0;
  top: 0;
}

.innerCanvas {
  position: absolute;
  left: 150px;
  top: 150px;
}

JS
$(document).ready(function() {
    canvas  = new fabric.Canvas('artcanvas');
  innerCanvas = new fabric.Canvas("innerCanvas");
  var rect = new fabric.Rect({
    fill: 'grey',
    width: 500,
    height: 500
  });
  canvas.add(rect);
  var rect2 = new fabric.Rect({
    fill: 'green',
    width: 200,
    height: 200
  });
  innerCanvas.add(rect2);
})

To handle the object serialization, you can do something like this:
var innerObjs = innerCanvas.toObject();
console.dir(innerObjs);
var outerObjs = canvas.toObject();
innerObjs.objects.forEach(function (obj) {
    obj.left += leftOffset; // offset of inner canvas
  obj.top += topOffset;
  outerObjs.objects.push(obj);
    });
var json = JSON.stringify(outerObjs);

This will then give you the JSON for all objects on both canvases
Comment: So for the first part - on save you could serialize the second canvas to an image, add to the first canvas as an image object and then save. Not pretty maybe but it should work? As for combining the JSON I think you only need to alter the left and top properties of each object on the inner canvas?
Comment: Thanks for trying to help. No. At X point of time, if I save the state of `artcanvas`, I miss the changes of `innerCanvas` and I have to deal with two states of canvas. Want to avoid it.
Comment: OK. In that case I think you need to explain in a bit more detail why it is that you need two separate canvas objects
Comment: Let say I am designing a T-shirt (he can select model as well) with user given logos and text. So my T-shirt will be on canvas 1 and the user play area (I want to give him a chance to drop logos and text with some pre defined. Otherwise he may drop the logo anywhere he like.) on t-shirt there will be another canvas where user can drop things. So at any point, If I save a main canvas,  the inner canvas also saves and I get a final output of the t-shirt with logos/text in the end. If they are seperate, I have to again process those both may get into a mess. Hope it explains a bit.
Comment: I understand. So when you save, what are you wanting to generate? An image or a list of objects that you can do further processing on?
Comment: An image to  let him to download and also I save a json in the database (fabric have a function `canvas.toJSON()` ). If I go with the solution you given, it is almost impossible to generate a combine image together :) and I have to deal with combining the json :(
Comment: So it is impossible to combine them ? if they are different I have to deal with their coordinates which I am opposing :./
Comment: I've added a section to handle the serialization
Comment: Thankyou John, Will give a hand in this if I didn't get any other clean solutions (*already voted up and can't again ha ha* ).
Answer: I have no understanding why you want to do this thing, but to put a canvas inside another canvas, you have one simple way:
canvas  = new fabric.Canvas('artcanvas');
innerCanvas = new fabric.Canvas("innerCanvas");
imageContainer = new fabric.Image(innerCanvas.lowerCanvasEl);
canvas.add(imageContainer);

Then depending what you want to do, you may need additional tweaks, but this should work out of the box.
Answer: Don't create a canvas
Most objects in fabric (from my limited experience) are at some point converted to a canvas. Creating an additional fabric canvas to manage a group of objects is kind of pointless as you are just adding overhead and mimicking fabrics built in groups object.
Fabric objects are basically DOM canvases wrappers.
The following example shows how fabric uses a canvas to store the content of a group. The demo creates a group and adds it to the fabric canvas, then gets the groups canvas and adds it to the DOM. Clicking on the group's canvas will add a circle. Note how it grows to accommodate the new circles.

const radius = 50;
const fill = "#0F0";
var pos = 60;

const canvas = new fabric.Canvas('fCanvas');

// create a fabric group and add two circles
const group = new fabric.Group([
    new fabric.Circle({radius, top : 5, fill,  left : 20 }),
    new fabric.Circle({radius, top : 5, fill,  left : 120 })
], { left: 0, top: 0 });

// add group to the fabric canvas;
canvas.add(group);

// get the groups canvas and add it to the DOM
document.body.appendChild(group._cacheContext.canvas);

// add event listener to add circles to the group
group._cacheContext.canvas.addEventListener("click",(e)=>{
  group.addWithUpdate(
      new fabric.Circle({radius, top : pos, fill : "blue",  left : 60 })
  );
  canvas.renderAll();
  pos += 60;
});
canvas {
   border : 2px solid black;
}
div {
   margin : 10px;
}

Fabric's canvas  "canvas = new fabric.Canvas('fCanvas');"

<canvas id="fCanvas" width="256" height="140"></canvas>

Fabric group canvas below. Click on it to add a circle.

Use a group rather than a new instance of a fabric canvas.
As you can see a canvas is generated for you. Adding another fabric canvas (Note that a fabric canvas is not the same as a DOM canvas) will only add more work for fabric to do, which already has a lot of work to do.
You are best of to use a group and have that hold the content of the other fabric object you wish to shadow. That would also contain its content in a group.
Just an image
And just a side not, a DOM canvas is an image and can be used by fabric just as any other image. It is sometimes better to do the rendering directly to the canvas rather than via fabric so you can avoid rendering overheads that fabric needs to operate.
To add a DOM canvas to fabric just add it as an image. The border and text are not fabric object, and apart from the code to render them take up no memory, and no additional CPU overhead that would be incurred if you used a fabric canvas and objects.

const canvas = new fabric.Canvas('fCanvas');

// create a standard DOM canvas
const myImage = document.createElement("canvas");

// size it add borders and text
myImage.width = myImage.height = 256;
const ctx = myImage.getContext("2d");
ctx.fillRect(0,0,256,256);
ctx.fillStyle = "white";
ctx.fillRect(4,4,248,248);
ctx.fillStyle = "black";
ctx.font = "32px arial";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("The DOM canvas!",128,128);

// use the canvas to create a fabric image and add it to fabrics canvas.
canvas.add( new fabric.Image(myImage, {
  left: (400 - 256) / 2,
  top: (400 - 256) / 2,
}));
canvas {
   border : 2px solid black;
}

<canvas id="fCanvas" width="400" height="400"></canvas>
Answer: innerCanvas.setCoords(); ìs a function, but you need it only after you set the coordinates. Or more precise, set these four elements:
innerCanvas.scaleX = 1;
innerCanvas.scaleY = 1;
innerCanvas.left = 150;
innerCanvas.top = 150;
innerCanvas.setCoords();
canvas.renderAll();


System.Net.Http.HttpClient cannot connect to web API via NSwag client (Windows Universal Platform)

Question: I wrote a simple .Net Core 3.0 API using Swashbuckle Swagger and generated an api client via NSwag Studio, then I put a generated Api Client to a .Net Standard 2.0 project.
I have a Universal Windows Platform application, which is meant to be connecting to the Web Api and send/receive data etc.
I put a simple code in MainPage.xaml.cs class with System.Net.Http.HttpClient inside
public MainPage()
    {
        this.InitializeComponent();
        var httpClient = new HttpClient();
        var apiClient = new ApiClient(ProjectConstants.API_URL, httpClient);
        var deviceService = new DeviceService(apiClient);
    }

When API is called later in deviceService my program throws an exception on SendAsync method in generated Api Client

"An error occurred while sending the request."

var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
I tested API Client and HttpClient on .Net Core console app and it worked fine.
I read about Http Client for UWP https://learn.microsoft.com/en-us/windows/uwp/networking/httpclient but it seems UWP should support System.Net.Http.HttpClient too, which I would love to stick to.
Is this a Universal Windows Platform bug or do I forgot about adding something necessary to a project?
Answer: The System.Net.Http.HttpClient API can be used across platforms, but we do recommend using APIs from Windows.Web.Http.HttpClient NameSpace which is easy to use. So you could use Windows.Web.Http.HttpClient API in UWP,and use GetAsync(PostAsync) to send a request, for example:
Uri requestUri = new Uri("http://www.contoso.com");
Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
Windows.Web.Http.HttpResponseMessage httpResponse = new Windows.Web.Http.HttpResponseMessage();
httpResponse = await httpClient.GetAsync(requestUri);

For more information about the differences between Windows.Web.Http and System.Net.Http.HttpClient, you can refer to this article
Comment: Well,
"Do you intend to write cross-platform .NET code (across UWP/ASP.NET 5/iOS and Android)?
If yes – then use System.Net.Http API. This allows you to write code that you can re-use on other .NET platforms such as ASP.NET 5 and .NET Framework desktop applications. "
I should stick to `System.Net.Http.HttpClient` in my projects
Comment: @Hantick Why you add `ConfigureAwait` after `SendAsync` that already use await key word?
Comment: @NicoZhu-MSFT it is auto-generated by NSwag
Comment: @Hantick, could you try to remove `ConfigureAwait` and test again?
Comment: @NicoZhu-MSFT I removed `.ConfigureAwait(false)` everywhere, no effect :(
Comment: @Hantick, Sorry to head that, but in uwp platform we suggest `Windows.Web.Http.HttpClient`  to used, if you want to make cross platform lib, you need implement httpclient separately base on `Windows.Web.Http.HttpClient`.
Answer: Does it have the same api as the portable HttpClient?


Why Hadoop is tightly bound to linux?

Question: I am new with Hadoop. What are the specific reasons why Hadoop is so tightly bound with Linux, and the cluster it runs upon is homogeneous?
I'm looking for really specific details that can tell me why Hadoop does not work well with windows, and if there are some libraries some specific scripts that are involved?
My project is to deploy Hadoop without using Cygwin. I have already seen the article from Hayes Davis where he explained how to install Hadoop without Cygwin, but he said that there are some bugs. I might start from scratch to properly configure Hadoop on Windows, but if any one can explain what, specifically, are the reasons that Hadoop doesn't work well on windows that would be very helpful.
Answer: Are you aware of the Hadoop work on which Microsoft and Hortonworks are collaborating, essentially committing changes to the Apache project for native Windows support?
The project is still in a preview phase, with Hadoop on Azure being the first part of the rollout.  This is Hadoop running on Windows Server 2008R2 in the Windows Azure cloud. It will also be available for installation on premises for building your own clusters.
I'd recommend learning more and signing up for the program, since you'd be recreating what they've already spent man years on.
Answer: According to their Quick Start page, it hasn't been well-tested yet.

GNU/Linux is supported as a development and production platform. Hadoop has been demonstrated on GNU/Linux clusters with 2000 nodes.
Win32 is supported as a development platform. Distributed operation has not been well tested on Win32, so it is not supported as a
  production platform.

Windows has much better remote management support than most people realize, but it's still tough to beat Linux when it comes to the ease (and price tag) of setting up a large compute farm. This is just a guess, but perhaps it's less likely that researchers who need to build such massive clusters want to put much of their budget toward OS licensing.
Answer: Tne validated answer is from 2012.
Here are the latest news from the Hadoop Wiki as of 2017

Hadoop version 2.2 onwards includes native support for Windows. The official Apache Hadoop releases do not include Windows binaries (yet, as of January 2014). However building a Windows package from the sources is fairly straightforward.

Why Hadoop is tightly bound to linux?


wireless ceiling fans with low voltage

Question: I am troubleshooting some electrical issues on three different ceiling fans in my upstairs bedrooms. All three are wireless Harbor Breeze ceiling fans. They all have the same issues but at varying levels. issues include:
dimness
fan run slower than it should
flickering
I measured the house power and I get 118-120v on all three boxes. So I then measured the voltage from the light output(blue wire) on each unit. the readings are as follows:
1st light: 90v - dimness, flickering
2nd light: 103v - slight dimness, flickering
3rd light: 50v - This guy just barely works
All of the wire nuts are tight and they are wired correctly. I have the same ceiling fan in my living room and it doesnt have any issues. I measure the light output on it and it reads 110v which I would expect to be normal.
What would cause this issue with three or four different voltage readings? I cant imagine that I would have three defective ceiling fans. With the house voltage reading normal could there still be an issue else where in the circuit? The last two fans are on the same breaker, but the first one is on its own.
Here is an example of the ceiling fan wiring:
Comment: Can you measure the voltage on the black wire coming out of each fan module?
Comment: Also, were these fans installed at the same time, or at different times?
Comment: Yes, I will measure it tomorrow when it's light out.

The fans were installed at the same time as far as I can tell. We bought a "flipped" home(mistake number 1) and all of the ceiling fans and light fixtures are new.
Comment: Hello. I measured the voltage coming out the black wire. The voltage reads zero when the fan is switched off. When I turn the fan on I get a voltage reading. There is a voltage reading with the fan on but of course I cant get a good reading because the fan starts to spin.
Comment: try disconnecting the black wire from the fan, then turning it on and taking a voltage reading :)
Answer: Your problems could be with the remote control receiver unit. These have power control circuitry inside that allows for on/off control of the fan and light and possibly speed control for the fan and dimming for the light. As with any electronic circuitry connected to the power line these can be damaged by a surge or serious spike on the power line.
One common cause of spikes and surges in some areas is thunder storms with accompanying lightening. You may want to look into swapping out one of these receiver units with a new one to see if it corrects the problem.
Note that this type of unit is permanently connected to the AC mains exposing it to storm surges all the time. In some instances the fan/light fixture may be wired up through a switch to shut it off. In cases where the switch is off during a storm it could account why some units escaped damage whilst others have failed.
Comment: Thanks Michael. I think I will try swapping the receivers and see if the issue continues.

wireless ceiling fans with low voltage


Let $n=2m$, where $m$ is odd. How many elements of order $2$ does the group $D_n/Z(D_n)$ have?

Question:
Let $n=2m$, where $m$ is odd. How many elements of order $2$ does the group $D_n/Z(D_n)$ have?

I don't how to begin this proof. All I have so far is that Dn/Z(Dn) should have one element of order 2.
Comment: The first thing you have to do is work out what $Z(D_n)$ is. Can you do that? Also, $D_n/Z(D_n)$ is not a subgroup, it's a quotient group.
Comment: would it be Z? just the integers
Comment: I think you misunderstand the notation. The integers are not involved. If $G$ is a group, $Z(G)$ is notation for the *center* of the group. So you need to know what $D_n$ means, and then you need to figure out what its center is.
Comment: I know Dn is the Dihedral group and for D4 the center is {Ro,R180} but im not sure what the center for Dn is. would it just be the Dihedral group without R0?
Comment: Huh? if by $R_0$ you mean the identity element of $D_n$, then that's always in the center. Do you know what "center" means in the context of group theory?
Comment: it means that the element is abelian with every other element in that group right? and i'm using R0 as the identity. I just don't understand what elements are in this factor group
Comment: The center of $G$ is the collection of elements of $G$, each of which commutes with every element of $G$. Now you have to figure out, if $n$ is twice an odd number, which elements of $D_n$ commute with every element of $D_n$. You can think about it geometrically: are there any rotations that commute with every flip? any flips that commute with every rotation? Or, you can go to generators and relations, if you know about that stuff: $D_n$ is the set of all elements of the form $a^ib^j$ with $0\le i\le n-1$, $0\le j\le1$, $a^n=1$, $b^2=1$, $ba=a^{-1}b$ and work out when two elements commute.
Comment: Hint :Notice that n = 2m where m is odd that implies $D_n$ has a sylow 2- subgroup.
Comment: I was never taught the concept of a sylow subgroup
Answer: Hint: notice that n = 2m where m is odd that implies $D_n$ has a sylow 2- subgroup.
Now see that $D_n$ is a finite group and $Z(D_n)$ the center of $D_n$ is a subgroup of $D_n$ then what can you say about the order and index of these groups and subgroups, also use Lagrange's theorem.
Comment: Our teacher never taught us what a sylow subgroup is.  I honestly do not understand this problem or where to begin.
Answer: SO I have that the Dn/Z(Dn)={R0,R180}. I also figured out that the order of Dn=(m+1)(n+1)=(mn)+2n+m+1. But I don't know where to go from here.


Python Pandas drop rows in one df based other df

Question: I have two dfs as below. I want to drop all rows for a userid from PersonDate_List which has datetime less than the min('datetime') for the same userid in df_userid_date.
PersonDate_List (cols={'userid','datetime'})
userid  datetime    Score
AB-4243 2/1/2016    0
AB-4243 2/2/2016    0
AB-4243 2/3/2016    0
AB-4243 2/4/2016    0
AB-4243 2/5/2016    0
AB-4243 2/6/2016    76
AB-4243 2/7/2016    84
AB-4243 2/8/2016    84
AB-4243 2/9/2016    81
AB-4243 2/10/2016   79
NP-7585 2/1/2016    22
NP-7585 2/2/2016    23.5
NP-7585 2/3/2016    30.15
NP-7585 2/4/2016    30.15
NP-7585 2/5/2016    30.15
NP-7585 2/6/2016    30.15
NP-7585 2/7/2016    0
NP-7585 2/8/2016    0
NP-7585 2/9/2016    22.5
NP-7585 2/10/2016   45.67
VX-4376 2/1/2016    0
VX-4376 2/2/2016    0
VX-4376 2/3/2016    0
VX-4376 2/4/2016    0
VX-4376 2/5/2016    0
VX-4376 2/6/2016    0
VX-4376 2/7/2016    0
VX-4376 2/8/2016    0
VX-4376 2/9/2016    0
VX-4376 2/10/2016   33.13

df_userid_date (cols={'userid','datetime'})
userid  datetime
AB-4243 2/6/2016
AB-4243 2/7/2016
AB-4243 2/9/2016
AB-4243 2/10/2016
NP-7585 2/1/2016
NP-7585 2/2/2016
NP-7585 2/3/2016
NP-7585 2/7/2016
NP-7585 2/8/2016
NP-7585 2/9/2016
NP-7585 2/10/2016
VX-4376 2/10/2016

I am looking for results like below;
userid  datetime    Score
AB-4243 2/6/2016    76
AB-4243 2/7/2016    84
AB-4243 2/8/2016    84
AB-4243 2/9/2016    81
AB-4243 2/10/2016   79
NP-7585 2/1/2016    22
NP-7585 2/2/2016    23.5
NP-7585 2/3/2016    30.15
NP-7585 2/4/2016    30.15
NP-7585 2/5/2016    30.15
NP-7585 2/6/2016    30.15
NP-7585 2/7/2016    0
NP-7585 2/8/2016    0
NP-7585 2/9/2016    22.5
NP-7585 2/10/2016   45.67
VX-4376 2/10/2016   33.13

I tried adding a min date flag to df_userid_date and then merging it but I am not able to get the condition right here.
Comment: Do you mean all userids in PersonDate_List (which, should probably not have the word "list" in the name for clarity sake)? Or just a single userid? Please provide snippets of each dataset.
Comment: @pshep123 yes all userid. I have updated the question with an example and expected output.
Answer: Try this way:
import numpy as np
df1 = pd.read_csv('PersonDate.csv')
df2 = pd.read_csv('useriddate.csv')
df1['datetime'] = pd.to_datetime(df1['datetime'])
df2['datetime'] = pd.to_datetime(df2['datetime'])
df3 = df1.merge(df2.groupby('userid',as_index=False).agg({'datetime' : np.min}), on='userid')
df3[df3["datetime_x"]>=df3["datetime_y"]]

Output:
    userid  datetime_x  Score   datetime_y
5   AB-4243 2016-02-06  76.00   2016-02-06
6   AB-4243 2016-02-07  84.00   2016-02-06
7   AB-4243 2016-02-08  84.00   2016-02-06
8   AB-4243 2016-02-09  81.00   2016-02-06
9   AB-4243 2016-02-10  79.00   2016-02-06
10  NP-7585 2016-02-01  22.00   2016-02-01
11  NP-7585 2016-02-02  23.50   2016-02-01
12  NP-7585 2016-02-03  30.15   2016-02-01
13  NP-7585 2016-02-04  30.15   2016-02-01
14  NP-7585 2016-02-05  30.15   2016-02-01
15  NP-7585 2016-02-06  30.15   2016-02-01
16  NP-7585 2016-02-07  0.00    2016-02-01
17  NP-7585 2016-02-08  0.00    2016-02-01
18  NP-7585 2016-02-09  22.50   2016-02-01
19  NP-7585 2016-02-10  45.67   2016-02-01
29  VX-4376 2016-02-10  33.13   2016-02-10

Comment: Awesome, such a simple solution, I love it. I was so brain freeze today couldn't think of anything, thanks.
Answer: I'm pretty sure there will be a more comprehensive way which result in shorter code. But if no more answer coming, you could use this:
import pandas as pd
import datetime

#Read data
df1 = pd.read_csv('df1.csv')
df2 = pd.read_csv('df2.csv')

#Format Datetime column
df1['datetime'] = df1['datetime'].apply(lambda x: datetime.datetime.strptime(x, '%m/%d/%Y'))
df2['datetime'] = df2['datetime'].apply(lambda x: datetime.datetime.strptime(x, '%m/%d/%Y'))

#Get min datetime in df2 for each id
min(list(df2[df2['userid']=='AB-4243']['datetime']))
temp = pd.DataFrame(list(set(df2['userid'])))
temp.columns = ['userid']
temp['min_datetime'] = temp['userid'].apply(lambda x: min(list(df2[df2['userid']==x]['datetime'])))
temp

#Merge in
df1 = df1.merge(temp, on='userid')

#Slicing
result = df1[df1['datetime'] >= df1['min_datetime']]

Result would be:
df1[df1['datetime'] >= df1['min_datetime']]
Out[65]:
     userid   datetime  Score min_datetime
5   AB-4243 2016-02-06  76.00   2016-02-06
6   AB-4243 2016-02-07  84.00   2016-02-06
7   AB-4243 2016-02-08  84.00   2016-02-06
8   AB-4243 2016-02-09  81.00   2016-02-06
9   AB-4243 2016-02-10  79.00   2016-02-06
10  NP-7585 2016-02-01  22.00   2016-02-01
11  NP-7585 2016-02-02  23.50   2016-02-01
12  NP-7585 2016-02-03  30.15   2016-02-01
13  NP-7585 2016-02-04  30.15   2016-02-01
14  NP-7585 2016-02-05  30.15   2016-02-01
15  NP-7585 2016-02-06  30.15   2016-02-01
16  NP-7585 2016-02-07   0.00   2016-02-01
17  NP-7585 2016-02-08   0.00   2016-02-01
18  NP-7585 2016-02-09  22.50   2016-02-01
19  NP-7585 2016-02-10  45.67   2016-02-01
29  VX-4376 2016-02-10  33.13   2016-02-10

Comment: I am sorry for the confusion but I have updated the question with some example and expected output.


Malloc using more memory than specified?

Question: I'm allocating memory for a string using malloc: s=(char*) malloc(sizeof(char)*4)
Why can I store more than 4 characters to the string? If I allocated 4 bytes of memory and each character requires 1 byte, why can I store 8 characters before the program crashes?
Comment: @EricPostpischil: "Anything can happen" in my comment does not mean anything can happen.
Comment: From a language perspective: most things you can do wrong in C trigger undefined behaviour instead of a specific behaviour like crashing. Undefined behaviour means that anything can happen, including appearing to work for some values or for some amount of time.
Comment: 1) Undefined behavior is... well, undefined. 2) malloc may allocate more than requested for alignment, housekeeping, or other reasons.
Comment: @Ry-: "Undefined" in the C standard does not mean anything can happen.
Comment: @Ry-: People learning a new subject are not helped by false statements. You may know what you mean, but a student has to learn many other things before they can figure out that your statement is literally false and you meant something else. Tell the truth. Do not write statements you know to be false.
Comment: @EricPostpischil: From the spec: "**undefined behavior**: behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements"  -- anything can happen.
Comment: @ChrisDodd: No, that does not mean anything can happen. It merely says the C standard does not say what happens. It does not, and cannot, revoke the specifications of the C implementation, the operating system, the hardware components. Nor can it revoke consumer protection laws, physical limits, or other constraints outside the C standard. Many C implementations provide extensions to the C standard (which the standard allows as conforming) that define behaviors the C standard does not. If "undefined" meant "anything can happen," those extensions could not be defined.
Comment: It it precisely "undefined" meaning "anything can happen" that *allows* those other things to be defined.  If it did not, they could not (or at least it would be much harder to define vendor-specific extensions to the language)
Comment: @EricPostpischil: People learning a new subject don't choose the least charitable face value interpretation of idioms, ignoring context like "from a language perspective".
Comment: @Ry-: Write true statements. Do not write false statements.
Comment: @ChrisDodd: "it precisely "undefined" meaning "anything can happen" that allows those other things to be defined.': No, an assertion that anything can happen is inconsistent with the fact that other specifications still control what can happen. It is **false** that anything can happen because there are other specifications and constraints on what can happen. If the C standard asserted that anything can happen, it would be overriding those other specifications. It cannot do that and it does not do that. "Undefined" is a surrender of control, not an overriding of control.
Comment: You seem to be claiming that "anything can happen" precludes certain things from happening, if those things happen to be thought of by anyone else.  That's a strange definition of "anything" in my book, but at this point we're arguing about the meaning of english words, not about anything in any standard.
Answer: you can do it i(in some cases) but this results in 'Undefined Behavior'. UB can produce many results, including seeming to work most of the time until your biggest customer tries to run your app on their busiest day.
You must not do this. There are various tools that you can use to detect it (electric fence, valgrind, for example)


Spring Data reactive repositories page count and total count

Question: In spring Data, I can easily perform queries such as:
Page<MyClass> findByX(String x, Pageable pageable);

In reactive Spring data (MongoDB), I couldn't find a valid way to paginate the result.
Mono<Page<MyClass>> findByX(String x, Pageable pageable);

seems like a good candidate but fails with an error that requires usage of Flux.buffer(size, skip)
If there is no valid way to do it, Is there a way to get the query total count without actually performing the query once without Page?
Comment: You have to change `Mono>` to `Flux` then in your repository you will be able to add the result to the content pageable and get the total items in the db.
Comment: it wasn't the question. Of course, I can use Flux (and this is what using because couldn't find a way to get the Page data). the question was how to get Page data as part of the response.
Answer: Reactive Spring Data MongoDB repositories do not provide paging in the sense of paging how it's designed for imperative repositories. Imperative paging requires additional details while fetching a page. In particular:

The number of returned records for a paging query
Optionally, total count of records the query yields if the number of
returned records is zero or matches the page size to calculate the
overall number of pages

Both aspects do not fit to the notion of efficient, non-blocking resource usage. Waiting until all records are received (to determine the first chunk of paging details) would remove a huge part of the benefits you get by reactive data access. Additionally, executing a count query is rather expensive, and increases the lag until you're able to process data.
You can still fetch chunks of data yourself by passing a Pageable (PageRequest) to repository query methods:
Flux<MyClass> findByX(String x, Pageable pageable);

Spring Data will apply pagination to the query by translating Pageable to LIMIT and OFFSET.
Spring Documentation says:

You can try the below code, I believe it should work for you to get the count
Mono<Long> countByXxxx(String x);

Comment: thanks for your answer. I do understand (and missed that part in the docs) that spring doesn't support it but I'm not entirely convinced regarding your answer. the fact that the request supports Pagination means that anyhow, You wait for the data (the chunks) to return and for the (specified page size) records. the "price" of the count query doesn't really matter - a simple zip operation is suffice. There is 1 major functionality that is working and implemented with MVC and not with webflux. not sure that there is a good reason behind it beside the fact that "it's just not support"
Comment: Going by your question .."If there is no valid way to do it, Is there a way to get the query total count without actually performing the query once without Page"... I believe my answer above suffices the query.
Comment: Now coming to point on how pagination work for MongoDb repository when used in a reactive way we have to understand that using a findByXXX method, Spring Data Mongo Reactive provides a variant to accept a pageable argument, but the findAll(reactive version) does not include such a variant, you have to do skip in the later operations if you really need the pagination feature. You can find further information on how different patterns are used during  pagination in this [link - Paging with the Bucket Pattern](https://www.mongodb.com/blog/post/paging-with-the-bucket-pattern--part-1)
Answer: This is how I did it:
public Mono<Page<Role>> findByTenantId(TenantId id, Pageable page) {
    return roleRepository.countByTenantId(id)
            .zipWith(roleRepository.findByTenantId(id, page).collectList())
            .map(countAndItems -> new PageImpl<Role>(countAndItems.getT2(),
                    page, countAndItems.getT1()));
}

It is true that in this way both streaming of result items only starts after the complete page has been loaded and we need to count toal results first.


Regarding the "You didn't need it anyway" achievement

Question: In the game Antimatter Dimensions, there is an achievement called "You didn't need it anyway", which is achievable when you: Infinity without having any 8th Antimatter Dimensions.
According to the guide on Fandom, it seems to be easily achievable even if you're at early Infinity section of the game. So, the guide says...

Reach Infinite antimatter without having any 8th Dimensions. To do this, get 6 IP worth of upgrades, buy as many Galaxies and Dimension Boosts as allowed within the boundaries of Infinity, then instead of Maxing all, Buy Max Tickspeed and buy 10 of all Dimensions except for the 8th. That way you can get a small boost to Dimensions 1-7.

Now, the problem is, the guide suggests you to buy as many Galaxies and Dimension Boosts. Even my limited knowledge about this game knows this is wrong, since Galaxies cannot be bought if you don't buy Dimension Boosts 5 times, which requires you to be own some of 8th Dimensions (and Galaxy itself requires you to be own some of 8th Dimensions).
This conflicts to the achievement's description, since it says without having any 8th Antimatter Dimensions. So, is the guide just wrong, or am I understanding the game wrongly? If so, how am I taking that wrong?
Answer: The guide is mostly correct, but it is missing some context, possibly to avoid spoilers. If you scroll down in the guide, you can see what allows this to work:

 Automated Dimension Boosts (C10): Very slow Challenge with no special
 tactics. You'll probably need 3 Galaxies because you only have 6
 dimensions meaning no Sacrifice and slower polynomial production.
 Doing this Challenge fulfills the You didn't need it anyway
 achievement as you cannot buy Eighth Dimensions anyway. You must get
 the "All Galaxies are twice as strong" upgrade for this challenge to
 be possible.

Without this context, the advice in the header appears contradictory and should probably be removed or tweaked. I can't access the page's history because it was moved, but I suspect that this was added later, possibly by someone who didn't fully understand the constraints.
Comment: You can access the page history. It's [here](https://antimatter-dimensions.fandom.com/wiki/Help:Guide?action=history) (for now, anyway)
Comment: I've actually unknowingly unlocked the achievement during the run, and I've completed the C10, so I guess that was the reason. Plus, I've noticed that other page - [Achievement](https://antimatter-dimensions.fandom.com/wiki/Achievements) - states that : *You can buy 8th ADs in the same Infinity, as long as you have 0 when you crunch.* Getting Galaxy resets ADs, so it seems to be completable during normal run.


How do I compile/run C++ code in the console?

Question: I'm trying to run my C++ code using the console. I used the header file conio.h like I did when I used Turbo C++ IDE in Windows, and I ran the code in console using
g++ filename.cpp

I have installed build-essentials  previously, but still I get the message:

conio.h file : No such file or directory

I have poked around a bit and learned that the header files for Windows and Linux differs, but am still to find a way to get all the header files required for basic and intermediate coding practice.
Help on this is appreciated. Please keep in mind that I'm very new to Ubuntu.
Answer: conio.h is a library that is windows specific. To my knowledge it comes with mingw32, a compiler that is a windows port of gcc. Try to set up your code so that it doesn't use it.
Also, note that linux uses (99% of the time) the gnu standard library (gnulibc). You can find its content here

For input/output you'd need the iostream (not iostream.h) header file. You can look at a more elaborate and complete list here.
Comment: So could you please make clear what are the basic header files that are required to run a cpp program (basic I/O and so forth) ? And is ncurses package really required as I read elsewhere?
Comment: updated the answer.
Comment: Afaik conio.h is not included in minGW, It is difficult to implement conio.h functions using iostream, so you should use ncurses or similar libraries for this purpose
Comment: thank you @green7 , the link is quite comprehensive and was one of the things I was looking for.
Could you please tell me which package I need to install for the standard library header files to be available? Or is it already in the build-essentials package that I have installed?
Comment: You don't need to install anything. Just write the program and compile it using `g++`
Answer: conio.h is turbo c++ specific header file, it is not a standard c++ header file
usage #include<headerfile.h> is no longer supported in c++, It is replaced by #include<headerfile>
Eg: use #include<iostream> instead of #include<iostream.h>
You can run turbo c++ in linux using dosbox, But it is highly discouraged, Always use standard syntax while learning a programming language
Comment: #include instead of #include? please review your comment.
Thanks.
Answer: The <iostream.h> header is old and deprecated.  Instead you should use <iostream> which is the new header. If you still get an error about your header file then check your include directories. Go to "Option" > "Directories..." and check your "Include Directories" for example: /home/user/cpp/custom-includes/


How do I delete an amount of characters from a file that I determine? (Python)

Question: I am taking input from a txt file and want to take 4 characters and then delete them in the file, then take the next 4 characters and read those.
So far I have this:
test_file = open("Test.txt", "r+")

text_in_file = test_file.read()
index = 4
intake_piece = text_in_file[:index]
print(intake_piece)

All I have found so far is how to delete exact lines that matches strings but I would like to delete characters to a point using the index number I choose.
edit:
I am essentially looking to read in the file, take the first 4 characters (it's a txt file that just has specific characters in a random order), do a function with those and move onto the next 4, until the end of the file.
I've managed to jury rig a way to achieve a similar result to what I want here:
index_start = 0
index_finish = 4
count =1

test_file = open("dna.txt", "r")

read_file = test_file.read()
file_size = read_file.__len__()
print((file_size))
i = 1
index = 0
while(index < file_size):

    print('the count is', count)
    count += 1

    index += 4
    print('index: ',index)
    intake = read_file[index_start:index_finish]
    print(intake)

    index_start += 4
    index_finish +=4

    text_file_output = open("Output%i.txt"%i,'w')
    i += 1
    text_file_output.write(intake)
    text_file_output.close()
    path = os.path.abspath("Output%i")
    directory = os.path.dirname(path)
    print(path)

test_file.close()

Comment: Is it always the _first 4_?
Comment: Do you really want to delete them from the file or just ignore them?
Comment: are you doing it recursively throughout the file or are you only concerned about the first 8 characters?
Comment: If your question is what's under the edit, `text_in_file.read(4)` will do. If the function returns `''`, it has reached the end. Though, I see no reason why not to read the whole file in one go and then use a loop to slice the string.
Comment: I'm not sure if it would be as good but I am looking to output the 4 characters into a cell in excel. Would using a string splitter make this easier or harder?
Comment: Okay, so, what is your complete question? Is it "I have a text file. I want to read 4 characters at a time and put them in excel cells"? How big is your file? What is the format of the file? Does it have any newlines, tabs, spaces you want to ignore? Show us an example.
Comment: I want to take a txt file that is 9kb in size and format it so that in excel there are 4 characters in each cell. The data itself just consists of TCAG characters without spaces. My latest edit on the post shows somewhat what I am looking to achieve.
Comment: Okay, that's clearer. However, you've already demonstrated a way to take 4 characters at a time, so what are you trying to get answered here?
Answer: If you are trying to remove the first 4 letters from the file, you can use regular expressions:
import re
characters = re.findall("[\w\W]", open('file.txt').read())
final_data = ''.join(characters[4:])

Comment: @JRE you do realise that to remove 4 characters from the start of a file you normally need to read/write the remainder of the file to another (which if it's large can be an expensive operation)? Can't you just leave the file there and read it in chunks, and if you need to pick bits from it use `file.seek` to jump bits already processed?
Comment: What've regular expressions got to do with this?
Comment: @JonClements my understand of the problem is that the OP wants to delete the first `n` characters, not lines. With `re.findall` the OP can get an entire listing of all the characters in the file, and then use the list slicing technique to remove the first `n`, or build on the slicing.
Comment: Okay... so I guess it depends whether we're talking characters or bytes then I guess... I was thinking `open('file.txt').read()[4:]`
Comment: You are right in that I would like to delete n characters after utilising them. The reason being that the file I will be using is too large to import and then do what I need to with the data.
Comment: @JonClements This is my first foray into this kind of programming so I'm unsure on specifics of read/write functionality. Ideally what I am looking to achieve is an output of three tables that use a number of characters I define. With the deletion of the start of the file I imagine it would help to run more smoothly, although I am happy to be wrong of course.


Test for arsenic / toxic enamel color (Scheele's Green / Schweinfurt Green)

Question: I've come across a beautiful art nouveau stove by Deville & Cie of Charleville, France, prob. enameled iron in a beautiful green, around 1900-1930 (lay guesstimate)
Is there a way to test for toxic arsenic colors like Scheele's green / Schweinfurt green / emerald green / Vienna green that doesn't require a chemistry kit? (Maybe an affordable finished test kit?)
Does anyone have knowledge either concerning old stoves (different paints for heat resistance?), concerning the manufacturer (known or allowed to use) or enamel coloring in that regard?
Is it generally (not) recommendable to put an object of that period in a sleeping / living area because of various toxic substances used during that period? Especially in a cat household, which might sleep on it and then lick himself clean.
PS: As a new member (on this exchange), I couldn't create the tags "enamel" or "toxic", maybe someone wants to do that.
Comment: How many times do you think it has got hot since 1930? or 1900? Off-gassing decreases over time and heat / cool cycles.
Comment: will it still off-gas toxic fumes? or will you be licking it?
Comment: There seems to be a concern with using wallpaper that has it, but an enamel stove that is not used for heating/cooking, the toxic stuff should be sealed in(if the paint is in good condition, not flaking off).   A clear coat should increase the safety.
Comment: As for the licking, that would mostly affect my cat which might sleep on it and then clean himself. As for the fumes, I don't know. The vendor is 90km from me, if there are enough reasons against it up front, I won't drive that far
Answer: If it is indeed enameled (in the manner suitable for stoves, rather than "paint called enamel paint") it is part of a thin layer of glass, melted on the surface of the iron, making it essentially inert.
Comment: But enamel means the transparent glass is mixed with coloring pigments, not poured over the colored layer, so, if the pigment was toxic and it is everywhere within the glass, there would some percentage actually be on the surface of the glass


Is there a reliable way to double assassinate?

Question: I'm playing Assassin's Creed: Brotherhood but I assume this applies to AC2 as well.
I'm trying to do an especially difficult Borgia captain assassination and it's proving frustrating because double assassinations seem to be very hit-and-miss. Sometimes I only assassinate one instead of both. Is there any surefire way to do it?
Comment: I'm not sure if it's anything like the second one... but see if there aren't any groups nearby that you can use for cover till you can get close (prostitutes, thieves, etc).  Just got the game last week for $27 so I'll be getting there soon I'm sure.

Cheers and good luck!
Answer: I don't think there is a surefire way of doing this, however you can improve your chances with the following things.

Position yourself in the middle of the guards, and make sure you are not locked onto any of them, and not looking at either of them either. [ this make that particular guard a target ]
Have the double blades equipped
Hold R1 [ assuming ps3 ], to perform the aggressive take down.
Throw down a smoke bomb to make it exceptionally easy.
Points 1-4 apply to air double assassinations as well, however I would suggest trying it from a ledge where you are close enough to the guards [ close enough that you can actually lock on to one of them ], so that you don't go into leap of faith.


FindAll documents that has an array of sub-documents

Question: Following is an example model:
UserModel == {
    name: String,
    friends: [ObjectId],
}

friends corresponds to a list of id of objects of some other model for example AboutModel.
AboutModel == {
    name: String,
}

Is it possible to find all Users who have a friend with _id="1234" in friends array?
Answer: user.find({friends: {$in: ['1234']}})


Rails to install sliding doors

Question: I'm including a picture of the sliding doors I need to install. I'm also including pics of the previous installation.
So my question: what's the name of the rails (if that's the correct word) for installing these doors?
Is there an easier way to install these?
Answer: Those doors appear to be a 4 fold "Bifold" door set and are not called sliding doors. Sliding doors are more typically "Bypass" doors or a "Barn" type door.
It does look like you are in need of a hardware replacement but armed with your pictures, measurements, and the proper name most hardware stores should be able to sell you a suitable replacement.
EDIT-As for an easier installation- If you can, I suggest making 2 pair of 2 doors that open from the middle towards both sides. Bifold door hardware is pretty "lightweight" and often will want to pop out of the track- especially when you are folding all 4 doors to one side- It is just pretty unwieldy.
Just a note, It seems that 3 of the 4 doors are installed upside down. The louvers should orient high on the inside of the closet and angle forward and down. The third door from the left is properly oriented and the other 3 are upside down.
Comment: If you compare the top rails it looks like 2 are upside-down and one is inside-out - lol. Not a lot of attention to detail went into that installation.
Answer: This amazon link has several types of replacement hardware.  the rails or track as more commonly called are made for 3 different types of pin hardware.

You have a single wheel track like what is shown in the picture.
There is a thinner pin style track where a nylon pin is sticking up in the track.
Last is the hanging multi wheel track.
I have seen a few with bottom tracks as well but that is rare as people don't like a bottom groove or to step on the track.

A great deal of the new hardware now is spring loaded so you just push the pins down and then it will slide in to place. If that is not possible and your doors are not hinged in place yet you can tilt them sideways when they are closed to get the hardware under the track.

I personally prefer the bi-fold doors over sliding doors when you don't have the ability to use pocket doors. since the sliding doors don't have a hinge attached to a wall they tend to derail more frequently in my experience and can be a real pain to put back on the track. also depending on the opening size you may not have the room to put sliding door hardware in place.

Rails to install sliding doors


Simple Intersection Algorithm for Ray and 3D Bézier Curves of Varying Thickness

Question: I'm trying to get an algorithm for intersecting a "tube" (a 3D cubic Bézier curve extruded by a possibly-changing radius) with the following required properties:

Computes intersections of ray and a 3D cubic Bézier curve.  Must not become confused, as some numerical algorithms do, by secondary rays, which start from the surface of the curve (i.e. at a zero).
Must support a varying radius along the curve (a linear function is fine).  The radius may be zero in at-most one point.
Hit point accuracy should be a function of floating-point precision or solver iterations.  I.e., the geometry must be correct, fully volumetric.
Some reasonable way of handling endpoints.  I'd prefer spherical caps, but flat ones would be okay too.  A choice would be nice.

I don't need the fastest-possible algorithm.  The easiest reasonable algorithm is what I'm looking for.
Can someone help me find an ray + 3D-cubic-Bézier intersection algorithm satisfying the above?  A paper link, a description, help pinning down references, etc.

I've had great difficulty with a literature search on this.  Here are some of the (few) papers I found:

"Ray Tracing for Curves Primitive".  I implemented this, but the hit depth seems to be incorrect.  I suspect this is because it assumes (erroneously) that the cross section of the curve will be circular, even if at an angle.
"Exploiting Budan-Fourier and Vincent's Theorems for Ray Tracing 3D Bézier Curves".  Seems over-complex, and doesn't seem to support varying radius.  Looks like it has the same bad assumption, and code isn't available.
"High-Quality Curve Rendering using Line Sampled Visibility".  Quadratic curves only, rasterizer-based, unclear if meets other criteria.
Answer: You say that you don't need the fastest possible algorithm, so instead of solving it analytically, you might try considering the numeric alternatives, which in this case could mean ray marching.
How you could do this is take steps down the ray and test if the point is inside or outside of this bezier tube.
You would iterate down the ray until you either find an intersection or leave the bounding box of this shape (or maybe when you take a maximum number of steps, or some other fail case).
The challenge then only becomes "how can I tell if a point is inside or outside of the shape?" which is a lot simpler.  If you had constant thickness you would just find the closest point on the bezier to your point and do a distance comparison.
Some details you might be interested in:

taking smaller steps, and more of them, will give you more accurate results, but will be more expensive computationally. That makes this algorithm tuneable for quality vs speed.
if the step size is too large or the tube is too thin, you may completely miss the tube when there is really a hit.
when/if you do find a hit, you are finding the first point inside the shape. The real answer is somewhere between the last sample and the current sample.  You could refine the hit location with a binary search or some other method if you wanted to.
you can likely increase the step size as you move farther from the camera. Smaller details are harder to see at greater distances.
you might be able to calculate or approximate the gradient of your point vs bezier tube function as you ray march. If so, this gradient can be used to give you a lower bound on the distance from your point to the bezier tube, which would let you take larger steps through empty space.

Regarding the "secondary ray" issue you mention like for shadow rays or reflection rays that comes up with both analytical and numerical solutions.  Getting a (probably) less precise answer than a numerical solution does make the problem worse, but there should be ways to get around it.
For instance, after you detect a hit, you could find a point on the surface near the hit even if it isn't where the hit was (like, push the hit point to the surface, in whatever direction is easiest to compute), add an epsilon (needed for analytical solutions anyways) and spawn secondary rays from there.
Another way could be to have every object have an ID and when ray marching / tracing, don't count intersections with the same ID as what you just hit.  This only really works for opaque convex objects though.
Comment: I dont think a analytic solution is even possible.


Displaying non-roman characters in a string

Question: In my app I receive from a remote host a string that is like this:
 "01 - \U00ab\U00d3\U00ba\U00d2\U00c2\U00b4\U00d5\U00b7\U00d5\U00e8\U00a4\U00d2\U00b9\U00b7\U00cd\U00a7 - \U00c8\U00d4\U00c3\U00d4\U00be\U00c3 \U00cd\U00d3\U00e4"
I know that this is a string in Thai language.  When I display it using UILabel of NSLog, it shows up as:
01 - «ÓºÒ´շÕè¤Ò¹·Í§ - ÈÔÃԾà ÍÓä
Is there a way to make the string show up correctly using Thai font?
Thanks,
Comment: How do you convert this string as an NSString?
Comment: I just do:
NSString *str = receivedString;
Answer: Shouldn't you be using something like
<code>+ (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc
</code>
if you know what the specific encoding is and it is not UTF8, or
<code>+ (id)stringWithUTF8String:(const char *)bytes
</code>
if that's what it is. Then the string should display. I expect the remote host says something about the encoding of the string in the response?
Comment: I have tried the following, but it still shows the strange-looking string that I have shown in my question above:
`code`

                const char *cstr = [receivedString UTF8String];
         myString = [NSString stringWithUTF8String:cstr];


Android Studio 3.0 Canary 1 - Simulator stuck on boot

Question: I tried running my App on Android O on the new Canary Build of Android Studio, but when I launch the Simulator it get's stuck at boot. It's been 20 mins now that is stuck.
This happens with both a Pixel XL and Nexus 5X preset.
It is working fine if I use API 25 (Nougat)

Has any of you experienced this problem and fixed it?
Comment: Have you tried to launch the same emulator image in a Windows PC? I think it's too early to say for sure it's a bug in the new emulator or a problem with your configuration
Comment: Not yet but I'm going to in a while
Answer: I finally figured out that I did not update all the components in the SDK Manager. After updating all of them the emulator ran fine


Streaming Wine Audio to Twitch

Question: I'm trying to steam some Dota 2 (via Wine) casts to Twitch using this shell script I found online:
#!/bin/bash

STREAM_KEY="(redacted)"
FPS="30"
INRES="1600x900"
OUTRES="1280x720"
QUAL="medium"

avconv \
  -f x11grab -s $INRES -r "$FPS" -i :0.0 \
  -f alsa -ac 2 -i pulse \
  -vcodec libx264 -s $OUTRES -preset $QUAL \
  -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b 712000 -bufsize 512k \
  -f flv "rtmp://live.justin.tv/app/$STREAM_KEY"

It streams the video fine, but I only get audio from my plugged in microphone and no audio from Dota 2. This wouldn't be terrible if I only cared about getting the sound effects, but I am sometimes co-casting with other people using the built-in voice chat, and since I am not getting any of their audio, it sounds like I am a madman.
I could try and use an external program for voice chat, but I don't really want to force any of my random co-casters to set it up on their end. So I'd like to be able to pipe both the Wine audio and my microphone audio to the stream.
Answer: You can do this by creating a null-sink and two loopback connectors:
pactl load-module module-null-sink
pactl load-module module-loopback
pactl load-module module-loopback

To configure those channels you need the pavucontrol tool (sudo apt-get install pavucontrol).

On the Playback tab select "All streams" and redirect the loopback streams to "Null output".
Then go to the "Recording" tab and also select "All streams". You should see both loopbacks again.
Set one to "Analog Stereo Internal Audio" (the microphone) and set the other one to "Analog Stereo Internal Audio Monitor" (the audio output).
After running your script you should see the avconv process in the list on the "Recording" tab. Set it to recording from "Null Output Monitor".

Soure

Streaming Wine Audio to Twitch


How to remove this 1940s door hardware from the door?

Question: I have a set of 1940s-era door hardware that seems to be broken so I'd like to remove it from the door. I have removed the knobs and latch but the cam is too big to fit through the holes on either side of the door:

side 1:

side 2:

Inside the hole for the latch is this metal piece:

that connects to the latch which is what is making it too wide to fit through the sides of the door. I cannot see any buttons or ways to detach this piece - any ideas how I can get this hardware out of my door? Thanks!
Comment: Please remove your "update" and copy/paste it into the box labeled "Your Answer". After all, this is a Question & Answer forum, not a general discussion site. In 2 days, the system will allow you to click the check mark showing that this question has an accepted answer and that will make it easier for others to learn from you. You can take the [tour] to learn more.
Answer: I was able to insert a screwdriver to depress a pin behind this metal piece which after some effort caused it to retract:

Once it was retracted, I was able to pull it out one of the sides:
Answer: The mechanism is installed & removed from the latch side. Once you've removed the knob, the screws on the latch side, and any other pieces that might hold it in, you should be able to pull it out. You may want to use something like a screwdriver for leverage, and it might be useful to run a knife around the edges of the metal plate around the latch to help detach from any surrounding paint.
Comment: @garibaldi: You might want to make that an Answer so folks can up-vote it.
Comment: Thanks for the advice. I was eventually able to figure it out - see the above update - by depressing a small pin that allowed this metal piece to retract.


Sistering a split joist not code?

Question: I know that building codes vary by jurisdiction so for the purposes of this question I am in Baltimore County, MD.
We have a split joist in our basement. It's a 2x8, about 10 feet long. One side is in a joist hanger, the other side is resting on top of a steel beam. I had a local builder come out and give an estimate which ended up being ~$2500.
Most of what I have seen online suggests using a bottle jack to slowly raise the joist to close the crack, and then sister in another 2x8 (or 2?) to the cracked one, sprinkle generously with glue, and nail them together. I asked the estimator if this was the process that would be used and he said that it was not code and that they would be cutting out and removing the split joist and replacing it altogether. They would also have to pull up carpet in the room above to secure the sheathing.
Am I getting fleeced? Is sistering another 2x8 not code? I want it done correctly but I got a bit of sticker shock at the cost.
Edit: Here's a picture. Center is the crack, left is one end of the joist, right is the other end:

Edit: Here is another picture of the metal clips:
Answer: I may regret answering this question without first seeing a picture of the joist, but I'll try.
There is nothing in the Code about sistering joists. There are references to "alternate design methods ", which sistering joists would apply. (See ICC Section 2308.8.2)
I'd leave the split joist installed and add a new joist on each side of it. I doubt the joist has sagged much and could easily be jacked back into position without damaging plaster walls, cracking windows, etc.
The new joist should sit on the beam in the same manner as the damaged joist (minimum of 1 1/2" bearing) and installed in a matching hanger on the other end.
In order to keep the new joists from possibly creating a squeaky floor, I'd use epoxy on top of the new joists.
I'd glue the damaged joist together and install a splice on each side to hold the joist together. Nail with 16d at 24" o.c. Staggered each side. (It's just to keep the old joist together. It's not supporting anything anymore.)
Comment: @SeanBright No, I'm not changing my opinion since you've posted the pictures. Time wise: this is a one day job for two workers, unless there's difficulty in getting the 10' joists into the basement. When finished you'll have 3 joists spaced about 6"-8" on center. I doubt a buyer will think it's a problem.
Comment: @JimStewart Actually, there is. Little known fact: The Code allows certain stresses for various types of wood, which most everyone uses. However, when the lumber is used in a repetitive installation, like floor joists, roof joists, etc., then those values can be increased. (Most designers don't use those higher values, because we don't want floors to be springy , leaves a nice safety factor, etc.) In this case, if it happened under my house, I'd just jack it up, screw It together, and then go have a Starbucks. (That split is pretty minor.)
Comment: This makes a lot of sense to me. It should be a relatively easy job because (a) it is only 10' - which is easy to get and easy to maneuver - and (b) you have full access without having to tear into walls or floors. If it was a 20' joist spanning over/through interior walls it would be a different story.
Comment: The only problem I see with this is that there is a joist hanger on one end of this joist, so wouldn't you need hangers supporting any new joists you add too?
Comment: @Dotes Yes, a joist hanger is required at one end. I outlined that in my original answer. The hanger will just need to be spaced far enough away from the original hanger so the flanges don't overlap. BTW, I now see a clip on the end that rests on the beam. I doubt if it's for holddown. I wonder what it's for...
Comment: You guys are the experts, but why is it not allowed to jack the crack closed and reinforce the cracked section with metal reinforcement 3 or 4 ft long on three sides of the joist?
Comment: @JimStewart That's called a "composite beam" and it's very hard to calculate stress, strain, etc. in the wood. I did it once or twice , and I hated it. It's easier to just add the joists. (And easier to prove to the Building Official too.)
Comment: @JimStewart And I'm no expert. I just like to argue.
Comment: It just seems that there is enough redundancy in US construction practices that one would not have to repair a cracked joist by retrofitting a new joist (even two) or  at a cost of $1000s!
Comment: Lee Sam, would you load the crack with glue before screwing it together? While it was jacked up and screwed would you sister on a 2x8 (or 2x6 on the lower part) on one side or both sides?
Comment: @JimStewart Glue is messy, but sistering would be easy.

Sistering a split joist not code?


How do I kill the Phantasm boss that keeps multiplying?

Question: The final boss of Spirit Crucible Elpys is a phantasm that, whenever you get him down to 25% he goes invulnerable and multiplies. It seems there's a max of 6 at any given time. How do you kill him without him multiplying further?
Comment: I found Poppibuster to help with this fight *a lot* since you can attach him (her?) to one of your other drivers and still build up level 4 affinity in this zone.
Answer: I was able to kill him by following a certain strategy:
When your current phantasm gets down to about 40% health, stop attacking it and target a different phantasm (using RB+Y or RB+A). The NPCs will finish the phantasm you're targeting off.
You should continue to do this until you're down to the last phantasm. I think once you get under a certain number of phantasms they stop multiplying.
Answer: I ended up beating the fight by being slightly overleveled ,dogpiling ourselves into a corner and trying to take advantage of AoE arts. When we were down to about ~3 shadows left, trying to evenly whittle them each down to about ~40% health each with targetting, then starting a chain attack and trying to use AoE attacks to burst them all down.
Comment: Pro-tip: Poppibuster (available from DLC side quest) is a blade that you can put on Rex, Zeke, Nia, or Morag (and change drivers whenever you want - no overdrive needed) that is immune to the ether absorbing debuffs that your other blades are affected by. Poppibuster is a tank blade, but he(she?) also has some really nice AoE blade arts. I put him on Rex for this fight. So, some great AoE attacks from Poppi and Poppibuster allowed me to clean this up without chain attacks.
Answer: Did this fight last night, lure them all into the poisonous water, they wont multiply when they are almost defeated. I found it out after 20 minutes of fighting and my tank fell down from the higher platform.
Comment: This is interesting. I'd need to see a video for this.
Answer: SPOILER*
you gotta just keep fighting them... its part of the story.
they eventually stop multiplying
Comment: They actually do not. I was fighting them for approx. 30 minutes before employing my strategy (which I found by pure chance).
Comment: @Seiyria Theres plenty of articles around the net to back this up so perhaps both methods are possible?
Comment: @kenjara it's hard to say when there are no clear triggers or telegraphs.


Can I change my Hero's name?

Question: So I have some hero's that got lucky and got a lot of experience. I want to reward him with a change to the default name. Can this be done?
Comment: in-game... no, but there is a way to change it using the developer console, if that would be ok (it could be seen as cheating).
Answer: Currently the name can not be changed via the game mechanics.
In the console however
var el = document.getElementById('wrap');
var ngEl = angular.element(el);
var scope = ngEl.scope();
scope.heroList[0].name;

repeat that changing the 0 until you find the name of the hero you are looking to change, then change that line to read
scope.heroList[0].name = "New hero name"

where the 0 is the number of the hero you discovered.

Can I change my Hero's name?


Wordpress Memory Exceeds after User login

Question: I have created a custom login for wordpress to let user login automatically into wordpress via a custom form on another page that is not on wordpress but on the same hosting. The form saves the name in a cookie and then redirects user to wordpress homepage where the plugin logins user using the following code  :
if (!is_user_logged_in()) {

   $user_login = $_COOKIE['user_name_from_the_form'];

   //get user's ID
    $user = get_userdatabylogin($user_login);
    $user_id = $user->ID;

    //login
    wp_set_current_user($user_id, $user_login);
    wp_set_auth_cookie($user_id);
    do_action('wp_login', $user_login);}

The problem is, this code sucessfully logins the user but if i visit homepage of the website , then it gives runtime error. All other pages work fine but on homepage, it gives runtime Application error (A yellow page open and shows "Server Error in '/' Application" .
If i disable the plugin and login to wordpress via wordpress login form, then it doesn't give any error.
I tried increasing the memory limit from php.ini to 128MB but this fixed the problem temporarily. After some time, if i refresh the homepage several times, this error again occurs.
Please guide me if there is any error in the code or something else. Thank you.
If i logout user via following code
wp_destroy_current_session();
   wp_clear_auth_cookie();
   wp_logout();

and refresh the home page, it works fine.
I have set the cookie time 3600 (i.e 1 hour).
Here is the complete function, that i am using :
function manage_user(){

if (isset($_COOKIE['user_name_from_the_form'])){} else {return 0;}

   if ($_COOKIE['user_name_from_the_form'] != '0') {

          if (!is_user_logged_in()) {

   $user_login = $_COOKIE['user_name_from_the_form'];

   //get user's ID
    $user = get_userdatabylogin($user_login);
    $user_id = $user->ID;

    //login
    wp_set_current_user($user_id, $user_login);
    wp_set_auth_cookie($user_id);
    do_action('wp_login', $user_login);}

} else {

   wp_destroy_current_session();
   wp_clear_auth_cookie();
   wp_logout();

}}
add_action('init', 'manage_user');

Comment: Give some more memory. Every extra plugin eats more.
Comment: How to increase memory for my custom plugin ? Its just a login/logout function. why its eating so much memory ?
Comment: why the error just occurs on homepage and not on any other page ?
Comment: You can not increase for a plugin, only either for a particular script or in general. Use the php.ini as before and double it and then watch if it is enough.
Comment: Hello @JohnSmith please check my answer.
Answer: Please add in wp-config.php
define('WP_MEMORY_LIMIT', '512M');
define('WP_MAX_MEMORY_LIMIT', '512M');

Comment: Hi, thank you for your help. I tried your solution but still it giving the same error. This is the snapshot of the error , i get:

https://drive.google.com/file/d/1S6z-QeNGY4Vq41nlYhuA033NbVYJkX2B/view?usp=sharing

Please note that only on homepage this error occurs. When i visit any other webpage of the website, it works absolutely fine.