问:
how to hide status bar when splash screen appears in iphone?
Is there a way to hide the status bar when showing splash screen in iPhone
and then show again in application?</p>

答: Add Status bar is initially hidden to YES in the info.plist file. This worked for me.

ContentLicense: CC BY-SA 4.0


来源: stackexchange

问:
How can I configure exuberant-ctags to ignore python keyword arguments?
I'm using exuberant-ctags to generate tags for my django project. In many places I'm calling functions and classes using keyword arguments.

```<code>$ cat models.py
from django.db import models

class Foo(models.Model):

    bar = models.CharField(
        help_text='The very important "bar" field',
        unique=True,
        max_length=100,
    )
</code>```

But when ctag parses these files, the keyword arguments are classified as variable declarations. This pollutes my tags files with a large number of false tags.

```<code>$ ctags -x models.py
Foo              class         3 models.py        class Foo(models.Model):
bar              variable      5 models.py        bar = models.CharField(
help_text        variable      6 models.py        help_text='The very important "bar" field',
max_length       variable      8 models.py        max_length=100,
unique           variable      7 models.py        unique=True,
</code>```

I've read the ctags docs, but I couldn't find anything that seemed obviously relevant.

Is there some built-in functionality in ctags that I could use? Or will I have to pipe the tag file through something like awk to filter out the false matches?

答:
It seems like a bug on ctags end, as per this PR : https://github.com/universal-ctags/ctags/pull/767

Make sure ctags is up to date, since the fix is now merged.

Since the pull request concerns multi-lines kwargs declaration, one can assume that putting them all on the same line will 'fix' the issue (but will most likely make your code break PEP8  recommendations).

ContentLicense: CC BY-SA 3.0

Body:
I'm using exuberant-ctags to generate tags for my django project. In many places I'm calling functions and classes using keyword arguments.

$ cat models.py
from django.db import models

class Foo(models.Model):

    bar = models.CharField(
        help_text='The very important "bar" field',
        unique=True,
        max_length=100,
    )

But when ctag parses these files, the keyword arguments are classified as variable declarations. This pollutes my tags files with a large number of false tags.

