Friday, August 24, 2018

SQLite for JSON

I am using Ionic2/Angular2.

I am looking to store data on the users device/browser. I could use Local Storage, but have read it's not reliable.

SQLite is reliable, but is SQL and not JSON. Also, I think it won't work in a browser because it requires a Cordova plugin.

Question

Is there a way to store JSON reliably locally accessible from a devise and a browser?

Thanks

Solved

Sounds like you are looking for Ionic Storage.

In the case of browser it will pick the browser storage available. If you prefer sqlite you have to install:

ionic plugin add cordova-sqlite-storage --save

The API takes key-value pairs to read/write to db. So storing json data is possible.


Monday, August 20, 2018

Display categories list in Wordpress without subcategories

I am attempting to show categories in a list, but without displaying subcatgories. My current code is:

cat_ID) != "") {
    echo "
    "; wp_list_categories('orderby=id&show_count=0&title_li= &use_desc_for_title=1&child_of='.$this_category->cat_ID); echo "
"; } }?>

Which displays the categories nicely

enter image description here

but when I added a sub-category it looked like this:

enter image description here

Any ideas? Thanks!

Solved

Use get_categories() instead. https://developer.wordpress.org/reference/functions/get_categories/#Get_only_top_level_categories

It has "parent" parameter which you can set to 0 and get desired result.


Sunday, August 19, 2018

How to call generic template function in a specialization version

Have a problem about how to call the generic template version in a specialization version.

Here is the sample code. But the "vector::push_back(a)" calls itself recursively.

#include 
#include 

using namespace std;

namespace std
{
        template<>
        void vector::push_back(const int &a)
        {
                cout << "in push_back: " << a << endl;
                vector::push_back(a);               // Want to call generic version
        }
}

int main()
{
        vector v;
        v.push_back(10);
        v.push_back(1);
        return 0;
}

Solved

When you create specialization for some template (no difference class of function), you tell to compiler to generate that one instead of general. So in fact if you have specialization you have no general version for that specialization and you can't call it, because it doesn't exists.


Well, to complement, I think it works for template function specification in some situations.

#include 
#include 

using namespace std;

class Base
{
public:
    virtual int test() {return 0;}
};

class Derived : public Base
{
public:
    virtual int test() {return 1;}
};

template
void TestOutput(T* a)
{
    cout << a->test() << endl;
}

template<>
void TestOutput(Derived* a)
{
    cout << "something else" << endl;
    TestOutput(a);
}

int main()
{
    Derived d;
    TestOutput(&d);
}

I compiled it with visual studio 2013 and the output is:

something else 1

Although I don't think you can always find a TestOutput function of Base to call the generic one.


You can simply extract the code into another template function:

    template
    void baseF(T t) { ... }

    template
    void F(T t) { baseF(t); }

    template<>
    void F(int t) { baseF(t); }

Friday, August 17, 2018

Applying row based filter instead of column based in LibreOffice or other SpreadSheet tool

We all know the standard filter, where you pick which rows to show depending on values in a particular column (or columns). Is it at all possible to the the same, but picking which columns should be visible depending on the values of a single row? The only ideas I have so far is to either write a macro or do it manually.

Solved

Can not post comment yet, so:

Can you do normal excel operations in your tool like:

copy the data area and pastespecial as transpose and then apply filter to columns.


As for the macro, I've put together a small helper extension that allows one to write python code straight into cells - check it at https://github.com/jsbueno/librepylot/releases/tag/0.7

After installing it, some code like the following in a cell could do what you want:

for col in range(0, 26): #A - Z
   S[0]._sheet.Columns.getByIndex(col)  =  bool(S[0][col, 0]._cell.getValue())

Above the first "0" in S[0] is the sheet number, the second "0" in S[0][col,0] is the index of the line with your values (line 1) here I just set the visibility based ont he truthness (!= 0) of the cell computed value. Use whatever python expression you want

These two lines of code should be put in as the text contents of a cell - taking care that the second line is indented, and that libreoffice does not change the first letters of any command to uppercase (and preventing other automatic conversions it does by default) A second cell should be written with the formula =pyexec(B1) (assuming the code is in cell b1) - Whenever you want to "rerun" hte filter, just edit either of the two cells.