Friday, 1 June 2018

Printing PDF with phantom js - @page rule not working

We're using the phantom JS to print out PDF from web pages (intranet site). My issue is not with the whole styling but just with the @page rule. None of the styles within the @page rule are applied.

Do you have any idea what this could be?

@page {
    size: auto;
    padding: 0 !important;
    margin: 10mm !important;
    page-break-before: avoid;
    border: none !important;
    page-break-after: avoid;
    page-break-inside: avoid;
    overflow: hidden !important;
    box-sizing: border-box !important;

    @top-left-corner {
        content: ""; /* has to be specified! */
        background-color: rgba(42, 201, 80, 0.220);
        border-bottom: solid green;
    }
}



from Printing PDF with phantom js - @page rule not working

Observable

I want to imlpement infinite-scrolling on my list of objects, they are Observable<Object[]>. Transferring them to promise and awaiting them is not an option since they need to be updated in realtime.

What I did is used .map() which kind-of works, but the problem is that angular is re-rendering the whole list whenever I take 20 items instead of 10 for example.

One solution would be to actually skip first 10 and load next 10 which would only add new elements to the page. However I'm not sure if it is possible?

Here is what I have

Typescript

// Every time this happens page goes to top
// because all the items are re-rendered, not only new ones
public onScroll(): void {
  this.take += 10; // on ngOnInit() take is set to 10.
  this.sales = this.filteringObservable.map(data => {
    return _.take(data, this.take);
  });
}

HTML

<div class="sales-container" infiniteScroll [infiniteScrollDistance]="2" [infiniteScrollThrottle]="50" (scrolled)="this.onScroll()">
  <app-sales-item *ngFor="let sale of this.sales | async" [sale]="sale"></app-sales-item>
</div>



from Observable- Can I skip/take?

Cython attemps to compile twice, and fails

I have a setup.py file that is very similar to the one shown here: https://stackoverflow.com/a/49866324/4080129. It looks like this:

from distutils.core import setup, Extension
from Cython.Build import cythonize
import numpy

sources = ["herdingspikes/detection_localisation/detect.pyx",
           "herdingspikes/detection_localisation/SpkDonline.cpp",
           "herdingspikes/detection_localisation/SpikeHandler.cpp",
           "herdingspikes/detection_localisation/ProcessSpikes.cpp",
           "herdingspikes/detection_localisation/FilterSpikes.cpp",
           "herdingspikes/detection_localisation/LocalizeSpikes.cpp"]

exts = [Extension(name='herdingspikes.detect',
                  sources=sources,
                  extra_compile_args=['-std=c++11', '-O3'],
                  include_dirs=[numpy.get_include()])]

setup(
    ext_modules=cythonize(exts),
    include_dirs=[numpy.get_include()]
)

There's a package with some pure-Python, and a submodule that contains Cython files. The setup.py is in the parent folder, not in the Cython one:

setup.py
herdingspikes/
    some_python.py
    detection_localisation/
        detect.pyx
        SpkDonline.cpp
        ...etc

Now, setup.py correctly compiles all the files module/submodule/file1.cpp etc. and saves the build to build/temp.linux-x86_64-3.6/module/submodule/file1.o . However, just after that, it tries to compile a file called file1.cpp, which doesn't exist (the correct one is module/submodule/file1.cpp, and has already been compiled).

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Iherdingspikes/detection_localisation -I/disk/scratch/martino/Clustering/HS2/HS2venv/lib/python3.6/site-packages/numpy/core/include -I/disk/scratch/martino/Clustering/HS2/HS2venv/lib/python3.6/site-packages/numpy/core/include -I/disk/scratch/martino/Clustering/HS2/HS2venv/include -I/disk/scratch/miniconda/envs/my_default/include/python3.6m -c SpkDonline.cpp -o build/temp.linux-x86_64-3.6/SpkDonline.o -std=c++11 -O3
gcc: error: SpkDonline.cpp: No such file or directory
gcc: fatal error: no input files
compilation terminated.
error: command 'gcc' failed with exit status 4

I'm very confused, this completely prevents my code from compiling...



from Cython attemps to compile twice, and fails