$ ctags -x models.py
Foo              class         3 models.py        class Foo(models.Model):
bar              variable      5 models.py        bar = models.CharField(
help_text        variable      6 models.py        help_text='The very important "bar" field',
max_length       variable      8 models.py        max_length=100,
unique           variable      7 models.py        unique=True,

I've read the ctags docs, but I couldn't find anything that seemed obviously relevant.

Is there some built-in functionality in ctags that I could use? Or will I have to pipe the tag file through something like awk to filter out the false matches?


问:
Ruby on Rails Oracle DB connection
My main database is a local mysql database, however I would like to occasionally connect to an Oracle database directly in my applications code.

The oracle database is hosted on another RHEL server.

I was unsuccessfull tried to install the ruby-OCI8 gem (ERROR: Failed to build gem native extension.)

I am wondering whether the oracle database has to be local in order to use this gem, or if there are any better ways of achieving this.

```<code>gem install ruby-oci8

Building native extensions.  This could take a while...
ERROR:  Error installing ruby-oci8:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for load library path...
  LD_LIBRARY_PATH...
    checking /opt/instantclient... yes
  /opt/instantclient/libclntsh.so.11.1 looks like an instant client.
checking for cc... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/ruby
        --with-instant-client
        --without-instant-client
./oraconf.rb:562:in `check_cc': RuntimeError (RuntimeError)
        from ./oraconf.rb:549:in `init'
        from ./oraconf.rb:1001:in `initialize'
        from ./oraconf.rb:343:in `new'
        from ./oraconf.rb:343:in `get'
        from extconf.rb:18
ng
---------------------------------------------------
Error Message:
  C compiler doesn't work correctly.
Backtrace:
  ./oraconf.rb:562:in `check_cc'
  ./oraconf.rb:549:in `init'
  ./oraconf.rb:1001:in `initialize'
  ./oraconf.rb:343:in `new'
  ./oraconf.rb:343:in `get'
  extconf.rb:18
---------------------------------------------------
See:
 * http://ruby-oci8.rubyforge.org/en/HowToInstall.html
 * http://ruby-oci8.rubyforge.org/en/ReportInstallProblem.html
</code>```

I checked the mkmf.log file:

```<code> "gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I.   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fs    tack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing  -fPIC conftest.c  -L. -L/usr/lib64 -L.      -rdynamic -Wl,-export-dynamic     -lruby-static  -lpthread -lrt -ldl -lcrypt -lm   -lc"
  /usr/bin/ld: skipping incompatible /usr/lib/libruby-static.a when searching for -lruby-static
  /usr/bin/ld: cannot find -lruby-static
  collect2: ld returned 1 exit status
  checked program was:
  /* begin */
  1: int main() { return 0; }
  8 /* end */
</code>```

答: See if this blog post helps you in getting through the OCI gem install http://jessehu.wordpress.com/2008/07/03/ruby-oci8-gem-available-2/</p>

ContentLicense: CC BY-SA 2.5

Title: Ruby on Rails Oracle DB connection

Body:
My main database is a local mysql database, however I would like to occasionally connect to an Oracle database directly in my applications code.

The oracle database is hosted on another RHEL server.

I was unsuccessfull tried to install the ruby-OCI8 gem (ERROR: Failed to build gem native extension.)

I am wondering whether the oracle database has to be local in order to use this gem, or if there are any better ways of achieving this.

gem install ruby-oci8

Building native extensions.  This could take a while...
ERROR:  Error installing ruby-oci8:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for load library path...
  LD_LIBRARY_PATH...
    checking /opt/instantclient... yes
  /opt/instantclient/libclntsh.so.11.1 looks like an instant client.
checking for cc... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/ruby
        --with-instant-client
        --without-instant-client
./oraconf.rb:562:in `check_cc': RuntimeError (RuntimeError)
        from ./oraconf.rb:549:in `init'
        from ./oraconf.rb:1001:in `initialize'
        from ./oraconf.rb:343:in `new'
        from ./oraconf.rb:343:in `get'
        from extconf.rb:18
ng
---------------------------------------------------
Error Message:
  C compiler doesn't work correctly.
Backtrace:
  ./oraconf.rb:562:in `check_cc'
  ./oraconf.rb:549:in `init'
  ./oraconf.rb:1001:in `initialize'
  ./oraconf.rb:343:in `new'
  ./oraconf.rb:343:in `get'
  extconf.rb:18
---------------------------------------------------
See:
 * http://ruby-oci8.rubyforge.org/en/HowToInstall.html
 * http://ruby-oci8.rubyforge.org/en/ReportInstallProblem.html

I checked the mkmf.log file:

 "gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I.   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fs    tack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing  -fPIC conftest.c  -L. -L/usr/lib64 -L.      -rdynamic -Wl,-export-dynamic     -lruby-static  -lpthread -lrt -ldl -lcrypt -lm   -lc"
  /usr/bin/ld: skipping incompatible /usr/lib/libruby-static.a when searching for -lruby-static
  /usr/bin/ld: cannot find -lruby-static
  collect2: ld returned 1 exit status
  checked program was:
  /* begin */
  1: int main() { return 0; }
  8 /* end */


问:
how should i handle (morphing) 4D objects in opengl?
i want to try writing a playground similar to this 4D toys,
so i started learning opengl.

from my current understanding, people use VBOs and uniform transformation matrix for mostly-static objects

 (like cubes, skeletal animations etc., which usually just involves transformations)

i also heard that morphing between models also uses VBOs for caching both models, since both of them will be well defined and not so much intermediates.

but in the 4D toys mentioned above, objects are morphing and clipped a lot.

and it is likely that there is no defined models, and many transitions in between.

(it might be a simple square now, and a spiky ball clipped in half later ).

in this case, is updating-vertex-VBO-per-frame or Vertex Arrays(which i saw in another question) a suitable solution?

答:
For starters I would use 4D -> 3D projection instead of cut by hyperplane. The result is not the same but will get you closer to your goal (so you can latter upgrade this to cut). So similarly like in 3D -> 2D conversions used in graphics you got 2 choices one is using perspective projection and second is just ignoring the 4th dimension coordinate while rendering. I will use the latter as it is simpler.

structures

To make this as simple as I can I will use wire-frame instead of BR rendering. So you need to handle 4D mesh (wire-frame). I would use 2 tables:

```<code>double pnt[];   // 4D point list (x,y,z,u)
int  lin[];     // lines point indexes (i0,i1)
</code>```

first one stores all the vertexes of your mesh and the second hold index pairs of points connected by lines in wire-frame representation.

transforms

If I would only ignore the 4th coordinate then we would not get the desired functionality. So to make the 4th dimension work we need to add 4D transform to orient our mesh in 4D before rendering. So use homogenous transform matrix and lets call ir rep. In 4D it should be 5x5 orthonormal matrix with 4x4 rotation part rot.

To make this even easier avoid smooth rotations for now (as in 4D that is not as easy) and compute random rotation 4x4 matrix instead. So just set all the cells randomly <-1,+1>. Handle each row as basis vector. To make them orthonormal just make them unit and exploit cross product. For more info see:

How to generate a randomly oriented, high dimension circle in python?

render

simply convert point table by your transform matrix

```<code>(x',y',z',u',W) = rep * (x,y,z,u,1)
</code>```

then take the (x,y,z`) and render ...

Here simple OpenGL/C++ example of 4D hyper cube:

//---------------------------------------------------------------------------
//--- Mesh 4D: ver 0.000 ----------------------------------------------------
//---------------------------------------------------------------------------
#ifndef _mesh4D_h
#define _mesh4D_h
//---------------------------------------------------------------------------
#include <math.h>
#include "nd_math.h"
#include "list.h"
//---------------------------------------------------------------------------
const double pi   =    M_PI;
const double pi2  =2.0*M_PI;
const double pipol=0.5*M_PI;
const double deg=M_PI/180.0;
const double rad=180.0/M_PI;
//---------------------------------------------------------------------------
class mesh4D
    {
public:
    matrix<5> rep;  // 4D uniform 5x5 transform matrix

    List<double> pnt;   // 4D point list (x,y,z,u)
    List<int>    lin;   // lines point indexes (i0,i1)

    mesh4D()    {}
    mesh4D(mesh4D& a)   { *this=a; }
    ~mesh4D()   {}
    mesh4D* operator = (const mesh4D *a) { *this=*a; return this; }
    //mesh4D* operator = (const mesh4D &a) { ...copy... return this; }

    void set_randomrep();               // random oriented uniform 4D transform matrix with origin (0,0,0,0)
    void set_hypercube(double a);

    void draw();
    };
//---------------------------------------------------------------------------
void mesh4D::set_randomrep()
    {
    int i,j;
    matrix<4> rot;
    rep.unit();
    rot.rnd();
    rot.orthonormal();
    for (i=0;i<4;i++)
     for (j=0;j<4;j++)
      rep[i][j]=rot[i][j];
    }
void mesh4D::set_hypercube(double a)
    {
    rep.unit(); // reset orientation
    pnt.num=0;  // clear point list
    lin.num=0;  // clear line list

    pnt.add(-a); pnt.add(-a); pnt.add(-a); pnt.add(-a);
    pnt.add(+a); pnt.add(-a); pnt.add(-a); pnt.add(-a);
    pnt.add(-a); pnt.add(+a); pnt.add(-a); pnt.add(-a);
    pnt.add(+a); pnt.add(+a); pnt.add(-a); pnt.add(-a);
    pnt.add(-a); pnt.add(-a); pnt.add(+a); pnt.add(-a);
    pnt.add(+a); pnt.add(-a); pnt.add(+a); pnt.add(-a);
    pnt.add(-a); pnt.add(+a); pnt.add(+a); pnt.add(-a);
    pnt.add(+a); pnt.add(+a); pnt.add(+a); pnt.add(-a);

    pnt.add(-a); pnt.add(-a); pnt.add(-a); pnt.add(+a);
    pnt.add(+a); pnt.add(-a); pnt.add(-a); pnt.add(+a);
    pnt.add(-a); pnt.add(+a); pnt.add(-a); pnt.add(+a);
    pnt.add(+a); pnt.add(+a); pnt.add(-a); pnt.add(+a);
    pnt.add(-a); pnt.add(-a); pnt.add(+a); pnt.add(+a);
    pnt.add(+a); pnt.add(-a); pnt.add(+a); pnt.add(+a);
    pnt.add(-a); pnt.add(+a); pnt.add(+a); pnt.add(+a);
    pnt.add(+a); pnt.add(+a); pnt.add(+a); pnt.add(+a);

    // A0
    lin.add( 0+0); lin.add( 0+1);
    lin.add( 0+1); lin.add( 0+3);
    lin.add( 0+3); lin.add( 0+2);
    lin.add( 0+2); lin.add( 0+0);
    // A1
    lin.add( 4+0); lin.add( 4+1);
    lin.add( 4+1); lin.add( 4+3);
    lin.add( 4+3); lin.add( 4+2);
    lin.add( 4+2); lin.add( 4+0);
    // A=A0+A1
    lin.add( 0+0); lin.add( 4+0);
    lin.add( 0+1); lin.add( 4+1);
    lin.add( 0+2); lin.add( 4+2);
    lin.add( 0+3); lin.add( 4+3);

    // B0
    lin.add( 8+0); lin.add( 8+1);
    lin.add( 8+1); lin.add( 8+3);
    lin.add( 8+3); lin.add( 8+2);
    lin.add( 8+2); lin.add( 8+0);
    // B1
    lin.add(12+0); lin.add(12+1);
    lin.add(12+1); lin.add(12+3);
    lin.add(12+3); lin.add(12+2);
    lin.add(12+2); lin.add(12+0);
    // B=B0+B1
    lin.add( 8+0); lin.add(12+0);
    lin.add( 8+1); lin.add(12+1);
    lin.add( 8+2); lin.add(12+2);
    lin.add( 8+3); lin.add(12+3);

    // hyper cube = A+B
    lin.add( 0+0); lin.add( 8+0);
    lin.add( 0+1); lin.add( 8+1);
    lin.add( 0+2); lin.add( 8+2);
    lin.add( 0+3); lin.add( 8+3);
    lin.add( 0+4); lin.add( 8+4);
    lin.add( 0+5); lin.add( 8+5);
    lin.add( 0+6); lin.add( 8+6);
    lin.add( 0+7); lin.add( 8+7);
    }
//---------------------------------------------------------------------------
void mesh4D::draw()
    {
    int i,j;
    double _zero=1e-3;
    vector<5> a,b;
    glBegin(GL_LINES);
    for (i=0;i<lin.num;)
        {
        // extrac first point
        j=lin[i]*4; i++;
        a.a[0]=pnt[j]; j++;
        a.a[1]=pnt[j]; j++;
        a.a[2]=pnt[j]; j++;
        a.a[3]=pnt[j]; j++;
        a.a[4]=1.0; // W=1
        // extrac second point
        j=lin[i]*4; i++;
        b.a[0]=pnt[j]; j++;
        b.a[1]=pnt[j]; j++;
        b.a[2]=pnt[j]; j++;
        b.a[3]=pnt[j]; j++;
        b.a[4]=1.0; // W=1
        // transform
        a=rep*a;
        b=rep*b;
        // render
        glVertex3dv(a.a);   // use just x,y,z
        glVertex3dv(b.a);   // use just x,y,z
        }
    glEnd();
    }
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
```

<p>I used mine dynamic <code>list.h</code> template so:</p>

<p><br><code>List<double> xxx;</code> is the same as <code>double xxx[];</code>
<br><code>xxx.add(5);</code> adds <code>5</code> to end of the list
<br><code>xxx[7]</code> access array element (safe)
<br><code>xxx.dat[7]</code> access array element (unsafe but fast direct access)
<br><code>xxx.num</code> is the actual used size of the array
<br><code>xxx.reset()</code> clears the array and set <code>xxx.num=0</code>
<br><code>xxx.allocate(100)</code> preallocate space for <code>100</code> items</p>

<p>the <code>nd_math.h</code> is mine lib for N-Dimensional computations. What you need is just <strong>4D,5D</strong> vector and <code>4x4</code>, <code>5x5</code> matrix math from linear algebra.</p>

<p>Both libs are a bit big in size and also legal issues prevent me to share their code here.</p>

<p>The usage is simple:</p>

<pre class="lang-cpp prettyprint-override"><code>// globals and init
mesh4D mesh
double animx=-50.0,danimx=0.0;
double animy=  0.0,danimy=2.0;
mesh.set_hypercube(0.5);

// render
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D( -2.0, 2.0, -2.0, 2.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotated(animx,1.0,0.0,0.0);
glRotated(animy,0.0,1.0,0.0);
mesh.draw();
glFlush();
SwapBuffers(hdc);

// some timer
animx+=danimx; if (animx>=360.0) animx-=360.0;
animy+=danimy; if (animy>=360.0) animy-=360.0;
call_render_here();

// on key press or mouse wheel or what ever
mesh.set_randomrep();
</code>```

And here preview for some rep rotations ...

so this way you can render any wire-frame mesh (even BR rendering should works this way).

If you want to upgrade to the cut then you should take each Wire-frame line and compute its intersection with cutting hyperplane. If we chose hyperplane that goes through point

```<code>O(0,0,0,u_cut)
</code>```

and has normal

```<code>N(0,0,0,1)
</code>```

Then the task will simplify a lot. there are 3 options. Lets consider edge line with endpoints A,B:

no intersection

```<code>((A.u > u_cut)&&(B.u > u_cut)) || ((A.u < u_cut)&&(B.u < u_cut))
</code>```

just ignore such edge

1 intersection

```<code>((A.u >= u_cut)&&(B.u <= u_cut)) || ((A.u <= u_cut)&&(B.u >= u_cut))
</code>```

so compute the intersection via linear interpolation

```<code>x = A.x + (B.x-A.x)*(u_cut-A.u)/(B.u-A.u)
y = A.y + (B.y-A.y)*(u_cut-A.u)/(B.u-A.u)
z = A.z + (B.z-A.z)*(u_cut-A.u)/(B.u-A.u)
</code>```

and remember such point and also edge to which it belongs to.

fully inside

```<code>(A.u == u_cut)&&(B.u == u_cut)
</code>```

just remember both endpoints and also render this edge.

After all edges are processed this way then you need to analyze the remembered intersection points and create new edges from them based on connectivity info between edges. I did not do this yet so I can not help with this. I would try to connect remembered points sharing the same neighbor but not sure if that is enough in 4D.

For more info take a look at related QAs I found or answer:

Visualising 4D objects in OpenGL

4D to 3D perspective projection

4D rotations

ND vector and square matrix math template

reper4D

configurable ND rendering engine + hyperspiral

[Edit1] code with perspective

//---------------------------------------------------------------------------
//--- Mesh 4D: ver 0.001 ----------------------------------------------------
//---------------------------------------------------------------------------
#ifndef _mesh4D_h
#define _mesh4D_h
//---------------------------------------------------------------------------
#include <math.h>
#include "nd_math.h"
#include "list.h"
//---------------------------------------------------------------------------
const double pi   =    M_PI;
const double pi2  =2.0*M_PI;
const double pipol=0.5*M_PI;
const double deg=M_PI/180.0;
const double rad=180.0/M_PI;
//---------------------------------------------------------------------------
class mesh4D
    {
public:
    matrix<5> rep;  // 4D uniform 5x5 transform matrix

    List<double> pnt;   // 4D point list (x,y,z,u)
    List<int>    lin;   // lines point indexes (i0,i1)

    mesh4D()    {}
    mesh4D(mesh4D& a)   { *this=a; }
    ~mesh4D()   {}
    mesh4D* operator = (const mesh4D *a) { *this=*a; return this; }
    //mesh4D* operator = (const mesh4D &a) { ...copy... return this; }

    void set_randomrep();               // random oriented uniform 4D transform matrix with origin (0,0,0,0)
    void set_hypercube(double a);

    void draw();
    };
//---------------------------------------------------------------------------
void mesh4D::set_randomrep()
    {
    int i,j;
    matrix<4> rot;
    rot.rnd();
    rot.orthonormal();
    for (i=0;i<4;i++)
     for (j=0;j<4;j++)
      rep[i][j]=rot[i][j];
    }
//---------------------------------------------------------------------------
void mesh4D::set_hypercube(double a)
    {
    rep.unit();     // reset orientation
    rep[0][4]=0.0;  // set position
    rep[1][4]=0.0;
    rep[2][4]=0.0;
    rep[3][4]=3.0*a;
    pnt.num=0;  // clear point list
    lin.num=0;  // clear line list

    pnt.add(-a); pnt.add(-a); pnt.add(-a); pnt.add(-a);
    pnt.add(+a); pnt.add(-a); pnt.add(-a); pnt.add(-a);
    pnt.add(-a); pnt.add(+a); pnt.add(-a); pnt.add(-a);
    pnt.add(+a); pnt.add(+a); pnt.add(-a); pnt.add(-a);
    pnt.add(-a); pnt.add(-a); pnt.add(+a); pnt.add(-a);
    pnt.add(+a); pnt.add(-a); pnt.add(+a); pnt.add(-a);
    pnt.add(-a); pnt.add(+a); pnt.add(+a); pnt.add(-a);
    pnt.add(+a); pnt.add(+a); pnt.add(+a); pnt.add(-a);

    pnt.add(-a); pnt.add(-a); pnt.add(-a); pnt.add(+a);
    pnt.add(+a); pnt.add(-a); pnt.add(-a); pnt.add(+a);
    pnt.add(-a); pnt.add(+a); pnt.add(-a); pnt.add(+a);
    pnt.add(+a); pnt.add(+a); pnt.add(-a); pnt.add(+a);
    pnt.add(-a); pnt.add(-a); pnt.add(+a); pnt.add(+a);
    pnt.add(+a); pnt.add(-a); pnt.add(+a); pnt.add(+a);
    pnt.add(-a); pnt.add(+a); pnt.add(+a); pnt.add(+a);
    pnt.add(+a); pnt.add(+a); pnt.add(+a); pnt.add(+a);

    // A0
    lin.add( 0+0); lin.add( 0+1);
    lin.add( 0+1); lin.add( 0+3);
    lin.add( 0+3); lin.add( 0+2);
    lin.add( 0+2); lin.add( 0+0);
    // A1
    lin.add( 4+0); lin.add( 4+1);
    lin.add( 4+1); lin.add( 4+3);
    lin.add( 4+3); lin.add( 4+2);
    lin.add( 4+2); lin.add( 4+0);
    // A=A0+A1
    lin.add( 0+0); lin.add( 4+0);
    lin.add( 0+1); lin.add( 4+1);
    lin.add( 0+2); lin.add( 4+2);
    lin.add( 0+3); lin.add( 4+3);

    // B0
    lin.add( 8+0); lin.add( 8+1);
    lin.add( 8+1); lin.add( 8+3);
    lin.add( 8+3); lin.add( 8+2);
    lin.add( 8+2); lin.add( 8+0);
    // B1
    lin.add(12+0); lin.add(12+1);
    lin.add(12+1); lin.add(12+3);
    lin.add(12+3); lin.add(12+2);
    lin.add(12+2); lin.add(12+0);
    // B=B0+B1
    lin.add( 8+0); lin.add(12+0);
    lin.add( 8+1); lin.add(12+1);
    lin.add( 8+2); lin.add(12+2);
    lin.add( 8+3); lin.add(12+3);

    // hyper cube = A+B
    lin.add( 0+0); lin.add( 8+0);
    lin.add( 0+1); lin.add( 8+1);
    lin.add( 0+2); lin.add( 8+2);
    lin.add( 0+3); lin.add( 8+3);
    lin.add( 0+4); lin.add( 8+4);
    lin.add( 0+5); lin.add( 8+5);
    lin.add( 0+6); lin.add( 8+6);
    lin.add( 0+7); lin.add( 8+7);
    }
//---------------------------------------------------------------------------
void mesh4D::draw()
    {
    int i,j;
    const double _zero=1e-3;
    double focal_length=1.0;

    vector<5> a,b;
    glBegin(GL_LINES);
    for (i=0;i<lin.num;)
        {
        // extrac first point
        j=lin[i]*4; i++;
        a.a[0]=pnt[j]; j++;
        a.a[1]=pnt[j]; j++;
        a.a[2]=pnt[j]; j++;
        a.a[3]=pnt[j]; j++;
        a.a[4]=1.0; // W=1
        // extrac second point
        j=lin[i]*4; i++;
        b.a[0]=pnt[j]; j++;
        b.a[1]=pnt[j]; j++;
        b.a[2]=pnt[j]; j++;
        b.a[3]=pnt[j]; j++;
        b.a[4]=1.0; // W=1
        // transform
        a=rep*a;
        b=rep*b;
        // perspective: camera projection plane u=0, focus at (0,0,0,-focal_length)
        if (a[3]>=0.0) a*=divide(focal_length,a[3]+focal_length); else a.zero();
        if (b[3]>=0.0) b*=divide(focal_length,b[3]+focal_length); else b.zero();
        // render
        glVertex3dv(a.a);   // use just x,y,z
        glVertex3dv(b.a);   // use just x,y,z
        }
    glEnd();
    }
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
```

<p><strong>And preview:</strong></p>

<p><img src="https://i.stack.imgur.com/lVR0U.gif" alt="hypercube with perspective"></p>

<p><strong>[Edit2] solid mesh and cross-section</strong></p>

<p>so I changed the architecture quite a bit. I moved the <strong>4D</strong> <code>5x5</code> homogenuous transform matrix (<code>reper4D</code>) to separate file and added colors and mesh definition by 4D simplexes (4 point 4 side tetrahedrons). The cut is simply computing the intersection (as described above) of simplex and cutting hyperplane resulting in either 3 points (triangle) , 4 points (tetrahedron) or 0 points. Which can be rendered easily (no need to analyze the connections between edges). For more info see this:</p>

<ul>
<li>Calculate 3D cross section of 4D shape (tesseract)</li>
</ul>

<p>Btw. I think this is how Miegakure works. Here updated code:</p>

<pre class="lang-cpp prettyprint-override"><code>//---------------------------------------------------------------------------
//--- Mesh 4D: ver 1.000 ----------------------------------------------------
//---------------------------------------------------------------------------
#ifndef _mesh4D_h
#define _mesh4D_h
//---------------------------------------------------------------------------
#include "list.h"
#include "reper4D.h"
//---------------------------------------------------------------------------
class mesh4D
    {
public:
    reper4D rep;        // 4D uniform 5x5 transform matrix

    List<double> pnt;   // 4D point list (x,y,z,w)
    List<int>    lin;   // 4D wireframe (i0,i1)
    List<int>    fac;   // 4D simplexes (i0,i1,i2,i3)
    List<DWORD>  col;   // simplex colors (RGB)

    mesh4D()    {}
    mesh4D(mesh4D& a)   { *this=a; }
    ~mesh4D()   {}
    mesh4D* operator = (const mesh4D *a) { *this=*a; return this; }
    //mesh4D* operator = (const mesh4D &a) { ...copy... return this; }

    void set_hypercube(double a);
    void draw_cut(double w_cut);                                        // render cross section by w=w_cut hyperplane
    void draw          (double focal_length=-1.0,double w_near=-1.0);   // render mesh      (focal_length<0) -> no perspective, else perspective view in W+ direction
    void draw_wireframe(double focal_length=-1.0,double w_near=-1.0);   // render wireframe (focal_length<0) -> no perspective, else perspective view in W+ direction
    };
//---------------------------------------------------------------------------
void mesh4D::set_hypercube(double a)
    {
    const double tab_pnt[]=
        {
        -a, -a, -a, -a,
        +a, -a, -a, -a,
        -a, +a, -a, -a,
        +a, +a, -a, -a,
        -a, -a, +a, -a,
        +a, -a, +a, -a,
        -a, +a, +a, -a,
        +a, +a, +a, -a,
        -a, -a, -a, +a,
        +a, -a, -a, +a,
        -a, +a, -a, +a,
        +a, +a, -a, +a,
        -a, -a, +a, +a,
        +a, -a, +a, +a,
        -a, +a, +a, +a,
        +a, +a, +a, +a,
        };
    const int tab_lin[]=
        {
        // A0
         0+0,  0+1,
         0+1,  0+3,
         0+3,  0+2,
         0+2,  0+0,
        // A1
         4+0,  4+1,
         4+1,  4+3,
         4+3,  4+2,
         4+2,  4+0,
        // A=A0+A1
         0+0,  4+0,
         0+1,  4+1,
         0+2,  4+2,
         0+3,  4+3,
        // B0
         8+0,  8+1,
         8+1,  8+3,
         8+3,  8+2,
         8+2,  8+0,
        // B1
        12+0, 12+1,
        12+1, 12+3,
        12+3, 12+2,
        12+2, 12+0,
        // B=B0+B1
         8+0, 12+0,
         8+1, 12+1,
         8+2, 12+2,
         8+3, 12+3,
        // hyper cube = A+B
         0+0,  8+0,
         0+1,  8+1,
         0+2,  8+2,
         0+3,  8+3,
         0+4,  8+4,
         0+5,  8+5,
         0+6,  8+6,
         0+7,  8+7,
        };
    // 5x simplex per cube
    #define _cube(a0,a1,a2,a3,a4,a5,a6,a7) a1,a2,a4,a7, a0,a1,a2,a4, a2,a4,a6,a7, a1,a2,a3,a7, a1,a4,a5,a7
    // 4D hypercube = 8 cubes
    const int tab_fac[]=
        {
        _cube( 0, 1, 2, 3, 4, 5, 6, 7),
        _cube( 0, 1, 2, 3, 8, 9,10,11),
        _cube( 4, 5, 6, 7,12,13,14,15),
        _cube( 8, 9,10,11,12,13,14,15),
        _cube( 0, 1, 4, 5, 8, 9,12,13),
        _cube( 0, 2, 4, 6, 8,10,12,14),
        _cube( 1, 3, 5, 7, 9,11,13,15),
        _cube( 2, 3, 6, 7,10,11,14,15),
        };
    #undef _cube
    const DWORD tab_col[]=
        {
        //  BBGGRR,    BBGGRR,    BBGGRR,    BBGGRR,    BBGGRR,
        0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000,
        0x0000FF00,0x0000FF00,0x0000FF00,0x0000FF00,0x0000FF00,
        0x000000FF,0x000000FF,0x000000FF,0x000000FF,0x000000FF,
        0x0000FFFF,0x0000FFFF,0x0000FFFF,0x0000FFFF,0x0000FFFF,
        0x00FF00FF,0x00FF00FF,0x00FF00FF,0x00FF00FF,0x00FF00FF,
        0x00FFFF00,0x00FFFF00,0x00FFFF00,0x00FFFF00,0x00FFFF00,
        0x00FFFFFF,0x00FFFFFF,0x00FFFFFF,0x00FFFFFF,0x00FFFFFF,
        0x004080FF,0x004080FF,0x004080FF,0x004080FF,0x004080FF,
        };

    int i,n;
    vector<4> p;
    rep.reset();
    pnt.num=0; for (i=0,n=sizeof(tab_pnt)/sizeof(tab_pnt[0]);i<n;i++) pnt.add(tab_pnt[i]);
    lin.num=0; for (i=0,n=sizeof(tab_lin)/sizeof(tab_lin[0]);i<n;i++) lin.add(tab_lin[i]);
    fac.num=0; for (i=0,n=sizeof(tab_fac)/sizeof(tab_fac[0]);i<n;i++) fac.add(tab_fac[i]);
    col.num=0; for (i=0,n=sizeof(tab_col)/sizeof(tab_col[0]);i<n;i++) col.add(tab_col[i]);
    }
//---------------------------------------------------------------------------
void mesh4D::draw_cut(double w_cut)
    {
    const double _zero=1e-6;
    const int edge2[]={0,1,0,2,0,3,1,2,2,3,3,1,-1}; // simplex wireframe i0,i1
    const int edge3[]={0,1,2,3,0,1,3,1,2,3,2,0,-1}; // simplex triangles i0,i1,i2
    int e,i,j,k,k0,k1,k2,inside[4];
    DWORD rgb;
    vector<4> p[4],q[4];
    vector<3> xyz[4],nor,a,b;
    for (i=0;i<fac.num;)
        {
        rgb=col[i>>2];
        // extrac points (x,y,z,w)
        for (k=0;k<4;k++)
            {
            j=fac[i]*4; i++;
            p[k].a[0]=pnt[j]; j++;
            p[k].a[1]=pnt[j]; j++;
            p[k].a[2]=pnt[j]; j++;
            p[k].a[3]=pnt[j]; j++;
            // transform
            rep.l2g(p[k],p[k]);
            inside[k]=1;
            }
        // process edge2 and compute cross section cut intersection points
        for (e=0,k=0;edge2[e]>=0;)
            {
            k0=edge2[e]; e++;
            k1=edge2[e]; e++;
            // fully inside
            if (fabs(p[k0][3]-w_cut)+fabs(p[k1][3]-w_cut)<=_zero)
                {
                if ((k<4)&&(inside[k0])){ q[k]=p[k0]; k++; inside[k0]=0; }
                if ((k<4)&&(inside[k1])){ q[k]=p[k1]; k++; inside[k1]=0; }
                continue;
                }
            // no intersection
            if (((p[k0][3]> w_cut)&&(p[k1][3]> w_cut))||((p[k0][3]< w_cut)&&(p[k1][3]< w_cut))) continue;
            // 1 intersection
            if (k<4)
                {
                q[k]=p[k1]-p[k0];
                q[k]*=divide(w_cut-p[k0][3],p[k1][3]-p[k0][3]);
                q[k]+=p[k0];
                q[k][3]=w_cut;
                k++;
                continue;
                }
            }
        // 4D -> 3D vector
        for (k0=0;k0<k;k0++) for (k1=0;k1<3;k1++) xyz[k0][k1]=q[k0][k1];
        // render triangle
        if (k==3)
            {
            // normal
            a=xyz[1]-xyz[0];
            b=xyz[2]-xyz[1];
            nor.cross(a,b);
            nor.unit();
            // render
            glBegin(GL_TRIANGLES);
            glNormal3dv(nor.a);
            glColor4ubv((BYTE*)(&rgb));
            glVertex3dv(xyz[0].a);
            glVertex3dv(xyz[1].a);
            glVertex3dv(xyz[2].a);
            glEnd();
            }
        // render simplex
        if (k==4)
         for (e=0;edge3[e]>=0;)
            {
            k0=edge3[e]; e++;
            k1=edge3[e]; e++;
            k2=edge3[e]; e++;
            // normal
            a=xyz[k1]-xyz[k0];
            b=xyz[k2]-xyz[k1];
            nor.cross(a,b);
            nor.unit();
            // render
            glBegin(GL_TRIANGLES);
            glNormal3dv(nor.a);
            glColor4ubv((BYTE*)(&rgb));
            glVertex3dv(xyz[k0].a);
            glVertex3dv(xyz[k1].a);
            glVertex3dv(xyz[k2].a);
            glEnd();
            }
        }
    }
//---------------------------------------------------------------------------
void mesh4D::draw(double focal_length,double w_near)
    {
    const int edge3[]={0,1,2,3,0,1,3,1,2,3,2,0,-1}; // simplex triangles i0,i1,i2
    int i,j,k,k0,k1,k2;
    DWORD rgb;
    vector<4> p;
    vector<3> xyz[4],nor,a,b;

    // 4D simplexes
    glColor3f(0.3,0.3,0.3);
    for (i=0;i<fac.num;)
        {
        rgb=col[i>>2];
        // extrac points (x,y,z,w)
        for (k=0;k<4;k++)
            {
            j=fac[i]*4; i++;
            p[0]=pnt[j]; j++;
            p[1]=pnt[j]; j++;
            p[2]=pnt[j]; j++;
            p[3]=pnt[j]; j++;
            // transform
            rep.l2g(p,p);
            // perspective projection
            if (focal_length>0.0)
                {
                p[3]-=w_near;
                if (p[3]>=0.0) p*=divide(focal_length,p[3]+focal_length); else p.zero();
                }
            // 4D -> 3D vector
            xyz[k].ld(p[0],p[1],p[2]);
            }
        // render simplex
        for (k=0;edge3[k]>=0;)
            {
            k0=edge3[k]; k++;
            k1=edge3[k]; k++;
            k2=edge3[k]; k++;
            // normal
            a=xyz[k1]-xyz[k0];
            b=xyz[k2]-xyz[k1];
            nor.cross(a,b);
            nor.unit();
            // render
//          glBegin(GL_LINE_LOOP);
            glBegin(GL_TRIANGLES);
            glNormal3dv(nor.a);
            glColor4ubv((BYTE*)(&rgb));
            glVertex3dv(xyz[k0].a);
            glVertex3dv(xyz[k1].a);
            glVertex3dv(xyz[k2].a);
            glEnd();
            }
        }
    }
//---------------------------------------------------------------------------
void mesh4D::draw_wireframe(double focal_length,double w_near)
    {
    int i,j,k;
    vector<4> p[4];
    // 4D wireframe
    glColor3f(1.0,1.0,1.0);
    glBegin(GL_LINES);
    for (i=0;i<lin.num;)
        {
        // extrac points (x,y,z,w)
        for (k=0;k<2;k++)
            {
            j=lin[i]*4; i++;
            p[k].a[0]=pnt[j]; j++;
            p[k].a[1]=pnt[j]; j++;
            p[k].a[2]=pnt[j]; j++;
            p[k].a[3]=pnt[j]; j++;
            // transform
            rep.l2g(p[k],p[k]);
            // perspective projection
            if (focal_length>0.0)
                {
                p[k][3]-=w_near;
                if (p[k][3]>=0.0) p[k]*=divide(focal_length,p[k][3]+focal_length); else p[k].zero();
                }
            // render
            glVertex3dv(p[k].a);    // use just x,y,z
            }
        }
    glEnd();
    }
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------
</code>```

And the preview for cross section render:

The worst part was to define the hypercube as set of simplexes ...

Body:
For starters I would use 4D -> 3D projection instead of cut by hyperplane. The result is not the same but will get you closer to your goal (so you can latter upgrade this to cut). So similarly like in 3D -> 2D conversions used in graphics you got 2 choices one is using perspective projection and second is just ignoring the 4th dimension coordinate while rendering. I will use the latter as it is simpler.

structures

To make this as simple as I can I will use wire-frame instead of BR rendering. So you need to handle 4D mesh (wire-frame). I would use 2 tables:

double pnt[];   // 4D point list (x,y,z,u)
int  lin[];     // lines point indexes (i0,i1)

first one stores all the vertexes of your mesh and the second hold index pairs of points connected by lines in wire-frame representation.

transforms

If I would only ignore the 4th coordinate then we would not get the desired functionality. So to make the 4th dimension work we need to add 4D transform to orient our mesh in 4D before rendering. So use homogenous transform matrix and lets call ir rep. In 4D it should be 5x5 orthonormal matrix with 4x4 rotation part rot.

To make this even easier avoid smooth rotations for now (as in 4D that is not as easy) and compute random rotation 4x4 matrix instead. So just set all the cells randomly <-1,+1>. Handle each row as basis vector. To make them orthonormal just make them unit and exploit cross product. For more info see:

How to generate a randomly oriented, high dimension circle in python?

render

simply convert point table by your transform matrix

(x',y',z',u',W) = rep * (x,y,z,u,1)

then take the (x,y,z`) and render ...

Here simple OpenGL/C++ example of 4D hyper cube:

//---------------------------------------------------------------------------
//--- Mesh 4D: ver 0.000 ----------------------------------------------------
//---------------------------------------------------------------------------
#ifndef _mesh4D_h
#define _mesh4D_h
//---------------------------------------------------------------------------
#include <math.h>
#include "nd_math.h"
#include "list.h"
//---------------------------------------------------------------------------
const double pi   =    M_PI;
const double pi2  =2.0*M_PI;
const double pipol=0.5*M_PI;
const double deg=M_PI/180.0;
const double rad=180.0/M_PI;
//---------------------------------------------------------------------------
class mesh4D
    {
public:
    matrix<5> rep;  // 4D uniform 5x5 transform matrix

    List<double> pnt;   // 4D point list (x,y,z,u)
    List<int>    lin;   // lines point indexes (i0,i1)

    mesh4D()    {}
    mesh4D(mesh4D& a)   { *this=a; }
    ~mesh4D()   {}
    mesh4D* operator = (const mesh4D *a) { *this=*a; return this; }
    //mesh4D* operator = (const mesh4D &a) { ...copy... return this; }

    void set_randomrep();               // random oriented uniform 4D transform matrix with origin (0,0,0,0)
    void set_hypercube(double a);

    void draw();
    };
//---------------------------------------------------------------------------
void mesh4D::set_randomrep()
    {
    int i,j;
    matrix<4> rot;
    rep.unit();
    rot.rnd();
    rot.orthonormal();
    for (i=0;i<4;i++)
     for (j=0;j<4;j++)
      rep[i][j]=rot[i][j];
    }
void mesh4D::set_hypercube(double a)
    {
    rep.unit(); // reset orientation
    pnt.num=0;  // clear point list
    lin.num=0;  // clear line list

    pnt.add(-a); pnt.add(-a); pnt.add(-a); pnt.add(-a);
    pnt.add(+a); pnt.add(-a); pnt.add(-a); pnt.add(-a);
    pnt.add(-a); pnt.add(+a); pnt.add(-a); pnt.add(-a);
    pnt.add(+a); pnt.add(+a); pnt.add(-a); pnt.add(-a);
    pnt.add(-a); pnt.add(-a); pnt.add(+a); pnt.add(-a);
    pnt.add(+a); pnt.add(-a); pnt.add(+a); pnt.add(-a);
    pnt.add(-a); pnt.add(+a); pnt.add(+a); pnt.add(-a);
    pnt.add(+a); pnt.add(+a); pnt.add(+a); pnt.add(-a);

    pnt.add(-a); pnt.add(-a); pnt.add(-a); pnt.add(+a);
    pnt.add(+a); pnt.add(-a); pnt.add(-a); pnt.add(+a);
    pnt.add(-a); pnt.add(+a); pnt.add(-a); pnt.add(+a);
    pnt.add(+a); pnt.add(+a); pnt.add(-a); pnt.add(+a);
    pnt.add(-a); pnt.add(-a); pnt.add(+a); pnt.add(+a);
    pnt.add(+a); pnt.add(-a); pnt.add(+a); pnt.add(+a);
    pnt.add(-a); pnt.add(+a); pnt.add(+a); pnt.add(+a);
    pnt.add(+a); pnt.add(+a); pnt.add(+a); pnt.add(+a);

    // A0
    lin.add( 0+0); lin.add( 0+1);
    lin.add( 0+1); lin.add( 0+3);
    lin.add( 0+3); lin.add( 0+2);
    lin.add( 0+2); lin.add( 0+0);
    // A1
    lin.add( 4+0); lin.add( 4+1);
    lin.add( 4+1); lin.add( 4+3);
    lin.add( 4+3); lin.add( 4+2);
    lin.add( 4+2); lin.add( 4+0);
    // A=A0+A1
    lin.add( 0+0); lin.add( 4+0);
    lin.add( 0+1); lin.add( 4+1);
    lin.add( 0+2); lin.add( 4+2);
    lin.add( 0+3); lin.add( 4+3);

    // B0
    lin.add( 8+0); lin.add( 8+1);
    lin.add( 8+1); lin.add( 8+3);
    lin.add( 8+3); lin.add( 8+2);
    lin.add( 8+2); lin.add( 8+0);
    // B1
    lin.add(12+0); lin.add(12+1);
    lin.add(12+1); lin.add(12+3);
    lin.add(12+3); lin.add(12+2);
    lin.add(12+2); lin.add(12+0);
    // B=B0+B1
    lin.add( 8+0); lin.add(12+0);
    lin.add( 8+1); lin.add(12+1);
    lin.add( 8+2); lin.add(12+2);
    lin.add( 8+3); lin.add(12+3);

    // hyper cube = A+B
    lin.add( 0+0); lin.add( 8+0);
    lin.add( 0+1); lin.add( 8+1);
    lin.add( 0+2); lin.add( 8+2);
    lin.add( 0+3); lin.add( 8+3);
    lin.add( 0+4); lin.add( 8+4);
    lin.add( 0+5); lin.add( 8+5);
    lin.add( 0+6); lin.add( 8+6);
    lin.add( 0+7); lin.add( 8+7);
    }
//---------------------------------------------------------------------------
void mesh4D::draw()
    {
    int i,j;
    double _zero=1e-3;
    vector<5> a,b;
    glBegin(GL_LINES);
    for (i=0;i<lin.num;)
        {
        // extrac first point
        j=lin[i]*4; i++;
        a.a[0]=pnt[j]; j++;
        a.a[1]=pnt[j]; j++;
        a.a[2]=pnt[j]; j++;
        a.a[3]=pnt[j]; j++;
        a.a[4]=1.0; // W=1
        // extrac second point
        j=lin[i]*4; i++;
        b.a[0]=pnt[j]; j++;
        b.a[1]=pnt[j]; j++;
        b.a[2]=pnt[j]; j++;
        b.a[3]=pnt[j]; j++;
        b.a[4]=1.0; // W=1
        // transform
        a=rep*a;
        b=rep*b;
        // render
        glVertex3dv(a.a);   // use just x,y,z
        glVertex3dv(b.a);   // use just x,y,z
        }
    glEnd();
    }
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

I used mine dynamic list.h template so:

List<double> xxx; is the same as double xxx[];

xxx.add(5); adds 5 to end of the list

xxx[7] access array element (safe)

xxx.dat[7] access array element (unsafe but fast direct access)

xxx.num is the actual used size of the array

xxx.reset() clears the array and set xxx.num=0

xxx.allocate(100) preallocate space for 100 items

the nd_math.h is mine lib for N-Dimensional computations. What you need is just 4D,5D vector and 4x4, 5x5 matrix math from linear algebra.

Both libs are a bit big in size and also legal issues prevent me to share their code here.

The usage is simple:

// globals and init
mesh4D mesh
double animx=-50.0,danimx=0.0;
double animy=  0.0,danimy=2.0;
mesh.set_hypercube(0.5);

// render
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D( -2.0, 2.0, -2.0, 2.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotated(animx,1.0,0.0,0.0);
glRotated(animy,0.0,1.0,0.0);
mesh.draw();
glFlush();
SwapBuffers(hdc);

// some timer
animx+=danimx; if (animx>=360.0) animx-=360.0;
animy+=danimy; if (animy>=360.0) animy-=360.0;
call_render_here();

// on key press or mouse wheel or what ever
mesh.set_randomrep();

And here preview for some rep rotations ...

so this way you can render any wire-frame mesh (even BR rendering should works this way).

If you want to upgrade to the cut then you should take each Wire-frame line and compute its intersection with cutting hyperplane. If we chose hyperplane that goes through point

O(0,0,0,u_cut)

and has normal

N(0,0,0,1)

Then the task will simplify a lot. there are 3 options. Lets consider edge line with endpoints A,B:

no intersection

((A.u > u_cut)&&(B.u > u_cut)) || ((A.u < u_cut)&&(B.u < u_cut))

just ignore such edge

1 intersection

((A.u >= u_cut)&&(B.u <= u_cut)) || ((A.u <= u_cut)&&(B.u >= u_cut))

so compute the intersection via linear interpolation

x = A.x + (B.x-A.x)*(u_cut-A.u)/(B.u-A.u)
y = A.y + (B.y-A.y)*(u_cut-A.u)/(B.u-A.u)
z = A.z + (B.z-A.z)*(u_cut-A.u)/(B.u-A.u)

and remember such point and also edge to which it belongs to.

fully inside

(A.u == u_cut)&&(B.u == u_cut)

just remember both endpoints and also render this edge.

After all edges are processed this way then you need to analyze the remembered intersection points and create new edges from them based on connectivity info between edges. I did not do this yet so I can not help with this. I would try to connect remembered points sharing the same neighbor but not sure if that is enough in 4D.

For more info take a look at related QAs I found or answer:

Visualising 4D objects in OpenGL

4D to 3D perspective projection

4D rotations

ND vector and square matrix math template

reper4D

configurable ND rendering engine + hyperspiral

[Edit1] code with perspective

//---------------------------------------------------------------------------
//--- Mesh 4D: ver 0.001 ----------------------------------------------------
//---------------------------------------------------------------------------
#ifndef _mesh4D_h
#define _mesh4D_h
//---------------------------------------------------------------------------
#include <math.h>
#include "nd_math.h"
#include "list.h"
//---------------------------------------------------------------------------
const double pi   =    M_PI;
const double pi2  =2.0*M_PI;
const double pipol=0.5*M_PI;
const double deg=M_PI/180.0;
const double rad=180.0/M_PI;
//---------------------------------------------------------------------------
class mesh4D
    {
public:
    matrix<5> rep;  // 4D uniform 5x5 transform matrix

    List<double> pnt;   // 4D point list (x,y,z,u)
    List<int>    lin;   // lines point indexes (i0,i1)

    mesh4D()    {}
    mesh4D(mesh4D& a)   { *this=a; }
    ~mesh4D()   {}
    mesh4D* operator = (const mesh4D *a) { *this=*a; return this; }
    //mesh4D* operator = (const mesh4D &a) { ...copy... return this; }

    void set_randomrep();               // random oriented uniform 4D transform matrix with origin (0,0,0,0)
    void set_hypercube(double a);

    void draw();
    };
//---------------------------------------------------------------------------
void mesh4D::set_randomrep()
    {
    int i,j;
    matrix<4> rot;
    rot.rnd();
    rot.orthonormal();
    for (i=0;i<4;i++)
     for (j=0;j<4;j++)
      rep[i][j]=rot[i][j];
    }
//---------------------------------------------------------------------------
void mesh4D::set_hypercube(double a)
    {
    rep.unit();     // reset orientation
    rep[0][4]=0.0;  // set position
    rep[1][4]=0.0;
    rep[2][4]=0.0;
    rep[3][4]=3.0*a;
    pnt.num=0;  // clear point list
    lin.num=0;  // clear line list

    pnt.add(-a); pnt.add(-a); pnt.add(-a); pnt.add(-a);
    pnt.add(+a); pnt.add(-a); pnt.add(-a); pnt.add(-a);
    pnt.add(-a); pnt.add(+a); pnt.add(-a); pnt.add(-a);
    pnt.add(+a); pnt.add(+a); pnt.add(-a); pnt.add(-a);
    pnt.add(-a); pnt.add(-a); pnt.add(+a); pnt.add(-a);
    pnt.add(+a); pnt.add(-a); pnt.add(+a); pnt.add(-a);
    pnt.add(-a); pnt.add(+a); pnt.add(+a); pnt.add(-a);
    pnt.add(+a); pnt.add(+a); pnt.add(+a); pnt.add(-a);

    pnt.add(-a); pnt.add(-a); pnt.add(-a); pnt.add(+a);
    pnt.add(+a); pnt.add(-a); pnt.add(-a); pnt.add(+a);
    pnt.add(-a); pnt.add(+a); pnt.add(-a); pnt.add(+a);
    pnt.add(+a); pnt.add(+a); pnt.add(-a); pnt.add(+a);
    pnt.add(-a); pnt.add(-a); pnt.add(+a); pnt.add(+a);
    pnt.add(+a); pnt.add(-a); pnt.add(+a); pnt.add(+a);
    pnt.add(-a); pnt.add(+a); pnt.add(+a); pnt.add(+a);
    pnt.add(+a); pnt.add(+a); pnt.add(+a); pnt.add(+a);

    // A0
    lin.add( 0+0); lin.add( 0+1);
    lin.add( 0+1); lin.add( 0+3);
    lin.add( 0+3); lin.add( 0+2);
    lin.add( 0+2); lin.add( 0+0);
    // A1
    lin.add( 4+0); lin.add( 4+1);
    lin.add( 4+1); lin.add( 4+3);
    lin.add( 4+3); lin.add( 4+2);
    lin.add( 4+2); lin.add( 4+0);
    // A=A0+A1
    lin.add( 0+0); lin.add( 4+0);
    lin.add( 0+1); lin.add( 4+1);
    lin.add( 0+2); lin.add( 4+2);
    lin.add( 0+3); lin.add( 4+3);

    // B0
    lin.add( 8+0); lin.add( 8+1);
    lin.add( 8+1); lin.add( 8+3);
    lin.add( 8+3); lin.add( 8+2);
    lin.add( 8+2); lin.add( 8+0);
    // B1
    lin.add(12+0); lin.add(12+1);
    lin.add(12+1); lin.add(12+3);
    lin.add(12+3); lin.add(12+2);
    lin.add(12+2); lin.add(12+0);
    // B=B0+B1
    lin.add( 8+0); lin.add(12+0);
    lin.add( 8+1); lin.add(12+1);
    lin.add( 8+2); lin.add(12+2);
    lin.add( 8+3); lin.add(12+3);

    // hyper cube = A+B
    lin.add( 0+0); lin.add( 8+0);
    lin.add( 0+1); lin.add( 8+1);
    lin.add( 0+2); lin.add( 8+2);
    lin.add( 0+3); lin.add( 8+3);
    lin.add( 0+4); lin.add( 8+4);
    lin.add( 0+5); lin.add( 8+5);
    lin.add( 0+6); lin.add( 8+6);
    lin.add( 0+7); lin.add( 8+7);
    }
//---------------------------------------------------------------------------
void mesh4D::draw()
    {
    int i,j;
    const double _zero=1e-3;
    double focal_length=1.0;

    vector<5> a,b;
    glBegin(GL_LINES);
    for (i=0;i<lin.num;)
        {
        // extrac first point
        j=lin[i]*4; i++;
        a.a[0]=pnt[j]; j++;
        a.a[1]=pnt[j]; j++;
        a.a[2]=pnt[j]; j++;
        a.a[3]=pnt[j]; j++;
        a.a[4]=1.0; // W=1
        // extrac second point
        j=lin[i]*4; i++;
        b.a[0]=pnt[j]; j++;
        b.a[1]=pnt[j]; j++;
        b.a[2]=pnt[j]; j++;
        b.a[3]=pnt[j]; j++;
        b.a[4]=1.0; // W=1
        // transform
        a=rep*a;
        b=rep*b;
        // perspective: camera projection plane u=0, focus at (0,0,0,-focal_length)
        if (a[3]>=0.0) a*=divide(focal_length,a[3]+focal_length); else a.zero();
        if (b[3]>=0.0) b*=divide(focal_length,b[3]+focal_length); else b.zero();
        // render
        glVertex3dv(a.a);   // use just x,y,z
        glVertex3dv(b.a);   // use just x,y,z
        }
    glEnd();
    }
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

And preview:

[Edit2] solid mesh and cross-section

so I changed the architecture quite a bit. I moved the 4D 5x5 homogenuous transform matrix (reper4D) to separate file and added colors and mesh definition by 4D simplexes (4 point 4 side tetrahedrons). The cut is simply computing the intersection (as described above) of simplex and cutting hyperplane resulting in either 3 points (triangle) , 4 points (tetrahedron) or 0 points. Which can be rendered easily (no need to analyze the connections between edges). For more info see this:

Calculate 3D cross section of 4D shape (tesseract)

Btw. I think this is how Miegakure works. Here updated code:

//---------------------------------------------------------------------------
//--- Mesh 4D: ver 1.000 ----------------------------------------------------
//---------------------------------------------------------------------------
#ifndef _mesh4D_h
#define _mesh4D_h
//---------------------------------------------------------------------------
#include "list.h"
#include "reper4D.h"
//---------------------------------------------------------------------------
class mesh4D
    {
public:
    reper4D rep;        // 4D uniform 5x5 transform matrix

    List<double> pnt;   // 4D point list (x,y,z,w)
    List<int>    lin;   // 4D wireframe (i0,i1)
    List<int>    fac;   // 4D simplexes (i0,i1,i2,i3)
    List<DWORD>  col;   // simplex colors (RGB)

    mesh4D()    {}
    mesh4D(mesh4D& a)   { *this=a; }
    ~mesh4D()   {}
    mesh4D* operator = (const mesh4D *a) { *this=*a; return this; }
    //mesh4D* operator = (const mesh4D &a) { ...copy... return this; }

    void set_hypercube(double a);
    void draw_cut(double w_cut);                                        // render cross section by w=w_cut hyperplane
    void draw          (double focal_length=-1.0,double w_near=-1.0);   // render mesh      (focal_length<0) -> no perspective, else perspective view in W+ direction
    void draw_wireframe(double focal_length=-1.0,double w_near=-1.0);   // render wireframe (focal_length<0) -> no perspective, else perspective view in W+ direction
    };
//---------------------------------------------------------------------------
void mesh4D::set_hypercube(double a)
    {
    const double tab_pnt[]=
        {
        -a, -a, -a, -a,
        +a, -a, -a, -a,
        -a, +a, -a, -a,
        +a, +a, -a, -a,
        -a, -a, +a, -a,
        +a, -a, +a, -a,
        -a, +a, +a, -a,
        +a, +a, +a, -a,
        -a, -a, -a, +a,
        +a, -a, -a, +a,
        -a, +a, -a, +a,
        +a, +a, -a, +a,
        -a, -a, +a, +a,
        +a, -a, +a, +a,
        -a, +a, +a, +a,
        +a, +a, +a, +a,
        };
    const int tab_lin[]=
        {
        // A0
         0+0,  0+1,
         0+1,  0+3,
         0+3,  0+2,
         0+2,  0+0,
        // A1
         4+0,  4+1,
         4+1,  4+3,
         4+3,  4+2,
         4+2,  4+0,
        // A=A0+A1
         0+0,  4+0,
         0+1,  4+1,
         0+2,  4+2,
         0+3,  4+3,
        // B0
         8+0,  8+1,
         8+1,  8+3,
         8+3,  8+2,
         8+2,  8+0,
        // B1
        12+0, 12+1,
        12+1, 12+3,
        12+3, 12+2,
        12+2, 12+0,
        // B=B0+B1
         8+0, 12+0,
         8+1, 12+1,
         8+2, 12+2,
         8+3, 12+3,
        // hyper cube = A+B
         0+0,  8+0,
         0+1,  8+1,
         0+2,  8+2,
         0+3,  8+3,
         0+4,  8+4,
         0+5,  8+5,
         0+6,  8+6,
         0+7,  8+7,
        };
    // 5x simplex per cube
    #define _cube(a0,a1,a2,a3,a4,a5,a6,a7) a1,a2,a4,a7, a0,a1,a2,a4, a2,a4,a6,a7, a1,a2,a3,a7, a1,a4,a5,a7
    // 4D hypercube = 8 cubes
    const int tab_fac[]=
        {
        _cube( 0, 1, 2, 3, 4, 5, 6, 7),
        _cube( 0, 1, 2, 3, 8, 9,10,11),
        _cube( 4, 5, 6, 7,12,13,14,15),
        _cube( 8, 9,10,11,12,13,14,15),
        _cube( 0, 1, 4, 5, 8, 9,12,13),
        _cube( 0, 2, 4, 6, 8,10,12,14),
        _cube( 1, 3, 5, 7, 9,11,13,15),
        _cube( 2, 3, 6, 7,10,11,14,15),
        };
    #undef _cube
    const DWORD tab_col[]=
        {
        //  BBGGRR,    BBGGRR,    BBGGRR,    BBGGRR,    BBGGRR,
        0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000,0x00FF0000,
        0x0000FF00,0x0000FF00,0x0000FF00,0x0000FF00,0x0000FF00,
        0x000000FF,0x000000FF,0x000000FF,0x000000FF,0x000000FF,
        0x0000FFFF,0x0000FFFF,0x0000FFFF,0x0000FFFF,0x0000FFFF,
        0x00FF00FF,0x00FF00FF,0x00FF00FF,0x00FF00FF,0x00FF00FF,
        0x00FFFF00,0x00FFFF00,0x00FFFF00,0x00FFFF00,0x00FFFF00,
        0x00FFFFFF,0x00FFFFFF,0x00FFFFFF,0x00FFFFFF,0x00FFFFFF,
        0x004080FF,0x004080FF,0x004080FF,0x004080FF,0x004080FF,
        };

    int i,n;
    vector<4> p;
    rep.reset();
    pnt.num=0; for (i=0,n=sizeof(tab_pnt)/sizeof(tab_pnt[0]);i<n;i++) pnt.add(tab_pnt[i]);
    lin.num=0; for (i=0,n=sizeof(tab_lin)/sizeof(tab_lin[0]);i<n;i++) lin.add(tab_lin[i]);
    fac.num=0; for (i=0,n=sizeof(tab_fac)/sizeof(tab_fac[0]);i<n;i++) fac.add(tab_fac[i]);
    col.num=0; for (i=0,n=sizeof(tab_col)/sizeof(tab_col[0]);i<n;i++) col.add(tab_col[i]);
    }
//---------------------------------------------------------------------------
void mesh4D::draw_cut(double w_cut)
    {
    const double _zero=1e-6;
    const int edge2[]={0,1,0,2,0,3,1,2,2,3,3,1,-1}; // simplex wireframe i0,i1
    const int edge3[]={0,1,2,3,0,1,3,1,2,3,2,0,-1}; // simplex triangles i0,i1,i2
    int e,i,j,k,k0,k1,k2,inside[4];
    DWORD rgb;
    vector<4> p[4],q[4];
    vector<3> xyz[4],nor,a,b;
    for (i=0;i<fac.num;)
        {
        rgb=col[i>>2];
        // extrac points (x,y,z,w)
        for (k=0;k<4;k++)
            {
            j=fac[i]*4; i++;
            p[k].a[0]=pnt[j]; j++;
            p[k].a[1]=pnt[j]; j++;
            p[k].a[2]=pnt[j]; j++;
            p[k].a[3]=pnt[j]; j++;
            // transform
            rep.l2g(p[k],p[k]);
            inside[k]=1;
            }
        // process edge2 and compute cross section cut intersection points
        for (e=0,k=0;edge2[e]>=0;)
            {
            k0=edge2[e]; e++;
            k1=edge2[e]; e++;
            // fully inside
            if (fabs(p[k0][3]-w_cut)+fabs(p[k1][3]-w_cut)<=_zero)
                {
                if ((k<4)&&(inside[k0])){ q[k]=p[k0]; k++; inside[k0]=0; }
                if ((k<4)&&(inside[k1])){ q[k]=p[k1]; k++; inside[k1]=0; }
                continue;
                }
            // no intersection
            if (((p[k0][3]> w_cut)&&(p[k1][3]> w_cut))||((p[k0][3]< w_cut)&&(p[k1][3]< w_cut))) continue;
            // 1 intersection
            if (k<4)
                {
                q[k]=p[k1]-p[k0];
                q[k]*=divide(w_cut-p[k0][3],p[k1][3]-p[k0][3]);
                q[k]+=p[k0];
                q[k][3]=w_cut;
                k++;
                continue;
                }
            }
        // 4D -> 3D vector
        for (k0=0;k0<k;k0++) for (k1=0;k1<3;k1++) xyz[k0][k1]=q[k0][k1];
        // render triangle
        if (k==3)
            {
            // normal
            a=xyz[1]-xyz[0];
            b=xyz[2]-xyz[1];
            nor.cross(a,b);
            nor.unit();
            // render
            glBegin(GL_TRIANGLES);
            glNormal3dv(nor.a);
            glColor4ubv((BYTE*)(&rgb));
            glVertex3dv(xyz[0].a);
            glVertex3dv(xyz[1].a);
            glVertex3dv(xyz[2].a);
            glEnd();
            }
        // render simplex
        if (k==4)
         for (e=0;edge3[e]>=0;)
            {
            k0=edge3[e]; e++;
            k1=edge3[e]; e++;
            k2=edge3[e]; e++;
            // normal
            a=xyz[k1]-xyz[k0];
            b=xyz[k2]-xyz[k1];
            nor.cross(a,b);
            nor.unit();
            // render
            glBegin(GL_TRIANGLES);
            glNormal3dv(nor.a);
            glColor4ubv((BYTE*)(&rgb));
            glVertex3dv(xyz[k0].a);
            glVertex3dv(xyz[k1].a);
            glVertex3dv(xyz[k2].a);
            glEnd();
            }
        }
    }
//---------------------------------------------------------------------------
void mesh4D::draw(double focal_length,double w_near)
    {
    const int edge3[]={0,1,2,3,0,1,3,1,2,3,2,0,-1}; // simplex triangles i0,i1,i2
    int i,j,k,k0,k1,k2;
    DWORD rgb;
    vector<4> p;
    vector<3> xyz[4],nor,a,b;

    // 4D simplexes
    glColor3f(0.3,0.3,0.3);
    for (i=0;i<fac.num;)
        {
        rgb=col[i>>2];
        // extrac points (x,y,z,w)
        for (k=0;k<4;k++)
            {
            j=fac[i]*4; i++;
            p[0]=pnt[j]; j++;
            p[1]=pnt[j]; j++;
            p[2]=pnt[j]; j++;
            p[3]=pnt[j]; j++;
            // transform
            rep.l2g(p,p);
            // perspective projection
            if (focal_length>0.0)
                {
                p[3]-=w_near;
                if (p[3]>=0.0) p*=divide(focal_length,p[3]+focal_length); else p.zero();
                }
            // 4D -> 3D vector
            xyz[k].ld(p[0],p[1],p[2]);
            }
        // render simplex
        for (k=0;edge3[k]>=0;)
            {
            k0=edge3[k]; k++;
            k1=edge3[k]; k++;
            k2=edge3[k]; k++;
            // normal
            a=xyz[k1]-xyz[k0];
            b=xyz[k2]-xyz[k1];
            nor.cross(a,b);
            nor.unit();
            // render
//          glBegin(GL_LINE_LOOP);
            glBegin(GL_TRIANGLES);
            glNormal3dv(nor.a);
            glColor4ubv((BYTE*)(&rgb));
            glVertex3dv(xyz[k0].a);
            glVertex3dv(xyz[k1].a);
            glVertex3dv(xyz[k2].a);
            glEnd();
            }
        }
    }
//---------------------------------------------------------------------------
void mesh4D::draw_wireframe(double focal_length,double w_near)
    {
    int i,j,k;
    vector<4> p[4];
    // 4D wireframe
    glColor3f(1.0,1.0,1.0);
    glBegin(GL_LINES);
    for (i=0;i<lin.num;)
        {
        // extrac points (x,y,z,w)
        for (k=0;k<2;k++)
            {
            j=lin[i]*4; i++;
            p[k].a[0]=pnt[j]; j++;
            p[k].a[1]=pnt[j]; j++;
            p[k].a[2]=pnt[j]; j++;
            p[k].a[3]=pnt[j]; j++;
            // transform
            rep.l2g(p[k],p[k]);
            // perspective projection
            if (focal_length>0.0)
                {
                p[k][3]-=w_near;
                if (p[k][3]>=0.0) p[k]*=divide(focal_length,p[k][3]+focal_length); else p[k].zero();
                }
            // render
            glVertex3dv(p[k].a);    // use just x,y,z
            }
        }
    glEnd();
    }
//---------------------------------------------------------------------------
#endif
//---------------------------------------------------------------------------

And the preview for cross section render:

The worst part was to define the hypercube as set of simplexes ...


问:
How to influence to another component in React (add dynamically child)
I'm new in React, please help.

I have three components   <Square / >, <Line / >, <Cell />.

And I have next structure <Cell /> in <Line / > - <Line / > in  <Square / >

In component <Square / > I have a button and onClick in it.

When I click Button, One more <Cell /> component should be added to <Line / > Component.

How can I do it?

Sorry if it is simple, I just learning.
Thanks

Bellow is my code

class Cell extends React.Component {
 render() {
  return (

  );
 }
}

class Line extends React.Component {
 render() {
  return (

    <Cell />

  )
 }
}

class Square extends React.Component {
 render() {
  return (

      <Line />

    <button className="square__button square__button_append square__button_col-append"
      onClick={()=>{alert(1)}}>
    </button>

  );
 }
}

ReactDOM.render(
  <Square />,
  document.getElementsByTagName('div')[0]
);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div /></code>```

答:
You want the common ancestor of your components to hold some state defining the cells (in the snippet below I use simple strings.). The state is then mutated by that component alone, by giving callbacks to its children if necessary. Please note that I construct an entirely new list on each setState, and don't just change the state object. This is a core concept in React and you should feel comfortable with it before you try more complex things.

Then you want your components to render the children that you give them and/or be able to render a list. Here I decided to put it all in Square, but it would probably be better to give the list to <Line>to render. In my snippet, Line is entirely unnecessary.

class Cell extends React.Component {
  render() {
    return (

{this.props.children}

    );
  }
}

class Line extends React.Component {
  render() {
    return (
{this.props.children}
 )
  }
}

class Square extends React.Component {
  constructor(props){
    super();
    this.state = {cells : []}
  }
  addCell(){
    let oldCells = this.state.cells,
        cells = oldCells.concat(["cell-" + oldCells.length]);
    this.setState({cells});
  }
  render() {
    return (

          <Line>
            {this.state.cells.map(
              (cellName) =>{return <Cell>{cellName}</Cell>;}
            )}
          </Line>

      <button className = "square__button square__button_append square__button_col-append"
      onClick = {() =>this.addCell()} >add a cell</button>

    );
  }
}

ReactDOM.render( <
  Square / > ,
  document.getElementsByTagName('div')[0]
);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.square {
  background-color: #EEE;
}</code>```

```

Body:
You want the common ancestor of your components to hold some state defining the cells (in the snippet below I use simple strings.). The state is then mutated by that component alone, by giving callbacks to its children if necessary. Please note that I construct an entirely new list on each setState, and don't just change the state object. This is a core concept in React and you should feel comfortable with it before you try more complex things.

Then you want your components to render the children that you give them and/or be able to render a list. Here I decided to put it all in Square, but it would probably be better to give the list to <Line>to render. In my snippet, Line is entirely unnecessary.

class Cell extends React.Component {
  render() {
    return ( <td>
      <div className = "square__cell" >{this.props.children}</div> </td>
    );
  }
}

class Line extends React.Component {
  render() {
    return ( <tr>{this.props.children}</tr> )
  }
}

class Square extends React.Component {
  constructor(props){
    super();
    this.state = {cells : []}
  }
  addCell(){
    let oldCells = this.state.cells,
        cells = oldCells.concat(["cell-" + oldCells.length]);
    this.setState({cells});
  }
  render() {
    return (
    <div className = "square" >
      <table className = "square__table" >
        <tbody >
          <Line>
            {this.state.cells.map(
              (cellName) =>{return <Cell>{cellName}</Cell>;}
            )}
          </Line>
        </tbody>
      </table>

      <button className = "square__button square__button_append square__button_col-append"
      onClick = {() =>this.addCell()} >add a cell</button>
      </div>
    );
  }
}

ReactDOM.render( <
  Square / > ,
  document.getElementsByTagName('div')[0]
);

.square {
  background-color: #EEE;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div />


问:
variables not populated with desired values
I am trying to make a 'cueent weather application'.
For this, in my jQuery code snippet, I use 2 variables by the name of 'latitude' & 'longitude'.
When I populate them with my current location's latitude & longitude respectively, it happens so quite efficiently, as reflected in my alert popup (the one inside the 'if' statement).
However, outside of this 'if' statement, the variables no longer retain their values, as shown in the 2nd alert popup.

```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  background-color : black;
}

.jumbotron {
  background-color : black;
  color : white;
}</code>```

Current Weather</hi>

```

Following is my code ..

https://codepen.io/iamrkcheers/pen/KqxyVZ

Any help is appreciated. Thank You.

答:
That is because the call to getCurrentPosition() is asynchronous where it passes the result to the position parameter in the function given as its own parameter. The alert() on the outside executes before the one on the inside, i.e.,  before the values are populated, the outer alert is executed with empty values.

Try for promise function using .then(alert()) for the outer alert.

Body:
I am trying to make a 'cueent weather application'.
For this, in my jQuery code snippet, I use 2 variables by the name of 'latitude' & 'longitude'.
When I populate them with my current location's latitude & longitude respectively, it happens so quite efficiently, as reflected in my alert popup (the one inside the 'if' statement).
However, outside of this 'if' statement, the variables no longer retain their values, as shown in the 2nd alert popup.

body {
  background-color : black;
}

.jumbotron {
  background-color : black;
  color : white;
}

Current Weather</hi>

Following is my code ..

https://codepen.io/iamrkcheers/pen/KqxyVZ

Any help is appreciated. Thank You.


问:
hash index vs elastic search
I'm new with MySQL and elasticsearch. I have been confused betweeen something called hash index versus elasticsearch. For example, if I have an "user" table, how can I find an user from specified email? I have thought about 2 resolution.
1. Using hash index: created new column like "email_hash" and create a hash index on this column and query base on this new column.
2. Just using elasticsearch.

I have been confused what resolution I should use? Or can I take both of them for better query performance? Any help is very appreciate. Thanks a lot.

答: Elastic search internally is an index but with lot more capabilities. If you just want a simple search where in you send the email and get the user back then just go with mysql. If you have much more requirements like find words in singular/plural forms or stemmed words. Its advised to use elastic search.</p>

Title: hash index vs elastic search


问:
add path to access folders in HTML files
I would like to add some shortcuts in HTML file, the objective is to have a file where I click on links to access to different Windows directory, for example I would like to access to this folder, and I tried to add a link in HTML but it doesn't work  (my folder path is : S:\software\public software\2-RPR\model\list of files</p>

```<code><a href="/">S:\software\public software\2-RPR\model>list of files</a>`  in an HTML file ?
</code>```

答:
for the record - please state clear questions and do some research before asking.

what you're asking is possible, but why would you? if someone else opens the html from their computer the links won't work any more.

to answer your question - use A tags:
Link text

of course it depends on your use case but this is NOT a good idea to do in your case

Body:
I would like to add some shortcuts in HTML file, the objective is to have a file where I click on links to access to different Windows directory, for example I would like to access to this folder, and I tried to add a link in HTML but it doesn't work  (my folder path is : S:\software\public software\2-RPR\model\list of files

S:\software\public software\2-RPR\model>list of files`  in an HTML file ?

Body:
for the record - please state clear questions and do some research before asking.

what you're asking is possible, but why would you? if someone else opens the html from their computer the links won't work any more.

to answer your question - use A tags:
<a href="/path/to/file/some_file_on_computer.pdf">Link text</a>

of course it depends on your use case but this is NOT a good idea to do in your case


问:
How to check if columns in dataframe are identical in R [produce matrix]
I have a large dataframe ncol =220 I want to compare the columns to see  if they may be identical and produce a matrix for ease of identification.

So what I have is

```<code>      x    y   z
1   dog   dog   cat
2   dog   dog   dog
3   cat   cat   cat
</code>```

What I want

```<code>     x     y     z
x   -     True   False
y   True     -   False
z   False False   -
</code>```

Is there a way to do this using identical() in R?

答:
Probably not very efficient but you can try:

```<code>seq_col <- seq_len(ncol(df))
sapply(seq_col, function(i) sapply(seq_col, function(j) identical(df[, i], df[, j])))
      # [,1]  [,2]  [,3]
# [1,]  TRUE  TRUE FALSE
# [2,]  TRUE  TRUE FALSE
# [3,] FALSE FALSE  TRUE
</code>```

It gives you what you want (except for the diagonal, which is all TRUE here) but there must be a package with a function to create a distance matrix based on character vectors. Maybe something with stringdist ?

Body:
I have a large dataframe ncol =220 I want to compare the columns to see  if they may be identical and produce a matrix for ease of identification.

So what I have is

      x    y   z
1   dog   dog   cat
2   dog   dog   dog
3   cat   cat   cat

What I want

     x     y     z
x   -     True   False
y   True     -   False
z   False False   -

Is there a way to do this using identical() in R?

Body:
Probably not very efficient but you can try:

seq_col <- seq_len(ncol(df))
sapply(seq_col, function(i) sapply(seq_col, function(j) identical(df[, i], df[, j])))
      # [,1]  [,2]  [,3]
# [1,]  TRUE  TRUE FALSE
# [2,]  TRUE  TRUE FALSE
# [3,] FALSE FALSE  TRUE

It gives you what you want (except for the diagonal, which is all TRUE here) but there must be a package with a function to create a distance matrix based on character vectors. Maybe something with stringdist ?


问:
Center div with equal margins. Margin-bottom not working with height 100vh?
No matter what I try to do, I can't get my div to have equal margins all the way around.

I assume margin-bottom/padding-bottom doesn't work when you set the height to 100vh or 100%?

I need it to be responsive so px values are no use here.

I've created a fiddle: https://jsfiddle.net/uLmkyqpf/

Code:

HTML:

```<code> <div class="mySec header">
   <div class="info">
      <ul id="headList">
        <li>
            <a data-section="top-left" id="link" href="#">ABOUT</a>
        </li>
        <li>
            <a data-section="getInvolved" id="link" href="#">CLASSES</a>
        </li>
          <li>
            <a data-section="footer" id="link" href="#">CONTACT</a>
        </li>
      </ul>
        <h1 class="title">Niki Gibbs Modern Pilates</h1>
        <p class="title2">Working From The Inside Out.</p>
        <img id="pilLogo" src="pilatesLog.png">
    </div>
</div>
</code>```

CSS:

```<code>body {
 margin: 0;
 padding: 0;
 font-family: 'Josefin Sans', sans-serif;
 background-color: #EFEFEF;
 text-align: center;
 overflow: hidden;
 height: 100%;
 width: 100%;
}
.mySec {
  position: relative;
  height: 100%;
  margin-right: 4%;
  margin-left: 4%;
  margin-top: 4%;
  padding-bottom: 4%;
  overflow: hidden;
}
.header {
    background: red; /* For browsers that do not support gradients */
    background: -webkit-linear-gradient(#FFC0CB, #9370DB); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(#FFC0CB, #9370DB ); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(#FFC0CB, #9370DB); /* For Firefox 3.6 to 15 */
}
#headList {
  list-style: none;
  font-family: 'Josefin Sans', sans-serif;
  position: relative;
  left: -1vw;
}
#headList li {
    display: inline;
}
#headList li a {
    color: #000;
    font-size: 1.4vw;
    padding: 2vw;
    text-decoration: none;
    letter-spacing: 2px;
    font-weight: 200;
}
.title {
  font-family: 'Amatic SC', cursive;
  font-size:8vw;
  position: relative;
  bottom: 8.3vh;
  color: #000;
}

.title2 {
  color: #000;
  position: relative;
  font-size: 2vw;
  bottom: 14vh;
}
#pilLogo {
    position: relative;
    left: 25vw;
    bottom: 41vh;
}
.info {
    position: relative;
    top: 25vh;
}
</code>```

答:
Using this previous SO answer as a reference, I modified your fiddle to keep an even margin around the whole box. I did this specifically by setting the height and width smaller than the viewport and then translating the box to the middle of the screen:

```<code>.mySec {
  display: block;
  position: relative;
  height: calc(95vh);
  width: calc(96vw - 1vh);
  transform: translate(calc((4vw + 1vh) / 2), 2.5vh);
  overflow: hidden;
}
</code>```

Here's a snippet for easy viewing:

body {
  margin: 0;
  padding: 0;
  font-family: 'Josefin Sans', sans-serif;
  background-color: #EFEFEF;
  text-align: center;
  overflow: hidden;
  height: 100%;
  width: 100%;
}

.mySec {
  display: block;
  position: relative;
  height: calc(95vh);
  width: calc(96vw - 1vh);
  transform: translate(calc((4vw + 1vh) / 2), 2.5vh);
  overflow: hidden;
}

.header {
  background: red;
  /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(#FFC0CB, #9370DB);
  /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(#FFC0CB, #9370DB);
  /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(#FFC0CB, #9370DB);
  /* For Firefox 3.6 to 15 */
}

#headList {
  list-style: none;
  font-family: 'Josefin Sans', sans-serif;
  position: relative;
  left: -1vw;
}

#headList li {
  display: inline;
}

#headList li a {
  color: #000;
  font-size: 1.4vw;
  padding: 2vw;
  text-decoration: none;
  letter-spacing: 2px;
  font-weight: 200;
}

.title {
  font-family: 'Amatic SC', cursive;
  font-size: 8vw;
  position: relative;
  bottom: 8.3vh;
  color: #000;
}

.title2 {
  color: #000;
  position: relative;
  font-size: 2vw;
  bottom: 14vh;
}

#pilLogo {
  position: relative;
  left: 25vw;
  bottom: 41vh;
}

.info {
  position: relative;
  top: 25vh;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="mySec header">
  <div class="info">
    <ul id="headList">
      <li>
        ABOUT
      </li>
      <li>
        CLASSES
      </li>
      <li>
        CONTACT
      </li>
    </ul>
    <h1 class="title">Niki Gibbs Modern Pilates</h1>
    <p class="title2">Working From The Inside Out.</p>
    <img id="pilLogo" src="pilatesLog.png">
  </div>
</div></code>```

Body:
No matter what I try to do, I can't get my div to have equal margins all the way around.

I assume margin-bottom/padding-bottom doesn't work when you set the height to 100vh or 100%?

I need it to be responsive so px values are no use here.

I've created a fiddle: https://jsfiddle.net/uLmkyqpf/

Code:

HTML:

            ABOUT

            CLASSES

            CONTACT

Niki Gibbs Modern Pilates

Working From The Inside Out.

CSS:

body {
 margin: 0;
 padding: 0;
 font-family: 'Josefin Sans', sans-serif;
 background-color: #EFEFEF;
 text-align: center;
 overflow: hidden;
 height: 100%;
 width: 100%;
}
.mySec {
  position: relative;
  height: 100%;
  margin-right: 4%;
  margin-left: 4%;
  margin-top: 4%;
  padding-bottom: 4%;
  overflow: hidden;
}
.header {
    background: red; /* For browsers that do not support gradients */
    background: -webkit-linear-gradient(#FFC0CB, #9370DB); /* For Safari 5.1 to 6.0 */
    background: -o-linear-gradient(#FFC0CB, #9370DB ); /* For Opera 11.1 to 12.0 */
    background: -moz-linear-gradient(#FFC0CB, #9370DB); /* For Firefox 3.6 to 15 */
}
#headList {
  list-style: none;
  font-family: 'Josefin Sans', sans-serif;
  position: relative;
  left: -1vw;
}
#headList li {
    display: inline;
}
#headList li a {
    color: #000;
    font-size: 1.4vw;
    padding: 2vw;
    text-decoration: none;
    letter-spacing: 2px;
    font-weight: 200;
}
.title {
  font-family: 'Amatic SC', cursive;
  font-size:8vw;
  position: relative;
  bottom: 8.3vh;
  color: #000;
}

.title2 {
  color: #000;
  position: relative;
  font-size: 2vw;
  bottom: 14vh;
}
#pilLogo {
    position: relative;
    left: 25vw;
    bottom: 41vh;
}
.info {
    position: relative;
    top: 25vh;
}

Body:
Using this previous SO answer as a reference, I modified your fiddle to keep an even margin around the whole box. I did this specifically by setting the height and width smaller than the viewport and then translating the box to the middle of the screen:

.mySec {
  display: block;
  position: relative;
  height: calc(95vh);
  width: calc(96vw - 1vh);
  transform: translate(calc((4vw + 1vh) / 2), 2.5vh);
  overflow: hidden;
}

Here's a snippet for easy viewing:

body {
  margin: 0;
  padding: 0;
  font-family: 'Josefin Sans', sans-serif;
  background-color: #EFEFEF;
  text-align: center;
  overflow: hidden;
  height: 100%;
  width: 100%;
}

.mySec {
  display: block;
  position: relative;
  height: calc(95vh);
  width: calc(96vw - 1vh);
  transform: translate(calc((4vw + 1vh) / 2), 2.5vh);
  overflow: hidden;
}

.header {
  background: red;
  /* For browsers that do not support gradients */
  background: -webkit-linear-gradient(#FFC0CB, #9370DB);
  /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(#FFC0CB, #9370DB);
  /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(#FFC0CB, #9370DB);
  /* For Firefox 3.6 to 15 */
}

#headList {
  list-style: none;
  font-family: 'Josefin Sans', sans-serif;
  position: relative;
  left: -1vw;
}

#headList li {
  display: inline;
}

#headList li a {
  color: #000;
  font-size: 1.4vw;
  padding: 2vw;
  text-decoration: none;
  letter-spacing: 2px;
  font-weight: 200;
}

.title {
  font-family: 'Amatic SC', cursive;
  font-size: 8vw;
  position: relative;
  bottom: 8.3vh;
  color: #000;
}

.title2 {
  color: #000;
  position: relative;
  font-size: 2vw;
  bottom: 14vh;
}

#pilLogo {
  position: relative;
  left: 25vw;
  bottom: 41vh;
}

.info {
  position: relative;
  top: 25vh;
}

<div class="mySec header">
  <div class="info">
    <ul id="headList">
      <li>
        <a data-section="top-left" id="link" href="#">ABOUT</a>
      </li>
      <li>
        <a data-section="getInvolved" id="link" href="#">CLASSES</a>
      </li>
      <li>
        <a data-section="footer" id="link" href="#">CONTACT</a>
      </li>
    </ul>
    <h1 class="title">Niki Gibbs Modern Pilates</h1>
    <p class="title2">Working From The Inside Out.</p>
    <img id="pilLogo" src="pilatesLog.png">
  </div>
</div>


问:
how to call ngDialog.open in unit tests using Jasmine
I am using Jasmine/Karma for unit testing and new to these frameworks.In contrller i am using ngDialog for model displaying and i want unit test cases for controller calling ngDialog.
Controller:

(function () {
    'use strict';
    angular.module('app')
      .controller('myController', MyController);

    CongratulationsController.$inject = ['$scope',
                                         '$rootScope',
                                         'ngDialog'];

    function CongratulationsController($scope, $rootScope, ngDialog) {

      $scope.myData = {name: 'test',
                      grade: '5'};

      $scope.modal1 = function() {
        ngDialog.open({ template: 'views/modal/modal-1html',
          className: 'ngdialog-theme-default',
          controller: 'ModalController',
          scope: $scope});
      };
      $scope.modal2 = function() {
        ngDialog.open({ template: 'views/modal/modal-2html',
          className: 'ngdialog-theme-default',
          controller: 'ModalController',
          scope: $scope});
      };
    }
}());
```

<p>Here is my <strong>Unit test</strong> :</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>'use strict';

describe('Controller: MyController', function () {
  var MyController,location, scope, ngDialogInstance;
  ngDialogInstance = {
    open: jasmine.createSpy('ngDialogInstance.open'),
    dismiss: jasmine.createSpy('modalInstance.dismiss')
  };
    // load the controller's module
    beforeEach(module('app'));
    // Initialize the controller and a mock scope
    beforeEach(inject(function ($controller, $location, $rootScope, _ngDialog_) {
      scope = $rootScope.$new();
        MyController= $controller('myController', {$scope: scope ,
          _ngDialog_: ngDialogInstance
          });
        location = $location;
        spyOn(scope, 'openModal1');
    }));
    it('test controller exists', function () {
        expect(!!MyController).toBe(true);
    });

  it('test controller calls ng dialog when it calls openModel method', function () {
    scope.openModal1();
    expect(scope.openModal1).toHaveBeenCalled();
    expect(ngDialogInstance.open).toHaveBeenCalled();
  });
});</code>```

when i am running aboove test case, getting below error.
its failing at  Expected spy ngDialogInstance.open to have been called.

can any one help me with this.

答:
This should be,

```<code>it('test controller calls ng dialog when it calls openModel method', function () {
    ngDialogInstance.open();
    scope.openModal1();
    expect(scope.openModal1).toHaveBeenCalled();
    expect(ngDialogInstance.open).toHaveBeenCalled();
});
</code>```

You have to include below line:

```<code>ngDialogInstance.open();
</code>```

Body:
I am using Jasmine/Karma for unit testing and new to these frameworks.In contrller i am using ngDialog for model displaying and i want unit test cases for controller calling ngDialog.
Controller:

(function () {
    'use strict';
    angular.module('app')
      .controller('myController', MyController);

    CongratulationsController.$inject = ['$scope',
                                         '$rootScope',
                                         'ngDialog'];

    function CongratulationsController($scope, $rootScope, ngDialog) {

      $scope.myData = {name: 'test',
                      grade: '5'};

      $scope.modal1 = function() {
        ngDialog.open({ template: 'views/modal/modal-1html',
          className: 'ngdialog-theme-default',
          controller: 'ModalController',
          scope: $scope});
      };
      $scope.modal2 = function() {
        ngDialog.open({ template: 'views/modal/modal-2html',
          className: 'ngdialog-theme-default',
          controller: 'ModalController',
          scope: $scope});
      };
    }
}());

Here is my Unit test :

'use strict';

describe('Controller: MyController', function () {
  var MyController,location, scope, ngDialogInstance;
  ngDialogInstance = {
    open: jasmine.createSpy('ngDialogInstance.open'),
    dismiss: jasmine.createSpy('modalInstance.dismiss')
  };
    // load the controller's module
    beforeEach(module('app'));
    // Initialize the controller and a mock scope
    beforeEach(inject(function ($controller, $location, $rootScope, _ngDialog_) {
      scope = $rootScope.$new();
        MyController= $controller('myController', {$scope: scope ,
          _ngDialog_: ngDialogInstance
          });
        location = $location;
        spyOn(scope, 'openModal1');
    }));
    it('test controller exists', function () {
        expect(!!MyController).toBe(true);
    });

  it('test controller calls ng dialog when it calls openModel method', function () {
    scope.openModal1();
    expect(scope.openModal1).toHaveBeenCalled();
    expect(ngDialogInstance.open).toHaveBeenCalled();
  });
});

when i am running aboove test case, getting below error.
its failing at  Expected spy ngDialogInstance.open to have been called.

can any one help me with this.

Body:
This should be,

it('test controller calls ng dialog when it calls openModel method', function () {
    ngDialogInstance.open();
    scope.openModal1();
    expect(scope.openModal1).toHaveBeenCalled();
    expect(ngDialogInstance.open).toHaveBeenCalled();
});

You have to include below line:

ngDialogInstance.open();


问:
Force child element visible outside an overflow:hidden parent
Only solution I found was to put a position: fixed on element I want to fully see. Any other options? (I dont want to 'cool-image' fixed). Help or hint would be awesome. Also, if anyone can explain solution - that would be even better

Fiddle: JSFiddle

HTML

```<code><div class="img-cont">
  <div id="slider">
    <ul>
      <li class="slide">
        <img src="http://www.sportspearl.com/wp-content/uploads/2017/05/football-150x150.png" >
        <div class="cool-image"></div>
      </li>
    </ul>
  </div>
</div>
</code>```

CSS

```<code>.img-cont{
    height: 270px;
    position: relative;
}
#slider {
    position: relative;
    background: green;
    overflow: hidden;
    width: 440px;
    height: 200px;
}
#slider ul{
    position: relative;
    margin: 0;
    padding: 0;
}
#slider ul li {
    position: relative;
    display: block;
    float: left;
    margin: 0;
    padding: 0;
    width: 440px;
    height: 270px;
    text-align: center;
    line-height: 300px;
}
div.cool-image{
    background-color: white;
    position: absolute;
    border: 5px solid #EEEEEE;
    width: 650px;
    height: 350px;
    z-index: 1;
    display: inline-block;
    background-repeat: no-repeat;
    background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Basketball.png/170px-Basketball.png);
    margin-left: -40px; /* Just to product situation */

    display: inline-block;
}
</code>```

答:
Unfortunately, you can't. The child element is only capable of changing within the parents region when the position is not set to fixed or absolute.

If you don't want to make the child fixed, you could try position:absolute; and set the parent to position: relative;

Like this...

```<code>.slide img {
  position: absolute;
  z-index: 2;
}
.slide {
  position: relative;
}
</code>```

Or you could try to only hide the overflow on 1 direction. Like overflow-y:hidden; Or overflow-x: hidden;

Body:
Only solution I found was to put a position: fixed on element I want to fully see. Any other options? (I dont want to 'cool-image' fixed). Help or hint would be awesome. Also, if anyone can explain solution - that would be even better

Fiddle: JSFiddle

HTML

CSS

.img-cont{
    height: 270px;
    position: relative;
}
#slider {
    position: relative;
    background: green;
    overflow: hidden;
    width: 440px;
    height: 200px;
}
#slider ul{
    position: relative;
    margin: 0;
    padding: 0;
}
#slider ul li {
    position: relative;
    display: block;
    float: left;
    margin: 0;
    padding: 0;
    width: 440px;
    height: 270px;
    text-align: center;
    line-height: 300px;
}
div.cool-image{
    background-color: white;
    position: absolute;
    border: 5px solid #EEEEEE;
    width: 650px;
    height: 350px;
    z-index: 1;
    display: inline-block;
    background-repeat: no-repeat;
    background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Basketball.png/170px-Basketball.png);
    margin-left: -40px; /* Just to product situation */

    display: inline-block;
}

Body:
Unfortunately, you can't. The child element is only capable of changing within the parents region when the position is not set to fixed or absolute.

If you don't want to make the child fixed, you could try position:absolute; and set the parent to position: relative;

Like this...

.slide img {
  position: absolute;
  z-index: 2;
}
.slide {
  position: relative;
}

Or you could try to only hide the overflow on 1 direction. Like overflow-y:hidden; Or overflow-x: hidden;


Title: How to convert values of a matrix into percentage without changing the format in R

Body:
I have a matrix which is res

 > res
                     [,1]         [,2]       [,3]       [,4]       [,5]
        [1,]  0.025431667  0.024636307 0.02812685 0.02733088 0.02807624
        [2,] -0.005383589  0.000000000 0.02807624 0.02258878 0.02322090
        [3,] -0.002674251 -0.002674251 0.05502400 0.00000000 0.01385476
        [4,]  0.055024000  0.061028259 0.05932779 0.05956794 0.05839394
        [5,]  0.059327790  0.059567938 0.05839394 0.06048811 0.05944368

I want to have the results as percentage and keep the data structure unchanged.

When I try something like percent(res) from scales I get a vector instead of a matrix

> percent(res)
 [1] "2.54%"  "-0.54%" "-0.27%" "5.50%"  "5.93%"  "2.46%"  "0.00%"  "-0.27%"
 [9] "6.10%"  "5.96%"  "2.81%"  "2.81%"  "5.50%"  "5.93%"  "5.84%"  "2.73%"
[17] "2.26%"  "0.00%"  "5.96%"  "6.05%"  "2.81%"  "2.32%"  "1.39%"  "5.84%"
[25] "5.94%"

Any suggestions?

Body:
You could do:

require(scales)
set.seed(1) # Just for reproducibility
res <- matrix(data = rnorm(20), nrow = 5, ncol = 4)

 > res
           [,1]       [,2]       [,3]        [,4]
[1,] -0.6264538 -0.8204684  1.5117812 -0.04493361
[2,]  0.1836433  0.4874291  0.3898432 -0.01619026
[3,] -0.8356286  0.7383247 -0.6212406  0.94383621
[4,]  1.5952808  0.5757814 -2.2146999  0.82122120
[5,]  0.3295078 -0.3053884  1.1249309  0.59390132

res[] <- percent(res)

> res
     [,1]   [,2]   [,3]    [,4]
[1,] "-63%" "-82%" "151%"  "-4%"
[2,] "18%"  "49%"  "39%"   "-2%"
[3,] "-84%" "74%"  "-62%"  "94%"
[4,] "160%" "58%"  "-221%" "82%"
[5,] "33%"  "-31%" "112%"  "59%"


问:
Is there a character in Excel to mask a STRING using TEXT function?
Is there a character to mask STRING values within the Excel TEXT function?

Attempting to use a mask of "0000-000000-00000-0000" seems to convert a string to a number.  I simply want to add hyphens in between a specific number of characters.

I have also tried "@@@@-@@@@@@-@@@@@-@@@@" and "####-######-#####-####" but to no avail.

Background:

In a previous question, it was determined that a particular custom number mask could not be applied to a string because of the 15 significant digit limitation in Excel.

The goal was to convert a TEXT value of 5145350002005000080 to 5145-350002-00500-0080 using the following formula:

```<code>=text(A1,"0000-000000-00000-0000")
</code>```

The output produced was:

5145-350002-00500-0000

答:
Select the cells->Press Ctrl+1->from Number Tab of Format Cells Dialog select "custom"  and paste in Type edit box Below.

"Boxes";"Boxes";"Boxes";"Boxes"

Source: Here

Body:
Is there a character to mask STRING values within the Excel TEXT function?

Attempting to use a mask of "0000-000000-00000-0000" seems to convert a string to a number.  I simply want to add hyphens in between a specific number of characters.

I have also tried "@@@@-@@@@@@-@@@@@-@@@@" and "####-######-#####-####" but to no avail.

Background:

In a previous question, it was determined that a particular custom number mask could not be applied to a string because of the 15 significant digit limitation in Excel.

The goal was to convert a TEXT value of 5145350002005000080 to 5145-350002-00500-0080 using the following formula:

=text(A1,"0000-000000-00000-0000")

The output produced was:

5145-350002-00500-0000


问:
How can I look in one worksheet and copy and paste into another workbook based off criteria from another worksheet?
Good Morning.

I have a workbook with multiple worksheets in it. Lets say worksheet A & B

In worksheet B I have multiple supplier columns some of them have X's in them and some of them don't

What I would like to know how to do is to be if there is an "X" present in the column then look to the leftmost Column (A) and look for that part number in Worksheet A.

When it finds the part number in Worksheet A, I would like to copy all of the rows and columns associated with it and paste it into a brand new workbook.

Typically the part number is showing on multiple rows let's say rows 1-6 and the information I'd like to copy spans across multiple columns Let's say to Column "T".

答:
Your question is not to clear.
Assuming that you mean you have one workbook with a worksheet named A and a worksheet named B, the algorithm you describe is something like this:

```<code>Sub Test()
Dim wb as Workbook
Dim wsA as Worksheet
Dim wsB as Worksheet
Dim suppliersRange as Range
Dim xRange as Range
Dim searchValue as string
Dim foundRange as Range

'The two worksheets in the initial book:
Set wsA = ThisWorkbook.Worksheets("A")
Set wsB = ThisWorkbook.Worksheets("B")

'The supplier column to search:
Set suppliersRange = wsB.Range("D:D") 'let's assume it column D for now.

Set xRange = suppliersRange.Find("X") 'Find "X"

If not xRange is nothing then
    searchValue = wsB.Range("A" & xRange.Row).value 'Get the value from column A to do the next search
End If

Set foundRange = wsA.UsedRange.Find(searchValue) 'Search for this number that we got with the previous step.

If not foundRange is nothing then 'If it's found
    Set wb = Workbooks.Add 'Create a new workbook
    wsA.UsedRange.Copy wb.Worksheets(1).Range("A1") 'And copy Sheet A in there
End If

Set foundRange = Nothing
Set xRange = Nothing
Set suppliersRange = Nothing
Set wsA = Nothing
Set wsB = Nothing
Set wb = Nothing

End Sub
</code>```

Note that since you do not specify what you mean with "multiple rows for a part" and/or what columns, etc. - I just copy the entire sheet contents. Of course you can filter out the actual range to copy, but this code for sure does the searches for you, creates the new workbook and copy-pastes from your Sheet A.

Body:
Your question is not to clear.
Assuming that you mean you have one workbook with a worksheet named A and a worksheet named B, the algorithm you describe is something like this:

Sub Test()
Dim wb as Workbook
Dim wsA as Worksheet
Dim wsB as Worksheet
Dim suppliersRange as Range
Dim xRange as Range
Dim searchValue as string
Dim foundRange as Range

'The two worksheets in the initial book:
Set wsA = ThisWorkbook.Worksheets("A")
Set wsB = ThisWorkbook.Worksheets("B")

'The supplier column to search:
Set suppliersRange = wsB.Range("D:D") 'let's assume it column D for now.

Set xRange = suppliersRange.Find("X") 'Find "X"

If not xRange is nothing then
    searchValue = wsB.Range("A" & xRange.Row).value 'Get the value from column A to do the next search
End If

Set foundRange = wsA.UsedRange.Find(searchValue) 'Search for this number that we got with the previous step.

If not foundRange is nothing then 'If it's found
    Set wb = Workbooks.Add 'Create a new workbook
    wsA.UsedRange.Copy wb.Worksheets(1).Range("A1") 'And copy Sheet A in there
End If

Set foundRange = Nothing
Set xRange = Nothing
Set suppliersRange = Nothing
Set wsA = Nothing
Set wsB = Nothing
Set wb = Nothing

End Sub

Note that since you do not specify what you mean with "multiple rows for a part" and/or what columns, etc. - I just copy the entire sheet contents. Of course you can filter out the actual range to copy, but this code for sure does the searches for you, creates the new workbook and copy-pastes from your Sheet A.